Changeset 17321 for branches/2521_ProblemRefactoring
- Timestamp:
- 10/06/19 22:51:53 (5 years ago)
- Location:
- branches/2521_ProblemRefactoring/HeuristicLab.Tests
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab.Tests/HeuristicLab.Problems.QuadraticAssignment-3.3/QAPMoveEvaluatorTest.cs
r17226 r17321 21 21 22 22 using System; 23 using System.Threading; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Data; … … 113 114 double moveAfter = QAPSwap2MoveEvaluator.Apply(assignment, currentMove, 114 115 moveBefore, symmetricWeights, symmetricDistances, lastMove); 115 double before = symmetricProblem.Evaluate(assignment );116 double after = symmetricProblem.Evaluate(nextAssignment );116 double before = symmetricProblem.Evaluate(assignment, CancellationToken.None); 117 double after = symmetricProblem.Evaluate(nextAssignment, CancellationToken.None); 117 118 118 119 Assert.IsTrue(moveAfter.IsAlmost(after - before), "Failed on symmetric matrices: " + Environment.NewLine … … 122 123 moveAfter = QAPSwap2MoveEvaluator.Apply(assignment, currentMove, 123 124 moveBefore, asymmetricWeights, asymmetricDistances, lastMove); 124 before = asymmetricProblem.Evaluate(assignment );125 after = asymmetricProblem.Evaluate(nextAssignment );125 before = asymmetricProblem.Evaluate(assignment, CancellationToken.None); 126 after = asymmetricProblem.Evaluate(nextAssignment, CancellationToken.None); 126 127 127 128 Assert.IsTrue(moveAfter.IsAlmost(after - before), "Failed on asymmetric matrices: " + Environment.NewLine … … 131 132 moveAfter = QAPSwap2MoveEvaluator.Apply(assignment, currentMove, 132 133 moveBefore, nonZeroDiagonalWeights, nonZeroDiagonalDistances, lastMove); 133 before = nonZeroDiagonalProblem.Evaluate(assignment );134 after = nonZeroDiagonalProblem.Evaluate(nextAssignment );134 before = nonZeroDiagonalProblem.Evaluate(assignment, CancellationToken.None); 135 after = nonZeroDiagonalProblem.Evaluate(nextAssignment, CancellationToken.None); 135 136 136 137 Assert.IsTrue(moveAfter.IsAlmost(after - before), "Failed on non-zero diagonal matrices: " + Environment.NewLine … … 149 150 150 151 // SYMMETRIC MATRICES 151 double before = symmetricProblem.Evaluate(assignment );152 double before = symmetricProblem.Evaluate(assignment, CancellationToken.None); 152 153 Swap2Manipulator.Apply(assignment, index1, index2); 153 double after = symmetricProblem.Evaluate(assignment );154 double after = symmetricProblem.Evaluate(assignment, CancellationToken.None); 154 155 double move = QAPSwap2MoveEvaluator.Apply(assignment, new Swap2Move(index1, index2, assignment), symmetricWeights, symmetricDistances); 155 156 Assert.IsTrue(move.IsAlmost(before - after), "Failed on symmetric matrices"); 156 157 157 158 // ASYMMETRIC MATRICES 158 before = asymmetricProblem.Evaluate(assignment );159 before = asymmetricProblem.Evaluate(assignment, CancellationToken.None); 159 160 Permutation clone = (Permutation)assignment.Clone(); 160 161 Swap2Manipulator.Apply(assignment, index1, index2); 161 after = asymmetricProblem.Evaluate(assignment );162 after = asymmetricProblem.Evaluate(assignment, CancellationToken.None); 162 163 move = QAPSwap2MoveEvaluator.Apply(clone, new Swap2Move(index1, index2), asymmetricWeights, asymmetricDistances); 163 164 Assert.IsTrue(move.IsAlmost(after - before), "Failed on asymmetric matrices"); 164 165 165 166 // NON-ZERO DIAGONAL ASSYMETRIC MATRICES 166 before = nonZeroDiagonalProblem.Evaluate(assignment );167 before = nonZeroDiagonalProblem.Evaluate(assignment, CancellationToken.None); 167 168 clone = (Permutation)assignment.Clone(); 168 169 Swap2Manipulator.Apply(assignment, index1, index2); 169 after = nonZeroDiagonalProblem.Evaluate(assignment );170 after = nonZeroDiagonalProblem.Evaluate(assignment, CancellationToken.None); 170 171 move = QAPSwap2MoveEvaluator.Apply(clone, new Swap2Move(index1, index2), nonZeroDiagonalWeights, nonZeroDiagonalDistances); 171 172 Assert.IsTrue(move.IsAlmost(after - before), "Failed on non-zero diagonal matrices"); … … 183 184 184 185 // SYMMETRIC MATRICES 185 double before = symmetricProblem.Evaluate(assignment );186 double before = symmetricProblem.Evaluate(assignment, CancellationToken.None); 186 187 InversionManipulator.Apply(assignment, Math.Min(index1, index2), Math.Max(index1, index2)); 187 double after = symmetricProblem.Evaluate(assignment );188 double after = symmetricProblem.Evaluate(assignment, CancellationToken.None); 188 189 double move = QAPInversionMoveEvaluator.Apply(assignment, new InversionMove(index1, index2, assignment), symmetricWeights, symmetricDistances); 189 190 Assert.IsTrue(move.IsAlmost(before - after), "Failed on symmetric matrices"); 190 191 191 192 // ASYMMETRIC MATRICES 192 before = asymmetricProblem.Evaluate(assignment );193 before = asymmetricProblem.Evaluate(assignment, CancellationToken.None); 193 194 Permutation clone = (Permutation)assignment.Clone(); 194 195 InversionManipulator.Apply(assignment, index1, index2); 195 after = asymmetricProblem.Evaluate(assignment );196 after = asymmetricProblem.Evaluate(assignment, CancellationToken.None); 196 197 move = QAPInversionMoveEvaluator.Apply(clone, new InversionMove(index1, index2), asymmetricWeights, asymmetricDistances); 197 198 Assert.IsTrue(move.IsAlmost(after - before), "Failed on asymmetric matrices"); 198 199 199 200 // NON-ZERO DIAGONAL ASYMMETRIC MATRICES 200 before = nonZeroDiagonalProblem.Evaluate(assignment );201 before = nonZeroDiagonalProblem.Evaluate(assignment, CancellationToken.None); 201 202 clone = (Permutation)assignment.Clone(); 202 203 InversionManipulator.Apply(assignment, index1, index2); 203 after = nonZeroDiagonalProblem.Evaluate(assignment );204 after = nonZeroDiagonalProblem.Evaluate(assignment, CancellationToken.None); 204 205 move = QAPInversionMoveEvaluator.Apply(clone, new InversionMove(index1, index2), nonZeroDiagonalWeights, nonZeroDiagonalDistances); 205 206 Assert.IsTrue(move.IsAlmost(after - before), "Failed on non-zero diagonal matrices"); … … 222 223 223 224 // SYMMETRIC MATRICES 224 double before = symmetricProblem.Evaluate(assignment );225 double before = symmetricProblem.Evaluate(assignment, CancellationToken.None); 225 226 Permutation clone = new Cloner().Clone(assignment); 226 227 TranslocationManipulator.Apply(assignment, index1, index2, insertPoint); 227 double after = symmetricProblem.Evaluate(assignment );228 double after = symmetricProblem.Evaluate(assignment, CancellationToken.None); 228 229 double move = QAPTranslocationMoveEvaluator.Apply(clone, new TranslocationMove(index1, index2, insertPoint, assignment), symmetricWeights, symmetricDistances); 229 230 Assert.IsTrue(move.IsAlmost(after - before), "Failed on symmetric matrices"); 230 231 231 232 // ASYMMETRIC MATRICES 232 before = asymmetricProblem.Evaluate(assignment );233 before = asymmetricProblem.Evaluate(assignment, CancellationToken.None); 233 234 clone = new Cloner().Clone(assignment); 234 235 TranslocationManipulator.Apply(assignment, index1, index2, insertPoint); 235 after = asymmetricProblem.Evaluate(assignment );236 after = asymmetricProblem.Evaluate(assignment, CancellationToken.None); 236 237 move = QAPTranslocationMoveEvaluator.Apply(clone, new TranslocationMove(index1, index2, insertPoint, assignment), asymmetricWeights, asymmetricDistances); 237 238 Assert.IsTrue(move.IsAlmost(after - before), "Failed on asymmetric matrices"); 238 239 239 240 // NON-ZERO DIAGONAL ASYMMETRIC MATRICES 240 before = nonZeroDiagonalProblem.Evaluate(assignment );241 before = nonZeroDiagonalProblem.Evaluate(assignment, CancellationToken.None); 241 242 clone = new Cloner().Clone(assignment); 242 243 TranslocationManipulator.Apply(assignment, index1, index2, insertPoint); 243 after = nonZeroDiagonalProblem.Evaluate(assignment );244 after = nonZeroDiagonalProblem.Evaluate(assignment, CancellationToken.None); 244 245 move = QAPTranslocationMoveEvaluator.Apply(clone, new TranslocationMove(index1, index2, insertPoint, assignment), nonZeroDiagonalWeights, nonZeroDiagonalDistances); 245 246 Assert.IsTrue(move.IsAlmost(after - before), "Failed on non-zero diagonal matrices"); … … 255 256 256 257 // SYMMETRIC MATRICES 257 double before = symmetricProblem.Evaluate(assignment );258 double before = symmetricProblem.Evaluate(assignment, CancellationToken.None); 258 259 double move = QAPScrambleMoveEvaluator.Apply(assignment, scramble, symmetricWeights, symmetricDistances); 259 260 ScrambleManipulator.Apply(assignment, scramble.StartIndex, scramble.ScrambledIndices); 260 double after = symmetricProblem.Evaluate(assignment );261 double after = symmetricProblem.Evaluate(assignment, CancellationToken.None); 261 262 Assert.IsTrue(move.IsAlmost(after - before), "Failed on symmetric matrices"); 262 263 263 264 // ASYMMETRIC MATRICES 264 before = asymmetricProblem.Evaluate(assignment );265 before = asymmetricProblem.Evaluate(assignment, CancellationToken.None); 265 266 move = QAPScrambleMoveEvaluator.Apply(assignment, scramble, asymmetricWeights, asymmetricDistances); 266 267 ScrambleManipulator.Apply(assignment, scramble.StartIndex, scramble.ScrambledIndices); 267 after = asymmetricProblem.Evaluate(assignment );268 after = asymmetricProblem.Evaluate(assignment, CancellationToken.None); 268 269 Assert.IsTrue(move.IsAlmost(after - before), "Failed on asymmetric matrices"); 269 270 270 271 // NON-ZERO DIAGONAL ASYMMETRIC MATRICES 271 before = nonZeroDiagonalProblem.Evaluate(assignment );272 before = nonZeroDiagonalProblem.Evaluate(assignment, CancellationToken.None); 272 273 move = QAPScrambleMoveEvaluator.Apply(assignment, scramble, nonZeroDiagonalWeights, nonZeroDiagonalDistances); 273 274 ScrambleManipulator.Apply(assignment, scramble.StartIndex, scramble.ScrambledIndices); 274 after = nonZeroDiagonalProblem.Evaluate(assignment );275 after = nonZeroDiagonalProblem.Evaluate(assignment, CancellationToken.None); 275 276 Assert.IsTrue(move.IsAlmost(after - before), "Failed on non-zero diagonal matrices"); 276 277 } -
branches/2521_ProblemRefactoring/HeuristicLab.Tests/HeuristicLab.Scripting-3.3/Script Sources/GAQAPScriptSource.cs
r13408 r17321 1 1 using System; 2 2 using System.Linq; 3 3 using System.Threading; 4 4 using HeuristicLab.Analysis; 5 5 using HeuristicLab.Data; … … 42 42 for (int i = 0; i < popSize; i++) { 43 43 population[i] = new Permutation(PermutationTypes.Absolute, qap.Weights.Rows, random); 44 qualities[i] = qap.Evaluate(population[i] );44 qualities[i] = qap.Evaluate(population[i], CancellationToken.None); 45 45 } 46 46 var bestQuality = qualities.Min(); … … 52 52 nextGen[i] = PartiallyMatchedCrossover.Apply(random, parents[i * 2], parents[i * 2 + 1]); 53 53 if (random.NextDouble() < mutationRate) Swap2Manipulator.Apply(random, nextGen[i]); 54 nextQual[i] = qap.Evaluate(nextGen[i] );54 nextQual[i] = qap.Evaluate(nextGen[i], CancellationToken.None); 55 55 if (nextQual[i] < bestQuality) { 56 56 bestQuality = nextQual[i];
Note: See TracChangeset
for help on using the changeset viewer.