Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3209 for trunk/sources


Ignore:
Timestamp:
03/24/10 21:15:04 (15 years ago)
Author:
abeham
Message:

Added 3-opt move and evaluators for the TSP
Added 2-opt move evaluators for TSP Geo and Euclidean
#889

Location:
trunk/sources
Files:
12 added
5 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/HeuristicLab.Encodings.PermutationEncoding-3.3.csproj

    r3200 r3209  
    108108    <Compile Include="Manipulators\TranslocationManipulator.cs" />
    109109    <Compile Include="Moves\ThreeIndexMove.cs" />
     110    <Compile Include="Moves\ThreeOpt\StochasticThreeOptMultiMoveGenerator.cs" />
    110111    <Compile Include="Moves\ThreeOpt\ThreeOptMove.cs">
    111112      <SubType>Code</SubType>
    112113    </Compile>
     114    <Compile Include="Moves\ThreeOpt\ThreeOptMoveGenerator.cs" />
     115    <Compile Include="Moves\ThreeOpt\ThreeOptMoveMaker.cs" />
    113116    <Compile Include="Moves\TwoOpt\PreventReaddTwoOptTabuMoveEvaluator.cs" />
    114117    <Compile Include="Moves\TwoOpt\StochasticTwoOptSingleMoveGenerator.cs" />
  • trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/SingleObjectiveTestFunctionProblem.cs

    r3187 r3209  
    252252    private void InitializeOperators() {
    253253      operators = new List<IOperator>();
    254       if (ApplicationManager.Manager != null) {
    255         foreach (IRealVectorOperator op in ApplicationManager.Manager.GetInstances<IRealVectorOperator>())
    256           operators.Add(op);
    257         UpdateMoveEvaluators();
    258         ParameterizeOperators();
    259       }
     254      if (ApplicationManager.Manager != null) operators.AddRange(ApplicationManager.Manager.GetInstances<IRealVectorOperator>().Cast<IOperator>());
     255      UpdateMoveEvaluators();
     256      ParameterizeOperators();
    260257      InitializeMoveGenerators();
    261258    }
  • trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/HeuristicLab.Problems.TravelingSalesman-3.3.csproj

    r3200 r3209  
    8787    <Compile Include="Evaluators\TSPGeoPathEvaluator.cs" />
    8888    <Compile Include="HeuristicLabProblemsTravelingSalesmanPlugin.cs" />
    89     <Compile Include="MoveEvaluators\ThreeOptMoveTSPCoordinatesPathEvaluator.cs" />
    90     <Compile Include="MoveEvaluators\ThreeOptMoveTSPRoundedEuclideanPathEvaluator.cs" />
     89    <Compile Include="MoveEvaluators\ThreeOpt\TSPThreeOptRoundedEuclideanPathMoveEvaluator.cs" />
     90    <Compile Include="MoveEvaluators\ThreeOpt\TSPThreeOptEuclideanPathMoveEvaluator.cs" />
     91    <Compile Include="MoveEvaluators\ThreeOpt\TSPThreeOptGeoPathMoveEvaluator.cs" />
     92    <Compile Include="MoveEvaluators\TwoOpt\TSPTwoOptEuclideanPathMoveEvaluator.cs" />
     93    <Compile Include="MoveEvaluators\TwoOpt\TSPTwoOptGeoPathMoveEvaluator.cs" />
     94    <Compile Include="MoveEvaluators\TwoOpt\TSPTwoOptPathMoveEvaluator.cs" />
     95    <Compile Include="MoveEvaluators\TwoOpt\TSPTwoOptRoundedEuclideanPathMoveEvaluator.cs" />
    9196    <Compile Include="TravelingSalesmanProblem.cs" />
    9297    <Compile Include="TSPLIBTourParser.cs" />
     
    104109    <Compile Include="Interfaces\ITSPPathEvaluator.cs" />
    105110    <Compile Include="Interfaces\ITSPPathMoveEvaluator.cs" />
    106     <Compile Include="MoveEvaluators\TwoOptMoveTSPRoundedEuclideanPathEvaluator.cs" />
     111    <Compile Include="MoveEvaluators\ThreeOpt\TSPThreeOptPathMoveEvaluator.cs" />
    107112    <Compile Include="MoveEvaluators\TSPPathMoveEvaluator.cs" />
    108113    <Compile Include="MoveEvaluators\TSPMoveEvaluator.cs" />
    109     <Compile Include="MoveEvaluators\TwoOptMoveTSPCoordinatesPathEvaluator.cs">
    110       <SubType>Code</SubType>
    111     </Compile>
    112114    <Compile Include="TSPLIBParser.cs" />
    113115    <Compile Include="Properties\AssemblyInfo.cs" />
  • trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/Interfaces/ITSPMoveEvaluator.cs

    r3158 r3209  
    2323using HeuristicLab.Data;
    2424using HeuristicLab.Optimization;
     25using System;
    2526
    2627namespace HeuristicLab.Problems.TravelingSalesman {
    2728  public interface ITSPMoveEvaluator : ISingleObjectiveMoveEvaluator, IMoveOperator {
     29    Type EvaluatorType { get; }
    2830  }
    2931}
  • trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/MoveEvaluators/TSPMoveEvaluator.cs

    r3158 r3209  
    2020#endregion
    2121
     22using System;
    2223using HeuristicLab.Core;
    2324using HeuristicLab.Data;
     
    3435  [StorableClass]
    3536  public abstract class TSPMoveEvaluator : SingleSuccessorOperator, ITSPMoveEvaluator, IMoveOperator {
     37    public abstract Type EvaluatorType { get; }
     38
    3639    public ILookupParameter<DoubleValue> QualityParameter {
    3740      get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
  • trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/MoveEvaluators/TSPPathMoveEvaluator.cs

    r3158 r3209  
    5454      Parameters.Add(new LookupParameter<BoolValue>("UseDistanceMatrix", "True if a distance matrix should be calculated (if it does not exist already) and used for evaluation, otherwise false."));
    5555    }
     56
     57    public override IOperation Apply() {
     58      Permutation permutation = PermutationParameter.ActualValue;
     59      DoubleMatrix coordinates = CoordinatesParameter.ActualValue;
     60      double relativeQualityDifference = 0;
     61      if (UseDistanceMatrixParameter.ActualValue.Value) {
     62        DoubleMatrix distanceMatrix = DistanceMatrixParameter.ActualValue;
     63        if (distanceMatrix == null) {
     64          distanceMatrix = CalculateDistanceMatrix(coordinates);
     65          DistanceMatrixParameter.ActualValue = distanceMatrix;
     66        }
     67        relativeQualityDifference = EvaluateByDistanceMatrix(permutation, distanceMatrix);
     68      } else relativeQualityDifference = EvaluateByCoordinates(permutation, coordinates);
     69      DoubleValue moveQuality = MoveQualityParameter.ActualValue;
     70      if (moveQuality == null) MoveQualityParameter.ActualValue = new DoubleValue(QualityParameter.ActualValue.Value + relativeQualityDifference);
     71      else moveQuality.Value = QualityParameter.ActualValue.Value + relativeQualityDifference;
     72      return base.Apply();
     73    }
     74
     75    protected abstract double CalculateDistance(double x1, double y1, double x2, double y2);
     76    protected abstract double EvaluateByDistanceMatrix(Permutation permutation, DoubleMatrix distanceMatrix);
     77    protected abstract double EvaluateByCoordinates(Permutation permutation, DoubleMatrix coordinates);
     78
     79    private DoubleMatrix CalculateDistanceMatrix(DoubleMatrix c) {
     80      DoubleMatrix distanceMatrix = new DoubleMatrix(c.Rows, c.Rows);
     81      for (int i = 0; i < distanceMatrix.Rows; i++) {
     82        for (int j = 0; j < distanceMatrix.Columns; j++)
     83          distanceMatrix[i, j] = CalculateDistance(c[i, 0], c[i, 1], c[j, 0], c[j, 1]);
     84      }
     85      return distanceMatrix;
     86    }
    5687  }
    5788}
  • trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/TravelingSalesmanProblem.cs

    r3199 r3209  
    253253      Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    254254      ParameterizeEvaluator();
     255      UpdateMoveEvaluators();
    255256      ParameterizeVisualizer();
    256257      ClearDistanceMatrix();
     
    296297      if (ApplicationManager.Manager != null) operators.AddRange(ApplicationManager.Manager.GetInstances<IPermutationOperator>());
    297298      ParameterizeOperators();
     299      UpdateMoveEvaluators();
    298300      InitializeMoveGenerators();
    299301    }
     
    308310          op.ThreeOptMoveParameter.ActualNameChanged += new EventHandler(MoveGenerator_ThreeOptMoveParameter_ActualNameChanged);
    309311        }
     312      }
     313    }
     314    private void UpdateMoveEvaluators() {
     315      if (ApplicationManager.Manager != null) {
     316        foreach (ITSPPathMoveEvaluator op in Operators.OfType<ITSPPathMoveEvaluator>().ToList())
     317          operators.Remove(op);
     318        foreach (ITSPPathMoveEvaluator op in ApplicationManager.Manager.GetInstances<ITSPPathMoveEvaluator>())
     319          if (op.EvaluatorType == Evaluator.GetType()) {
     320            operators.Add(op);
     321          }
     322        ParameterizeOperators();
     323        OnOperatorsChanged();
    310324      }
    311325    }
     
    347361        op.DistanceMatrixParameter.ActualName = DistanceMatrixParameter.Name;
    348362        op.UseDistanceMatrixParameter.ActualName = UseDistanceMatrixParameter.Name;
     363        op.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
     364        op.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
    349365      }
    350366    }
Note: See TracChangeset for help on using the changeset viewer.