Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/09/10 05:45:39 (15 years ago)
Author:
swagner
Message:

Worked on linkage between algorithms and problems (#898)

  • finished TSP and started to work on SGA
File:
1 edited

Legend:

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

    r2906 r2975  
    3232  [Item("TSPPathEvaluator", "A base class for operators which evaluate TSP solutions given in path representation.")]
    3333  [EmptyStorableClass]
    34   public abstract class TSPPathEvaluator : TSPEvaluator {
    35     public LookupParameter<DoubleMatrixData> CoordinatesParameter {
    36       get { return (LookupParameter<DoubleMatrixData>)Parameters["Coordinates"]; }
    37     }
    38     public LookupParameter<Permutation> PermutationParameter {
    39       get { return (LookupParameter<Permutation>)Parameters["Permutation"]; }
     34  public abstract class TSPPathEvaluator : TSPEvaluator, ITSPPathEvaluator {
     35    public ILookupParameter<Permutation> PermutationParameter {
     36      get { return (ILookupParameter<Permutation>)Parameters["Permutation"]; }
    4037    }
    4138
    4239    protected TSPPathEvaluator()
    4340      : base() {
    44       Parameters.Add(new LookupParameter<DoubleMatrixData>("Coordinates", "The x- and y-Coordinates of the cities."));
    4541      Parameters.Add(new LookupParameter<Permutation>("Permutation", "The TSP solution given in path representation which should be evaluated."));
    4642    }
    4743
    48     public override IOperation Apply() {
    49       DoubleMatrixData coordinates = CoordinatesParameter.ActualValue;
     44    public sealed override IOperation Apply() {
    5045      Permutation permutation = PermutationParameter.ActualValue;
    5146
    5247      double length = 0;
    5348      for (int i = 0; i < permutation.Length - 1; i++)
    54         length += CalculateDistance(coordinates[permutation[i], 0],
    55                                     coordinates[permutation[i], 1],
    56                                     coordinates[permutation[i + 1], 0],
    57                                     coordinates[permutation[i + 1], 1]);
    58       length += CalculateDistance(coordinates[permutation[permutation.Length - 1], 0],
    59                                   coordinates[permutation[permutation.Length - 1], 1],
    60                                   coordinates[permutation[0], 0],
    61                                   coordinates[permutation[0], 1]);
     49        length += CalculateDistance(permutation[i], permutation[i + 1]);
     50      length += CalculateDistance(permutation[permutation.Length - 1], permutation[0]);
    6251      QualityParameter.ActualValue = new DoubleData(length);
    6352
     
    6655
    6756    /// <summary>
    68     /// Calculates the distance between two points.
     57    /// Calculates the distance between two cities.
    6958    /// </summary>
    70     /// <param name="x1">The x-coordinate of point 1.</param>
    71     /// <param name="y1">The y-coordinate of point 1.</param>
    72     /// <param name="x2">The x-coordinate of point 2.</param>
    73     /// <param name="y2">The y-coordinate of point 2.</param>
     59    /// <param name="a">The index of the first city.</param>
     60    /// <param name="b">The index of the second city.</param>
    7461    /// <returns>The calculated distance.</returns>
    75     protected abstract double CalculateDistance(double x1, double y1, double x2, double y2);
     62    protected abstract double CalculateDistance(int a, int b);
    7663  }
    7764}
Note: See TracChangeset for help on using the changeset viewer.