Changeset 4825 for trunk/sources/HeuristicLab.Problems.TravelingSalesman
- Timestamp:
- 11/17/10 07:41:28 (14 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3
- Files:
-
- 1 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/Evaluators/TSPCoordinatesPathEvaluator.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 TSP solution given in path representation which should be evaluated.")); 55 55 Parameters.Add(new LookupParameter<DoubleMatrix>("Coordinates", "The x- and y-Coordinates of the cities.")); 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 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 … … 61 74 if (UseDistanceMatrixParameter.ActualValue.Value) { 62 75 Permutation p = PermutationParameter.ActualValue; 63 D oubleMatrix dm = DistanceMatrixParameter.ActualValue;76 DistanceMatrix dm = DistanceMatrixParameter.ActualValue; 64 77 65 78 if (dm == null) { // calculate distance matrix 66 79 DoubleMatrix c = CoordinatesParameter.ActualValue; 67 80 68 dm = new D oubleMatrix(c.Rows, c.Rows);81 dm = new DistanceMatrix(c.Rows, c.Rows); 69 82 for (int i = 0; i < dm.Rows; i++) { 70 83 for (int j = 0; j < dm.Columns; j++) 71 84 dm[i, j] = CalculateDistance(c[i, 0], c[i, 1], c[j, 0], c[j, 1]); 72 85 } 73 DistanceMatrixParameter.ActualValue = (D oubleMatrix)dm.AsReadOnly();86 DistanceMatrixParameter.ActualValue = (DistanceMatrix)dm.AsReadOnly(); 74 87 } 75 88 -
trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/HeuristicLab.Problems.TravelingSalesman-3.3.csproj
r4703 r4825 109 109 <Compile Include="Analyzers\TSPPopulationDiversityAnalyzer.cs" /> 110 110 <Compile Include="Analyzers\TSPAlleleFrequencyAnalyzer.cs" /> 111 <Compile Include="DistanceMatrix.cs" /> 111 112 <Compile Include="Evaluators\TSPEuclideanPathEvaluator.cs" /> 112 113 <Compile Include="Evaluators\TSPGeoPathEvaluator.cs" /> -
trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/Interfaces/ITSPCoordinatesPathEvaluator.cs
r4068 r4825 29 29 public interface ITSPCoordinatesPathEvaluator : ITSPPathEvaluator { 30 30 ILookupParameter<DoubleMatrix> CoordinatesParameter { get; } 31 ILookupParameter<D oubleMatrix> DistanceMatrixParameter { get; }31 ILookupParameter<DistanceMatrix> DistanceMatrixParameter { get; } 32 32 ILookupParameter<BoolValue> UseDistanceMatrixParameter { get; } 33 33 } -
trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/Interfaces/ITSPPathMoveEvaluator.cs
r4068 r4825 27 27 public interface ITSPPathMoveEvaluator : ITSPMoveEvaluator, IPermutationMoveOperator { 28 28 ILookupParameter<DoubleMatrix> CoordinatesParameter { get; } 29 ILookupParameter<D oubleMatrix> DistanceMatrixParameter { get; }29 ILookupParameter<DistanceMatrix> DistanceMatrixParameter { get; } 30 30 ILookupParameter<BoolValue> UseDistanceMatrixParameter { get; } 31 31 } -
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); -
trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/TravelingSalesmanProblem.cs
r4722 r4825 55 55 get { return (ValueParameter<DoubleMatrix>)Parameters["Coordinates"]; } 56 56 } 57 public OptionalValueParameter<D oubleMatrix> DistanceMatrixParameter {58 get { return (OptionalValueParameter<D oubleMatrix>)Parameters["DistanceMatrix"]; }57 public OptionalValueParameter<DistanceMatrix> DistanceMatrixParameter { 58 get { return (OptionalValueParameter<DistanceMatrix>)Parameters["DistanceMatrix"]; } 59 59 } 60 60 public ValueParameter<BoolValue> UseDistanceMatrixParameter { … … 89 89 set { CoordinatesParameter.Value = value; } 90 90 } 91 public D oubleMatrix DistanceMatrix {91 public DistanceMatrix DistanceMatrix { 92 92 get { return DistanceMatrixParameter.Value; } 93 93 set { DistanceMatrixParameter.Value = value; } … … 144 144 : base(original, cloner) { 145 145 this.operators = original.operators.Select(x => (IOperator)cloner.Clone(x)).ToList(); 146 this.DistanceMatrixParameter.Value = original.DistanceMatrixParameter.Value;147 146 AttachEventHandlers(); 148 147 } … … 157 156 Parameters.Add(new ValueParameter<BoolValue>("Maximization", "Set to false as the Traveling Salesman Problem is a minimization problem.", new BoolValue(false))); 158 157 Parameters.Add(new ValueParameter<DoubleMatrix>("Coordinates", "The x- and y-Coordinates of the cities.")); 159 Parameters.Add(new OptionalValueParameter<D oubleMatrix>("DistanceMatrix", "The matrix which contains the distances between the cities."));158 Parameters.Add(new OptionalValueParameter<DistanceMatrix>("DistanceMatrix", "The matrix which contains the distances between the cities.")); 160 159 Parameters.Add(new ValueParameter<BoolValue>("UseDistanceMatrix", "True if a distance matrix should be calculated and used for evaluation, otherwise false.", new BoolValue(true))); 161 160 Parameters.Add(new ValueParameter<IPermutationCreator>("SolutionCreator", "The operator which should be used to create new TSP solutions.", creator)); … … 163 162 Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this TSP instance.")); 164 163 Parameters.Add(new OptionalValueParameter<Permutation>("BestKnownSolution", "The best known solution of this TSP instance.")); 164 165 DistanceMatrixParameter.ReactOnValueToStringChangedAndValueItemImageChanged = false; 165 166 166 167 Coordinates = new DoubleMatrix(new double[,] { … … 258 259 // BackwardsCompatibility3.3 259 260 #region Backwards compatible code (remove with 3.4) 261 OptionalValueParameter<DoubleMatrix> oldDistanceMatrixParameter = Parameters["DistanceMatrix"] as OptionalValueParameter<DoubleMatrix>; 262 if (oldDistanceMatrixParameter != null) { 263 Parameters.Remove(oldDistanceMatrixParameter); 264 Parameters.Add(new OptionalValueParameter<DistanceMatrix>("DistanceMatrix", "The matrix which contains the distances between the cities.")); 265 DistanceMatrixParameter.GetsCollected = oldDistanceMatrixParameter.GetsCollected; 266 DistanceMatrixParameter.ReactOnValueToStringChangedAndValueItemImageChanged = false; 267 if (oldDistanceMatrixParameter.Value != null) { 268 DoubleMatrix oldDM = oldDistanceMatrixParameter.Value; 269 DistanceMatrix newDM = new DistanceMatrix(oldDM.Rows, oldDM.Columns, oldDM.ColumnNames, oldDM.RowNames); 270 newDM.SortableView = oldDM.SortableView; 271 for (int i = 0; i < newDM.Rows; i++) 272 for (int j = 0; j < newDM.Columns; j++) 273 newDM[i, j] = oldDM[i, j]; 274 DistanceMatrixParameter.Value = (DistanceMatrix)newDM.AsReadOnly(); 275 } 276 } 277 260 278 if (operators == null) InitializeOperators(); 261 279 #endregion
Note: See TracChangeset
for help on using the changeset viewer.