- Timestamp:
- 03/09/10 05:45:39 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.TSP/3.3/TSPPathEvaluator.cs
r2906 r2975 32 32 [Item("TSPPathEvaluator", "A base class for operators which evaluate TSP solutions given in path representation.")] 33 33 [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"]; } 40 37 } 41 38 42 39 protected TSPPathEvaluator() 43 40 : base() { 44 Parameters.Add(new LookupParameter<DoubleMatrixData>("Coordinates", "The x- and y-Coordinates of the cities."));45 41 Parameters.Add(new LookupParameter<Permutation>("Permutation", "The TSP solution given in path representation which should be evaluated.")); 46 42 } 47 43 48 public override IOperation Apply() { 49 DoubleMatrixData coordinates = CoordinatesParameter.ActualValue; 44 public sealed override IOperation Apply() { 50 45 Permutation permutation = PermutationParameter.ActualValue; 51 46 52 47 double length = 0; 53 48 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]); 62 51 QualityParameter.ActualValue = new DoubleData(length); 63 52 … … 66 55 67 56 /// <summary> 68 /// Calculates the distance between two points.57 /// Calculates the distance between two cities. 69 58 /// </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> 74 61 /// <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); 76 63 } 77 64 }
Note: See TracChangeset
for help on using the changeset viewer.