Changeset 2988 for trunk/sources/HeuristicLab.Problems.TSP/3.3/Evaluators/TSPDistanceMatrixPathEvaluator.cs
- Timestamp:
- 03/10/10 04:16:18 (15 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/TSPDistanceMatrixPathEvaluator.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; … … 32 33 [Creatable("Test")] 33 34 [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 } 35 39 public ILookupParameter<DoubleMatrixData> DistanceMatrixParameter { 36 40 get { return (ILookupParameter<DoubleMatrixData>)Parameters["DistanceMatrix"]; } … … 39 43 public TSPDistanceMatrixPathEvaluator() 40 44 : base() { 45 Parameters.Add(new LookupParameter<Permutation>("Permutation", "The TSP solution given in path representation which should be evaluated.")); 41 46 Parameters.Add(new LookupParameter<DoubleMatrixData>("DistanceMatrix", "The distance matrix of the cities.")); 42 47 } 43 48 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(); 47 60 } 48 61 }
Note: See TracChangeset
for help on using the changeset viewer.