diff --git a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/DeliverService.java b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/DeliverService.java index 430929a9..c98da473 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/DeliverService.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/DeliverService.java @@ -7,6 +7,8 @@ public final class DeliverService implements DeliveryActivity{ private Delivery delivery; + private Capacity capacity; + private double arrTime; private double endTime; @@ -14,14 +16,20 @@ public final class DeliverService implements DeliveryActivity{ public DeliverService(Delivery delivery) { super(); this.delivery = delivery; + capacity = Capacity.invert(delivery.getCapacity()); } private DeliverService(DeliverService deliveryActivity){ this.delivery=deliveryActivity.getJob(); this.arrTime=deliveryActivity.getArrTime(); this.endTime=deliveryActivity.getEndTime(); + capacity = deliveryActivity.getCapacity(); } + /** + * @deprecated use getCapacity() instead + */ + @Deprecated @Override public int getCapacityDemand() { return delivery.getCapacityDemand()*-1; @@ -89,6 +97,6 @@ public final class DeliverService implements DeliveryActivity{ @Override public Capacity getCapacity() { - return null; + return capacity; } } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/DeliverShipment.java b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/DeliverShipment.java index 1f13df88..3b274749 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/DeliverShipment.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/DeliverShipment.java @@ -7,18 +7,24 @@ import jsprit.core.problem.job.Shipment; public final class DeliverShipment implements DeliveryActivity{ private Shipment shipment; + private double endTime; + private double arrTime; + private Capacity capacity; + public DeliverShipment(Shipment shipment) { super(); this.shipment = shipment; + this.capacity = Capacity.invert(shipment.getCapacity()); } public DeliverShipment(DeliverShipment deliveryShipmentActivity) { this.shipment = (Shipment) deliveryShipmentActivity.getJob(); this.arrTime = deliveryShipmentActivity.getArrTime(); this.endTime = deliveryShipmentActivity.getEndTime(); + this.capacity = deliveryShipmentActivity.getCapacity(); } @Override @@ -26,6 +32,10 @@ public final class DeliverShipment implements DeliveryActivity{ return shipment; } + /** + * @deprecated use getCapacity() instead + */ + @Deprecated @Override public int getCapacityDemand() { return shipment.getCapacityDemand()*-1; @@ -88,6 +98,6 @@ public final class DeliverShipment implements DeliveryActivity{ @Override public Capacity getCapacity() { - return null; + return capacity; } } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/PickupService.java b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/PickupService.java index 5d768c91..0bb8a9b1 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/PickupService.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/PickupService.java @@ -82,7 +82,12 @@ public final class PickupService implements PickupActivity{ return pickup; } + /** + * @deprecated use getCapacity() instead + * + */ @Override + @Deprecated public int getCapacityDemand() { return pickup.getCapacityDemand(); } @@ -94,8 +99,7 @@ public final class PickupService implements PickupActivity{ @Override public Capacity getCapacity() { - // TODO Auto-generated method stub - return null; + return pickup.getCapacity(); } } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/PickupShipment.java b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/PickupShipment.java index 21abbf98..dc8c377f 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/PickupShipment.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/PickupShipment.java @@ -28,6 +28,10 @@ public final class PickupShipment implements PickupActivity{ return shipment; } + /** + * @deprecated use getCapacity() instead + */ + @Deprecated @Override public int getCapacityDemand() { return shipment.getCapacityDemand(); diff --git a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/ServiceActivity.java b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/ServiceActivity.java index 98ec22ed..fd3f2fe7 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/ServiceActivity.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/ServiceActivity.java @@ -28,8 +28,6 @@ public class ServiceActivity implements JobActivity{ public double endTime; - public int capacityDemand; - /** * @return the arrTime */ @@ -65,24 +63,13 @@ public class ServiceActivity implements JobActivity{ public static ServiceActivity newInstance(Service service){ return new ServiceActivity(service); } - - /** - * creates a new instance of {@link ServiceActivity} with a flag that indicates whether smthing is unloaded or loaded. - * - * @param service - * @param capacityDemand - * @return - */ -// public static ServiceActivity newInstance(Service service, boolean isPickup){ -// return new ServiceActivity(service, capacityDemand); -// } + private final Service service; protected ServiceActivity(Service service) { counter++; this.service = service; - this.capacityDemand = service.getCapacityDemand(); } protected ServiceActivity(ServiceActivity serviceActivity) { @@ -90,7 +77,6 @@ public class ServiceActivity implements JobActivity{ this.service = serviceActivity.getJob(); this.arrTime = serviceActivity.getArrTime(); this.endTime = serviceActivity.getEndTime(); - this.capacityDemand = serviceActivity.getCapacityDemand(); } @@ -133,9 +119,13 @@ public class ServiceActivity implements JobActivity{ return service.getTimeWindow().getEnd(); } + /** + * @deprecated use getCapacity() instead + */ @Override + @Deprecated public int getCapacityDemand() { - return this.capacityDemand; + return service.getCapacityDemand(); } @Override @@ -170,8 +160,7 @@ public class ServiceActivity implements JobActivity{ @Override public Capacity getCapacity() { - // TODO Auto-generated method stub - return null; + return service.getCapacity(); } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestInserter.java b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestInserter.java index 74a90766..4052d31c 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestInserter.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestInserter.java @@ -5,6 +5,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import jsprit.core.algorithm.recreate.listener.InsertionListeners; import jsprit.core.algorithm.state.UpdateEndLocationIfRouteIsOpen; +import jsprit.core.problem.Capacity; import jsprit.core.problem.driver.Driver; import jsprit.core.problem.job.Service; import jsprit.core.problem.job.Shipment; @@ -73,6 +74,8 @@ public class TestInserter { @Test public void whenInsertingShipmentAndRouteIsClosed_itInsertsCorrectly(){ Shipment shipment = mock(Shipment.class); + Capacity capacity = Capacity.Builder.newInstance().build(); + when(shipment.getCapacity()).thenReturn(capacity); Vehicle vehicle = mock(Vehicle.class); when(vehicle.getStartLocationId()).thenReturn("vehLoc"); when(vehicle.getEndLocationId()).thenReturn("vehLoc"); @@ -82,6 +85,7 @@ public class TestInserter { VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addPickup(shipment).addDelivery(shipment).build(); //start - pick(shipment) - del(shipment) - end Shipment shipmentToInsert = mock(Shipment.class); + when(shipmentToInsert.getCapacity()).thenReturn(capacity); when(shipmentToInsert.getDeliveryLocation()).thenReturn("delLoc"); when(shipmentToInsert.getPickupLocation()).thenReturn("pickLoc"); InsertionData iData = mock(InsertionData.class); @@ -101,6 +105,8 @@ public class TestInserter { @Test public void whenInsertingShipmentAndRouteIsOpen_itInsertsCorrectlyAndSwitchesEndLocation(){ Shipment shipment = mock(Shipment.class); + Capacity capacity = Capacity.Builder.newInstance().build(); + when(shipment.getCapacity()).thenReturn(capacity); Vehicle vehicle = mock(Vehicle.class); when(vehicle.isReturnToDepot()).thenReturn(false); when(vehicle.getId()).thenReturn("vehId"); @@ -108,6 +114,7 @@ public class TestInserter { VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addPickup(shipment).addDelivery(shipment).build(); //start - pick(shipment) - del(shipment) - end Shipment shipmentToInsert = mock(Shipment.class); + when(shipmentToInsert.getCapacity()).thenReturn(capacity); when(shipmentToInsert.getDeliveryLocation()).thenReturn("delLoc"); when(shipmentToInsert.getPickupLocation()).thenReturn("pickLoc"); InsertionData iData = mock(InsertionData.class); @@ -127,12 +134,15 @@ public class TestInserter { @Test public void whenSwitchingVehicleAndRouteIsClosed_newStartAndEndShouldBeTheLocationOfNewVehicle(){ Shipment shipment = mock(Shipment.class); + Capacity capacity = Capacity.Builder.newInstance().build(); + when(shipment.getCapacity()).thenReturn(capacity); Vehicle vehicle = VehicleImpl.Builder.newInstance("vehId").setStartLocationId("vehLoc").setType(mock(VehicleType.class)).build(); Vehicle newVehicle = VehicleImpl.Builder.newInstance("newVehId").setStartLocationId("newVehLoc").setType(mock(VehicleType.class)).build(); VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addPickup(shipment).addDelivery(shipment).build(); //start - pick(shipment) - del(shipment) - end Shipment shipmentToInsert = mock(Shipment.class); + when(shipmentToInsert.getCapacity()).thenReturn(capacity); when(shipmentToInsert.getDeliveryLocation()).thenReturn("delLoc"); when(shipmentToInsert.getPickupLocation()).thenReturn("pickLoc"); @@ -150,12 +160,15 @@ public class TestInserter { @Test public void whenSwitchingVehicleAndRouteIsOpen_endLocationShouldBeTheLocationOfTheLastActivity(){ Shipment shipment = mock(Shipment.class); + Capacity capacity = Capacity.Builder.newInstance().build(); + when(shipment.getCapacity()).thenReturn(capacity); Vehicle vehicle = VehicleImpl.Builder.newInstance("vehId").setReturnToDepot(false).setStartLocationId("vehLoc").setType(mock(VehicleType.class)).build(); Vehicle newVehicle = VehicleImpl.Builder.newInstance("newVehId").setReturnToDepot(false).setStartLocationId("newVehLoc").setType(mock(VehicleType.class)).build(); VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addPickup(shipment).addDelivery(shipment).build(); //start - pick(shipment) - del(shipment) - end Shipment shipmentToInsert = mock(Shipment.class); + when(shipmentToInsert.getCapacity()).thenReturn(capacity); when(shipmentToInsert.getDeliveryLocation()).thenReturn("delLoc"); when(shipmentToInsert.getPickupLocation()).thenReturn("pickLoc"); @@ -173,6 +186,8 @@ public class TestInserter { @Test public void whenInsertingShipmentAtBeginningAndSwitchingVehicleAndRouteIsOpen_endLocationShouldBeTheLocationOfTheLastActivity(){ Shipment shipment = mock(Shipment.class); + Capacity capacity = Capacity.Builder.newInstance().build(); + when(shipment.getCapacity()).thenReturn(capacity); when(shipment.getDeliveryLocation()).thenReturn("oldShipmentDelLoc"); Vehicle vehicle = VehicleImpl.Builder.newInstance("vehId").setReturnToDepot(false).setStartLocationId("vehLoc").setType(mock(VehicleType.class)).build(); Vehicle newVehicle = VehicleImpl.Builder.newInstance("newVehId").setReturnToDepot(false).setStartLocationId("newVehLoc").setType(mock(VehicleType.class)).build(); @@ -180,6 +195,7 @@ public class TestInserter { VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addPickup(shipment).addDelivery(shipment).build(); //start - pick(shipment) - del(shipment) - end Shipment shipmentToInsert = mock(Shipment.class); + when(shipmentToInsert.getCapacity()).thenReturn(capacity); when(shipmentToInsert.getDeliveryLocation()).thenReturn("delLoc"); when(shipmentToInsert.getPickupLocation()).thenReturn("pickLoc"); diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/state/HardPickupAndDeliveryShipmentActivityConstraintTest.java b/jsprit-core/src/test/java/jsprit/core/algorithm/state/HardPickupAndDeliveryShipmentActivityConstraintTest.java index 4ab35777..def68ea8 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/state/HardPickupAndDeliveryShipmentActivityConstraintTest.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/state/HardPickupAndDeliveryShipmentActivityConstraintTest.java @@ -4,6 +4,7 @@ import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import jsprit.core.algorithm.state.StateManager; +import jsprit.core.problem.Capacity; import jsprit.core.problem.VehicleRoutingProblem; import jsprit.core.problem.constraint.PickupAndDeliverShipmentLoadActivityLevelConstraint; import jsprit.core.problem.constraint.HardActivityStateLevelConstraint.ConstraintsStatus; @@ -39,6 +40,8 @@ public class HardPickupAndDeliveryShipmentActivityConstraintTest { stateManager = new StateManager(mock(VehicleRoutingProblem.class)); shipment = mock(Shipment.class); when(shipment.getCapacityDemand()).thenReturn(1); + Capacity capacity = Capacity.Builder.newInstance().addDimension(0, 1).build(); + when(shipment.getCapacity()).thenReturn(capacity); iFacts = new JobInsertionContext(null, null, vehicle, null, 0.0); constraint = new PickupAndDeliverShipmentLoadActivityLevelConstraint(stateManager); } diff --git a/jsprit-core/src/test/java/jsprit/core/problem/job/ShipmentTest.java b/jsprit-core/src/test/java/jsprit/core/problem/job/ShipmentTest.java index 1cc95988..31e7417f 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/job/ShipmentTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/job/ShipmentTest.java @@ -200,7 +200,7 @@ public class ShipmentTest { assertEquals(2.0,s.getDeliveryTimeWindow().getEnd(),0.01); } - @Test(expected=IllegalStateException.class) + @Test(expected=IllegalArgumentException.class) public void whenShipmentHasNegativeCapacityVal_throwIllegalStateExpception(){ @SuppressWarnings("unused") Shipment one = Shipment.Builder.newInstance("s").setPickupLocation("foo").setDeliveryLocation("foofoo") diff --git a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/VehicleRouteBuilderTest.java b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/VehicleRouteBuilderTest.java index 389527a7..806390af 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/VehicleRouteBuilderTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/VehicleRouteBuilderTest.java @@ -3,6 +3,7 @@ package jsprit.core.problem.solution.route; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import jsprit.core.problem.Capacity; import jsprit.core.problem.driver.Driver; import jsprit.core.problem.job.Shipment; import jsprit.core.problem.vehicle.Vehicle; @@ -30,6 +31,8 @@ public class VehicleRouteBuilderTest { @Test(expected=IllegalStateException.class) public void whenShipmentIsPickedDeliveredAndDeliveredAgain_throwsException(){ Shipment s = mock(Shipment.class); + Capacity capacity = Capacity.Builder.newInstance().build(); + when(s.getCapacity()).thenReturn(capacity); VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(mock(Vehicle.class), mock(Driver.class)); builder.addPickup(s); builder.addDelivery(s); @@ -39,6 +42,8 @@ public class VehicleRouteBuilderTest { @Test(expected=IllegalStateException.class) public void whenShipmentIsPickedUpThoughButHasNotBeenDeliveredAndRouteIsBuilt_throwsException(){ Shipment s = mock(Shipment.class); + Capacity capacity = Capacity.Builder.newInstance().build(); + when(s.getCapacity()).thenReturn(capacity); VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(mock(Vehicle.class), mock(Driver.class)); builder.addPickup(s); builder.addPickup(mock(Shipment.class)); @@ -50,6 +55,9 @@ public class VehicleRouteBuilderTest { public void whenTwoShipmentsHaveBeenAdded_nuOfActivitiesMustEqualFour(){ Shipment s = mock(Shipment.class); Shipment s2 = mock(Shipment.class); + Capacity capacity = Capacity.Builder.newInstance().build(); + when(s.getCapacity()).thenReturn(capacity); + when(s2.getCapacity()).thenReturn(capacity); VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(mock(Vehicle.class), mock(Driver.class)); builder.addPickup(s); builder.addPickup(s2); @@ -63,6 +71,9 @@ public class VehicleRouteBuilderTest { public void whenBuildingClosedRoute_routeEndShouldHaveLocationOfVehicle(){ Shipment s = mock(Shipment.class); Shipment s2 = mock(Shipment.class); + Capacity capacity = Capacity.Builder.newInstance().build(); + when(s.getCapacity()).thenReturn(capacity); + when(s2.getCapacity()).thenReturn(capacity); Vehicle vehicle = mock(Vehicle.class); when(vehicle.isReturnToDepot()).thenReturn(true); when(vehicle.getStartLocationId()).thenReturn("vehLoc"); @@ -80,6 +91,9 @@ public class VehicleRouteBuilderTest { public void whenBuildingOpenRoute_routeEndShouldHaveLocationOfLastActivity(){ Shipment s = mock(Shipment.class); Shipment s2 = mock(Shipment.class); + Capacity capacity = Capacity.Builder.newInstance().build(); + when(s.getCapacity()).thenReturn(capacity); + when(s2.getCapacity()).thenReturn(capacity); when(s2.getDeliveryLocation()).thenReturn("delLoc"); Vehicle vehicle = mock(Vehicle.class); when(vehicle.isReturnToDepot()).thenReturn(false); @@ -97,6 +111,9 @@ public class VehicleRouteBuilderTest { public void whenSettingDepartureTime(){ Shipment s = mock(Shipment.class); Shipment s2 = mock(Shipment.class); + Capacity capacity = Capacity.Builder.newInstance().build(); + when(s.getCapacity()).thenReturn(capacity); + when(s2.getCapacity()).thenReturn(capacity); when(s2.getDeliveryLocation()).thenReturn("delLoc"); Vehicle vehicle = mock(Vehicle.class); when(vehicle.isReturnToDepot()).thenReturn(false); @@ -117,6 +134,9 @@ public class VehicleRouteBuilderTest { public void whenSettingEndTime(){ Shipment s = mock(Shipment.class); Shipment s2 = mock(Shipment.class); + Capacity capacity = Capacity.Builder.newInstance().build(); + when(s.getCapacity()).thenReturn(capacity); + when(s2.getCapacity()).thenReturn(capacity); when(s2.getDeliveryLocation()).thenReturn("delLoc"); Vehicle vehicle = mock(Vehicle.class); when(vehicle.isReturnToDepot()).thenReturn(false); diff --git a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/DefaultShipmentActivityFactoryTest.java b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/DefaultShipmentActivityFactoryTest.java index bfb5c566..426222a5 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/DefaultShipmentActivityFactoryTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/DefaultShipmentActivityFactoryTest.java @@ -1,5 +1,30 @@ package jsprit.core.problem.solution.route.activity; -public class DefaultShipmentActivityFactoryTest { +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import jsprit.core.problem.job.Shipment; +import org.junit.Test; + +public class DefaultShipmentActivityFactoryTest { + + @Test + public void whenCreatingPickupActivityWithShipment_itShouldReturnPickupShipment(){ + DefaultShipmentActivityFactory factory = new DefaultShipmentActivityFactory(); + Shipment shipment = Shipment.Builder.newInstance("s") + .setPickupLocation("pLoc").setDeliveryLocation("dLoc").build(); + TourActivity act = factory.createPickup(shipment); + assertNotNull(act); + assertTrue(act instanceof PickupShipment); + } + + @Test + public void whenCreatingDeliverActivityWithShipment_itShouldReturnDeliverShipment(){ + DefaultShipmentActivityFactory factory = new DefaultShipmentActivityFactory(); + Shipment shipment = Shipment.Builder.newInstance("s") + .setPickupLocation("pLoc").setDeliveryLocation("dLoc").build(); + TourActivity act = factory.createDelivery(shipment); + assertNotNull(act); + assertTrue(act instanceof DeliverShipment); + } } diff --git a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/DefaultTourActivityFactoryTest.java b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/DefaultTourActivityFactoryTest.java new file mode 100644 index 00000000..50000ac9 --- /dev/null +++ b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/DefaultTourActivityFactoryTest.java @@ -0,0 +1,40 @@ +package jsprit.core.problem.solution.route.activity; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import jsprit.core.problem.job.Delivery; +import jsprit.core.problem.job.Pickup; +import jsprit.core.problem.job.Service; + +import org.junit.Test; + +public class DefaultTourActivityFactoryTest { + + @Test + public void whenCreatingActivityWithService_itShouldReturnPickupService(){ + DefaultTourActivityFactory factory = new DefaultTourActivityFactory(); + Service service = Service.Builder.newInstance("service").setLocationId("loc").build(); + TourActivity act = factory.createActivity(service); + assertNotNull(act); + assertTrue(act instanceof PickupService); + } + + @Test + public void whenCreatingActivityWithPickup_itShouldReturnPickupService(){ + DefaultTourActivityFactory factory = new DefaultTourActivityFactory(); + Pickup service = (Pickup) Pickup.Builder.newInstance("service").setLocationId("loc").build(); + TourActivity act = factory.createActivity(service); + assertNotNull(act); + assertTrue(act instanceof PickupService); + } + + @Test + public void whenCreatingActivityWithDelivery_itShouldReturnDeliverService(){ + DefaultTourActivityFactory factory = new DefaultTourActivityFactory(); + Delivery service = (Delivery) Delivery.Builder.newInstance("service").setLocationId("loc").build(); + TourActivity act = factory.createActivity(service); + assertNotNull(act); + assertTrue(act instanceof DeliverService); + } + +} diff --git a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/DefaultTourActivityTest.java b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/DefaultTourActivityTest.java deleted file mode 100644 index de1e1eb1..00000000 --- a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/DefaultTourActivityTest.java +++ /dev/null @@ -1,5 +0,0 @@ -package jsprit.core.problem.solution.route.activity; - -public class DefaultTourActivityTest { - -} diff --git a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/DeliverServiceTest.java b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/DeliverServiceTest.java index 3bae8ee7..a959de9f 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/DeliverServiceTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/DeliverServiceTest.java @@ -1,5 +1,76 @@ package jsprit.core.problem.solution.route.activity; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import jsprit.core.problem.job.Delivery; + +import org.junit.Before; +import org.junit.Test; + public class DeliverServiceTest { + private Delivery service; + + private DeliverService deliver; + + @Before + public void doBefore(){ + service = (Delivery) Delivery.Builder.newInstance("service").setLocationId("loc"). + setTimeWindow(TimeWindow.newInstance(1., 2.)). + addCapacityDimension(0, 10).addCapacityDimension(1, 100).addCapacityDimension(2, 1000).build(); + deliver = new DeliverService(service); + } + + @Test + public void whenCallingCapacity_itShouldReturnCorrectCapacity(){ + assertEquals(-10,deliver.getCapacity().get(0)); + assertEquals(-100,deliver.getCapacity().get(1)); + assertEquals(-1000,deliver.getCapacity().get(2)); + } + + @SuppressWarnings("deprecation") + @Test + public void whenCallingCapacityDemand_itShouldReturnCapDimWithIndex0(){ + assertEquals(-10,deliver.getCapacityDemand()); + } + + @Test + public void whenStartIsIniWithEarliestStart_itShouldBeSetCorrectly(){ + assertEquals(1.,deliver.getTheoreticalEarliestOperationStartTime(),0.01); + } + + @Test + public void whenStartIsIniWithLatestStart_itShouldBeSetCorrectly(){ + assertEquals(2.,deliver.getTheoreticalLatestOperationStartTime(),0.01); + } + + @Test + public void whenSettingArrTime_itShouldBeSetCorrectly(){ + deliver.setArrTime(4.0); + assertEquals(4.,deliver.getArrTime(),0.01); + } + + @Test + public void whenSettingEndTime_itShouldBeSetCorrectly(){ + deliver.setEndTime(5.0); + assertEquals(5.,deliver.getEndTime(),0.01); + } + + @Test + public void whenIniLocationId_itShouldBeSetCorrectly(){ + assertEquals("loc",deliver.getLocationId()); + } + + @Test + public void whenCopyingStart_itShouldBeDoneCorrectly(){ + DeliverService copy = (DeliverService) deliver.duplicate(); + assertEquals(1.,copy.getTheoreticalEarliestOperationStartTime(),0.01); + assertEquals(2.,copy.getTheoreticalLatestOperationStartTime(),0.01); + assertEquals("loc",copy.getLocationId()); + assertEquals(-10,copy.getCapacity().get(0)); + assertEquals(-100,copy.getCapacity().get(1)); + assertEquals(-1000,copy.getCapacity().get(2)); + assertTrue(copy!=deliver); + } + } diff --git a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/DeliverShipmentTest.java b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/DeliverShipmentTest.java index f0fe9aa3..8ce624b4 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/DeliverShipmentTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/DeliverShipmentTest.java @@ -1,5 +1,88 @@ package jsprit.core.problem.solution.route.activity; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import jsprit.core.problem.job.Shipment; + +import org.junit.Before; +import org.junit.Test; + public class DeliverShipmentTest { + + private Shipment shipment; + + private DeliverShipment deliver; + + @Before + public void doBefore(){ + shipment = Shipment.Builder.newInstance("shipment").setPickupLocation("pickupLoc") + .setDeliveryLocation("deliveryLoc") + .setPickupTimeWindow(TimeWindow.newInstance(1., 2.)) + .setDeliveryTimeWindow(TimeWindow.newInstance(3., 4.)) + .addCapacityDimension(0, 10).addCapacityDimension(1, 100).addCapacityDimension(2, 1000).build(); + deliver = new DeliverShipment(shipment); + } + + @Test + public void whenCallingCapacity_itShouldReturnCorrectCapacity(){ + assertEquals(-10,deliver.getCapacity().get(0)); + assertEquals(-100,deliver.getCapacity().get(1)); + assertEquals(-1000,deliver.getCapacity().get(2)); + } + + @SuppressWarnings("deprecation") + @Test + public void whenCallingCapacityDemand_itShouldReturnCapDimWithIndex0(){ + assertEquals(-10,deliver.getCapacityDemand()); + } + + @Test + public void whenStartIsIniWithEarliestStart_itShouldBeSetCorrectly(){ + assertEquals(3.,deliver.getTheoreticalEarliestOperationStartTime(),0.01); + } + + @Test + public void whenStartIsIniWithLatestStart_itShouldBeSetCorrectly(){ + assertEquals(4.,deliver.getTheoreticalLatestOperationStartTime(),0.01); + } + + @Test + public void whenSettingArrTime_itShouldBeSetCorrectly(){ + deliver.setArrTime(4.0); + assertEquals(4.,deliver.getArrTime(),0.01); + } + + @Test + public void whenSettingEndTime_itShouldBeSetCorrectly(){ + deliver.setEndTime(5.0); + assertEquals(5.,deliver.getEndTime(),0.01); + } + + @Test + public void whenIniLocationId_itShouldBeSetCorrectly(){ + assertEquals("deliveryLoc",deliver.getLocationId()); + } + + @Test + public void whenCopyingStart_itShouldBeDoneCorrectly(){ + DeliverShipment copy = (DeliverShipment) deliver.duplicate(); + assertEquals(3.,copy.getTheoreticalEarliestOperationStartTime(),0.01); + assertEquals(4.,copy.getTheoreticalLatestOperationStartTime(),0.01); + assertEquals("deliveryLoc",copy.getLocationId()); + assertEquals(-10,copy.getCapacity().get(0)); + assertEquals(-100,copy.getCapacity().get(1)); + assertEquals(-1000,copy.getCapacity().get(2)); + assertTrue(copy!=deliver); + } + + + @Test + public void whenGettingCapacity_itShouldReturnItCorrectly(){ + Shipment shipment = Shipment.Builder.newInstance("s").setPickupLocation("pickLoc").setDeliveryLocation("delLoc") + .addCapacityDimension(0, 10).addCapacityDimension(1, 100).build(); + PickupShipment pick = new PickupShipment(shipment); + assertEquals(10,pick.getCapacity().get(0)); + assertEquals(100,pick.getCapacity().get(1)); + } } diff --git a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/PickupServiceTest.java b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/PickupServiceTest.java index 868354ce..53473674 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/PickupServiceTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/PickupServiceTest.java @@ -1,5 +1,76 @@ package jsprit.core.problem.solution.route.activity; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import jsprit.core.problem.job.Service; + +import org.junit.Before; +import org.junit.Test; + public class PickupServiceTest { + + private Service service; + + private PickupService pickup; + + @Before + public void doBefore(){ + service = Service.Builder.newInstance("service").setLocationId("loc"). + setTimeWindow(TimeWindow.newInstance(1., 2.)). + addCapacityDimension(0, 10).addCapacityDimension(1, 100).addCapacityDimension(2, 1000).build(); + pickup = new PickupService(service); + } + + @Test + public void whenCallingCapacity_itShouldReturnCorrectCapacity(){ + assertEquals(10,pickup.getCapacity().get(0)); + assertEquals(100,pickup.getCapacity().get(1)); + assertEquals(1000,pickup.getCapacity().get(2)); + } + + @SuppressWarnings("deprecation") + @Test + public void whenCallingCapacityDemand_itShouldReturnCapDimWithIndex0(){ + assertEquals(10,pickup.getCapacityDemand()); + } + + @Test + public void whenStartIsIniWithEarliestStart_itShouldBeSetCorrectly(){ + assertEquals(1.,pickup.getTheoreticalEarliestOperationStartTime(),0.01); + } + + @Test + public void whenStartIsIniWithLatestStart_itShouldBeSetCorrectly(){ + assertEquals(2.,pickup.getTheoreticalLatestOperationStartTime(),0.01); + } + + @Test + public void whenSettingArrTime_itShouldBeSetCorrectly(){ + pickup.setArrTime(4.0); + assertEquals(4.,pickup.getArrTime(),0.01); + } + + @Test + public void whenSettingEndTime_itShouldBeSetCorrectly(){ + pickup.setEndTime(5.0); + assertEquals(5.,pickup.getEndTime(),0.01); + } + + @Test + public void whenIniLocationId_itShouldBeSetCorrectly(){ + assertEquals("loc",pickup.getLocationId()); + } + + @Test + public void whenCopyingStart_itShouldBeDoneCorrectly(){ + PickupService copy = (PickupService) pickup.duplicate(); + assertEquals(1.,copy.getTheoreticalEarliestOperationStartTime(),0.01); + assertEquals(2.,copy.getTheoreticalLatestOperationStartTime(),0.01); + assertEquals("loc",copy.getLocationId()); + assertEquals(10,copy.getCapacity().get(0)); + assertEquals(100,copy.getCapacity().get(1)); + assertEquals(1000,copy.getCapacity().get(2)); + assertTrue(copy!=pickup); + } } diff --git a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/PickupShipmentTest.java b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/PickupShipmentTest.java index 1f60cc6b..45a49684 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/PickupShipmentTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/PickupShipmentTest.java @@ -1,12 +1,81 @@ package jsprit.core.problem.solution.route.activity; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import jsprit.core.problem.job.Shipment; +import org.junit.Before; import org.junit.Test; public class PickupShipmentTest { + private Shipment shipment; + + private PickupShipment pickup; + + @Before + public void doBefore(){ + shipment = Shipment.Builder.newInstance("shipment").setPickupLocation("pickupLoc") + .setDeliveryLocation("deliveryLoc") + .setPickupTimeWindow(TimeWindow.newInstance(1., 2.)) + .setDeliveryTimeWindow(TimeWindow.newInstance(3., 4.)) + .addCapacityDimension(0, 10).addCapacityDimension(1, 100).addCapacityDimension(2, 1000).build(); + pickup = new PickupShipment(shipment); + } + + @Test + public void whenCallingCapacity_itShouldReturnCorrectCapacity(){ + assertEquals(10,pickup.getCapacity().get(0)); + assertEquals(100,pickup.getCapacity().get(1)); + assertEquals(1000,pickup.getCapacity().get(2)); + } + + @SuppressWarnings("deprecation") + @Test + public void whenCallingCapacityDemand_itShouldReturnCapDimWithIndex0(){ + assertEquals(10,pickup.getCapacityDemand()); + } + + @Test + public void whenStartIsIniWithEarliestStart_itShouldBeSetCorrectly(){ + assertEquals(1.,pickup.getTheoreticalEarliestOperationStartTime(),0.01); + } + + @Test + public void whenStartIsIniWithLatestStart_itShouldBeSetCorrectly(){ + assertEquals(2.,pickup.getTheoreticalLatestOperationStartTime(),0.01); + } + + @Test + public void whenSettingArrTime_itShouldBeSetCorrectly(){ + pickup.setArrTime(4.0); + assertEquals(4.,pickup.getArrTime(),0.01); + } + + @Test + public void whenSettingEndTime_itShouldBeSetCorrectly(){ + pickup.setEndTime(5.0); + assertEquals(5.,pickup.getEndTime(),0.01); + } + + @Test + public void whenIniLocationId_itShouldBeSetCorrectly(){ + assertEquals("pickupLoc",pickup.getLocationId()); + } + + @Test + public void whenCopyingStart_itShouldBeDoneCorrectly(){ + PickupShipment copy = (PickupShipment) pickup.duplicate(); + assertEquals(1.,copy.getTheoreticalEarliestOperationStartTime(),0.01); + assertEquals(2.,copy.getTheoreticalLatestOperationStartTime(),0.01); + assertEquals("pickupLoc",copy.getLocationId()); + assertEquals(10,copy.getCapacity().get(0)); + assertEquals(100,copy.getCapacity().get(1)); + assertEquals(1000,copy.getCapacity().get(2)); + assertTrue(copy!=pickup); + } + + @Test public void whenGettingCapacity_itShouldReturnItCorrectly(){ Shipment shipment = Shipment.Builder.newInstance("s").setPickupLocation("pickLoc").setDeliveryLocation("delLoc") @@ -15,11 +84,5 @@ public class PickupShipmentTest { assertEquals(10,pick.getCapacity().get(0)); assertEquals(100,pick.getCapacity().get(1)); } - - @Test - public void whenCopyingAct_itShouldCopyItCorrectly(){ - } - - } diff --git a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/ServiceActivityTest.java b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/ServiceActivityTest.java index b9ca0599..bd70b2ef 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/ServiceActivityTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/ServiceActivityTest.java @@ -16,20 +16,85 @@ ******************************************************************************/ package jsprit.core.problem.solution.route.activity; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import jsprit.core.problem.job.Service; import jsprit.core.problem.solution.route.activity.ServiceActivity; +import org.junit.Before; import org.junit.Test; public class ServiceActivityTest { + + private Service service; + + private ServiceActivity serviceActivity; + + @Before + public void doBefore(){ + service = Service.Builder.newInstance("service").setLocationId("loc"). + setTimeWindow(TimeWindow.newInstance(1., 2.)). + addCapacityDimension(0, 10).addCapacityDimension(1, 100).addCapacityDimension(2, 1000).build(); + serviceActivity = ServiceActivity.newInstance(service); + } + + @Test + public void whenCallingCapacity_itShouldReturnCorrectCapacity(){ + assertEquals(10,serviceActivity.getCapacity().get(0)); + assertEquals(100,serviceActivity.getCapacity().get(1)); + assertEquals(1000,serviceActivity.getCapacity().get(2)); + } + + @SuppressWarnings("deprecation") + @Test + public void whenCallingCapacityDemand_itShouldReturnCapDimWithIndex0(){ + assertEquals(10,serviceActivity.getCapacityDemand()); + } + + @Test + public void whenStartIsIniWithEarliestStart_itShouldBeSetCorrectly(){ + assertEquals(1.,serviceActivity.getTheoreticalEarliestOperationStartTime(),0.01); + } + + @Test + public void whenStartIsIniWithLatestStart_itShouldBeSetCorrectly(){ + assertEquals(2.,serviceActivity.getTheoreticalLatestOperationStartTime(),0.01); + } + + @Test + public void whenSettingArrTime_itShouldBeSetCorrectly(){ + serviceActivity.setArrTime(4.0); + assertEquals(4.,serviceActivity.getArrTime(),0.01); + } + + @Test + public void whenSettingEndTime_itShouldBeSetCorrectly(){ + serviceActivity.setEndTime(5.0); + assertEquals(5.,serviceActivity.getEndTime(),0.01); + } + + @Test + public void whenIniLocationId_itShouldBeSetCorrectly(){ + assertEquals("loc",serviceActivity.getLocationId()); + } + + @Test + public void whenCopyingStart_itShouldBeDoneCorrectly(){ + ServiceActivity copy = (ServiceActivity) serviceActivity.duplicate(); + assertEquals(1.,copy.getTheoreticalEarliestOperationStartTime(),0.01); + assertEquals(2.,copy.getTheoreticalLatestOperationStartTime(),0.01); + assertEquals("loc",copy.getLocationId()); + assertTrue(copy!=serviceActivity); + } + + @Test public void whenTwoDeliveriesHaveTheSameUnderlyingJob_theyAreEqual(){ - Service s1 = Service.Builder.newInstance("s", 10).setLocationId("loc").build(); - Service s2 = Service.Builder.newInstance("s", 10).setLocationId("loc").build(); + Service s1 = Service.Builder.newInstance("s").setLocationId("loc").build(); + Service s2 = Service.Builder.newInstance("s").setLocationId("loc").build(); ServiceActivity d1 = ServiceActivity.newInstance(s1); ServiceActivity d2 = ServiceActivity.newInstance(s2); @@ -39,8 +104,8 @@ public class ServiceActivityTest { @Test public void whenTwoDeliveriesHaveTheDifferentUnderlyingJob_theyAreNotEqual(){ - Service s1 = Service.Builder.newInstance("s", 10).setLocationId("loc").build(); - Service s2 = Service.Builder.newInstance("s1", 10).setLocationId("loc").build(); + Service s1 = Service.Builder.newInstance("s").setLocationId("loc").build(); + Service s2 = Service.Builder.newInstance("s1").setLocationId("loc").build(); ServiceActivity d1 = ServiceActivity.newInstance(s1); ServiceActivity d2 = ServiceActivity.newInstance(s2); diff --git a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/TestTour.java b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/TestTour.java index 8b7b1c0e..7a13e016 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/TestTour.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/TestTour.java @@ -40,7 +40,7 @@ public class TestTour { @Before public void doBefore(){ - service = Service.Builder.newInstance("yo", 10).setLocationId("loc").build(); + service = Service.Builder.newInstance("yo").addCapacityDimension(0, 10).setLocationId("loc").build(); act = ServiceActivity.newInstance(service); tour = new TourActivities(); } @@ -73,7 +73,7 @@ public class TestTour { assertEquals(0, tour.getActivities().size()); tour.addActivity(act); assertEquals(1, tour.getActivities().size()); - Service anotherServiceInstance = Service.Builder.newInstance("yo", 10).setLocationId("loc").build(); + Service anotherServiceInstance = Service.Builder.newInstance("yo").addCapacityDimension(0, 10).setLocationId("loc").build(); assertTrue(service.equals(anotherServiceInstance)); boolean removed = tour.removeJob(anotherServiceInstance); assertTrue(removed); @@ -82,7 +82,7 @@ public class TestTour { @Test public void whenAddingAShipmentActivity_tourShouldServeShipment(){ - Shipment s = Shipment.Builder.newInstance("s", 1).setDeliveryLocation("delLoc").setPickupLocation("pickLoc").build(); + Shipment s = Shipment.Builder.newInstance("s").addCapacityDimension(0, 1).setDeliveryLocation("delLoc").setPickupLocation("pickLoc").build(); TourShipmentActivityFactory fac = new DefaultShipmentActivityFactory(); TourActivity pickupShipment = fac.createPickup(s); TourActivity deliverShipment = fac.createDelivery(s); @@ -96,7 +96,7 @@ public class TestTour { @Test public void whenRemovingShipment_tourShouldNotServiceItAnymore(){ - Shipment s = Shipment.Builder.newInstance("s", 1).setDeliveryLocation("delLoc").setPickupLocation("pickLoc").build(); + Shipment s = Shipment.Builder.newInstance("s").addCapacityDimension(0, 1).setDeliveryLocation("delLoc").setPickupLocation("pickLoc").build(); TourShipmentActivityFactory fac = new DefaultShipmentActivityFactory(); TourActivity pickupShipment = fac.createPickup(s); TourActivity deliverShipment = fac.createDelivery(s); @@ -110,7 +110,7 @@ public class TestTour { @Test public void whenRemovingShipment_theirCorrespondingActivitiesShouldBeRemoved(){ - Shipment s = Shipment.Builder.newInstance("s", 1).setDeliveryLocation("delLoc").setPickupLocation("pickLoc").build(); + Shipment s = Shipment.Builder.newInstance("s").addCapacityDimension(0, 1).setDeliveryLocation("delLoc").setPickupLocation("pickLoc").build(); TourShipmentActivityFactory fac = new DefaultShipmentActivityFactory(); TourActivity pickupShipment = fac.createPickup(s); TourActivity deliverShipment = fac.createDelivery(s);