Changeset 6801 for branches/GeneralizedQAP/HeuristicLab.Problems.QuadraticAssignment/3.3/Tests/QAPMoveEvaluatorTest.cs
- Timestamp:
- 09/20/11 07:51:42 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GeneralizedQAP/HeuristicLab.Problems.QuadraticAssignment/3.3/Tests/QAPMoveEvaluatorTest.cs
r6685 r6801 87 87 [TestMethod] 88 88 public void Swap2MoveEvaluatorFastEvaluationTest() { 89 90 89 for (int i = 0; i < 500; i++) { 91 90 Swap2Move lastMove = new Swap2Move(random.Next(ProblemSize), random.Next(ProblemSize)); … … 257 256 } 258 257 258 [TestMethod] 259 public void AffinitySwapMoveEvaluatorTest() { 260 for (int i = 0; i < 500; i++) { 261 int index1, index2, index3, index4; 262 do { 263 index1 = random.Next(ProblemSize); 264 index2 = random.Next(ProblemSize); 265 index3 = random.Next(ProblemSize); 266 index4 = random.Next(ProblemSize); 267 } while (!(index1 != index2 && index1 != index3 && index1 != index4 && index2 != index3 && index2 != index4 && index3 != index4)); 268 AffinitySwapMove affinityMove = new AffinitySwapMove(); 269 affinityMove.AddSwap(index1, index2); 270 affinityMove.AddSwap(index3, index4); 271 Assert.IsTrue(affinityMove.GetSwapLocation(index1) == index2 272 && affinityMove.GetSwapLocation(index2) == index1 273 && affinityMove.GetSwapLocation(index3) == index4 274 && affinityMove.GetSwapLocation(index4) == index3); 275 276 // SYMMETRIC MATRICES 277 double before = QAPEvaluator.Apply(assignment, symmetricWeights, symmetricDistances); 278 Permutation clone = (Permutation)assignment.Clone(); 279 Swap2Manipulator.Apply(assignment, index1, index2); 280 Swap2Manipulator.Apply(assignment, index3, index4); 281 double after = QAPEvaluator.Apply(assignment, symmetricWeights, symmetricDistances); 282 double move = AffinitySwapMoveEvaluator.Apply(clone, affinityMove, symmetricWeights, symmetricDistances); 283 Assert.IsTrue(move.IsAlmost(after - before), "Failed on symmetric matrices"); 284 285 // ASYMMETRIC MATRICES 286 before = QAPEvaluator.Apply(assignment, asymmetricWeights, asymmetricDistances); 287 clone = (Permutation)assignment.Clone(); 288 Swap2Manipulator.Apply(assignment, index1, index2); 289 Swap2Manipulator.Apply(assignment, index3, index4); 290 after = QAPEvaluator.Apply(assignment, asymmetricWeights, asymmetricDistances); 291 move = AffinitySwapMoveEvaluator.Apply(clone, affinityMove, asymmetricWeights, asymmetricDistances); 292 Assert.IsTrue(move.IsAlmost(after - before), "Failed on asymmetric matrices"); 293 294 // NON-ZERO DIAGONAL ASSYMETRIC MATRICES 295 before = QAPEvaluator.Apply(assignment, nonZeroDiagonalWeights, nonZeroDiagonalDistances); 296 clone = (Permutation)assignment.Clone(); 297 Swap2Manipulator.Apply(assignment, index1, index2); 298 Swap2Manipulator.Apply(assignment, index3, index4); 299 after = QAPEvaluator.Apply(assignment, nonZeroDiagonalWeights, nonZeroDiagonalDistances); 300 move = AffinitySwapMoveEvaluator.Apply(clone, affinityMove, nonZeroDiagonalWeights, nonZeroDiagonalDistances); 301 Assert.IsTrue(move.IsAlmost(after - before), "Failed on non-zero diagonal matrices"); 302 } 303 } 304 259 305 } 260 306 }
Note: See TracChangeset
for help on using the changeset viewer.