Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/20/11 07:51:42 (13 years ago)
Author:
abeham
Message:

#1649

  • Added affinity-based move
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GeneralizedQAP/HeuristicLab.Problems.QuadraticAssignment/3.3/Tests/QAPMoveEvaluatorTest.cs

    r6685 r6801  
    8787    [TestMethod]
    8888    public void Swap2MoveEvaluatorFastEvaluationTest() {
    89 
    9089      for (int i = 0; i < 500; i++) {
    9190        Swap2Move lastMove = new Swap2Move(random.Next(ProblemSize), random.Next(ProblemSize));
     
    257256    }
    258257
     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
    259305  }
    260306}
Note: See TracChangeset for help on using the changeset viewer.