Changeset 14677 for branches/OptimizationNetworks/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPTW/CVRPPDTW/CVRPPDTWEvaluator.cs
- Timestamp:
- 02/16/17 15:16:55 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note: See TracChangeset
for help on using the changeset viewer.