Changeset 11269
 Timestamp:
 08/05/14 11:37:29 (9 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.Orienteering/3.3/OrienteeringProblem.cs
r11261 r11269 172 172 } 173 173 ParameterizeSolutionCreator(); 174 CalculateDistanceMatrix();174 UpdateDistanceMatrix(); 175 175 } 176 176 private void CoordinatesValue_ItemChanged(object sender, EventArgs<int, int> e) { 177 CalculateDistanceMatrix();177 UpdateDistanceMatrix(); 178 178 } 179 179 private void CoordinatesValue_Reset(object sender, EventArgs e) { 180 180 ParameterizeSolutionCreator(); 181 CalculateDistanceMatrix();181 UpdateDistanceMatrix(); 182 182 } 183 183 private void StartingPointParameter_ValueChanged(object sender, EventArgs e) { … … 295 295 #endregion 296 296 297 private void CalculateDistanceMatrix() { 298 var distances = new double[Coordinates.Rows, Coordinates.Rows]; 299 for (int i = 0; i < Coordinates.Rows; i++) { 300 for (int j = 0; j < Coordinates.Rows; j++) { 301 double distanceX = Math.Abs(Coordinates[i, 0]  Coordinates[j, 0]); 302 double distanceY = Math.Abs(Coordinates[i, 1]  Coordinates[j, 1]); 303 distances[i, j] = Math.Sqrt(Math.Pow(distanceX, 2) + Math.Pow(distanceY, 2)); 297 private DistanceMatrix CalculateDistanceMatrix(double[,] coordinates) { 298 var distances = DistanceHelper.GetDistanceMatrix(DistanceMeasure.Euclidean, coordinates, null, coordinates.GetLength(0)); 299 300 return new DistanceMatrix(distances); 301 } 302 private void UpdateDistanceMatrix() { 303 var coordinates = Coordinates; 304 int dimension = coordinates.Rows; 305 var distances = DistanceMatrix; 306 for (int i = 0; i < dimension  1; i++) { 307 for (int j = i + 1; j < dimension; j++) { 308 double x1 = coordinates[i, 0]; 309 double y1 = coordinates[i, 1]; 310 double x2 = coordinates[j, 0]; 311 double y2 = coordinates[j, 1]; 312 distances[i, j] = Math.Sqrt((x1  x2) * (x1  x2) + (y1  y2) * (y1  y2)); 313 distances[j, i] = distances[i, j]; 304 314 } 305 315 } 306 DistanceMatrix = new DistanceMatrix(distances);307 316 } 308 317 309 318 private void InitializeInitialOrienteeringInstance() { 310 Coordinates = new DoubleMatrix(new double[21, 2] {319 var coordinates = new double[21, 2] { 311 320 { 4.60, 7.10 }, { 5.70, 11.40 }, { 4.40, 12.30 }, { 2.80, 14.30 }, { 3.20, 10.30 }, 312 321 { 3.50, 9.80 }, { 4.40, 8.40 }, { 7.80, 11.00 }, { 8.80, 9.80 }, { 7.70, 8.20 }, … … 314 323 { 14.10, 14.20 }, { 11.20, 13.60 }, { 9.70, 16.40 }, { 9.50, 18.80 }, { 4.70, 16.80 }, 315 324 { 5.00, 5.60 } 316 }); 317 CalculateDistanceMatrix(); 325 }; 326 Coordinates = new DoubleMatrix(coordinates); 327 DistanceMatrix = CalculateDistanceMatrix(coordinates); 318 328 319 329 StartingPoint.Value = 0; … … 338 348 339 349 Coordinates = new DoubleMatrix(data.Coordinates); 340 if (data.Distances != null) 341 DistanceMatrix = new DistanceMatrix(data.Distances); 342 else 343 CalculateDistanceMatrix(); 344 345 StartingPoint = new IntValue(0);// Depot is interpreted as start and endpoint (default) 346 TerminusPoint = new IntValue(0); 350 DistanceMatrix = data.Distances != null 351 ? new DistanceMatrix(data.Distances) 352 : CalculateDistanceMatrix(data.Coordinates); 353 354 StartingPoint = new IntValue(0); // Depot is interpreted as start point 355 TerminusPoint = new IntValue(0); // Last city is interpreted als end point 347 356 348 357 MaximumDistance = new DoubleValue(data.Capacity * 2); // capacity is interpreted as max distance 349 358 Scores = new DoubleArray(data.Demands); // demands are interpreted as scores 350 351 352 359 353 360 OnReset();
Note: See TracChangeset
for help on using the changeset viewer.