- Timestamp:
- 03/24/10 21:15:04 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/MoveEvaluators
- Files:
-
- 10 added
- 4 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/MoveEvaluators/TSPMoveEvaluator.cs
r3158 r3209 20 20 #endregion 21 21 22 using System; 22 23 using HeuristicLab.Core; 23 24 using HeuristicLab.Data; … … 34 35 [StorableClass] 35 36 public abstract class TSPMoveEvaluator : SingleSuccessorOperator, ITSPMoveEvaluator, IMoveOperator { 37 public abstract Type EvaluatorType { get; } 38 36 39 public ILookupParameter<DoubleValue> QualityParameter { 37 40 get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; } -
trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/MoveEvaluators/TSPPathMoveEvaluator.cs
r3158 r3209 54 54 Parameters.Add(new LookupParameter<BoolValue>("UseDistanceMatrix", "True if a distance matrix should be calculated (if it does not exist already) and used for evaluation, otherwise false.")); 55 55 } 56 57 public override IOperation Apply() { 58 Permutation permutation = PermutationParameter.ActualValue; 59 DoubleMatrix coordinates = CoordinatesParameter.ActualValue; 60 double relativeQualityDifference = 0; 61 if (UseDistanceMatrixParameter.ActualValue.Value) { 62 DoubleMatrix distanceMatrix = DistanceMatrixParameter.ActualValue; 63 if (distanceMatrix == null) { 64 distanceMatrix = CalculateDistanceMatrix(coordinates); 65 DistanceMatrixParameter.ActualValue = distanceMatrix; 66 } 67 relativeQualityDifference = EvaluateByDistanceMatrix(permutation, distanceMatrix); 68 } else relativeQualityDifference = EvaluateByCoordinates(permutation, coordinates); 69 DoubleValue moveQuality = MoveQualityParameter.ActualValue; 70 if (moveQuality == null) MoveQualityParameter.ActualValue = new DoubleValue(QualityParameter.ActualValue.Value + relativeQualityDifference); 71 else moveQuality.Value = QualityParameter.ActualValue.Value + relativeQualityDifference; 72 return base.Apply(); 73 } 74 75 protected abstract double CalculateDistance(double x1, double y1, double x2, double y2); 76 protected abstract double EvaluateByDistanceMatrix(Permutation permutation, DoubleMatrix distanceMatrix); 77 protected abstract double EvaluateByCoordinates(Permutation permutation, DoubleMatrix coordinates); 78 79 private DoubleMatrix CalculateDistanceMatrix(DoubleMatrix c) { 80 DoubleMatrix distanceMatrix = new DoubleMatrix(c.Rows, c.Rows); 81 for (int i = 0; i < distanceMatrix.Rows; i++) { 82 for (int j = 0; j < distanceMatrix.Columns; j++) 83 distanceMatrix[i, j] = CalculateDistance(c[i, 0], c[i, 1], c[j, 0], c[j, 1]); 84 } 85 return distanceMatrix; 86 } 56 87 } 57 88 }
Note: See TracChangeset
for help on using the changeset viewer.