Changeset 14677 for branches/OptimizationNetworks/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPTW
- Timestamp:
- 02/16/17 15:16:55 (8 years ago)
- Location:
- branches/OptimizationNetworks/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPTW
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OptimizationNetworks/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPTW/CVRPPDTW/CVRPPDTWEvaluation.cs
r14185 r14677 23 23 24 24 namespace HeuristicLab.Problems.VehicleRouting.ProblemInstances { 25 public class CVRPPDTW InsertionInfo : CVRPTWInsertionInfo {25 public class CVRPPDTWStopInsertionInfo : CVRPTWStopInsertionInfo { 26 26 private List<int> visited; 27 27 … … 36 36 } 37 37 38 public CVRPPDTW InsertionInfo(int start, int end, double spareCapacity, double tourStartTime,38 public CVRPPDTWStopInsertionInfo(int start, int end, double distance, double spareCapacity, 39 39 double arrivalTime, double leaveTime, double spareTime, double waitingTime, List<int> visited, double arrivalSpareCapacity) 40 : base(start, end, spareCapacity, tourStartTime, arrivalTime, leaveTime, spareTime, waitingTime) {40 : base(start, end, distance, spareCapacity, arrivalTime, leaveTime, spareTime, waitingTime) { 41 41 this.visited = visited; 42 42 this.arrivalSpareCapacity = arrivalSpareCapacity; -
branches/OptimizationNetworks/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPTW/CVRPPDTW/CVRPPDTWEvaluator.cs
r14185 r14677 43 43 44 44 protected override void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour, IVRPEncoding solution) { 45 TourInsertionInfo tourInfo = new TourInsertionInfo(solution.GetVehicleAssignment(solution.GetTourIndex(tour)));46 eval.InsertionInfo.AddTourInsertionInfo(tourInfo);45 var cvrpInstance = (IHomogenousCapacitatedProblemInstance)instance; 46 double capacity = cvrpInstance.Capacity.Value; 47 47 double originalQuality = eval.Quality; 48 48 49 IHomogenousCapacitatedProblemInstance cvrpInstance = instance as IHomogenousCapacitatedProblemInstance;50 49 DoubleArray demand = instance.Demand; 51 50 52 ITimeWindowedProblemInstance vrptw = instance as ITimeWindowedProblemInstance;51 var vrptw = (ITimeWindowedProblemInstance)instance; 53 52 DoubleArray dueTime = vrptw.DueTime; 54 53 DoubleArray readyTime = vrptw.ReadyTime; 55 54 DoubleArray serviceTimes = vrptw.ServiceTime; 56 55 57 IPickupAndDeliveryProblemInstance pdp = instance as IPickupAndDeliveryProblemInstance;56 var pdp = (IPickupAndDeliveryProblemInstance)instance; 58 57 IntArray pickupDeliveryLocation = pdp.PickupDeliveryLocation; 59 58 60 double capacity = cvrpInstance.Capacity.Value;61 59 62 60 double time = 0.0; … … 73 71 double tourStartTime = readyTime[0]; 74 72 time = tourStartTime; 73 74 var tourInfo = new CVRPTWTourInsertionInfo(solution.GetVehicleAssignment(solution.GetTourIndex(tour)), capacity, tourStartTime); 75 eval.InsertionInfo.AddTourInsertionInfo(tourInfo); 75 76 76 77 //simulate a tour, start and end at depot … … 84 85 85 86 //drive there 86 double currentDista ce = vrptw.GetDistance(start, end, solution);87 time += currentDista ce;88 distance += currentDista ce;87 double currentDistance = vrptw.GetDistance(start, end, solution); 88 time += currentDistance; 89 distance += currentDistance; 89 90 90 91 double arrivalTime = time; … … 115 116 116 117 bool validPickupDelivery = 117 validPickupDelivery =118 118 ((demand[end] >= 0) || 119 119 (stops.ContainsKey(pickupDeliveryLocation[end]))); … … 129 129 130 130 double spareCapacity = capacity - currentLoad; 131 CVRPPDTWInsertionInfo stopInfo = new CVRPPDTWInsertionInfo(start, end, spareCapacity, tourStartTime,131 var stopInfo = new CVRPPDTWStopInsertionInfo(start, end, currentDistance, spareCapacity, 132 132 arrivalTime, time, spareTime, waitTime, new List<int>(stops.Keys), arrivalSpareCapacity); 133 133 tourInfo.AddStopInsertionInfo(stopInfo); … … 141 141 eval.VehicleUtilization += 1; 142 142 143 ( eval as CVRPEvaluation).Overload += overweight;143 ((CVRPEvaluation)eval).Overload += overweight; 144 144 double tourPenalty = 0; 145 145 double penalty = overweight * cvrpInstance.OverloadPenalty.Value; … … 148 148 tourPenalty += penalty; 149 149 150 ( eval as CVRPTWEvaluation).Tardiness += tardiness;151 ( eval as CVRPTWEvaluation).TravelTime += time;150 ((CVRPTWEvaluation)eval).Tardiness += tardiness; 151 ((CVRPTWEvaluation)eval).TravelTime += time; 152 152 153 153 penalty = tardiness * vrptw.TardinessPenalty.Value; … … 156 156 tourPenalty += penalty; 157 157 158 ( eval as CVRPPDTWEvaluation).PickupViolations += pickupViolations;158 ((CVRPPDTWEvaluation)eval).PickupViolations += pickupViolations; 159 159 penalty = pickupViolations * pdp.PickupViolationPenalty.Value; 160 160 eval.Penalty += penalty; … … 169 169 protected override double GetTourInsertionCosts(IVRPProblemInstance instance, IVRPEncoding solution, TourInsertionInfo tourInsertionInfo, int index, int customer, 170 170 out bool feasible) { 171 CVRPPDTWInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index) as CVRPPDTWInsertionInfo; 171 var tourInfo = (CVRPTWTourInsertionInfo)tourInsertionInfo; 172 var insertionInfo = (CVRPPDTWStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(index); 172 173 173 174 double costs = 0; … … 175 176 bool tourFeasible = true; 176 177 177 ICapacitatedProblemInstance cvrp = instance as ICapacitatedProblemInstance;178 var cvrp = (ICapacitatedProblemInstance)instance; 178 179 double overloadPenalty = cvrp.OverloadPenalty.Value; 179 180 180 ITimeWindowedProblemInstance vrptw = instance as ITimeWindowedProblemInstance;181 var vrptw = (ITimeWindowedProblemInstance)instance; 181 182 DoubleArray dueTime = vrptw.DueTime; 182 183 DoubleArray readyTime = vrptw.ReadyTime; … … 184 185 double tardinessPenalty = vrptw.TardinessPenalty.Value; 185 186 186 IPickupAndDeliveryProblemInstance pdp = instance as IPickupAndDeliveryProblemInstance;187 IPickupAndDeliveryProblemInstance pdp = (IPickupAndDeliveryProblemInstance)instance; 187 188 IntArray pickupDeliveryLocation = pdp.PickupDeliveryLocation; 188 189 double pickupPenalty = pdp.PickupViolationPenalty.Value; … … 215 216 216 217 if (index > 0) 217 time = ( tourInsertionInfo.GetStopInsertionInfo(index - 1) as CVRPTWInsertionInfo).LeaveTime;218 time = ((CVRPTWStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(index - 1)).LeaveTime; 218 219 else 219 time = insertionInfo.TourStartTime;220 time = tourInfo.TourStartTime; 220 221 221 222 time += instance.GetDistance(insertionInfo.Start, customer, solution); … … 228 229 time += instance.GetDistance(customer, insertionInfo.End, solution); 229 230 230 double additionalTime = time - ( tourInsertionInfo.GetStopInsertionInfo(index) as CVRPTWInsertionInfo).ArrivalTime;231 double additionalTime = time - ((CVRPTWStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(index)).ArrivalTime; 231 232 for (int i = index; i < tourInsertionInfo.GetStopCount(); i++) { 232 CVRPTWInsertionInfo nextStop = tourInsertionInfo.GetStopInsertionInfo(i) as CVRPTWInsertionInfo;233 var nextStop = (CVRPTWStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(i); 233 234 234 235 if (demand >= 0) { … … 246 247 } else if (validPickup) { 247 248 if (nextStop.SpareCapacity < 0) { 249 // ABE: The costs decrease when there is overload!? 248 250 costs += Math.Max(demand, nextStop.SpareCapacity) * overloadPenalty; 249 251 } … … 263 265 //check due date, decrease tardiness 264 266 if (nextStop.SpareTime < 0) { 267 // ABE: Again, the costs decrease when there is tardiness!? 265 268 costs += Math.Max(nextStop.SpareTime, additionalTime) * tardinessPenalty; 266 269 } -
branches/OptimizationNetworks/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPTW/CVRPTWEvaluation.cs
r14185 r14677 20 20 #endregion 21 21 22 using System; 23 using System.Globalization; 24 using System.Text; 22 25 23 26 namespace HeuristicLab.Problems.VehicleRouting.ProblemInstances { 24 public class CVRPTWInsertionInfo : CVRPInsertionInfo { 25 private double tourStartTime; 26 27 public double TourStartTime { 28 get { return tourStartTime; } 29 } 27 public class CVRPTWStopInsertionInfo : CVRPStopInsertionInfo { 30 28 31 29 private double arrivalTime; … … 53 51 } 54 52 55 public CVRPTWInsertionInfo(int start, int end, double spareCapacity, double tourStartTime, double arrivalTime, double leaveTime, double spareTime, double waitingTime) 56 : base(start, end, spareCapacity) { 57 this.tourStartTime = tourStartTime; 53 public CVRPTWStopInsertionInfo(int start, int end, double distance, double spareCapacity, double arrivalTime, double leaveTime, double spareTime, double waitingTime) 54 : base(start, end, distance, spareCapacity) { 58 55 this.arrivalTime = arrivalTime; 59 56 this.leaveTime = leaveTime; 60 57 this.spareTime = spareTime; 61 58 this.waitingTime = waitingTime; 59 } 60 61 protected override void GetStopInsertionReport(StringBuilder builder) { 62 base.GetStopInsertionReport(builder); 63 builder.Append("SpareTime:\t"); 64 builder.AppendLine(SpareTime.ToString(CultureInfo.CurrentCulture)); 65 builder.Append("ArrivalTime:\t"); 66 builder.AppendLine(ArrivalTime.ToString(CultureInfo.CurrentCulture)); 67 builder.Append("WaitingTime:\t"); 68 builder.AppendLine(Math.Max(0, WaitingTime).ToString(CultureInfo.CurrentCulture)); 69 builder.Append("LeaveTime:\t"); 70 builder.AppendLine(LeaveTime.ToString(CultureInfo.CurrentCulture)); 71 } 72 } 73 74 public class CVRPTWTourInsertionInfo : CVRPTourInsertionInfo { 75 private double tourStartTime; 76 77 public double TourStartTime { 78 get { return tourStartTime; } 79 } 80 81 public CVRPTWTourInsertionInfo(int vehicle, double capacity, double tourStartTime) 82 : base(vehicle, capacity) { 83 this.tourStartTime = tourStartTime; 84 } 85 86 protected override void GetTourInsertionReport(StringBuilder builder) { 87 base.GetTourInsertionReport(builder); 88 builder.Append("Tour start:\t"); 89 builder.AppendLine(TourStartTime.ToString(CultureInfo.CurrentCulture)); 62 90 } 63 91 } … … 66 94 public double Tardiness { get; set; } 67 95 public double TravelTime { get; set; } 96 97 protected override void GetEvaluationReport(StringBuilder builder) { 98 base.GetEvaluationReport(builder); 99 builder.Append("TravelTime:\t"); 100 builder.AppendLine(TravelTime.ToString(CultureInfo.CurrentCulture)); 101 builder.Append("Tardiness:\t"); 102 builder.AppendLine(Tardiness.ToString(CultureInfo.CurrentCulture)); 103 } 68 104 } 69 105 } -
branches/OptimizationNetworks/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPTW/CVRPTWEvaluator.cs
r14185 r14677 46 46 47 47 protected override void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour, IVRPEncoding solution) { 48 TourInsertionInfo tourInfo = new TourInsertionInfo(solution.GetVehicleAssignment(solution.GetTourIndex(tour)));49 eval.InsertionInfo.AddTourInsertionInfo(tourInfo); 48 var cvrpInstance = (IHomogenousCapacitatedProblemInstance)instance; 49 50 50 double originalQuality = eval.Quality; 51 51 52 IHomogenousCapacitatedProblemInstance cvrpInstance = instance as IHomogenousCapacitatedProblemInstance;53 52 DoubleArray demand = instance.Demand; 54 53 55 ITimeWindowedProblemInstance vrptw = instance as ITimeWindowedProblemInstance;54 var vrptw = (ITimeWindowedProblemInstance)instance; 56 55 DoubleArray dueTime = vrptw.DueTime; 57 56 DoubleArray readyTime = vrptw.ReadyTime; … … 67 66 68 67 double capacity = cvrpInstance.Capacity.Value; 69 for (int i = 0; i <= tour.Stops.Count; i++) { 70 int end = 0; 71 if (i < tour.Stops.Count) 72 end = tour.Stops[i]; 73 74 delivered += demand[end]; 75 } 76 77 double spareCapacity = capacity - delivered; 78 68 79 69 double tourStartTime = readyTime[0]; 80 70 time = tourStartTime; 71 72 var tourInfo = new CVRPTWTourInsertionInfo(solution.GetVehicleAssignment(solution.GetTourIndex(tour)), cvrpInstance.Capacity.Value, tourStartTime); 73 eval.InsertionInfo.AddTourInsertionInfo(tourInfo); 81 74 82 75 //simulate a tour, start and end at depot … … 90 83 91 84 //drive there 92 double currentDistace = vrptw.GetDistance(start, end, solution); 93 time += currentDistace; 94 distance += currentDistace; 85 double currentDistance = vrptw.GetDistance(start, end, solution); 86 time += currentDistance; 87 distance += currentDistance; 88 delivered += demand[end]; 95 89 96 90 double arrivalTime = time; … … 117 111 time += currentServiceTime; 118 112 119 CVRPTWInsertionInfo stopInfo = new CVRPTWInsertionInfo(start, end, spareCapacity, tourStartTime, arrivalTime, time, spareTime, waitTime);113 var stopInfo = new CVRPTWStopInsertionInfo(start, end, currentDistance, capacity - delivered, arrivalTime, time, spareTime, waitTime); 120 114 tourInfo.AddStopInsertionInfo(stopInfo); 121 115 } … … 130 124 } 131 125 132 ( eval as CVRPEvaluation).Overload += overweight;126 ((CVRPEvaluation)eval).Overload += overweight; 133 127 double tourPenalty = 0; 134 128 double penalty = overweight * cvrpInstance.OverloadPenalty.Value; … … 151 145 protected override double GetTourInsertionCosts(IVRPProblemInstance instance, IVRPEncoding solution, TourInsertionInfo tourInsertionInfo, int index, int customer, 152 146 out bool feasible) { 153 CVRPTWInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index) as CVRPTWInsertionInfo; 147 var tourInfo = (CVRPTWTourInsertionInfo)tourInsertionInfo; 148 var insertionInfo = (CVRPTWStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(index); 154 149 155 150 double costs = 0; 156 151 feasible = tourInsertionInfo.Penalty < double.Epsilon; 157 152 158 ICapacitatedProblemInstance cvrp = instance as ICapacitatedProblemInstance;153 var cvrp = (ICapacitatedProblemInstance)instance; 159 154 double overloadPenalty = cvrp.OverloadPenalty.Value; 160 155 161 ITimeWindowedProblemInstance vrptw = instance as ITimeWindowedProblemInstance;156 var vrptw = (ITimeWindowedProblemInstance)instance; 162 157 DoubleArray dueTime = vrptw.DueTime; 163 158 DoubleArray readyTime = vrptw.ReadyTime; … … 172 167 173 168 double demand = instance.Demand[customer]; 174 if (demand > insertionInfo.SpareCapacity) {169 if (demand > tourInfo.SpareCapacity) { 175 170 feasible = false; 176 if ( insertionInfo.SpareCapacity >= 0)177 costs += (demand - insertionInfo.SpareCapacity) * overloadPenalty;171 if (tourInfo.SpareCapacity >= 0) 172 costs += (demand - tourInfo.SpareCapacity) * overloadPenalty; 178 173 else 179 174 costs += demand * overloadPenalty; … … 184 179 185 180 if (index > 0) 186 time = ( tourInsertionInfo.GetStopInsertionInfo(index - 1) as CVRPTWInsertionInfo).LeaveTime;181 time = ((CVRPTWStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(index - 1)).LeaveTime; 187 182 else 188 time = insertionInfo.TourStartTime;183 time = tourInfo.TourStartTime; 189 184 190 185 time += instance.GetDistance(insertionInfo.Start, customer, solution); … … 197 192 time += instance.GetDistance(customer, insertionInfo.End, solution); 198 193 199 double additionalTime = time - ( tourInsertionInfo.GetStopInsertionInfo(index) as CVRPTWInsertionInfo).ArrivalTime;194 double additionalTime = time - ((CVRPTWStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(index)).ArrivalTime; 200 195 for (int i = index; i < tourInsertionInfo.GetStopCount(); i++) { 201 CVRPTWInsertionInfo nextStop = tourInsertionInfo.GetStopInsertionInfo(i) as CVRPTWInsertionInfo;196 var nextStop = (CVRPTWStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(i); 202 197 203 198 if (additionalTime < 0) { … … 254 249 base.SetResultParameters(tourEvaluation); 255 250 256 TardinessParameter.ActualValue.Value = ( tourEvaluation as CVRPTWEvaluation).Tardiness;257 TravelTimeParameter.ActualValue.Value = ( tourEvaluation as CVRPTWEvaluation).TravelTime;251 TardinessParameter.ActualValue.Value = ((CVRPTWEvaluation)tourEvaluation).Tardiness; 252 TravelTimeParameter.ActualValue.Value = ((CVRPTWEvaluation)tourEvaluation).TravelTime; 258 253 } 259 254
Note: See TracChangeset
for help on using the changeset viewer.