Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6801


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

#1649

  • Added affinity-based move
Location:
branches/GeneralizedQAP
Files:
6 added
5 edited

Legend:

Unmodified
Added
Removed
  • branches/GeneralizedQAP/HeuristicLab.Problems.QuadraticAssignment.Algorithms/3.3/Plugin.cs.frame

    r6628 r6801  
    2828  [PluginDependency("HeuristicLab.Collections", "3.3")]
    2929  [PluginDependency("HeuristicLab.Common", "3.3")]
    30   [PluginDependency("HeuristicLab.Common.Resources", "3.3")]
    3130  [PluginDependency("HeuristicLab.Core", "3.3")]
    3231  [PluginDependency("HeuristicLab.Data", "3.3")]
  • branches/GeneralizedQAP/HeuristicLab.Problems.QuadraticAssignment.Views/3.3/Plugin.cs.frame

    r6548 r6801  
    2626  [PluginFile("HeuristicLab.Problems.QuadraticAssignment.Views-3.3.dll", PluginFileType.Assembly)]
    2727  [PluginDependency("HeuristicLab.Analysis", "3.3")]
     28  [PluginDependency("HeuristicLab.Collections", "3.3")]
    2829  [PluginDependency("HeuristicLab.Common", "3.3")]
    2930  [PluginDependency("HeuristicLab.Common.Resources", "3.3")]
     
    3435  [PluginDependency("HeuristicLab.MainForm", "3.3")]
    3536  [PluginDependency("HeuristicLab.MainForm.WindowsForms", "3.3")]
     37  [PluginDependency("HeuristicLab.Optimization", "3.3")]
    3638  [PluginDependency("HeuristicLab.Problems.QuadraticAssignment", "3.3")]
    3739  public class HeuristicLabProblemsQuadraticAssignmentViewsPlugin : PluginBase {
  • branches/GeneralizedQAP/HeuristicLab.Problems.QuadraticAssignment/3.3/HeuristicLab.Problems.QuadraticAssignment-3.3.csproj

    r6733 r6801  
    111111    <Compile Include="Analyzers\QAPAlleleFrequencyAnalyzer.cs" />
    112112    <Compile Include="Analyzers\QAPPopulationDiversityAnalyzer.cs" />
     113    <Compile Include="Evaluators\AffinitySwapMoveEvaluator.cs" />
    113114    <Compile Include="Evaluators\QAPScrambleMoveEvaluator.cs" />
    114115    <Compile Include="Evaluators\QAPSwap2MoveEvaluator.cs" />
     
    119120      <SubType>Code</SubType>
    120121    </Compile>
     122    <Compile Include="Interfaces\IAffinitySwapMoveOperator.cs" />
    121123    <Compile Include="Interfaces\IQAPEvaluator.cs" />
    122124    <Compile Include="Interfaces\IQAPMoveEvaluator.cs" />
    123125    <Compile Include="LocalImprovement\QAPExhaustiveSwap2LocalImprovement.cs" />
     126    <Compile Include="Moves\AffinitySwapMove.cs" />
     127    <Compile Include="Moves\StochasticAffinitySwapMoveGenerator.cs" />
     128    <Compile Include="Moves\AffinitySwapMoveMaker.cs" />
    124129    <Compile Include="Parsers\QAPLIBSolutionParser.cs" />
    125130    <Compile Include="Parsers\QAPLIBParser.cs" />
     
    449454    <EmbeddedResource Include="Data\sko49.sln" />
    450455  </ItemGroup>
     456  <ItemGroup />
    451457  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
    452458  <PropertyGroup>
  • branches/GeneralizedQAP/HeuristicLab.Problems.QuadraticAssignment/3.3/QuadraticAssignmentProblem.cs

    r6628 r6801  
    268268      Operators.RemoveAll(x => x is ISingleObjectiveMoveEvaluator);
    269269      Operators.AddRange(ApplicationManager.Manager.GetInstances<IQAPMoveEvaluator>());
     270      Operators.AddRange(ApplicationManager.Manager.GetInstances<IAffinitySwapMoveOperator>().Where(x => !(x is IQAPMoveEvaluator)));
    270271      Operators.Add(new BestQAPSolutionAnalyzer());
    271272      Operators.Add(new QAPAlleleFrequencyAnalyzer());
     
    326327        op.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
    327328      }
     329      foreach (IAffinitySwapMoveOperator op in Operators.OfType<IAffinitySwapMoveOperator>()) {
     330        op.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
     331        op.WeightsParameter.ActualName = WeightsParameter.Name;
     332        op.DistancesParameter.ActualName = DistancesParameter.Name;
     333      }
    328334      if (Operators.OfType<IMoveGenerator>().Any()) {
    329335        string inversionMove = Operators.OfType<IMoveGenerator>().OfType<IPermutationInversionMoveOperator>().First().InversionMoveParameter.ActualName;
     
    336342        foreach (IPermutationSwap2MoveOperator op in Operators.OfType<IPermutationSwap2MoveOperator>()) {
    337343          op.Swap2MoveParameter.ActualName = swapMove;
     344        }
     345        string affinitySwapMove = Operators.OfType<IMoveGenerator>().OfType<IAffinitySwapMoveOperator>().First().AffinitySwapMoveParameter.ActualName;
     346        foreach (IAffinitySwapMoveOperator op in Operators.OfType<IAffinitySwapMoveOperator>()) {
     347          op.AffinitySwapMoveParameter.ActualName = affinitySwapMove;
    338348        }
    339349      }
  • 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.