diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/job/Shipment.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/job/Shipment.java index 4b8dc755..171f6e98 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/job/Shipment.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/job/Shipment.java @@ -59,6 +59,8 @@ public class Shipment extends AbstractJob { private double pickupServiceTime = 0.0; + private double pickupLoadingTime = 0.0; + private double deliveryServiceTime = 0.0; private Capacity.Builder capacityBuilder = Capacity.Builder.newInstance(); @@ -156,6 +158,22 @@ public class Shipment extends AbstractJob { return this; } + /** + * Sets pickupLoadingTime. + *

+ *

ServiceTime is intended to be the time the implied activity takes at the pickup-location. + * + * @param loadingTime the loading time / loading duration the pickup of the associated shipment takes + * @return builder + * @throws IllegalArgumentException if loadingTime < 0.0 + */ + public Builder setPickupLoadingTime(double loadingTime) { + if (loadingTime < 0.0) + throw new IllegalArgumentException("The loading time of a shipment must not be < 0.0."); + this.pickupLoadingTime = loadingTime; + return this; + } + /** * Sets the timeWindow for the pickup, i.e. the time-period in which a pickup operation is * allowed to START. @@ -354,6 +372,8 @@ public class Shipment extends AbstractJob { private final double pickupServiceTime; + private final double pickupLoadingTime; + private final double deliveryServiceTime; private final Capacity capacity; @@ -380,6 +400,7 @@ public class Shipment extends AbstractJob { setUserData(builder.userData); this.id = builder.id; this.pickupServiceTime = builder.pickupServiceTime; + this.pickupLoadingTime = builder.pickupLoadingTime; this.deliveryServiceTime = builder.deliveryServiceTime; this.capacity = builder.capacity; this.skills = builder.skills; @@ -413,6 +434,17 @@ public class Shipment extends AbstractJob { return pickupServiceTime; } + /** + * Returns the pickup service-time. + *

+ *

By default service-time is 0.0. + * + * @return service-time + */ + public double getPickupLoadingTime() { + return pickupLoadingTime; + } + public Location getDeliveryLocation() { return deliveryLocation_; } diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/solution/route/activity/PickupShipment.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/solution/route/activity/PickupShipment.java index d1f32c3a..6f79fb73 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/solution/route/activity/PickupShipment.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/solution/route/activity/PickupShipment.java @@ -23,7 +23,7 @@ import com.graphhopper.jsprit.core.problem.Location; import com.graphhopper.jsprit.core.problem.job.Job; import com.graphhopper.jsprit.core.problem.job.Shipment; -public final class PickupShipment extends AbstractActivity implements PickupActivity{ +public class PickupShipment extends AbstractActivity implements PickupActivity{ private Shipment shipment; @@ -40,7 +40,7 @@ public final class PickupShipment extends AbstractActivity implements PickupActi this.shipment = shipment; } - private PickupShipment(PickupShipment pickupShipmentActivity) { + protected PickupShipment(PickupShipment pickupShipmentActivity) { this.shipment = (Shipment) pickupShipmentActivity.getJob(); this.arrTime = pickupShipmentActivity.getArrTime(); this.endTime = pickupShipmentActivity.getEndTime(); diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/job/ShipmentTest.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/job/ShipmentTest.java index 7e271092..164689c8 100644 --- a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/job/ShipmentTest.java +++ b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/job/ShipmentTest.java @@ -458,10 +458,22 @@ public class ShipmentTest { } @Test - public void whenNotAddingMaxTimeInVehicle_itShouldBeDefault(){ + public void whenNotAddingMaxTimeInVehicle_itShouldBeDefault() { Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc")).setDeliveryLocation(Location.newInstance("loc")) .build(); Assert.assertEquals(Double.MAX_VALUE, s.getMaxTimeInVehicle(),0.001); } + @Test + public void testLoadingTime() { + Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc")).setDeliveryLocation(Location.newInstance("loc")) + .setPickupLoadingTime(10.546).build(); + Assert.assertEquals(10.546, s.getPickupLoadingTime(),0.001); + } + + @Test(expected = IllegalArgumentException.class) + public void testNegativeLoadingTime() { + Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc")).setDeliveryLocation(Location.newInstance("loc")) + .setPickupLoadingTime(-5).build(); + } }