Changeset 4015 for trunk/sources/HeuristicLab.Problems.VehicleRouting
- Timestamp:
- 07/08/10 11:23:02 (14 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Analyzers/BestVRPSolutionAnalyzer.cs
r3938 r4015 41 41 get { return (ScopeTreeLookupParameter<IVRPEncoding>)Parameters["VRPSolution"]; } 42 42 } 43 public ILookupParameter<DoubleMatrix> DistanceMatrixParameter { 44 get { return (ILookupParameter<DoubleMatrix>)Parameters["DistanceMatrix"]; } 45 } 46 public ILookupParameter<BoolValue> UseDistanceMatrixParameter { 47 get { return (ILookupParameter<BoolValue>)Parameters["UseDistanceMatrix"]; } 48 } 43 49 public LookupParameter<DoubleMatrix> CoordinatesParameter { 44 50 get { return (LookupParameter<DoubleMatrix>)Parameters["Coordinates"]; } 51 } 52 public ILookupParameter<DoubleArray> ReadyTimeParameter { 53 get { return (ILookupParameter<DoubleArray>)Parameters["ReadyTime"]; } 54 } 55 public ILookupParameter<DoubleArray> DueTimeParameter { 56 get { return (ILookupParameter<DoubleArray>)Parameters["DueTime"]; } 57 } 58 public ILookupParameter<DoubleArray> ServiceTimeParameter { 59 get { return (ILookupParameter<DoubleArray>)Parameters["ServiceTime"]; } 45 60 } 46 61 public ScopeTreeLookupParameter<DoubleValue> QualityParameter { … … 73 88 Parameters.Add(new ScopeTreeLookupParameter<IVRPEncoding>("VRPSolution", "The VRP solutions which should be evaluated.")); 74 89 Parameters.Add(new LookupParameter<DoubleMatrix>("Coordinates", "The x- and y-Coordinates of the cities.")); 90 Parameters.Add(new LookupParameter<DoubleMatrix>("DistanceMatrix", "The matrix which contains the distances between the cities.")); 91 Parameters.Add(new LookupParameter<BoolValue>("UseDistanceMatrix", "True if a distance matrix should be calculated and used for evaluation, otherwise false.")); 92 Parameters.Add(new LookupParameter<DoubleArray>("ReadyTime", "The ready time of each customer.")); 93 Parameters.Add(new LookupParameter<DoubleArray>("DueTime", "The due time of each customer.")); 94 Parameters.Add(new LookupParameter<DoubleArray>("ServiceTime", "The service time of each customer.")); 95 75 96 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The qualities of the VRP solutions which should be analyzed.")); 76 97 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Distance", "The distances of the VRP solutions which should be analyzed.")); … … 101 122 solution = new VRPSolution(coordinates, best.Clone() as IVRPEncoding, new DoubleValue(qualities[i].Value), 102 123 new DoubleValue(distances[i].Value), new DoubleValue(overloads[i].Value), new DoubleValue(tardinesses[i].Value), 103 new DoubleValue(travelTimes[i].Value), new DoubleValue(vehiclesUtilizations[i].Value)); 124 new DoubleValue(travelTimes[i].Value), new DoubleValue(vehiclesUtilizations[i].Value), 125 DistanceMatrixParameter.ActualValue, UseDistanceMatrixParameter.ActualValue, 126 ReadyTimeParameter.ActualValue, DueTimeParameter.ActualValue, ServiceTimeParameter.ActualValue); 104 127 BestSolutionParameter.ActualValue = solution; 105 128 results.Add(new Result("Best VRP Solution", solution)); … … 114 137 solution.TravelTime.Value = travelTimes[i].Value; 115 138 solution.VehicleUtilization.Value = vehiclesUtilizations[i].Value; 116 117 if (solution.Quality.Value < solution.Distance.Value) { 118 } 139 solution.DistanceMatrix = DistanceMatrixParameter.ActualValue; 140 solution.UseDistanceMatrix = UseDistanceMatrixParameter.ActualValue; 141 solution.ReadyTime = ReadyTimeParameter.ActualValue; 142 solution.DueTime = DueTimeParameter.ActualValue; 143 solution.ServiceTime = ServiceTimeParameter.ActualValue; 119 144 } 120 145 } -
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Evaluators/VRPEvaluator.cs
r3947 r4015 143 143 } 144 144 145 private static double CalculateDistance(int start, int end, DoubleMatrix coordinates) {146 double distance = 0.0;147 148 distance =149 Math.Sqrt(150 Math.Pow(coordinates[start, 0] - coordinates[end, 0], 2) +151 Math.Pow(coordinates[start, 1] - coordinates[end, 1], 2));152 153 return distance;154 }155 156 private static DoubleMatrix CreateDistanceMatrix(DoubleMatrix coordinates)157 {158 DoubleMatrix distanceMatrix = new DoubleMatrix(coordinates.Rows, coordinates.Rows);159 160 for (int i = 0; i < distanceMatrix.Rows; i++) {161 for (int j = i; j < distanceMatrix.Columns; j++) {162 double distance = CalculateDistance(i, j, coordinates);163 164 distanceMatrix[i, j] = distance;165 distanceMatrix[j, i] = distance;166 }167 }168 169 return distanceMatrix;170 }171 172 private static double GetDistance(int start, int end,173 DoubleMatrix coordinates, ILookupParameter<DoubleMatrix> distanceMatrix, BoolValue useDistanceMatrix) {174 double distance = 0.0;175 176 if (useDistanceMatrix.Value) {177 if (distanceMatrix.ActualValue == null) {178 distanceMatrix.ActualValue = CreateDistanceMatrix(coordinates);179 }180 181 distance = distanceMatrix.ActualValue[start, end];182 } else {183 distance = CalculateDistance(start, end, coordinates);184 }185 186 return distance;187 }188 189 145 private static TourEvaluation EvaluateTour(Tour tour, DoubleArray dueTimeArray, 190 146 DoubleArray serviceTimeArray, DoubleArray readyTimeArray, DoubleArray demandArray, DoubleValue capacity, … … 210 166 211 167 //drive there 212 double currentDistace = GetDistance(start, end, coordinates, distanceMatrix, useDistanceMatrix);168 double currentDistace = VehicleRoutingProblem.GetDistance(start, end, coordinates, distanceMatrix, useDistanceMatrix); 213 169 distance += currentDistace; 214 170 time += currentDistace; -
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/MoveEvaluators/VRPMoveEvaluator.cs
r3947 r4015 145 145 MoveTravelTimeParameter.ActualValue = new DoubleValue(tourEval.TravelTime); 146 146 147 if (tourEval.Quality < tourEval.Distance) {148 }149 150 147 return base.Apply(); 151 148 } -
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/VRPSolution.cs
r3938 r4015 142 142 } 143 143 } 144 [Storable] 145 private DoubleMatrix distanceMatrix; 146 public DoubleMatrix DistanceMatrix { 147 get { return distanceMatrix; } 148 set { 149 if (distanceMatrix != value) { 150 distanceMatrix = value; 151 } 152 } 153 } 154 [Storable] 155 private BoolValue useDistanceMatrix; 156 public BoolValue UseDistanceMatrix { 157 get { return useDistanceMatrix; } 158 set { 159 if (useDistanceMatrix != value) { 160 useDistanceMatrix = value; 161 } 162 } 163 } 164 [Storable] 165 private DoubleArray readyTime; 166 public DoubleArray ReadyTime { 167 get { return readyTime; } 168 set { 169 if (readyTime != value) { 170 readyTime = value; 171 } 172 } 173 } 174 [Storable] 175 private DoubleArray dueTime; 176 public DoubleArray DueTime { 177 get { return dueTime; } 178 set { 179 if (dueTime != value) { 180 dueTime = value; 181 } 182 } 183 } 184 [Storable] 185 private DoubleArray serviceTime; 186 public DoubleArray ServiceTime { 187 get { return serviceTime; } 188 set { 189 if (serviceTime != value) { 190 serviceTime = value; 191 } 192 } 193 } 144 194 145 195 public VRPSolution() : base() { } … … 147 197 public VRPSolution(DoubleMatrix coordinates, IVRPEncoding solution, DoubleValue quality, 148 198 DoubleValue distance, DoubleValue overload, DoubleValue tardiness, DoubleValue travelTime, 149 DoubleValue vehicleUtilization) 199 DoubleValue vehicleUtilization, DoubleMatrix distanceMatrix, BoolValue useDistanceMatrix, 200 DoubleArray readyTime, DoubleArray dueTime, DoubleArray serviceTime) 150 201 : base() { 151 202 this.coordinates = coordinates; … … 157 208 this.travelTime = travelTime; 158 209 this.vehicleUtilization = vehicleUtilization; 210 this.distanceMatrix = distanceMatrix; 211 this.useDistanceMatrix = useDistanceMatrix; 212 this.readyTime = readyTime; 213 this.dueTime = dueTime; 214 this.serviceTime = serviceTime; 159 215 Initialize(); 160 216 } … … 167 223 if (solution != null) RegisterSolutionEvents(); 168 224 if (quality != null) RegisterQualityEvents(); 225 if (distance != null) RegisterDistanceEvents(); 226 if (overload != null) RegisterOverloadEvents(); 227 if (tardiness != null) RegisterTardinessEvents(); 228 if (travelTime != null) RegisterTravelTimeEvents(); 229 if (vehicleUtilization != null) RegisterVehicleUtilizationEvents(); 169 230 } 170 231 … … 180 241 clone.travelTime = (DoubleValue)cloner.Clone(travelTime); 181 242 clone.vehicleUtilization = (DoubleValue)cloner.Clone(vehicleUtilization); 243 clone.distanceMatrix = (DoubleMatrix)cloner.Clone(distanceMatrix); 244 clone.useDistanceMatrix = (BoolValue)cloner.Clone(useDistanceMatrix); 245 clone.readyTime = (DoubleArray)cloner.Clone(readyTime); 246 clone.dueTime = (DoubleArray)cloner.Clone(dueTime); 247 clone.serviceTime = (DoubleArray)cloner.Clone(serviceTime); 182 248 clone.Initialize(); 183 249 return clone; -
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/VehicleRoutingProblem.cs
r3947 r4015 222 222 } 223 223 224 private static double CalculateDistance(int start, int end, DoubleMatrix coordinates) { 225 double distance = 0.0; 226 227 distance = 228 Math.Sqrt( 229 Math.Pow(coordinates[start, 0] - coordinates[end, 0], 2) + 230 Math.Pow(coordinates[start, 1] - coordinates[end, 1], 2)); 231 232 return distance; 233 } 234 235 private static DoubleMatrix CreateDistanceMatrix(DoubleMatrix coordinates) { 236 DoubleMatrix distanceMatrix = new DoubleMatrix(coordinates.Rows, coordinates.Rows); 237 238 for (int i = 0; i < distanceMatrix.Rows; i++) { 239 for (int j = i; j < distanceMatrix.Columns; j++) { 240 double distance = CalculateDistance(i, j, coordinates); 241 242 distanceMatrix[i, j] = distance; 243 distanceMatrix[j, i] = distance; 244 } 245 } 246 247 return distanceMatrix; 248 } 249 250 public static double GetDistance(int start, int end, 251 DoubleMatrix coordinates, ILookupParameter<DoubleMatrix> distanceMatrix, BoolValue useDistanceMatrix) { 252 double distance = 0.0; 253 254 if (useDistanceMatrix.Value) { 255 if (distanceMatrix.ActualValue == null) { 256 distanceMatrix.ActualValue = CreateDistanceMatrix(coordinates); 257 } 258 259 distance = distanceMatrix.ActualValue[start, end]; 260 } else { 261 distance = CalculateDistance(start, end, coordinates); 262 } 263 264 return distance; 265 } 266 267 public static double GetDistance(int start, int end, 268 DoubleMatrix coordinates, DoubleMatrix distanceMatrix, BoolValue useDistanceMatrix) { 269 double distance = 0.0; 270 271 if (useDistanceMatrix.Value) { 272 distance = distanceMatrix[start, end]; 273 } else { 274 distance = CalculateDistance(start, end, coordinates); 275 } 276 277 return distance; 278 } 279 224 280 public void ImportFromSolomon(string solomonFileName) { 225 281 SolomonParser parser = new SolomonParser(solomonFileName);
Note: See TracChangeset
for help on using the changeset viewer.