Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2988


Ignore:
Timestamp:
03/10/10 04:16:18 (14 years ago)
Author:
swagner
Message:

Worked on linkage between algorithms and problems (#898)

  • restructured HeuristicLab.Problems.TSP project
  • adapted TSP evaluators class hierarchy to avoid performance problems
Location:
trunk/sources/HeuristicLab.Problems.TSP/3.3
Files:
2 added
1 deleted
1 edited
8 moved

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.TSP/3.3/Evaluators/TSPCoordinatesPathEvaluator.cs

    r2985 r2988  
    2222using HeuristicLab.Core;
    2323using HeuristicLab.Data;
     24using HeuristicLab.Encodings.Permutation;
    2425using HeuristicLab.Parameters;
    2526using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3132  [Item("TSPCoordinatesPathEvaluator", "A base class for operators which evaluate TSP solutions given in path representation using city coordinates.")]
    3233  [EmptyStorableClass]
    33   public abstract class TSPCoordinatesPathEvaluator : TSPPathEvaluator, ITSPCoordinatesPathEvaluator {
     34  public abstract class TSPCoordinatesPathEvaluator : TSPEvaluator, ITSPCoordinatesPathEvaluator {
     35    public ILookupParameter<Permutation> PermutationParameter {
     36      get { return (ILookupParameter<Permutation>)Parameters["Permutation"]; }
     37    }
    3438    public ILookupParameter<DoubleMatrixData> CoordinatesParameter {
    3539      get { return (ILookupParameter<DoubleMatrixData>)Parameters["Coordinates"]; }
     
    3842    protected TSPCoordinatesPathEvaluator()
    3943      : base() {
     44      Parameters.Add(new LookupParameter<Permutation>("Permutation", "The TSP solution given in path representation which should be evaluated."));
    4045      Parameters.Add(new LookupParameter<DoubleMatrixData>("Coordinates", "The x- and y-Coordinates of the cities."));
    4146    }
    4247
    43     protected sealed override double CalculateDistance(int a, int b) {
    44       DoubleMatrixData coordinates = CoordinatesParameter.ActualValue;
    45       return CalculateDistance(coordinates[a, 0], coordinates[a, 1],
    46                                coordinates[b, 0], coordinates[b, 1]);
     48    public sealed override IOperation Apply() {
     49      Permutation p = PermutationParameter.ActualValue;
     50      DoubleMatrixData c = CoordinatesParameter.ActualValue;
     51
     52      double length = 0;
     53      for (int i = 0; i < p.Length - 1; i++)
     54        length += CalculateDistance(c[p[i], 0], c[p[i], 1], c[p[i + 1], 0], c[p[i + 1], 1]);
     55      length += CalculateDistance(c[p[p.Length - 1], 0], c[p[p.Length - 1], 1], c[p[0], 0], c[p[0], 1]);
     56      QualityParameter.ActualValue = new DoubleData(length);
     57
     58      return base.Apply();
    4759    }
    4860
  • trunk/sources/HeuristicLab.Problems.TSP/3.3/Evaluators/TSPDistanceMatrixPathEvaluator.cs

    r2985 r2988  
    2222using HeuristicLab.Core;
    2323using HeuristicLab.Data;
     24using HeuristicLab.Encodings.Permutation;
    2425using HeuristicLab.Parameters;
    2526using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3233  [Creatable("Test")]
    3334  [EmptyStorableClass]
    34   public sealed class TSPDistanceMatrixPathEvaluator : TSPPathEvaluator, ITSPDistanceMatrixPathEvaluator {
     35  public sealed class TSPDistanceMatrixPathEvaluator : TSPEvaluator, ITSPDistanceMatrixPathEvaluator {
     36    public ILookupParameter<Permutation> PermutationParameter {
     37      get { return (ILookupParameter<Permutation>)Parameters["Permutation"]; }
     38    }
    3539    public ILookupParameter<DoubleMatrixData> DistanceMatrixParameter {
    3640      get { return (ILookupParameter<DoubleMatrixData>)Parameters["DistanceMatrix"]; }
     
    3943    public TSPDistanceMatrixPathEvaluator()
    4044      : base() {
     45      Parameters.Add(new LookupParameter<Permutation>("Permutation", "The TSP solution given in path representation which should be evaluated."));
    4146      Parameters.Add(new LookupParameter<DoubleMatrixData>("DistanceMatrix", "The distance matrix of the cities."));
    4247    }
    4348
    44     protected override double CalculateDistance(int a, int b) {
    45       DoubleMatrixData distanceMatrix = DistanceMatrixParameter.ActualValue;
    46       return distanceMatrix[a, b];
     49    public sealed override IOperation Apply() {
     50      Permutation p = PermutationParameter.ActualValue;
     51      DoubleMatrixData d = DistanceMatrixParameter.ActualValue;
     52
     53      double length = 0;
     54      for (int i = 0; i < p.Length - 1; i++)
     55        length += d[p[i], p[i + 1]];
     56      length += d[p[p.Length - 1], p[0]];
     57      QualityParameter.ActualValue = new DoubleData(length);
     58
     59      return base.Apply();
    4760    }
    4861  }
  • trunk/sources/HeuristicLab.Problems.TSP/3.3/HeuristicLab.Problems.TSP-3.3.csproj

    r2975 r2988  
    8484  </ItemGroup>
    8585  <ItemGroup>
    86     <Compile Include="TSPCoordinatesPathEvaluator.cs" />
    87     <Compile Include="ITSPDistanceMatrixPathEvaluator.cs" />
    88     <Compile Include="ITSPCoordinatesPathEvaluator.cs" />
    89     <Compile Include="ITSPPathEvaluator.cs" />
     86    <Compile Include="Evaluators\TSPCoordinatesPathEvaluator.cs" />
     87    <Compile Include="Evaluators\TSPDistanceMatrixPathEvaluator.cs" />
     88    <Compile Include="Evaluators\TSPEvaluator.cs" />
     89    <Compile Include="Evaluators\TSPRoundedEuclideanPathEvaluator.cs" />
     90    <Compile Include="Interfaces\ITSPCoordinatesPathEvaluator.cs" />
     91    <Compile Include="Interfaces\ITSPDistanceMatrixPathEvaluator.cs" />
     92    <Compile Include="Interfaces\ITSPEvaluator.cs" />
     93    <Compile Include="Interfaces\ITSPPathEvaluator.cs" />
    9094    <Compile Include="HeuristicLabProblemsTSPPlugin.cs" />
    91     <Compile Include="TSPEvaluator.cs" />
    92     <Compile Include="ITSPEvaluator.cs" />
    93     <Compile Include="TSPDistanceMatrixPathEvaluator.cs" />
    9495    <Compile Include="TSPLIBParser.cs" />
    95     <Compile Include="TSPRoundedEuclideanPathEvaluator.cs" />
    96     <Compile Include="TSPPathEvaluator.cs" />
    9796    <Compile Include="TSP.cs" />
    9897    <Compile Include="Properties\AssemblyInfo.cs" />
Note: See TracChangeset for help on using the changeset viewer.