Skip to content

Commit 11320d3

Browse files
committed
High level Setup Time
with multi Vehicle support
1 parent d5ca717 commit 11320d3

37 files changed

+437
-76
lines changed

jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/box/Jsprit.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,10 +623,15 @@ public double getCosts(VehicleRoutingProblemSolution solution) {
623623

624624
for (VehicleRoute route : solution.getRoutes()) {
625625
costs += route.getVehicle().getType().getVehicleCostParams().fix;
626+
double coef = 1.0;
627+
if(route.getVehicle() != null)
628+
coef = route.getVehicle().getCoefSetupTime();
626629
boolean hasBreak = false;
627630
TourActivity prevAct = route.getStart();
628631
for (TourActivity act : route.getActivities()) {
629632
if (act instanceof BreakActivity) hasBreak = true;
633+
if(!prevAct.getLocation().equals(act.getLocation()))
634+
costs += act.getSetupTime() * coef * route.getVehicle().getType().getVehicleCostParams().perTransportTimeUnit;
630635
costs += vrp.getTransportCosts().getTransportCost(prevAct.getLocation(), act.getLocation(), prevAct.getEndTime(), route.getDriver(), route.getVehicle());
631636
costs += vrp.getActivityCosts().getActivityCost(act, act.getArrTime(), route.getDriver(), route.getVehicle());
632637
prevAct = act;

jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/recreate/AuxilliaryCostCalculator.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ public double costOfPath(final List<TourActivity> path, final double depTime, fi
5050
if (path.isEmpty()) {
5151
return 0.0;
5252
}
53+
double coef = 1.0;
54+
if(vehicle != null)
55+
coef = vehicle.getCoefSetupTime();
5356
double cost = 0.0;
5457
Iterator<TourActivity> actIter = path.iterator();
5558
TourActivity prevAct = actIter.next();
@@ -63,8 +66,12 @@ public double costOfPath(final List<TourActivity> path, final double depTime, fi
6366
return cost;
6467
}
6568
}
66-
double transportCost = routingCosts.getTransportCost(prevAct.getLocation(), act.getLocation(), departureTimePrevAct, driver, vehicle);
67-
double transportTime = routingCosts.getTransportTime(prevAct.getLocation(), act.getLocation(), departureTimePrevAct, driver, vehicle);
69+
double setup_time_prevAct_act = 0.0;
70+
if(!prevAct.getLocation().equals(act.getLocation()))
71+
setup_time_prevAct_act = act.getSetupTime() * coef;
72+
double setupCost = setup_time_prevAct_act * vehicle.getType().getVehicleCostParams().perTransportTimeUnit;
73+
double transportCost = setupCost + routingCosts.getTransportCost(prevAct.getLocation(), act.getLocation(), departureTimePrevAct, driver, vehicle);
74+
double transportTime = setup_time_prevAct_act + routingCosts.getTransportTime(prevAct.getLocation(), act.getLocation(), departureTimePrevAct, driver, vehicle);
6875
cost += transportCost;
6976
double actStartTime = departureTimePrevAct + transportTime;
7077
departureTimePrevAct = Math.max(actStartTime, act.getTheoreticalEarliestOperationStartTime()) + activityCosts.getActivityDuration(act,actStartTime,driver,vehicle);

jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/recreate/BreakInsertionCalculator.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ public InsertionData getInsertionData(final VehicleRoute currentRoute, final Job
118118
*/
119119
double additionalICostsAtRouteLevel = softRouteConstraint.getCosts(insertionContext);
120120

121+
double coef = 1.0;
122+
if(newVehicle != null)
123+
coef = newVehicle.getCoefSetupTime();
124+
121125
double bestCost = bestKnownCosts;
122126
additionalICostsAtRouteLevel += additionalAccessEgressCalculator.getCosts(insertionContext);
123127

@@ -163,7 +167,11 @@ public InsertionData getInsertionData(final VehicleRoute currentRoute, final Job
163167
breakThis = false;
164168
}
165169
}
166-
double nextActArrTime = prevActStartTime + transportCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), prevActStartTime, newDriver, newVehicle);
170+
double setup_time_nextAct = 0.0;
171+
if(!prevAct.getLocation().equals(nextAct.getLocation()))
172+
setup_time_nextAct = nextAct.getSetupTime() * coef;
173+
double transportTime_prevAct_nextAct = setup_time_nextAct + transportCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), prevActStartTime, newDriver, newVehicle);
174+
double nextActArrTime = prevActStartTime + transportTime_prevAct_nextAct;
167175
prevActStartTime = Math.max(nextActArrTime, nextAct.getTheoreticalEarliestOperationStartTime()) + activityCosts.getActivityDuration(nextAct,nextActArrTime,newDriver,newVehicle);
168176
prevAct = nextAct;
169177
actIndex++;

jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/recreate/LocalActivityInsertionCostsCalculator.java

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,30 @@ public LocalActivityInsertionCostsCalculator(VehicleRoutingTransportCosts routin
5656

5757
@Override
5858
public double getCosts(JobInsertionContext iFacts, TourActivity prevAct, TourActivity nextAct, TourActivity newAct, double depTimeAtPrevAct) {
59+
double coef = 1.0;
60+
if(iFacts.getNewVehicle() != null)
61+
coef = iFacts.getNewVehicle().getCoefSetupTime();
62+
double setup_time_prevAct_newAct = 0.0;
63+
if(!prevAct.getLocation().equals(newAct.getLocation()))
64+
setup_time_prevAct_newAct = newAct.getSetupTime() * coef;
65+
double setup_cost_prevAct_newAct = setup_time_prevAct_newAct * iFacts.getNewVehicle().getType().getVehicleCostParams().perTransportTimeUnit;
66+
double tp_costs_prevAct_newAct = setup_cost_prevAct_newAct + routingCosts.getTransportCost(prevAct.getLocation(), newAct.getLocation(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
67+
double tp_time_prevAct_newAct = setup_time_prevAct_newAct + routingCosts.getTransportTime(prevAct.getLocation(), newAct.getLocation(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
5968

60-
double tp_costs_prevAct_newAct = routingCosts.getTransportCost(prevAct.getLocation(), newAct.getLocation(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
61-
double tp_time_prevAct_newAct = routingCosts.getTransportTime(prevAct.getLocation(), newAct.getLocation(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
6269
double newAct_arrTime = depTimeAtPrevAct + tp_time_prevAct_newAct;
6370
double newAct_endTime = Math.max(newAct_arrTime, newAct.getTheoreticalEarliestOperationStartTime()) + activityCosts.getActivityDuration(newAct, newAct_arrTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
6471

6572
double act_costs_newAct = activityCosts.getActivityCost(newAct, newAct_arrTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
6673

6774
if (isEnd(nextAct) && !toDepot(iFacts.getNewVehicle())) return tp_costs_prevAct_newAct;
6875

69-
double tp_costs_newAct_nextAct = routingCosts.getTransportCost(newAct.getLocation(), nextAct.getLocation(), newAct_endTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
70-
double tp_time_newAct_nextAct = routingCosts.getTransportTime(newAct.getLocation(), nextAct.getLocation(), newAct_endTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
76+
double setup_time_newAct_nextAct = 0.0;
77+
if(!newAct.getLocation().equals(nextAct.getLocation()))
78+
setup_time_newAct_nextAct = nextAct.getSetupTime() * coef;
79+
double setup_cost_newAct_nextAct = setup_time_newAct_nextAct * iFacts.getNewVehicle().getType().getVehicleCostParams().perTransportTimeUnit;
80+
double tp_costs_newAct_nextAct = setup_cost_newAct_nextAct + routingCosts.getTransportCost(newAct.getLocation(), nextAct.getLocation(), newAct_endTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
81+
double tp_time_newAct_nextAct = setup_time_newAct_nextAct + routingCosts.getTransportTime(newAct.getLocation(), nextAct.getLocation(), newAct_endTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
82+
7183
double nextAct_arrTime = newAct_endTime + tp_time_newAct_nextAct;
7284
double endTime_nextAct_new = Math.max(nextAct_arrTime, nextAct.getTheoreticalEarliestOperationStartTime()) + activityCosts.getActivityDuration(nextAct, newAct_arrTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
7385
double act_costs_nextAct = activityCosts.getActivityCost(nextAct, nextAct_arrTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
@@ -79,8 +91,14 @@ public double getCosts(JobInsertionContext iFacts, TourActivity prevAct, TourAct
7991
double tp_costs_prevAct_nextAct = routingCosts.getTransportCost(prevAct.getLocation(), nextAct.getLocation(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
8092
oldCosts += tp_costs_prevAct_nextAct;
8193
} else {
82-
double tp_costs_prevAct_nextAct = routingCosts.getTransportCost(prevAct.getLocation(), nextAct.getLocation(), prevAct.getEndTime(), iFacts.getRoute().getDriver(), iFacts.getRoute().getVehicle());
83-
double arrTime_nextAct = depTimeAtPrevAct + routingCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), prevAct.getEndTime(), iFacts.getRoute().getDriver(), iFacts.getRoute().getVehicle());
94+
double setup_time_prevAct_nextAct = 0.0;
95+
if(!prevAct.getLocation().equals(nextAct.getLocation()))
96+
setup_time_prevAct_nextAct = nextAct.getSetupTime() * coef;
97+
double setup_cost_prevAct_nextAct = setup_time_prevAct_nextAct * iFacts.getNewVehicle().getType().getVehicleCostParams().perTransportTimeUnit;
98+
double tp_costs_prevAct_nextAct = setup_cost_prevAct_nextAct + routingCosts.getTransportCost(prevAct.getLocation(), nextAct.getLocation(), prevAct.getEndTime(), iFacts.getRoute().getDriver(), iFacts.getRoute().getVehicle());
99+
double tp_time_prevAct_nextAct = setup_time_prevAct_nextAct + routingCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), prevAct.getEndTime(), iFacts.getRoute().getDriver(), iFacts.getRoute().getVehicle());
100+
101+
double arrTime_nextAct = depTimeAtPrevAct + tp_time_prevAct_nextAct;
84102
double endTime_nextAct_old = Math.max(arrTime_nextAct, nextAct.getTheoreticalEarliestOperationStartTime()) + activityCosts.getActivityDuration(nextAct, nextAct_arrTime, iFacts.getRoute().getDriver(),iFacts.getRoute().getVehicle());
85103
double actCost_nextAct = activityCosts.getActivityCost(nextAct, arrTime_nextAct, iFacts.getRoute().getDriver(), iFacts.getRoute().getVehicle());
86104

jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/recreate/ServiceInsertionCalculator.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ public InsertionData getInsertionData(final VehicleRoute currentRoute, final Job
111111
*/
112112
double additionalICostsAtRouteLevel = softRouteConstraint.getCosts(insertionContext);
113113

114+
double coef = 1.0;
115+
if(newVehicle != null)
116+
coef = newVehicle.getCoefSetupTime();
117+
114118
double bestCost = bestKnownCosts;
115119
additionalICostsAtRouteLevel += additionalAccessEgressCalculator.getCosts(insertionContext);
116120
TimeWindow bestTimeWindow = null;
@@ -156,7 +160,11 @@ public InsertionData getInsertionData(final VehicleRoute currentRoute, final Job
156160
}
157161
}
158162
if(not_fulfilled_break) break;
159-
double nextActArrTime = prevActStartTime + transportCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), prevActStartTime, newDriver, newVehicle);
163+
double setup_time_nextAct = 0.0;
164+
if(!prevAct.getLocation().equals(nextAct.getLocation()))
165+
setup_time_nextAct = nextAct.getSetupTime() * coef;
166+
double transportTime_prevAct_nextAct = setup_time_nextAct + transportCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), prevActStartTime, newDriver, newVehicle);
167+
double nextActArrTime = prevActStartTime + transportTime_prevAct_nextAct;
160168
prevActStartTime = Math.max(nextActArrTime, nextAct.getTheoreticalEarliestOperationStartTime()) + activityCosts.getActivityDuration(nextAct,nextActArrTime,newDriver,newVehicle);
161169
prevAct = nextAct;
162170
actIndex++;

jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/recreate/ServiceInsertionOnRouteLevelCalculator.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ public InsertionData getInsertionData(final VehicleRoute currentRoute, final Job
140140
double best_insertion_costs = best_known_insertion_costs;
141141
Service service = (Service) jobToInsert;
142142

143+
double coef = 1.0;
144+
if(newVehicle != null)
145+
coef = newVehicle.getCoefSetupTime();
143146

144147
/**
145148
* some inis
@@ -189,8 +192,13 @@ public InsertionData getInsertionData(final VehicleRoute currentRoute, final Job
189192
/**
190193
* calculate transport and activity costs with new vehicle (without inserting k)
191194
*/
192-
double transportCost_prevAct_nextAct_newVehicle = transportCosts.getTransportCost(prevAct.getLocation(), nextAct.getLocation(), prevActDepTime_newVehicle, newDriver, newVehicle);
193-
double transportTime_prevAct_nextAct_newVehicle = transportCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), prevActDepTime_newVehicle, newDriver, newVehicle);
195+
double setup_time_prevAct_nextAct_newVehicle = 0.0;
196+
if(!prevAct.getLocation().equals(nextAct.getLocation()))
197+
setup_time_prevAct_nextAct_newVehicle = nextAct.getSetupTime() * coef;
198+
double setup_cost_prevAct_nextAct_newVehicle = setup_time_prevAct_nextAct_newVehicle * newVehicle.getType().getVehicleCostParams().perTransportTimeUnit;
199+
double transportCost_prevAct_nextAct_newVehicle = setup_cost_prevAct_nextAct_newVehicle + transportCosts.getTransportCost(prevAct.getLocation(), nextAct.getLocation(), prevActDepTime_newVehicle, newDriver, newVehicle);
200+
double transportTime_prevAct_nextAct_newVehicle = setup_time_prevAct_nextAct_newVehicle + transportCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), prevActDepTime_newVehicle, newDriver, newVehicle);
201+
194202
double arrTime_nextAct_newVehicle = prevActDepTime_newVehicle + transportTime_prevAct_nextAct_newVehicle;
195203
double activityCost_nextAct = activityCosts.getActivityCost(nextAct, arrTime_nextAct_newVehicle, newDriver, newVehicle);
196204

jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/recreate/ShipmentInsertionCalculator.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ public InsertionData getInsertionData(final VehicleRoute currentRoute, final Job
106106
*/
107107
double additionalICostsAtRouteLevel = softRouteConstraint.getCosts(insertionContext);
108108

109+
double coef = 1.0;
110+
if(newVehicle != null)
111+
coef = newVehicle.getCoefSetupTime();
112+
109113
double bestCost = bestKnownCosts;
110114
additionalICostsAtRouteLevel += additionalAccessEgressCalculator.getCosts(insertionContext);
111115

@@ -161,7 +165,13 @@ else if (pickupShipmentConstraintStatus.equals(ConstraintsStatus.FULFILLED)) {
161165
double pickupAIC = calculate(insertionContext, prevAct, pickupShipment, nextAct, prevActEndTime);
162166

163167
TourActivity prevAct_deliveryLoop = pickupShipment;
164-
double shipmentPickupArrTime = prevActEndTime + transportCosts.getTransportTime(prevAct.getLocation(), pickupShipment.getLocation(), prevActEndTime, newDriver, newVehicle);
168+
169+
double shipmentPickupSetupTime = 0.0;
170+
if(!prevAct.getLocation().equals(pickupShipment.getLocation()))
171+
shipmentPickupSetupTime = pickupShipment.getSetupTime() * coef;
172+
double transportTime_prevAct_pickupShipment = shipmentPickupSetupTime + transportCosts.getTransportTime(prevAct.getLocation(), pickupShipment.getLocation(), prevActEndTime, newDriver, newVehicle);
173+
174+
double shipmentPickupArrTime = prevActEndTime + transportTime_prevAct_pickupShipment;
165175
double shipmentPickupEndTime = Math.max(shipmentPickupArrTime, pickupShipment.getTheoreticalEarliestOperationStartTime()) + activityCosts.getActivityDuration(pickupShipment, shipmentPickupArrTime, newDriver, newVehicle);
166176

167177
pickupContext.setArrivalTime(shipmentPickupArrTime);
@@ -213,7 +223,11 @@ else if (pickupShipmentConstraintStatus.equals(ConstraintsStatus.FULFILLED)) {
213223
}
214224
if (deliveryInsertionNotFulfilledBreak) break;
215225
//update prevAct and endTime
216-
double nextActArrTime = prevActEndTime_deliveryLoop + transportCosts.getTransportTime(prevAct_deliveryLoop.getLocation(), nextAct_deliveryLoop.getLocation(), prevActEndTime_deliveryLoop, newDriver, newVehicle);
226+
double setupTime_prevActdLoop_nextAct_dLoop = 0.0;
227+
if(!prevAct_deliveryLoop.getLocation().equals(nextAct_deliveryLoop.getLocation()))
228+
setupTime_prevActdLoop_nextAct_dLoop = nextAct_deliveryLoop.getSetupTime() * coef;
229+
double transportTime_prevActdLoop_nextActdLoop = setupTime_prevActdLoop_nextAct_dLoop + transportCosts.getTransportTime(prevAct_deliveryLoop.getLocation(), nextAct_deliveryLoop.getLocation(), prevActEndTime_deliveryLoop, newDriver, newVehicle);
230+
double nextActArrTime = prevActEndTime_deliveryLoop + transportTime_prevActdLoop_nextActdLoop;
217231
prevActEndTime_deliveryLoop = Math.max(nextActArrTime, nextAct_deliveryLoop.getTheoreticalEarliestOperationStartTime()) + activityCosts.getActivityDuration(nextAct_deliveryLoop,nextActArrTime,newDriver,newVehicle);
218232
prevAct_deliveryLoop = nextAct_deliveryLoop;
219233
j++;
@@ -223,7 +237,11 @@ else if (pickupShipmentConstraintStatus.equals(ConstraintsStatus.FULFILLED)) {
223237
break;
224238
}
225239
//update prevAct and endTime
226-
double nextActArrTime = prevActEndTime + transportCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), prevActEndTime, newDriver, newVehicle);
240+
double setupTime_prevAct_nextAct = 0.0;
241+
if(!prevAct.getLocation().equals(nextAct.getLocation()))
242+
setupTime_prevAct_nextAct = nextAct.getSetupTime() * coef;
243+
double transportTime_prevAct_nextAct = setupTime_prevAct_nextAct + transportCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), prevActEndTime, newDriver, newVehicle);
244+
double nextActArrTime = prevActEndTime + transportTime_prevAct_nextAct;
227245
prevActEndTime = Math.max(nextActArrTime, nextAct.getTheoreticalEarliestOperationStartTime()) + activityCosts.getActivityDuration(nextAct,nextActArrTime,newDriver,newVehicle);
228246
prevAct = nextAct;
229247
i++;

0 commit comments

Comments
 (0)