Changeset 14677 for branches/OptimizationNetworks/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/MultiDepotVRP/MDCVRP/MDCVRPTW
- Timestamp:
- 02/16/17 15:16:55 (8 years ago)
- Location:
- branches/OptimizationNetworks/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/MultiDepotVRP/MDCVRP/MDCVRPTW
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OptimizationNetworks/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/MultiDepotVRP/MDCVRP/MDCVRPTW/MDCVRPPDTW/MDCVRPPDTWEvaluator.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);47 45 double originalQuality = eval.Quality; 48 46 49 IHeterogenousCapacitatedProblemInstance cvrpInstance = instance as IHeterogenousCapacitatedProblemInstance;47 var cvrpInstance = (IHeterogenousCapacitatedProblemInstance)instance; 50 48 DoubleArray demand = instance.Demand; 51 49 52 ITimeWindowedProblemInstance vrptw = instance as ITimeWindowedProblemInstance;50 var vrptw = (ITimeWindowedProblemInstance)instance; 53 51 DoubleArray dueTime = vrptw.DueTime; 54 52 DoubleArray readyTime = vrptw.ReadyTime; 55 53 DoubleArray serviceTimes = vrptw.ServiceTime; 56 54 57 IPickupAndDeliveryProblemInstance pdp = instance as IPickupAndDeliveryProblemInstance;55 var pdp = (IPickupAndDeliveryProblemInstance)instance; 58 56 IntArray pickupDeliveryLocation = pdp.PickupDeliveryLocation; 59 57 60 IMultiDepotProblemInstance mdp = instance as IMultiDepotProblemInstance;58 var mdp = (IMultiDepotProblemInstance)instance; 61 59 IntArray vehicleAssignment = mdp.VehicleDepotAssignment; 62 60 int depots = mdp.Depots.Value; … … 81 79 double tourStartTime = readyTime[0]; 82 80 time = tourStartTime; 81 82 var tourInfo = new CVRPTWTourInsertionInfo(solution.GetVehicleAssignment(solution.GetTourIndex(tour)), capacity, tourStartTime); 83 eval.InsertionInfo.AddTourInsertionInfo(tourInfo); 83 84 84 85 //simulate a tour, start and end at depot … … 92 93 93 94 //drive there 94 double currentDista ce = vrptw.GetDistance(start, end, solution);95 time += currentDista ce;96 distance += currentDista ce;95 double currentDistance = vrptw.GetDistance(start, end, solution); 96 time += currentDistance; 97 distance += currentDistance; 97 98 98 99 double arrivalTime = time; … … 129 130 //Pickup / deliver 130 131 bool validPickupDelivery = 131 validPickupDelivery =132 132 ((demand[end - 1] >= 0) || 133 133 (stops.ContainsKey(pickupDeliveryLocation[end - 1]))); … … 144 144 145 145 double spareCapacity = capacity - currentLoad; 146 CVRPPDTWInsertionInfo stopInfo = new CVRPPDTWInsertionInfo(start, end, spareCapacity, tourStartTime,146 var stopInfo = new CVRPPDTWStopInsertionInfo(start, end, currentDistance, spareCapacity, 147 147 arrivalTime, time, spareTime, waitTime, new List<int>(stops.Keys), arrivalSpareCapacity); 148 148 tourInfo.AddStopInsertionInfo(stopInfo); … … 156 156 eval.VehicleUtilization += 1; 157 157 158 ( eval as CVRPEvaluation).Overload += overweight;158 ((CVRPEvaluation)eval).Overload += overweight; 159 159 double tourPenalty = 0; 160 160 double penalty = overweight * cvrpInstance.OverloadPenalty.Value; … … 163 163 tourPenalty += penalty; 164 164 165 ( eval as CVRPTWEvaluation).Tardiness += tardiness;165 ((CVRPTWEvaluation)eval).Tardiness += tardiness; 166 166 (eval as CVRPTWEvaluation).TravelTime += time; 167 167 … … 171 171 tourPenalty += penalty; 172 172 173 ( eval as CVRPPDTWEvaluation).PickupViolations += pickupViolations;173 ((CVRPPDTWEvaluation)eval).PickupViolations += pickupViolations; 174 174 penalty = pickupViolations * pdp.PickupViolationPenalty.Value; 175 175 eval.Penalty += penalty; … … 184 184 protected override double GetTourInsertionCosts(IVRPProblemInstance instance, IVRPEncoding solution, TourInsertionInfo tourInsertionInfo, int index, int customer, 185 185 out bool feasible) { 186 CVRPPDTWInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index) as CVRPPDTWInsertionInfo; 186 var tourInfo = (CVRPTWTourInsertionInfo)tourInsertionInfo; 187 var insertionInfo = (CVRPPDTWStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(index); 187 188 188 189 double costs = 0; … … 230 231 231 232 if (index > 0) 232 time = ( tourInsertionInfo.GetStopInsertionInfo(index - 1) as CVRPTWInsertionInfo).LeaveTime;233 time = ((CVRPTWStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(index - 1)).LeaveTime; 233 234 else 234 time = insertionInfo.TourStartTime;235 time = tourInfo.TourStartTime; 235 236 236 237 time += startDistance; … … 246 247 time += endDistance; 247 248 248 double additionalTime = time - ( tourInsertionInfo.GetStopInsertionInfo(index) as CVRPTWInsertionInfo).ArrivalTime;249 double additionalTime = time - ((CVRPTWStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(index)).ArrivalTime; 249 250 for (int i = index; i < tourInsertionInfo.GetStopCount(); i++) { 250 CVRPTWInsertionInfo nextStop = tourInsertionInfo.GetStopInsertionInfo(i) as CVRPTWInsertionInfo;251 var nextStop = (CVRPTWStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(i); 251 252 252 253 if (demand >= 0) { -
branches/OptimizationNetworks/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/MultiDepotVRP/MDCVRP/MDCVRPTW/MDCVRPTWEvaluator.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);50 48 double originalQuality = eval.Quality; 51 49 52 IHeterogenousCapacitatedProblemInstance cvrpInstance = instance as IHeterogenousCapacitatedProblemInstance;50 var cvrpInstance = (IHeterogenousCapacitatedProblemInstance)instance; 53 51 DoubleArray demand = instance.Demand; 54 55 ITimeWindowedProblemInstance vrptw = instance as ITimeWindowedProblemInstance;52 53 var vrptw = (ITimeWindowedProblemInstance)instance; 56 54 DoubleArray dueTime = vrptw.DueTime; 57 55 DoubleArray readyTime = vrptw.ReadyTime; 58 56 DoubleArray serviceTimes = vrptw.ServiceTime; 59 57 60 IMultiDepotProblemInstance mdp = instance as IMultiDepotProblemInstance;58 var mdp = (IMultiDepotProblemInstance)instance; 61 59 IntArray vehicleAssignment = mdp.VehicleDepotAssignment; 62 60 int depots = mdp.Depots.Value; … … 75 73 76 74 double capacity = cvrpInstance.Capacity[vehicle]; 77 for (int i = 0; i < tour.Stops.Count; i++) {78 delivered += instance.GetDemand(tour.Stops[i]);79 }80 81 double spareCapacity = capacity - delivered;82 75 83 76 double tourStartTime = vrptw.ReadyTime[depot]; 84 77 time = tourStartTime; 78 79 var tourInfo = new CVRPTWTourInsertionInfo(solution.GetVehicleAssignment(solution.GetTourIndex(tour)), capacity, tourStartTime); 80 eval.InsertionInfo.AddTourInsertionInfo(tourInfo); 85 81 86 82 //simulate a tour, start and end at depot … … 90 86 start = tour.Stops[i - 1]; 91 87 int end = 0; 92 if (i < tour.Stops.Count) 88 if (i < tour.Stops.Count) { 93 89 end = tour.Stops[i]; 90 delivered += instance.GetDemand(end); 91 } 94 92 95 93 //drive there 96 double currentDista ce = vrptw.GetDistance(start, end, solution);97 time += currentDista ce;98 distance += currentDista ce;94 double currentDistance = vrptw.GetDistance(start, end, solution); 95 time += currentDistance; 96 distance += currentDistance; 99 97 100 98 double arrivalTime = time; … … 129 127 time += currentServiceTime; 130 128 131 CVRPTWInsertionInfo stopInfo = new CVRPTWInsertionInfo(start, end, spareCapacity, tourStartTime, arrivalTime, time, spareTime, waitTime);129 var stopInfo = new CVRPTWStopInsertionInfo(start, end, currentDistance, capacity - delivered, arrivalTime, time, spareTime, waitTime); 132 130 tourInfo.AddStopInsertionInfo(stopInfo); 133 131 } … … 142 140 } 143 141 144 ( eval as CVRPEvaluation).Overload += overweight;142 ((CVRPEvaluation)eval).Overload += overweight; 145 143 double tourPenalty = 0; 146 144 double penalty = overweight * cvrpInstance.OverloadPenalty.Value; … … 149 147 tourPenalty += penalty; 150 148 151 ( eval as CVRPTWEvaluation).Tardiness += tardiness;152 ( eval as CVRPTWEvaluation).TravelTime += time;149 ((CVRPTWEvaluation)eval).Tardiness += tardiness; 150 ((CVRPTWEvaluation)eval).TravelTime += time; 153 151 154 152 penalty = tardiness * vrptw.TardinessPenalty.Value; … … 163 161 protected override double GetTourInsertionCosts(IVRPProblemInstance instance, IVRPEncoding solution, TourInsertionInfo tourInsertionInfo, int index, int customer, 164 162 out bool feasible) { 165 CVRPTWInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index) as CVRPTWInsertionInfo; 163 var tourInfo = (CVRPTWTourInsertionInfo)tourInsertionInfo; 164 var insertionInfo = (CVRPTWStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(index); 166 165 167 166 double costs = 0; 168 167 feasible = tourInsertionInfo.Penalty < double.Epsilon; 169 168 170 ICapacitatedProblemInstance cvrp = instance as ICapacitatedProblemInstance;169 var cvrp = (ICapacitatedProblemInstance)instance; 171 170 double overloadPenalty = cvrp.OverloadPenalty.Value; 172 171 173 ITimeWindowedProblemInstance vrptw = instance as ITimeWindowedProblemInstance;172 var vrptw = (ITimeWindowedProblemInstance)instance; 174 173 DoubleArray dueTime = vrptw.DueTime; 175 174 DoubleArray readyTime = vrptw.ReadyTime; … … 177 176 double tardinessPenalty = vrptw.TardinessPenalty.Value; 178 177 179 IMultiDepotProblemInstance mdp = instance as IMultiDepotProblemInstance;178 var mdp = (IMultiDepotProblemInstance)instance; 180 179 int depots = mdp.Depots.Value; 181 180 … … 184 183 185 184 double demand = instance.GetDemand(customer); 186 if (demand > insertionInfo.SpareCapacity) {185 if (demand > tourInfo.SpareCapacity) { 187 186 feasible = false; 188 187 189 if ( insertionInfo.SpareCapacity >= 0)190 costs += (demand - insertionInfo.SpareCapacity) * overloadPenalty;188 if (tourInfo.SpareCapacity >= 0) 189 costs += (demand - tourInfo.SpareCapacity) * overloadPenalty; 191 190 else 192 191 costs += demand * overloadPenalty; … … 197 196 198 197 if (index > 0) 199 time = ( tourInsertionInfo.GetStopInsertionInfo(index - 1) as CVRPTWInsertionInfo).LeaveTime;198 time = ((CVRPTWStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(index - 1)).LeaveTime; 200 199 else 201 time = insertionInfo.TourStartTime;200 time = tourInfo.TourStartTime; 202 201 203 202 time += startDistance; … … 213 212 time += endDistance; 214 213 215 double additionalTime = time - ( tourInsertionInfo.GetStopInsertionInfo(index) as CVRPTWInsertionInfo).ArrivalTime;214 double additionalTime = time - ((CVRPTWStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(index)).ArrivalTime; 216 215 for (int i = index; i < tourInsertionInfo.GetStopCount(); i++) { 217 CVRPTWInsertionInfo nextStop = tourInsertionInfo.GetStopInsertionInfo(i) as CVRPTWInsertionInfo;216 var nextStop = (CVRPTWStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(i); 218 217 219 218 if (additionalTime < 0) { … … 270 269 base.SetResultParameters(tourEvaluation); 271 270 272 TardinessParameter.ActualValue.Value = ( tourEvaluation as CVRPTWEvaluation).Tardiness;273 TravelTimeParameter.ActualValue.Value = ( tourEvaluation as CVRPTWEvaluation).TravelTime;271 TardinessParameter.ActualValue.Value = ((CVRPTWEvaluation)tourEvaluation).Tardiness; 272 TravelTimeParameter.ActualValue.Value = ((CVRPTWEvaluation)tourEvaluation).TravelTime; 274 273 } 275 274
Note: See TracChangeset
for help on using the changeset viewer.