Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/02/12 19:09:48 (12 years ago)
Author:
jkarder
Message:

#1331:

  • added operators for TestFunctions problems
  • added more path relinking operators for the TravelingSalesman and the Knapsack problem
  • added 2-tier version of the SolutionPoolUpdateMethod
  • added parameters and adjusted types
  • added some exception handling
  • adjusted event handling
  • updated plugin dependencies
  • minor code improvements
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/TravelingSalesman/TravelingSalesmanImprovementOperator.cs

    r7756 r7775  
    138138
    139139      for (int i = 0; i < ImprovementAttempts.Value; i++) {
    140         int a = Random.Next(currSol.Length - 1);
    141         int b = Random.Next(currSol.Length - 1);
     140        int a = Random.Next(currSol.Length);
     141        int b = Random.Next(currSol.Length);
    142142        Invert(currSol, a, b);
    143143        currLength = TSPEuclideanPathEvaluator.Apply(Evaluator as TSPCoordinatesPathEvaluator, Coordinates, currSol);
    144144        if (currLength < bestLength) {
    145145          bestLength = currLength;
    146           bestSol = (Permutation)currSol.Clone();
     146          bestSol = currSol.Clone() as Permutation;
    147147        }
    148148        Invert(currSol, a, b);
     
    155155
    156156    private void Invert(Permutation sol, int i, int j) {
    157       if (i != j) {
    158         for (int a = 0; a < Math.Abs(i - j) / 2; a++) {
    159           int tmp = sol[(i + a) % sol.Length];
    160           sol[(i + a) % sol.Length] = sol[(j - a + sol.Length) % sol.Length];
    161           sol[(j - a + sol.Length) % sol.Length] = tmp;
    162         }
    163       }
     157      if (i != j)
     158        for (int a = 0; a < Math.Abs(i - j) / 2; a++)
     159          if (sol[(i + a) % sol.Length] != sol[(j - a + sol.Length) % sol.Length]) {
     160            // XOR swap
     161            sol[(i + a) % sol.Length] ^= sol[(j - a + sol.Length) % sol.Length];
     162            sol[(j - a + sol.Length) % sol.Length] ^= sol[(i + a) % sol.Length];
     163            sol[(i + a) % sol.Length] ^= sol[(j - a + sol.Length) % sol.Length];
     164          }
    164165    }
    165166  }
Note: See TracChangeset for help on using the changeset viewer.