- Timestamp:
- 06/20/11 13:36:49 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/VRPUtilities.cs
r5445 r6449 25 25 26 26 namespace HeuristicLab.Problems.VehicleRouting { 27 public struct DistanceMatrix { 28 public DoubleMatrix Matrix { get; set; } 29 public BoolValue UseDistanceMatrix { get; set; } 30 } 31 27 32 public sealed class VRPUtilities { 28 33 public static double CalculateDistance(int start, int end, DoubleMatrix coordinates) { … … 50 55 51 56 return distanceMatrix; 57 } 58 59 public static DistanceMatrix GetDistanceMatrix(DoubleMatrix coordinates, IParameter distanceMatrix, BoolValue useDistanceMatrix) { 60 DistanceMatrix result = new DistanceMatrix(); 61 62 if (useDistanceMatrix.Value) { 63 result.UseDistanceMatrix = new BoolValue(true); 64 if (distanceMatrix is IValueParameter<DoubleMatrix>) { 65 if ((distanceMatrix as IValueParameter<DoubleMatrix>).Value == null) { 66 (distanceMatrix as IValueParameter<DoubleMatrix>).Value = CreateDistanceMatrix(coordinates); 67 } 68 69 result.Matrix = (distanceMatrix as IValueParameter<DoubleMatrix>).Value; 70 } else { 71 if (distanceMatrix.ActualValue == null) { 72 distanceMatrix.ActualValue = CreateDistanceMatrix(coordinates); 73 } 74 75 result.Matrix = (distanceMatrix.ActualValue as DoubleMatrix); 76 } 77 } else { 78 result.UseDistanceMatrix = new BoolValue(false); 79 result.Matrix = coordinates; 80 } 81 82 return result; 83 } 84 85 public static double GetDistance(int start, int end, DistanceMatrix distMatrix) { 86 double distance = 0.0; 87 88 if (distMatrix.UseDistanceMatrix.Value) 89 distance = distMatrix.Matrix[start, end]; 90 else 91 distance = CalculateDistance(start, end, distMatrix.Matrix); 92 93 return distance; 52 94 } 53 95
Note: See TracChangeset
for help on using the changeset viewer.