- Timestamp:
- 11/17/10 07:41:28 (14 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/MoveEvaluators
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/MoveEvaluators/TSPPathMoveEvaluator.cs
r4722 r4825 40 40 get { return (ILookupParameter<DoubleMatrix>)Parameters["Coordinates"]; } 41 41 } 42 public ILookupParameter<D oubleMatrix> DistanceMatrixParameter {43 get { return (ILookupParameter<D oubleMatrix>)Parameters["DistanceMatrix"]; }42 public ILookupParameter<DistanceMatrix> DistanceMatrixParameter { 43 get { return (ILookupParameter<DistanceMatrix>)Parameters["DistanceMatrix"]; } 44 44 } 45 45 public ILookupParameter<BoolValue> UseDistanceMatrixParameter { … … 54 54 Parameters.Add(new LookupParameter<Permutation>("Permutation", "The solution as permutation.")); 55 55 Parameters.Add(new LookupParameter<DoubleMatrix>("Coordinates", "The city's coordinates.")); 56 Parameters.Add(new LookupParameter<D oubleMatrix>("DistanceMatrix", "The matrix which contains the distances between the cities."));56 Parameters.Add(new LookupParameter<DistanceMatrix>("DistanceMatrix", "The matrix which contains the distances between the cities.")); 57 57 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.")); 58 } 59 60 [StorableHook(HookType.AfterDeserialization)] 61 private void AfterDeserialization() { 62 // BackwardsCompatibility3.3 63 #region Backwards compatible code (remove with 3.4) 64 LookupParameter<DoubleMatrix> oldDistanceMatrixParameter = Parameters["DistanceMatrix"] as LookupParameter<DoubleMatrix>; 65 if (oldDistanceMatrixParameter != null) { 66 Parameters.Remove(oldDistanceMatrixParameter); 67 Parameters.Add(new LookupParameter<DistanceMatrix>("DistanceMatrix", "The matrix which contains the distances between the cities.")); 68 DistanceMatrixParameter.ActualName = oldDistanceMatrixParameter.ActualName; 69 } 70 #endregion 58 71 } 59 72 … … 63 76 double relativeQualityDifference = 0; 64 77 if (UseDistanceMatrixParameter.ActualValue.Value) { 65 D oubleMatrix distanceMatrix = DistanceMatrixParameter.ActualValue;78 DistanceMatrix distanceMatrix = DistanceMatrixParameter.ActualValue; 66 79 if (distanceMatrix == null) { 67 80 distanceMatrix = CalculateDistanceMatrix(coordinates); … … 77 90 78 91 protected abstract double CalculateDistance(double x1, double y1, double x2, double y2); 79 protected abstract double EvaluateByDistanceMatrix(Permutation permutation, D oubleMatrix distanceMatrix);92 protected abstract double EvaluateByDistanceMatrix(Permutation permutation, DistanceMatrix distanceMatrix); 80 93 protected abstract double EvaluateByCoordinates(Permutation permutation, DoubleMatrix coordinates); 81 94 82 private D oubleMatrix CalculateDistanceMatrix(DoubleMatrix c) {83 D oubleMatrix distanceMatrix = new DoubleMatrix(c.Rows, c.Rows);95 private DistanceMatrix CalculateDistanceMatrix(DoubleMatrix c) { 96 DistanceMatrix distanceMatrix = new DistanceMatrix(c.Rows, c.Rows); 84 97 for (int i = 0; i < distanceMatrix.Rows; i++) { 85 98 for (int j = 0; j < distanceMatrix.Columns; j++) 86 99 distanceMatrix[i, j] = CalculateDistance(c[i, 0], c[i, 1], c[j, 0], c[j, 1]); 87 100 } 88 return distanceMatrix;101 return (DistanceMatrix)distanceMatrix.AsReadOnly(); 89 102 } 90 103 } -
trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/MoveEvaluators/ThreeOpt/TSPTranslocationMovePathEvaluator.cs
r4722 r4825 82 82 } 83 83 84 protected override double EvaluateByDistanceMatrix(Permutation permutation, D oubleMatrix distanceMatrix) {84 protected override double EvaluateByDistanceMatrix(Permutation permutation, DistanceMatrix distanceMatrix) { 85 85 TranslocationMove move = TranslocationMoveParameter.ActualValue; 86 86 int edge1source = permutation.GetCircular(move.Index1 - 1); -
trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/MoveEvaluators/TwoOpt/TSPInversionMovePathEvaluator.cs
r4722 r4825 67 67 } 68 68 69 protected override double EvaluateByDistanceMatrix(Permutation permutation, D oubleMatrix distanceMatrix) {69 protected override double EvaluateByDistanceMatrix(Permutation permutation, DistanceMatrix distanceMatrix) { 70 70 InversionMove move = InversionMoveParameter.ActualValue; 71 71 int edge1source = permutation.GetCircular(move.Index1 - 1);
Note: See TracChangeset
for help on using the changeset viewer.