Changeset 12969 for branches/gteufl/HeuristicLab.Problems.TravelingSalesman/3.3/Improvers/TSPImprovementOperator.cs
- Timestamp:
- 09/25/15 14:39:59 (9 years ago)
- Location:
- branches/gteufl
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/gteufl
- Property svn:ignore
-
old new 8 8 FxCopResults.txt 9 9 Google.ProtocolBuffers-0.9.1.dll 10 Google.ProtocolBuffers-2.4.1.473.dll 10 11 HeuristicLab 3.3.5.1.ReSharper.user 11 12 HeuristicLab 3.3.6.0.ReSharper.user 12 13 HeuristicLab.4.5.resharper.user 13 14 HeuristicLab.ExtLibs.6.0.ReSharper.user 15 HeuristicLab.Scripting.Development 14 16 HeuristicLab.resharper.user 15 17 ProtoGen.exe … … 17 19 _ReSharper.HeuristicLab 18 20 _ReSharper.HeuristicLab 3.3 21 _ReSharper.HeuristicLab 3.3 Tests 19 22 _ReSharper.HeuristicLab.ExtLibs 20 23 bin 21 24 protoc.exe 22 _ReSharper.HeuristicLab 3.3 Tests 23 Google.ProtocolBuffers-2.4.1.473.dll 25 obj
-
- Property svn:mergeinfo changed
-
Property
svn:global-ignores
set to
*.nuget
packages
- Property svn:ignore
-
branches/gteufl/HeuristicLab.Problems.TravelingSalesman/3.3/Improvers/TSPImprovementOperator.cs
r9456 r12969 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 95 95 96 96 public override IOperation Apply() { 97 Permutation currSol= CurrentScope.Variables[SolutionParameter.ActualName].Value as Permutation;98 if ( currSol== null)97 var solution = CurrentScope.Variables[SolutionParameter.ActualName].Value as Permutation; 98 if (solution == null) 99 99 throw new ArgumentException("Cannot improve solution because it has the wrong type."); 100 if ( currSol.PermutationType != PermutationTypes.RelativeUndirected)100 if (solution.PermutationType != PermutationTypes.RelativeUndirected) 101 101 throw new ArgumentException("Cannot improve solution because the permutation type is not supported."); 102 102 103 103 for (int i = 0; i < ImprovementAttempts.Value; i++) { 104 int a = Random.Next(currSol.Length); 105 int b = Random.Next(currSol.Length); 106 double oldFirstEdgeLength = DistanceMatrix[currSol[a], currSol[(a - 1 + currSol.Length) % currSol.Length]]; 107 double oldSecondEdgeLength = DistanceMatrix[currSol[b], currSol[(b + 1) % currSol.Length]]; 108 double newFirstEdgeLength = DistanceMatrix[currSol[b], currSol[(a - 1 + currSol.Length) % currSol.Length]]; 109 double newSecondEdgeLength = DistanceMatrix[currSol[a], currSol[(b + 1 + currSol.Length) % currSol.Length]]; 110 if (newFirstEdgeLength + newSecondEdgeLength < oldFirstEdgeLength + oldSecondEdgeLength) 111 Invert(currSol, a, b); 104 var move = StochasticInversionSingleMoveGenerator.Apply(solution, Random); 105 double moveQualtiy = TSPInversionMovePathEvaluator.EvaluateByDistanceMatrix(solution, move, DistanceMatrix); 106 if (moveQualtiy < 0) 107 InversionManipulator.Apply(solution, move.Index1, move.Index2); 112 108 } 113 109 … … 116 112 return base.Apply(); 117 113 } 118 119 private void Invert(Permutation sol, int i, int j) {120 if (i != j)121 for (int a = 0; a < Math.Abs(i - j) / 2; a++)122 if (sol[(i + a) % sol.Length] != sol[(j - a + sol.Length) % sol.Length]) {123 // XOR swap124 sol[(i + a) % sol.Length] ^= sol[(j - a + sol.Length) % sol.Length];125 sol[(j - a + sol.Length) % sol.Length] ^= sol[(i + a) % sol.Length];126 sol[(i + a) % sol.Length] ^= sol[(j - a + sol.Length) % sol.Length];127 }128 }129 114 } 130 115 }
Note: See TracChangeset
for help on using the changeset viewer.