diff --git a/jsprit-core/src/main/java/jsprit/core/problem/io/VrpXMLReader.java b/jsprit-core/src/main/java/jsprit/core/problem/io/VrpXMLReader.java index ac1b00e8..337dc6be 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/io/VrpXMLReader.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/io/VrpXMLReader.java @@ -222,7 +222,7 @@ public class VrpXMLReader{ if(service==null) throw new IllegalStateException("service to serviceId " + serviceId + " is missing (reference in one of your initial routes). make sure you define the service you refer to here in ."); //!!!since job is part of initial route, it does not belong to jobs in problem, i.e. variable jobs that can be assigned/scheduled freezedJobIds.add(serviceId); - routeBuilder.addService(service, arrTime, endTime); + routeBuilder.addService(service); } else{ String shipmentId = actConfig.getString("shipmentId"); @@ -231,10 +231,10 @@ public class VrpXMLReader{ if(shipment == null) throw new IllegalStateException("shipment to shipmentId " + shipmentId + " is missing (reference in one of your initial routes). make sure you define the shipment you refer to here in ."); freezedJobIds.add(shipmentId); if(type.equals("pickupShipment")){ - routeBuilder.addPickup(shipment, arrTime, endTime); + routeBuilder.addPickup(shipment); } else if(type.equals("deliverShipment")){ - routeBuilder.addDelivery(shipment, arrTime, endTime); + routeBuilder.addDelivery(shipment); } else throw new IllegalStateException("type " + type + " is not supported. Use 'pickupShipment' or 'deliverShipment' here"); } @@ -283,7 +283,7 @@ public class VrpXMLReader{ String serviceId = actConfig.getString("serviceId"); if(serviceId != null) { Service service = getService(serviceId); - routeBuilder.addService(service, arrTime, endTime); + routeBuilder.addService(service); } else{ String shipmentId = actConfig.getString("shipmentId"); @@ -291,10 +291,10 @@ public class VrpXMLReader{ Shipment shipment = getShipment(shipmentId); if(shipment == null) throw new IllegalStateException("shipment with id " + shipmentId + " does not exist."); if(type.equals("pickupShipment")){ - routeBuilder.addPickup(shipment, arrTime, endTime); + routeBuilder.addPickup(shipment); } else if(type.equals("deliverShipment")){ - routeBuilder.addDelivery(shipment, arrTime, endTime); + routeBuilder.addDelivery(shipment); } else throw new IllegalStateException("type " + type + " is not supported. Use 'pickupShipment' or 'deliverShipment' here"); } 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 00d88c1a..854dad66 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 @@ -1,16 +1,16 @@ /******************************************************************************* - * Copyright (C) 2013 Stefan Schroeder - * + * Copyright (C) 2014 Stefan Schroeder + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ @@ -20,9 +20,7 @@ import jsprit.core.problem.AbstractActivity; import jsprit.core.problem.JobActivityFactory; import jsprit.core.problem.driver.Driver; import jsprit.core.problem.driver.DriverImpl; -import jsprit.core.problem.job.Job; -import jsprit.core.problem.job.Service; -import jsprit.core.problem.job.Shipment; +import jsprit.core.problem.job.*; import jsprit.core.problem.solution.route.activity.*; import jsprit.core.problem.vehicle.Vehicle; import jsprit.core.problem.vehicle.VehicleImpl; @@ -149,6 +147,7 @@ public class VehicleRoute { * * @param serviceActivityFactory the factory to create serviceActivities */ + @Deprecated public Builder setServiceActivityFactory(TourActivityFactory serviceActivityFactory) { this.serviceActivityFactory = serviceActivityFactory; return this; @@ -161,6 +160,7 @@ public class VehicleRoute { * * @param shipmentActivityFactory the factory to create shipmentActivities */ + @Deprecated public Builder setShipmentActivityFactory(TourShipmentActivityFactory shipmentActivityFactory) { this.shipmentActivityFactory = shipmentActivityFactory; return this; @@ -220,68 +220,55 @@ public class VehicleRoute { * @return this builder * @throws IllegalArgumentException if service is null */ - @SuppressWarnings("deprecation") public Builder addService(Service service){ if(service == null) throw new IllegalArgumentException("service must not be null"); - addService(service,0.0,0.0); - return this; - } - - /** - * Adds a service with specified activity arrival- and endTime. - * - *

This implies that for this service a serviceActivity is created with {@link TourActivityFactory} and added to the sequence of tourActivities. - * - *

Basically this activity is then scheduled with an activity arrival and activity endTime. - * - * @param service to be added - * @param arrTime at service activity - * @param endTime of service activity - * @return builder - */ - @Deprecated - public Builder addService(Service service, double arrTime, double endTime){ - List acts = jobActivityFactory.createActivities(service); + List acts = jobActivityFactory.createActivities(service); TourActivity act = acts.get(0); - act.setArrTime(arrTime); - act.setEndTime(endTime); - tourActivities.addActivity(act); + tourActivities.addActivity(act); return this; } - - /** + + /** + * Adds a pickup to this route. + * + * @param pickup pickup to be added + * @return the builder + */ + public Builder addPickup(Pickup pickup){ + if(pickup == null) throw new IllegalArgumentException("pickup must not be null"); + addService(pickup); + return this; + } + + /** + * Adds a delivery to this route. + * + * @param delivery delivery to be added + * @return the builder + */ + public Builder addDelivery(Delivery delivery){ + if(delivery == null) throw new IllegalArgumentException("delivery must not be null"); + addService(delivery); + return this; + } + + /** * Adds a the pickup of the specified shipment. * * @param shipment to be picked up and added to this route * @throws IllegalStateException if method has already been called with the specified shipment. * @return the builder */ - @SuppressWarnings("deprecation") public Builder addPickup(Shipment shipment){ - addPickup(shipment,0.,0.); - return this; - } - - /** - * Adds a the pickup of the specified shipment at specified arrival and end-time. - * - * @param shipment to be picked up and added to this route - * @throws IllegalStateException if method has already been called with the specified shipment. - * @return builder - */ - @Deprecated - public Builder addPickup(Shipment shipment, double arrTime, double endTime){ - if(openShipments.contains(shipment)) throw new IllegalStateException("shipment has already been added. cannot add it twice."); + if(openShipments.contains(shipment)) throw new IllegalStateException("shipment has already been added. cannot add it twice."); List acts = jobActivityFactory.createActivities(shipment); TourActivity act = acts.get(0); - act.setArrTime(arrTime); - act.setEndTime(endTime); tourActivities.addActivity(act); openShipments.add(shipment); openActivities.put(shipment,acts.get(1)); - return this; + return this; } - + /** * Adds a the delivery of the specified shipment. * @@ -289,31 +276,16 @@ public class VehicleRoute { * @throws IllegalStateException if specified shipment has not been picked up yet (i.e. method addPickup(shipment) has not been called yet). * @return builder */ - @SuppressWarnings("deprecation") public Builder addDelivery(Shipment shipment){ - addDelivery(shipment,0.,0.); - return this; - } - - /** - * Adds a the delivery of the specified shipment at a specified arrival and endTime. - * - * @param shipment to be delivered and added to this route - * @throws IllegalStateException if specified shipment has not been picked up yet (i.e. method addPickup(shipment) has not been called yet). - * @return the builder - */ - @Deprecated - public Builder addDelivery(Shipment shipment, double arrTime, double endTime){ - if(openShipments.contains(shipment)){ + if(openShipments.contains(shipment)){ TourActivity act = openActivities.get(shipment); - act.setArrTime(arrTime); - act.setEndTime(endTime); tourActivities.addActivity(act); openShipments.remove(shipment); } else{ throw new IllegalStateException("cannot deliver shipment. shipment " + shipment + " needs to be picked up first."); } - return this; + return this; } + /** * Builds the route. 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 b85f7bd1..3b0c9c70 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 @@ -308,6 +308,20 @@ public class TestVehicleRoute { } + @Test + public void whenAddingPickup_itShouldBeAdded(){ + + Pickup pickup = (Pickup) Pickup.Builder.newInstance("pick").setLocationId("pickLoc").build(); + VehicleImpl vehicle = VehicleImpl.Builder.newInstance("vehicle").setStartLocationId("startLoc").build(); + VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle).addPickup(pickup).build(); + + TourActivity act = route.getActivities().get(0); + assertTrue(act.getName().equals("pickup")); + assertTrue(act instanceof PickupService); + assertTrue(((TourActivity.JobActivity)act).getJob() instanceof Pickup); + + } + @Test public void whenAddingDelivery_itShouldBeTreatedAsDelivery(){ @@ -321,4 +335,18 @@ public class TestVehicleRoute { assertTrue(((TourActivity.JobActivity)act).getJob() instanceof Delivery); } + + @Test + public void whenAddingDelivery_itShouldBeAdded(){ + + Delivery delivery = (Delivery) Delivery.Builder.newInstance("delivery").setLocationId("deliveryLoc").build(); + VehicleImpl vehicle = VehicleImpl.Builder.newInstance("vehicle").setStartLocationId("startLoc").build(); + VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle).addDelivery(delivery).build(); + + TourActivity act = route.getActivities().get(0); + assertTrue(act.getName().equals("delivery")); + assertTrue(act instanceof DeliverService); + assertTrue(((TourActivity.JobActivity)act).getJob() instanceof Delivery); + + } }