Changeset 17711 for branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP
- Timestamp:
- 08/03/20 18:06:16 (4 years ago)
- Location:
- branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP
- Files:
-
- 4 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPProblemInstance.cs
r17226 r17711 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using HEAL.Attic; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; 27 28 using HeuristicLab.Data; 28 using HeuristicLab.Optimization;29 29 using HeuristicLab.Parameters; 30 using HEAL.Attic;31 using HeuristicLab.PluginInfrastructure;32 30 using HeuristicLab.Problems.VehicleRouting.Interfaces; 33 31 using HeuristicLab.Problems.VehicleRouting.Variants; … … 67 65 } 68 66 69 protected override IEnumerable<IOperator> GetOperators() { 70 return base.GetOperators() 71 .Where(o => o is IHomogenousCapacitatedOperator).Cast<IOperator>(); 72 } 73 74 protected override IEnumerable<IOperator> GetAnalyzers() { 75 return ApplicationManager.Manager.GetInstances<ICapacitatedOperator>() 76 .Where(o => o is IAnalyzer) 77 .Cast<IOperator>().Union(base.GetAnalyzers()); 78 } 79 80 protected override IVRPEvaluator Evaluator { 81 get { 82 return new CVRPEvaluator(); 83 } 67 public override IEnumerable<IOperator> FilterOperators(IEnumerable<IOperator> operators) { 68 return base.FilterOperators(operators).Where(x => x is IHomogenousCapacitatedOperator); 69 } 70 protected override VRPEvaluation CreateTourEvaluation() { 71 return new CVRPEvaluation(); 72 } 73 74 protected override void EvaluateTour(VRPEvaluation eval, Tour tour, IVRPEncodedSolution solution) { 75 TourInsertionInfo tourInfo = new TourInsertionInfo(solution.GetVehicleAssignment(solution.GetTourIndex(tour))); ; 76 eval.InsertionInfo.AddTourInsertionInfo(tourInfo); 77 double originalQuality = eval.Quality; 78 79 double delivered = 0.0; 80 double overweight = 0.0; 81 double distance = 0.0; 82 83 double capacity = Capacity.Value; 84 for (int i = 0; i <= tour.Stops.Count; i++) { 85 int end = 0; 86 if (i < tour.Stops.Count) 87 end = tour.Stops[i]; 88 89 delivered += Demand[end]; 90 } 91 92 double spareCapacity = capacity - delivered; 93 94 //simulate a tour, start and end at depot 95 for (int i = 0; i <= tour.Stops.Count; i++) { 96 int start = 0; 97 if (i > 0) 98 start = tour.Stops[i - 1]; 99 int end = 0; 100 if (i < tour.Stops.Count) 101 end = tour.Stops[i]; 102 103 //drive there 104 double currentDistace = GetDistance(start, end, solution); 105 distance += currentDistace; 106 107 CVRPInsertionInfo stopInfo = new CVRPInsertionInfo(start, end, spareCapacity); 108 tourInfo.AddStopInsertionInfo(stopInfo); 109 } 110 111 eval.Quality += FleetUsageFactor.Value; 112 eval.Quality += DistanceFactor.Value * distance; 113 114 eval.Distance += distance; 115 eval.VehicleUtilization += 1; 116 117 if (delivered > capacity) { 118 overweight = delivered - capacity; 119 } 120 121 (eval as CVRPEvaluation).Overload += overweight; 122 double penalty = overweight * OverloadPenalty.Value; 123 eval.Penalty += penalty; 124 eval.Quality += penalty; 125 tourInfo.Penalty = penalty; 126 tourInfo.Quality = eval.Quality - originalQuality; 127 128 eval.IsFeasible = overweight == 0; 129 } 130 131 protected override double GetTourInsertionCosts(IVRPEncodedSolution solution, TourInsertionInfo tourInsertionInfo, int index, int customer, 132 out bool feasible) { 133 CVRPInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index) as CVRPInsertionInfo; 134 135 double costs = 0; 136 feasible = tourInsertionInfo.Penalty < double.Epsilon; 137 138 double overloadPenalty = OverloadPenalty.Value; 139 140 double distance = GetDistance(insertionInfo.Start, insertionInfo.End, solution); 141 double newDistance = 142 GetDistance(insertionInfo.Start, customer, solution) + 143 GetDistance(customer, insertionInfo.End, solution); 144 costs += DistanceFactor.Value * (newDistance - distance); 145 146 double demand = Demand[customer]; 147 if (demand > insertionInfo.SpareCapacity) { 148 feasible = false; 149 150 if (insertionInfo.SpareCapacity >= 0) 151 costs += (demand - insertionInfo.SpareCapacity) * overloadPenalty; 152 else 153 costs += demand * overloadPenalty; 154 } 155 156 return costs; 84 157 } 85 158 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPTW/CVRPPDTW/CVRPPDTWProblemInstance.cs
r17226 r17711 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using HEAL.Attic; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; 27 28 using HeuristicLab.Data; 28 using HeuristicLab.Optimization;29 29 using HeuristicLab.Parameters; 30 using HEAL.Attic;31 using HeuristicLab.PluginInfrastructure;32 30 using HeuristicLab.Problems.VehicleRouting.Interfaces; 33 31 using HeuristicLab.Problems.VehicleRouting.Variants; … … 67 65 } 68 66 69 protected override IEnumerable<IOperator> GetOperators() {70 return71 ApplicationManager.Manager.GetInstances<IPickupAndDeliveryOperator>()72 .Where(o => !(o is IAnalyzer))73 .Cast<IOperator>().Union(base.GetOperators());74 }75 76 protected override IEnumerable<IOperator> GetAnalyzers() {77 return ApplicationManager.Manager.GetInstances<IPickupAndDeliveryOperator>()78 .Where(o => o is IAnalyzer)79 .Cast<IOperator>().Union(base.GetAnalyzers());80 }81 82 protected override IVRPEvaluator Evaluator {83 get {84 return new CVRPPDTWEvaluator();85 }86 }87 88 67 public int GetPickupDeliveryLocation(int city) { 89 68 return PickupDeliveryLocation[city]; 69 } 70 71 public override IEnumerable<IOperator> FilterOperators(IEnumerable<IOperator> operators) { 72 return base.FilterOperators(operators).Where(x => x is IPickupAndDeliveryOperator); 73 } 74 75 protected override VRPEvaluation CreateTourEvaluation() { 76 return new CVRPPDTWEvaluation(); 77 } 78 79 protected override void EvaluateTour(VRPEvaluation eval, Tour tour, IVRPEncodedSolution solution) { 80 TourInsertionInfo tourInfo = new TourInsertionInfo(solution.GetVehicleAssignment(solution.GetTourIndex(tour))); 81 eval.InsertionInfo.AddTourInsertionInfo(tourInfo); 82 double originalQuality = eval.Quality; 83 84 double capacity = Capacity.Value; 85 86 double time = 0.0; 87 double waitingTime = 0.0; 88 double serviceTime = 0.0; 89 double tardiness = 0.0; 90 double overweight = 0.0; 91 double distance = 0.0; 92 93 double currentLoad = 0.0; 94 Dictionary<int, bool> stops = new Dictionary<int, bool>(); 95 int pickupViolations = 0; 96 97 double tourStartTime = ReadyTime[0]; 98 time = tourStartTime; 99 100 //simulate a tour, start and end at depot 101 for (int i = 0; i <= tour.Stops.Count; i++) { 102 int start = 0; 103 if (i > 0) 104 start = tour.Stops[i - 1]; 105 int end = 0; 106 if (i < tour.Stops.Count) 107 end = tour.Stops[i]; 108 109 //drive there 110 double currentDistace = GetDistance(start, end, solution); 111 time += currentDistace; 112 distance += currentDistace; 113 114 double arrivalTime = time; 115 116 //check if it was serviced on time 117 if (time > DueTime[end]) 118 tardiness += time - DueTime[end]; 119 120 //wait 121 double currentWaitingTime = 0.0; 122 if (time < ReadyTime[end]) 123 currentWaitingTime = ReadyTime[end] - time; 124 125 double waitTime = ReadyTime[end] - time; 126 127 waitingTime += currentWaitingTime; 128 time += currentWaitingTime; 129 130 double spareTime = DueTime[end] - time; 131 132 //service 133 double currentServiceTime = ServiceTime[end]; 134 serviceTime += currentServiceTime; 135 time += currentServiceTime; 136 137 //Pickup / deliver 138 double arrivalSpareCapacity = capacity - currentLoad; 139 140 bool validPickupDelivery = 141 validPickupDelivery = 142 ((Demand[end] >= 0) || 143 (stops.ContainsKey(PickupDeliveryLocation[end]))); 144 145 if (validPickupDelivery) { 146 currentLoad += Demand[end]; 147 } else { 148 pickupViolations++; 149 } 150 151 if (currentLoad > capacity) 152 overweight += currentLoad - capacity; 153 154 double spareCapacity = capacity - currentLoad; 155 CVRPPDTWInsertionInfo stopInfo = new CVRPPDTWInsertionInfo(start, end, spareCapacity, tourStartTime, 156 arrivalTime, time, spareTime, waitTime, new List<int>(stops.Keys), arrivalSpareCapacity); 157 tourInfo.AddStopInsertionInfo(stopInfo); 158 159 stops.Add(end, true); 160 } 161 162 eval.Quality += FleetUsageFactor.Value; 163 eval.Quality += DistanceFactor.Value * distance; 164 eval.Distance += distance; 165 eval.VehicleUtilization += 1; 166 167 (eval as CVRPEvaluation).Overload += overweight; 168 double tourPenalty = 0; 169 double penalty = overweight * OverloadPenalty.Value; 170 eval.Penalty += penalty; 171 eval.Quality += penalty; 172 tourPenalty += penalty; 173 174 (eval as CVRPTWEvaluation).Tardiness += tardiness; 175 (eval as CVRPTWEvaluation).TravelTime += time; 176 177 penalty = tardiness * TardinessPenalty.Value; 178 eval.Penalty += penalty; 179 eval.Quality += penalty; 180 tourPenalty += penalty; 181 182 (eval as CVRPPDTWEvaluation).PickupViolations += pickupViolations; 183 penalty = pickupViolations * PickupViolationPenalty.Value; 184 eval.Penalty += penalty; 185 tourPenalty += penalty; 186 187 eval.Quality += penalty; 188 eval.Quality += time * TimeFactor.Value; 189 tourInfo.Penalty = tourPenalty; 190 tourInfo.Quality = eval.Quality - originalQuality; 191 192 eval.IsFeasible = overweight == 0 && tardiness == 0 && pickupViolations == 0; 193 } 194 195 protected override double GetTourInsertionCosts(IVRPEncodedSolution solution, TourInsertionInfo tourInsertionInfo, int index, int customer, 196 out bool feasible) { 197 CVRPPDTWInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index) as CVRPPDTWInsertionInfo; 198 199 double costs = 0; 200 feasible = tourInsertionInfo.Penalty < double.Epsilon; 201 bool tourFeasible = true; 202 203 double overloadPenalty = OverloadPenalty.Value; 204 double tardinessPenalty = TardinessPenalty.Value; 205 double pickupPenalty = PickupViolationPenalty.Value; 206 207 double distance = GetDistance(insertionInfo.Start, insertionInfo.End, solution); 208 double newDistance = 209 GetDistance(insertionInfo.Start, customer, solution) + 210 GetDistance(customer, insertionInfo.End, solution); 211 costs += DistanceFactor.Value * (newDistance - distance); 212 213 double demand = Demand[customer]; 214 if (demand > insertionInfo.ArrivalSpareCapacity) { 215 tourFeasible = feasible = false; 216 if (insertionInfo.ArrivalSpareCapacity >= 0) 217 costs += (demand - insertionInfo.ArrivalSpareCapacity) * overloadPenalty; 218 else 219 costs += demand * overloadPenalty; 220 } 221 int destination = PickupDeliveryLocation[customer]; 222 223 bool validPickup = true; 224 if (demand < 0 && !insertionInfo.Visited.Contains(destination)) { 225 tourFeasible = feasible = false; 226 validPickup = false; 227 costs += pickupPenalty; 228 } 229 230 double time = 0; 231 double tardiness = 0; 232 233 if (index > 0) 234 time = (tourInsertionInfo.GetStopInsertionInfo(index - 1) as CVRPTWInsertionInfo).LeaveTime; 235 else 236 time = insertionInfo.TourStartTime; 237 238 time += GetDistance(insertionInfo.Start, customer, solution); 239 if (time > DueTime[customer]) { 240 tardiness += time - DueTime[customer]; 241 } 242 if (time < ReadyTime[customer]) 243 time += ReadyTime[customer] - time; 244 time += ServiceTime[customer]; 245 time += GetDistance(customer, insertionInfo.End, solution); 246 247 double additionalTime = time - (tourInsertionInfo.GetStopInsertionInfo(index) as CVRPTWInsertionInfo).ArrivalTime; 248 for (int i = index; i < tourInsertionInfo.GetStopCount(); i++) { 249 CVRPTWInsertionInfo nextStop = tourInsertionInfo.GetStopInsertionInfo(i) as CVRPTWInsertionInfo; 250 251 if (demand >= 0) { 252 if (nextStop.End == destination) { 253 demand = 0; 254 costs -= pickupPenalty; 255 if (tourInsertionInfo.Penalty == pickupPenalty && tourFeasible) 256 feasible = true; 257 } else if (nextStop.SpareCapacity < 0) { 258 costs += demand * overloadPenalty; 259 } else if (nextStop.SpareCapacity < demand) { 260 tourFeasible = feasible = false; 261 costs += (demand - nextStop.SpareCapacity) * overloadPenalty; 262 } 263 } else if (validPickup) { 264 if (nextStop.SpareCapacity < 0) { 265 costs += Math.Max(demand, nextStop.SpareCapacity) * overloadPenalty; 266 } 267 } 268 269 if (additionalTime < 0) { 270 //arrive earlier than before 271 //wait probably 272 if (nextStop.WaitingTime < 0) { 273 double wait = nextStop.WaitingTime - additionalTime; 274 if (wait > 0) 275 additionalTime += wait; 276 } else { 277 additionalTime = 0; 278 } 279 280 //check due date, decrease tardiness 281 if (nextStop.SpareTime < 0) { 282 costs += Math.Max(nextStop.SpareTime, additionalTime) * tardinessPenalty; 283 } 284 } else { 285 //arrive later than before, probably don't have to wait 286 if (nextStop.WaitingTime > 0) { 287 additionalTime -= Math.Min(additionalTime, nextStop.WaitingTime); 288 } 289 290 //check due date 291 if (nextStop.SpareTime > 0) { 292 double spare = nextStop.SpareTime - additionalTime; 293 if (spare < 0) 294 tardiness += -spare; 295 } else { 296 tardiness += additionalTime; 297 } 298 } 299 } 300 301 costs += additionalTime * TimeFactor.Value; 302 303 if (tardiness > 0) { 304 tourFeasible = feasible = false; 305 } 306 307 costs += tardiness * tardinessPenalty; 308 309 return costs; 90 310 } 91 311 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPTW/CVRPTWProblemInstance.cs
r17226 r17711 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using HEAL.Attic; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; 27 28 using HeuristicLab.Data; 28 using HeuristicLab.Optimization;29 29 using HeuristicLab.Parameters; 30 using HEAL.Attic;31 using HeuristicLab.PluginInfrastructure;32 30 using HeuristicLab.Problems.VehicleRouting.Interfaces; 33 31 using HeuristicLab.Problems.VehicleRouting.Variants; … … 89 87 } 90 88 91 protected override IEnumerable<IOperator> GetOperators() { 92 return base.GetOperators() 93 .Where(o => o is ITimeWindowedOperator).Cast<IOperator>(); 94 } 95 96 protected override IEnumerable<IOperator> GetAnalyzers() { 97 return ApplicationManager.Manager.GetInstances<ITimeWindowedOperator>() 98 .Where(o => o is IAnalyzer) 99 .Cast<IOperator>().Union(base.GetAnalyzers()); 100 } 101 102 protected override IVRPEvaluator Evaluator { 103 get { 104 return new CVRPTWEvaluator(); 105 } 89 public override IEnumerable<IOperator> FilterOperators(IEnumerable<IOperator> operators) { 90 return base.FilterOperators(operators).Where(x => x is ITimeWindowedOperator); 91 } 92 93 protected override VRPEvaluation CreateTourEvaluation() { 94 return new CVRPTWEvaluation(); 95 } 96 97 protected override void EvaluateTour(VRPEvaluation eval, Tour tour, IVRPEncodedSolution solution) { 98 TourInsertionInfo tourInfo = new TourInsertionInfo(solution.GetVehicleAssignment(solution.GetTourIndex(tour))); 99 eval.InsertionInfo.AddTourInsertionInfo(tourInfo); 100 double originalQuality = eval.Quality; 101 102 double time = 0.0; 103 double waitingTime = 0.0; 104 double serviceTime = 0.0; 105 double tardiness = 0.0; 106 double delivered = 0.0; 107 double overweight = 0.0; 108 double distance = 0.0; 109 110 double capacity = Capacity.Value; 111 for (int i = 0; i <= tour.Stops.Count; i++) { 112 int end = 0; 113 if (i < tour.Stops.Count) 114 end = tour.Stops[i]; 115 116 delivered += Demand[end]; 117 } 118 119 double spareCapacity = capacity - delivered; 120 121 double tourStartTime = ReadyTime[0]; 122 time = tourStartTime; 123 124 //simulate a tour, start and end at depot 125 for (int i = 0; i <= tour.Stops.Count; i++) { 126 int start = 0; 127 if (i > 0) 128 start = tour.Stops[i - 1]; 129 int end = 0; 130 if (i < tour.Stops.Count) 131 end = tour.Stops[i]; 132 133 //drive there 134 double currentDistace = GetDistance(start, end, solution); 135 time += currentDistace; 136 distance += currentDistace; 137 138 double arrivalTime = time; 139 140 //check if it was serviced on time 141 if (time > DueTime[end]) { 142 tardiness += time - DueTime[end]; 143 } 144 145 //wait 146 double currentWaitingTime = 0.0; 147 if (time < ReadyTime[end]) 148 currentWaitingTime = ReadyTime[end] - time; 149 150 double waitTime = ReadyTime[end] - time; 151 152 waitingTime += currentWaitingTime; 153 time += currentWaitingTime; 154 155 double spareTime = DueTime[end] - time; 156 157 //service 158 double currentServiceTime = ServiceTime[end]; 159 serviceTime += currentServiceTime; 160 time += currentServiceTime; 161 162 CVRPTWInsertionInfo stopInfo = new CVRPTWInsertionInfo(start, end, spareCapacity, tourStartTime, arrivalTime, time, spareTime, waitTime); 163 tourInfo.AddStopInsertionInfo(stopInfo); 164 } 165 166 eval.Quality += FleetUsageFactor.Value; 167 eval.Quality += DistanceFactor.Value * distance; 168 eval.Distance += distance; 169 eval.VehicleUtilization += 1; 170 171 if (delivered > capacity) { 172 overweight = delivered - capacity; 173 } 174 175 (eval as CVRPEvaluation).Overload += overweight; 176 double tourPenalty = 0; 177 double penalty = overweight * OverloadPenalty.Value; 178 eval.Penalty += penalty; 179 eval.Quality += penalty; 180 tourPenalty += penalty; 181 182 (eval as CVRPTWEvaluation).Tardiness += tardiness; 183 (eval as CVRPTWEvaluation).TravelTime += time; 184 185 penalty = tardiness * TardinessPenalty.Value; 186 eval.Penalty += penalty; 187 eval.Quality += penalty; 188 tourPenalty += penalty; 189 eval.Quality += time * TimeFactor.Value; 190 tourInfo.Penalty = tourPenalty; 191 tourInfo.Quality = eval.Quality - originalQuality; 192 193 eval.IsFeasible = overweight == 0 && tardiness == 0; 194 } 195 196 protected override double GetTourInsertionCosts(IVRPEncodedSolution solution, TourInsertionInfo tourInsertionInfo, int index, int customer, 197 out bool feasible) { 198 CVRPTWInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index) as CVRPTWInsertionInfo; 199 200 double costs = 0; 201 feasible = tourInsertionInfo.Penalty < double.Epsilon; 202 203 double overloadPenalty = OverloadPenalty.Value; 204 double tardinessPenalty = TardinessPenalty.Value; 205 206 double distance = GetDistance(insertionInfo.Start, insertionInfo.End, solution); 207 double newDistance = 208 GetDistance(insertionInfo.Start, customer, solution) + 209 GetDistance(customer, insertionInfo.End, solution); 210 costs += DistanceFactor.Value * (newDistance - distance); 211 212 double demand = Demand[customer]; 213 if (demand > insertionInfo.SpareCapacity) { 214 feasible = false; 215 if (insertionInfo.SpareCapacity >= 0) 216 costs += (demand - insertionInfo.SpareCapacity) * overloadPenalty; 217 else 218 costs += demand * overloadPenalty; 219 } 220 221 double time = 0; 222 double tardiness = 0; 223 224 if (index > 0) 225 time = (tourInsertionInfo.GetStopInsertionInfo(index - 1) as CVRPTWInsertionInfo).LeaveTime; 226 else 227 time = insertionInfo.TourStartTime; 228 229 time += GetDistance(insertionInfo.Start, customer, solution); 230 if (time > DueTime[customer]) { 231 tardiness += time - DueTime[customer]; 232 } 233 if (time < ReadyTime[customer]) 234 time += ReadyTime[customer] - time; 235 time += ServiceTime[customer]; 236 time += GetDistance(customer, insertionInfo.End, solution); 237 238 double additionalTime = time - (tourInsertionInfo.GetStopInsertionInfo(index) as CVRPTWInsertionInfo).ArrivalTime; 239 for (int i = index; i < tourInsertionInfo.GetStopCount(); i++) { 240 CVRPTWInsertionInfo nextStop = tourInsertionInfo.GetStopInsertionInfo(i) as CVRPTWInsertionInfo; 241 242 if (additionalTime < 0) { 243 //arrive earlier than before 244 //wait probably 245 if (nextStop.WaitingTime < 0) { 246 double wait = nextStop.WaitingTime - additionalTime; 247 if (wait > 0) 248 additionalTime += wait; 249 } else { 250 additionalTime = 0; 251 } 252 253 //check due date, decrease tardiness 254 if (nextStop.SpareTime < 0) { 255 costs += Math.Max(nextStop.SpareTime, additionalTime) * tardinessPenalty; 256 } 257 } else { 258 //arrive later than before, probably don't have to wait 259 if (nextStop.WaitingTime > 0) { 260 additionalTime -= Math.Min(additionalTime, nextStop.WaitingTime); 261 } 262 263 //check due date 264 if (nextStop.SpareTime > 0) { 265 double spare = nextStop.SpareTime - additionalTime; 266 if (spare < 0) 267 tardiness += -spare; 268 } else { 269 tardiness += additionalTime; 270 } 271 } 272 } 273 274 costs += additionalTime * TimeFactor.Value; 275 276 if (tardiness > 0) { 277 feasible = false; 278 } 279 280 costs += tardiness * tardinessPenalty; 281 282 return costs; 106 283 } 107 284 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/SingleDepotVRPProblemInstance.cs
r17698 r17711 26 26 using HeuristicLab.Core; 27 27 using HeuristicLab.Data; 28 using HeuristicLab.Optimization;29 using HeuristicLab.PluginInfrastructure;30 28 using HeuristicLab.Problems.VehicleRouting.Interfaces; 31 29 using HeuristicLab.Problems.VehicleRouting.Variants; … … 35 33 [StorableType("A45435DD-F615-45C6-8456-5A49EE5D3C8E")] 36 34 public class SingleDepotVRPProblemInstance : VRPProblemInstance, ISingleDepotProblemInstance { 37 protected override IEnumerable<IOperator> GetOperators() {38 return ApplicationManager.Manager.GetInstances<ISingleDepotOperator>().Cast<IOperator>();39 }40 35 41 protected override IEnumerable<IOperator> GetAnalyzers() { 42 return ApplicationManager.Manager.GetInstances<ISingleDepotOperator>() 43 .Where(o => o is IAnalyzer) 44 .Cast<IOperator>(); 36 public override IEnumerable<IOperator> FilterOperators(IEnumerable<IOperator> operators) { 37 return base.FilterOperators(operators).Where(x => x is ISingleDepotOperator); 45 38 } 46 39 … … 50 43 } 51 44 } 45 protected override void EvaluateTour(VRPEvaluation eval, Tour tour, IVRPEncodedSolution solution) { 46 TourInsertionInfo tourInfo = new TourInsertionInfo(solution.GetVehicleAssignment(solution.GetTourIndex(tour))); 47 eval.InsertionInfo.AddTourInsertionInfo(tourInfo); 52 48 53 protected override IVRPEvaluator Evaluator { 54 get { 55 return new SingleDepotVRPEvaluator(); 49 double distance = 0.0; 50 double quality = 0.0; 51 52 //simulate a tour, start and end at depot 53 for (int i = 0; i <= tour.Stops.Count; i++) { 54 int start = 0; 55 if (i > 0) 56 start = tour.Stops[i - 1]; 57 int end = 0; 58 if (i < tour.Stops.Count) 59 end = tour.Stops[i]; 60 61 //drive there 62 double currentDistace = GetDistance(start, end, solution); 63 distance += currentDistace; 64 65 StopInsertionInfo stopInfo = new StopInsertionInfo(start, end); 66 tourInfo.AddStopInsertionInfo(stopInfo); 56 67 } 68 69 //Fleet usage 70 quality += FleetUsageFactor.Value; 71 //Distance 72 quality += DistanceFactor.Value * distance; 73 74 eval.Distance += distance; 75 eval.VehicleUtilization += 1; 76 77 tourInfo.Quality = quality; 78 eval.Quality += quality; 57 79 } 58 80 59 protected override IVRPCreator Creator { 60 get { 61 return new HeuristicLab.Problems.VehicleRouting.Encodings.Alba.RandomCreator(); 62 } 81 protected override double GetTourInsertionCosts(IVRPEncodedSolution solution, TourInsertionInfo tourInsertionInfo, int index, int customer, 82 out bool feasible) { 83 StopInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index); 84 85 double costs = 0; 86 feasible = true; 87 88 double distance = GetDistance(insertionInfo.Start, insertionInfo.End, solution); 89 double newDistance = 90 GetDistance(insertionInfo.Start, customer, solution) + 91 GetDistance(customer, insertionInfo.End, solution); 92 93 costs += DistanceFactor.Value * (newDistance - distance); 94 95 return costs; 63 96 } 97 64 98 65 99 [StorableConstructor]
Note: See TracChangeset
for help on using the changeset viewer.