Changeset 6752 for branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPTW/CVRPPDTW/CVRPPDTWEvaluator.cs
- Timestamp:
- 09/13/11 16:00:19 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPTW/CVRPPDTW/CVRPPDTWEvaluator.cs
r6710 r6752 48 48 49 49 protected override void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour) { 50 TourInsertionInfo tourInfo = new TourInsertionInfo(); 51 eval.InsertionInfo.AddTourInsertionInfo(tourInfo); 52 50 53 IHomogenousCapacitatedProblemInstance cvrpInstance = instance as IHomogenousCapacitatedProblemInstance; 51 54 DoubleArray demand = instance.Demand; … … 86 89 distance += currentDistace; 87 90 91 double arrivalTime = time; 92 88 93 //check if it was serviced on time 89 94 if (time > dueTime[end]) … … 94 99 if (time < readyTime[end]) 95 100 currentWaitingTime = readyTime[end] - time; 101 102 double waitTime = readyTime[end] - time; 103 96 104 waitingTime += currentWaitingTime; 97 105 time += currentWaitingTime; 106 107 double spareTime = dueTime[end] - time; 98 108 99 109 //service … … 103 113 104 114 //Pickup / deliver 115 double arrivalSpareCapacity = capacity - currentLoad; 116 105 117 bool validPickupDelivery = 106 118 validPickupDelivery = … … 110 122 if (validPickupDelivery) { 111 123 currentLoad += demand[end]; 112 113 if (currentLoad > capacity)114 overweight += currentLoad - capacity;115 124 } else { 116 125 pickupViolations++; 117 126 } 127 128 if (currentLoad > capacity) 129 overweight += currentLoad - capacity; 130 131 double spareCapacity = capacity - currentLoad; 132 CVRPPDTWInsertionInfo stopInfo = new CVRPPDTWInsertionInfo(start, end, spareCapacity, arrivalTime, time, spareTime, waitTime, new List<int>(stops.Keys), arrivalSpareCapacity); 133 tourInfo.AddStopInsertionInfo(stopInfo); 118 134 119 135 stops.Add(end, true); … … 126 142 127 143 (eval as CVRPEvaluation).Overload += overweight; 144 double tourPenalty = 0; 128 145 double penalty = overweight * cvrpInstance.OverloadPenalty.Value; 129 146 eval.Penalty += penalty; 130 147 eval.Quality += penalty; 148 tourPenalty += penalty; 131 149 132 150 (eval as CVRPTWEvaluation).Tardiness += tardiness; … … 136 154 eval.Penalty += penalty; 137 155 eval.Quality += penalty; 156 tourPenalty += penalty; 138 157 139 158 (eval as CVRPPDTWEvaluation).PickupViolations += pickupViolations; 140 159 penalty = pickupViolations * pdp.PickupViolationPenalty.Value; 141 160 eval.Penalty += penalty; 161 tourPenalty += penalty; 142 162 143 163 eval.Quality += penalty; 144 164 eval.Quality += time * vrptw.TimeFactor.Value; 165 tourInfo.Penalty = tourPenalty; 166 } 167 168 protected override double GetTourInsertionCosts(IVRPProblemInstance instance, TourInsertionInfo tourInsertionInfo, int index, int customer, 169 out bool feasible) { 170 CVRPPDTWInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index) as CVRPPDTWInsertionInfo; 171 172 double costs = 0; 173 feasible = tourInsertionInfo.Penalty < double.Epsilon; 174 bool tourFeasible = true; 175 176 ICapacitatedProblemInstance cvrp = instance as ICapacitatedProblemInstance; 177 double overloadPenalty = cvrp.OverloadPenalty.Value; 178 179 ITimeWindowedProblemInstance vrptw = instance as ITimeWindowedProblemInstance; 180 DoubleArray dueTime = vrptw.DueTime; 181 DoubleArray readyTime = vrptw.ReadyTime; 182 DoubleArray serviceTimes = vrptw.ServiceTime; 183 double tardinessPenalty = vrptw.TardinessPenalty.Value; 184 185 IPickupAndDeliveryProblemInstance pdp = instance as IPickupAndDeliveryProblemInstance; 186 IntArray pickupDeliveryLocation = pdp.PickupDeliveryLocation; 187 double pickupPenalty = pdp.PickupViolationPenalty.Value; 188 189 double distance = instance.GetDistance(insertionInfo.Start, insertionInfo.End); 190 double newDistance = 191 instance.GetDistance(insertionInfo.Start, customer) + 192 instance.GetDistance(customer, insertionInfo.End); 193 costs += instance.DistanceFactor.Value * (newDistance - distance); 194 195 double demand = instance.Demand[customer]; 196 if (demand > insertionInfo.ArrivalSpareCapacity) { 197 tourFeasible = feasible = false; 198 if (insertionInfo.ArrivalSpareCapacity >= 0) 199 costs += (demand - insertionInfo.ArrivalSpareCapacity) * overloadPenalty; 200 else 201 costs += demand * overloadPenalty; 202 } 203 int destination = pickupDeliveryLocation[customer]; 204 205 bool validPickup = true; 206 if (demand < 0 && !insertionInfo.Visited.Contains(destination)) { 207 tourFeasible = feasible = false; 208 validPickup = false; 209 costs += pickupPenalty; 210 } 211 212 double time = 0; 213 double tardiness = 0; 214 215 if (index > 0) 216 time = (tourInsertionInfo.GetStopInsertionInfo(index - 1) as CVRPTWInsertionInfo).LeaveTime; 217 time += instance.GetDistance(insertionInfo.Start, customer); 218 if (time > dueTime[customer]) { 219 tardiness += time - dueTime[customer]; 220 } 221 if (time < readyTime[customer]) 222 time += readyTime[customer] - time; 223 time += serviceTimes[customer]; 224 time += instance.GetDistance(customer, insertionInfo.End); 225 226 double additionalTime = time - (tourInsertionInfo.GetStopInsertionInfo(index) as CVRPTWInsertionInfo).ArrivalTime; 227 for (int i = index; i < tourInsertionInfo.GetStopCount(); i++) { 228 CVRPTWInsertionInfo nextStop = tourInsertionInfo.GetStopInsertionInfo(i) as CVRPTWInsertionInfo; 229 230 if (demand >= 0) { 231 if (nextStop.End == destination) { 232 demand = 0; 233 costs -= pickupPenalty; 234 if (tourInsertionInfo.Penalty == pickupPenalty && tourFeasible) 235 feasible = true; 236 } else if (nextStop.SpareCapacity < 0) { 237 costs += demand * overloadPenalty; 238 } else if (nextStop.SpareCapacity < demand) { 239 tourFeasible = feasible = false; 240 costs += (demand - nextStop.SpareCapacity) * overloadPenalty; 241 } 242 } else if (validPickup) { 243 if (nextStop.SpareCapacity < 0) { 244 costs += Math.Max(demand, nextStop.SpareCapacity) * overloadPenalty; 245 } 246 } 247 248 if (additionalTime < 0) { 249 //arrive earlier than before 250 //wait probably 251 if (nextStop.WaitingTime < 0) { 252 double wait = nextStop.WaitingTime - additionalTime; 253 if (wait > 0) 254 additionalTime += wait; 255 } else { 256 additionalTime = 0; 257 } 258 259 //check due date, decrease tardiness 260 if (nextStop.SpareTime < 0) { 261 costs += Math.Max(nextStop.SpareTime, additionalTime) * tardinessPenalty; 262 } 263 } else { 264 //arrive later than before, probably don't have to wait 265 if (nextStop.WaitingTime > 0) { 266 additionalTime -= Math.Min(additionalTime, nextStop.WaitingTime); 267 } 268 269 //check due date 270 if (nextStop.SpareTime > 0) { 271 double spare = nextStop.SpareTime - additionalTime; 272 if (spare < 0) 273 tardiness += -spare; 274 } else { 275 tardiness += additionalTime; 276 } 277 } 278 } 279 280 costs += additionalTime * vrptw.TimeFactor.Value; 281 282 if (tardiness > 0) { 283 tourFeasible = feasible = false; 284 } 285 286 costs += tardiness * tardinessPenalty; 287 288 return costs; 145 289 } 146 290
Note: See TracChangeset
for help on using the changeset viewer.