- Timestamp:
- 08/09/11 11:01:08 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GP.Grammar.Editor/HeuristicLab.Problems.QuadraticAssignment/3.3/Tests/QAPMoveEvaluatorTest.cs
r5933 r6647 60 60 for (int i = 0; i < ProblemSize - 1; i++) { 61 61 for (int j = i + 1; j < ProblemSize; j++) { 62 symmetricDistances[i, j] = random.Next(ProblemSize );62 symmetricDistances[i, j] = random.Next(ProblemSize * 100); 63 63 symmetricDistances[j, i] = symmetricDistances[i, j]; 64 symmetricWeights[i, j] = random.Next(ProblemSize );64 symmetricWeights[i, j] = random.Next(ProblemSize * 100); 65 65 symmetricWeights[j, i] = symmetricWeights[i, j]; 66 asymmetricDistances[i, j] = random.Next(ProblemSize );67 asymmetricDistances[j, i] = random.Next(ProblemSize );68 asymmetricWeights[i, j] = random.Next(ProblemSize );69 asymmetricWeights[j, i] = random.Next(ProblemSize );70 nonZeroDiagonalDistances[i, j] = random.Next(ProblemSize );71 nonZeroDiagonalDistances[j, i] = random.Next(ProblemSize );72 nonZeroDiagonalWeights[i, j] = random.Next(ProblemSize );73 nonZeroDiagonalWeights[j, i] = random.Next(ProblemSize );66 asymmetricDistances[i, j] = random.Next(ProblemSize * 100); 67 asymmetricDistances[j, i] = random.Next(ProblemSize * 100); 68 asymmetricWeights[i, j] = random.Next(ProblemSize * 100); 69 asymmetricWeights[j, i] = random.Next(ProblemSize * 100); 70 nonZeroDiagonalDistances[i, j] = random.Next(ProblemSize * 100); 71 nonZeroDiagonalDistances[j, i] = random.Next(ProblemSize * 100); 72 nonZeroDiagonalWeights[i, j] = random.Next(ProblemSize * 100); 73 nonZeroDiagonalWeights[j, i] = random.Next(ProblemSize * 100); 74 74 } 75 nonZeroDiagonalDistances[i, i] = random.Next(ProblemSize );76 nonZeroDiagonalWeights[i, i] = random.Next(ProblemSize );75 nonZeroDiagonalDistances[i, i] = random.Next(ProblemSize * 100); 76 nonZeroDiagonalWeights[i, i] = random.Next(ProblemSize * 100); 77 77 } 78 78 int index = random.Next(ProblemSize); 79 79 if (nonZeroDiagonalDistances[index, index] == 0) 80 nonZeroDiagonalDistances[index, index] = random.Next(1, ProblemSize );80 nonZeroDiagonalDistances[index, index] = random.Next(1, ProblemSize * 100); 81 81 index = random.Next(ProblemSize); 82 82 if (nonZeroDiagonalWeights[index, index] == 0) 83 nonZeroDiagonalWeights[index, index] = random.Next(1, ProblemSize );83 nonZeroDiagonalWeights[index, index] = random.Next(1, ProblemSize * 100); 84 84 assignment = new Permutation(PermutationTypes.Absolute, ProblemSize, random); 85 } 86 87 [TestMethod] 88 public void Swap2MoveEvaluatorFastEvaluationTest() { 89 90 for (int i = 0; i < 500; i++) { 91 Swap2Move lastMove = new Swap2Move(random.Next(ProblemSize), random.Next(ProblemSize)); 92 Permutation prevAssignment = (Permutation)assignment.Clone(); 93 Swap2Manipulator.Apply(assignment, lastMove.Index1, lastMove.Index2); 94 Permutation nextAssignment = (Permutation)assignment.Clone(); 95 Swap2Move currentMove = new Swap2Move(random.Next(ProblemSize), random.Next(ProblemSize)); 96 Swap2Manipulator.Apply(nextAssignment, currentMove.Index1, currentMove.Index2); 97 98 double moveBefore = QAPSwap2MoveEvaluator.Apply(prevAssignment, currentMove, symmetricWeights, symmetricDistances); 99 double moveAfter = QAPSwap2MoveEvaluator.Apply(assignment, currentMove, 100 moveBefore, symmetricWeights, symmetricDistances, lastMove); 101 double before = QAPEvaluator.Apply(assignment, symmetricWeights, symmetricDistances); 102 double after = QAPEvaluator.Apply(nextAssignment, symmetricWeights, symmetricDistances); 103 104 Assert.IsTrue(moveAfter.IsAlmost(after - before), "Failed on symmetric matrices: " + Environment.NewLine 105 + "Quality changed from " + before + " to " + after + " (" + (after - before).ToString() + "), but move quality change was " + moveAfter + "."); 106 107 moveBefore = QAPSwap2MoveEvaluator.Apply(prevAssignment, currentMove, asymmetricWeights, asymmetricDistances); 108 moveAfter = QAPSwap2MoveEvaluator.Apply(assignment, currentMove, 109 moveBefore, asymmetricWeights, asymmetricDistances, lastMove); 110 before = QAPEvaluator.Apply(assignment, asymmetricWeights, asymmetricDistances); 111 after = QAPEvaluator.Apply(nextAssignment, asymmetricWeights, asymmetricDistances); 112 113 Assert.IsTrue(moveAfter.IsAlmost(after - before), "Failed on asymmetric matrices: " + Environment.NewLine 114 + "Quality changed from " + before + " to " + after + " (" + (after - before).ToString() + "), but move quality change was " + moveAfter + "."); 115 116 moveBefore = QAPSwap2MoveEvaluator.Apply(prevAssignment, currentMove, nonZeroDiagonalWeights, nonZeroDiagonalDistances); 117 moveAfter = QAPSwap2MoveEvaluator.Apply(assignment, currentMove, 118 moveBefore, nonZeroDiagonalWeights, nonZeroDiagonalDistances, lastMove); 119 before = QAPEvaluator.Apply(assignment, nonZeroDiagonalWeights, nonZeroDiagonalDistances); 120 after = QAPEvaluator.Apply(nextAssignment, nonZeroDiagonalWeights, nonZeroDiagonalDistances); 121 122 Assert.IsTrue(moveAfter.IsAlmost(after - before), "Failed on non-zero diagonal matrices: " + Environment.NewLine 123 + "Quality changed from " + before + " to " + after + " (" + (after - before).ToString() + "), but move quality change was " + moveAfter + "."); 124 } 85 125 } 86 126
Note: See TracChangeset
for help on using the changeset viewer.