Changeset 2988 for trunk/sources/HeuristicLab.Problems.TSP/3.3/Evaluators/TSPCoordinatesPathEvaluator.cs
- Timestamp:
- 03/10/10 04:16:18 (14 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.TSP/3.3/Evaluators
- Files:
-
- 1 added
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.TSP/3.3/Evaluators/TSPCoordinatesPathEvaluator.cs
r2985 r2988 22 22 using HeuristicLab.Core; 23 23 using HeuristicLab.Data; 24 using HeuristicLab.Encodings.Permutation; 24 25 using HeuristicLab.Parameters; 25 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 31 32 [Item("TSPCoordinatesPathEvaluator", "A base class for operators which evaluate TSP solutions given in path representation using city coordinates.")] 32 33 [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 } 34 38 public ILookupParameter<DoubleMatrixData> CoordinatesParameter { 35 39 get { return (ILookupParameter<DoubleMatrixData>)Parameters["Coordinates"]; } … … 38 42 protected TSPCoordinatesPathEvaluator() 39 43 : base() { 44 Parameters.Add(new LookupParameter<Permutation>("Permutation", "The TSP solution given in path representation which should be evaluated.")); 40 45 Parameters.Add(new LookupParameter<DoubleMatrixData>("Coordinates", "The x- and y-Coordinates of the cities.")); 41 46 } 42 47 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(); 47 59 } 48 60
Note: See TracChangeset
for help on using the changeset viewer.