diff --git a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/VehicleRoute.java b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/VehicleRoute.java index e1c3083f..835458a6 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/VehicleRoute.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/VehicleRoute.java @@ -372,19 +372,52 @@ public class VehicleRoute { } /** - * Sets the vehicle and its departureTime. + * Sets the vehicle and its departureTime from vehicle.getStartLocationId(). * *

This implies the following:
* if start and end are null, new start and end activities are created.
- *

startActivity is initialized with the location of the specified vehicle. the time-window of this activity is initialized - * as follows: [time-window.start = vehicle.getEarliestDeparture()][time-window.end = vehicle.getLatestArrival()] - *

endActivity is initialized with the location of the specified vehicle as well. time-window of this activity:[time-window.start = vehicle.getEarliestDeparture()][time-window.end = vehicle.getLatestArrival()] - *

start.endTime is set to the specified departureTime - *

Note that start end end-locations are always initialized with the location of the specified vehicle. (this will change soon, then there will be start and end location of vehicle which can be different, 23.01.14) + *

startActivity is initialized with the start-location of the specified vehicle (vehicle.getStartLocationId()). the time-window of this activity is initialized + * such that [startActivity.getTheoreticalEarliestOperationStartTime() = vehicle.getEarliestDeparture()][startActivity.getTheoreticalLatestOperationStartTime() = vehicle.getLatestArrival()] + *

endActivity is initialized with the end-location of the specified vehicle (vehicle.getEndLocationId()). The time-window of the + * endActivity is initialized such that [endActivity.getTheoreticalEarliestOperationStartTime() = vehicle.getEarliestDeparture()][endActivity.getTheoreticalLatestOperationStartTime() = vehicle.getLatestArrival()] + *

startActivity.endTime (startActivity.getEndTime()) is set to max{vehicle.getEarliestDeparture(), vehicleDepTime}. + * thus, vehicle.getEarliestDeparture() is a physical constraint that has to be met. * * @param vehicle * @param vehicleDepTime */ + public void setVehicleAndDepartureTime(Vehicle vehicle, double vehicleDepTime){ + this.vehicle = vehicle; + if(start == null && end == null){ + start = Start.newInstance(vehicle.getStartLocationId(), vehicle.getEarliestDeparture(), vehicle.getLatestArrival()); + end = End.newInstance(vehicle.getEndLocationId(), vehicle.getEarliestDeparture(), vehicle.getLatestArrival()); + } + start.setEndTime(Math.max(vehicleDepTime, vehicle.getEarliestDeparture())); + start.setTheoreticalEarliestOperationStartTime(vehicle.getEarliestDeparture()); + start.setTheoreticalLatestOperationStartTime(vehicle.getLatestArrival()); + start.setLocationId(vehicle.getLocationId()); + end.setLocationId(vehicle.getLocationId()); + end.setTheoreticalEarliestOperationStartTime(vehicle.getEarliestDeparture()); + end.setTheoreticalLatestOperationStartTime(vehicle.getLatestArrival()); + } + + /** + * Sets the vehicle and its departureTime from vehicle.getStartLocationId(). + * + *

This implies the following:
+ * if start and end are null, new start and end activities are created.
+ *

startActivity is initialized with the start-location of the specified vehicle (vehicle.getStartLocationId()). the time-window of this activity is initialized + * such that [startActivity.getTheoreticalEarliestOperationStartTime() = vehicle.getEarliestDeparture()][startActivity.getTheoreticalLatestOperationStartTime() = vehicle.getLatestArrival()] + *

endActivity is initialized with the end-location of the specified vehicle (vehicle.getEndLocationId()). The time-window of the + * endActivity is initialized such that [endActivity.getTheoreticalEarliestOperationStartTime() = vehicle.getEarliestDeparture()][endActivity.getTheoreticalLatestOperationStartTime() = vehicle.getLatestArrival()] + *

startActivity.endTime (startActivity.getEndTime()) is set to max{vehicle.getEarliestDeparture(), vehicleDepTime}. + * thus, vehicle.getEarliestDeparture() is a physical constraint that has to be met. + * + * @param vehicle + * @param vehicleDepTime + * @deprecated use .setVehicleAndDepartureTime(Vehicle vehicle, double vehicleDepTime) instead + */ + @Deprecated public void setVehicle(Vehicle vehicle, double vehicleDepTime){ this.vehicle = vehicle; setStartAndEnd(vehicle, vehicleDepTime); @@ -393,14 +426,14 @@ public class VehicleRoute { private void setStartAndEnd(Vehicle vehicle, double vehicleDepTime) { if(!(vehicle instanceof NoVehicle)){ if(start == null && end == null){ - start = Start.newInstance(vehicle.getLocationId(), vehicle.getEarliestDeparture(), vehicle.getLatestArrival()); - end = End.newInstance(vehicle.getLocationId(), vehicle.getEarliestDeparture(), vehicle.getLatestArrival()); + start = Start.newInstance(vehicle.getStartLocationId(), vehicle.getEarliestDeparture(), vehicle.getLatestArrival()); + end = End.newInstance(vehicle.getEndLocationId(), vehicle.getEarliestDeparture(), vehicle.getLatestArrival()); } - start.setEndTime(vehicleDepTime); + start.setEndTime(Math.max(vehicleDepTime, vehicle.getEarliestDeparture())); start.setTheoreticalEarliestOperationStartTime(vehicle.getEarliestDeparture()); start.setTheoreticalLatestOperationStartTime(vehicle.getLatestArrival()); - start.setLocationId(vehicle.getLocationId()); - end.setLocationId(vehicle.getLocationId()); + start.setLocationId(vehicle.getStartLocationId()); + end.setLocationId(vehicle.getEndLocationId()); end.setTheoreticalEarliestOperationStartTime(vehicle.getEarliestDeparture()); end.setTheoreticalLatestOperationStartTime(vehicle.getLatestArrival()); } diff --git a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/TestVehicleRoute.java b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/TestVehicleRoute.java index afa57d79..135ee7ec 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/TestVehicleRoute.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/TestVehicleRoute.java @@ -246,5 +246,9 @@ public class TestVehicleRoute { assertEquals(2,count); } } + + public void whenBuildingRouteWithVehicleThatHasDifferentStartAndEndLocation_routeMustBeBuiltCorrectly(){ + + } }