by default, it returns to the depot. + * + * @author stefan + * + */ public static class Builder { static Logger log = Logger.getLogger(Builder.class); private String id; From 39859f379e6b4dee4ed8bdcdf635b80d1f0b1834 Mon Sep 17 00:00:00 2001 From: Stefan Schroeder <4sschroeder@gmail.com> Date: Mon, 2 Dec 2013 17:50:09 +0100 Subject: [PATCH 05/12] delete import not used --- .../src/main/java/jsprit/examples/SolomonOpenExample.java | 1 - 1 file changed, 1 deletion(-) diff --git a/jsprit-examples/src/main/java/jsprit/examples/SolomonOpenExample.java b/jsprit-examples/src/main/java/jsprit/examples/SolomonOpenExample.java index 6cba5e5c..ae2be7ca 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/SolomonOpenExample.java +++ b/jsprit-examples/src/main/java/jsprit/examples/SolomonOpenExample.java @@ -27,7 +27,6 @@ import jsprit.core.algorithm.selector.SelectBest; import jsprit.core.problem.VehicleRoutingProblem; import jsprit.core.problem.io.VrpXMLReader; import jsprit.core.problem.solution.VehicleRoutingProblemSolution; -import jsprit.instance.reader.SolomonReader; public class SolomonOpenExample { From b28753108c3df1bec4cea4c179e2e7d4c5def15c Mon Sep 17 00:00:00 2001 From: oblonski <4sschroeder@gmail.com> Date: Mon, 2 Dec 2013 21:19:20 +0100 Subject: [PATCH 06/12] deprecate .addProblemConstraint(...) --- .../jsprit/core/problem/VehicleRoutingProblem.java | 13 ++++++++++--- .../jsprit/examples/VRPWithBackhaulsExample.java | 4 +++- .../jsprit/examples/VRPWithBackhaulsExample2.java | 3 ++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/jsprit-core/src/main/java/jsprit/core/problem/VehicleRoutingProblem.java b/jsprit-core/src/main/java/jsprit/core/problem/VehicleRoutingProblem.java index 8a2bf8fd..67919155 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/VehicleRoutingProblem.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/VehicleRoutingProblem.java @@ -25,9 +25,7 @@ import java.util.Map; import jsprit.core.problem.cost.VehicleRoutingActivityCosts; import jsprit.core.problem.cost.VehicleRoutingTransportCosts; import jsprit.core.problem.driver.Driver; -import jsprit.core.problem.job.Delivery; import jsprit.core.problem.job.Job; -import jsprit.core.problem.job.Pickup; import jsprit.core.problem.job.Service; import jsprit.core.problem.job.Shipment; import jsprit.core.problem.solution.route.activity.TourActivity; @@ -64,9 +62,11 @@ public class VehicleRoutingProblem { * *
DELIVERIES_FIRST corresponds to the vehicle routing problem with back hauls, i.e. before a vehicle is not entirely unloaded, no pickup can be made. * + * @deprecated define constraint directly - since constraints are too diverse to put them in an enum * @author stefan * */ + @Deprecated public enum Constraint { DELIVERIES_FIRST } @@ -186,7 +186,12 @@ public class VehicleRoutingProblem { }; } - + /** + * + * @deprecated use .addConstraint(new ServiceDeliveriesFirstConstraint()) + * @param constraint + */ + @Deprecated public void addProblemConstraint(Constraint constraint){ if(!problemConstraints.contains(constraint)) problemConstraints.add(constraint); } @@ -313,9 +318,11 @@ public class VehicleRoutingProblem { /** * Sets the neighborhood. * + * @deprecated use HardRoute- or ActivityLevelConstraint instead * @param neighborhood * @return */ + @Deprecated public Builder setNeighborhood(Neighborhood neighborhood){ this.neighborhood = neighborhood; return this; diff --git a/jsprit-examples/src/main/java/jsprit/examples/VRPWithBackhaulsExample.java b/jsprit-examples/src/main/java/jsprit/examples/VRPWithBackhaulsExample.java index 5105b27e..defe942d 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/VRPWithBackhaulsExample.java +++ b/jsprit-examples/src/main/java/jsprit/examples/VRPWithBackhaulsExample.java @@ -28,6 +28,7 @@ import jsprit.core.algorithm.io.VehicleRoutingAlgorithms; import jsprit.core.algorithm.selector.SelectBest; import jsprit.core.problem.VehicleRoutingProblem; import jsprit.core.problem.VehicleRoutingProblem.Constraint; +import jsprit.core.problem.constraint.ServiceDeliveriesFirstConstraint; import jsprit.core.problem.io.VrpXMLReader; import jsprit.core.problem.solution.VehicleRoutingProblemSolution; @@ -62,7 +63,8 @@ public class VRPWithBackhaulsExample { /* * Finally, the problem can be built. By default, transportCosts are crowFlyDistances (as usually used for vrp-instances). */ - vrpBuilder.addProblemConstraint(Constraint.DELIVERIES_FIRST); +// vrpBuilder.addProblemConstraint(Constraint.DELIVERIES_FIRST); + vrpBuilder.addConstraint(new ServiceDeliveriesFirstConstraint()); VehicleRoutingProblem vrp = vrpBuilder.build(); diff --git a/jsprit-examples/src/main/java/jsprit/examples/VRPWithBackhaulsExample2.java b/jsprit-examples/src/main/java/jsprit/examples/VRPWithBackhaulsExample2.java index 8e611a48..10840db6 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/VRPWithBackhaulsExample2.java +++ b/jsprit-examples/src/main/java/jsprit/examples/VRPWithBackhaulsExample2.java @@ -28,6 +28,7 @@ import jsprit.core.algorithm.io.VehicleRoutingAlgorithms; import jsprit.core.algorithm.selector.SelectBest; import jsprit.core.problem.VehicleRoutingProblem; import jsprit.core.problem.VehicleRoutingProblem.Constraint; +import jsprit.core.problem.constraint.ServiceDeliveriesFirstConstraint; import jsprit.core.problem.io.VrpXMLReader; import jsprit.core.problem.solution.VehicleRoutingProblemSolution; @@ -62,7 +63,7 @@ public class VRPWithBackhaulsExample2 { /* * add the backhaul constraint to the problem */ - vrpBuilder.addProblemConstraint(Constraint.DELIVERIES_FIRST); + vrpBuilder.addConstraint(new ServiceDeliveriesFirstConstraint()); /* * Finally, the problem can be built. By default, transportCosts are crowFlyDistances (as usually used for vrp-instances). From 8f23104fbed417102c63ceef7dd9f06ed5067466 Mon Sep 17 00:00:00 2001 From: oblonski <4sschroeder@gmail.com> Date: Tue, 3 Dec 2013 07:51:30 +0100 Subject: [PATCH 07/12] test constraints --- .../problem/VehicleRoutingProblemBuilderTest.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/jsprit-core/src/test/java/jsprit/core/problem/VehicleRoutingProblemBuilderTest.java b/jsprit-core/src/test/java/jsprit/core/problem/VehicleRoutingProblemBuilderTest.java index 71467722..05465ca9 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/VehicleRoutingProblemBuilderTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/VehicleRoutingProblemBuilderTest.java @@ -17,8 +17,9 @@ package jsprit.core.problem; import static org.junit.Assert.assertEquals; -import jsprit.core.problem.VehicleRoutingProblem; +import static org.mockito.Mockito.mock; import jsprit.core.problem.VehicleRoutingProblem.FleetSize; +import jsprit.core.problem.constraint.Constraint; import jsprit.core.problem.job.Job; import jsprit.core.problem.job.Shipment; import jsprit.core.problem.vehicle.Vehicle; @@ -82,5 +83,15 @@ public class VehicleRoutingProblemBuilderTest { assertEquals(s2,vrp.getJobs().get("s2")); } + @Test + public void whenConstraintsAdded_theyShouldAppearInConstraintCollection(){ + Constraint c1 = mock(Constraint.class); + Constraint c2 = mock(Constraint.class); + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + builder.addConstraint(c1).addConstraint(c2); + VehicleRoutingProblem problem = builder.build(); + assertEquals(2,problem.getConstraints().size()); + } + } From a78d2644880e915eb04f4005898d6aa59f2d541e Mon Sep 17 00:00:00 2001 From: oblonski <4sschroeder@gmail.com> Date: Tue, 3 Dec 2013 07:52:24 +0100 Subject: [PATCH 08/12] deprecate unnecessary methods --- .../core/problem/VehicleRoutingProblem.java | 157 ++++++++++-------- 1 file changed, 86 insertions(+), 71 deletions(-) diff --git a/jsprit-core/src/main/java/jsprit/core/problem/VehicleRoutingProblem.java b/jsprit-core/src/main/java/jsprit/core/problem/VehicleRoutingProblem.java index 67919155..539a192d 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/VehicleRoutingProblem.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/VehicleRoutingProblem.java @@ -186,17 +186,6 @@ public class VehicleRoutingProblem { }; } - /** - * - * @deprecated use .addConstraint(new ServiceDeliveriesFirstConstraint()) - * @param constraint - */ - @Deprecated - public void addProblemConstraint(Constraint constraint){ - if(!problemConstraints.contains(constraint)) problemConstraints.add(constraint); - } - - /** * Sets routing costs. * @@ -223,39 +212,6 @@ public class VehicleRoutingProblem { return this; } - /** - * Sets the fleetComposition. - * - *
FleetComposition is either FleetComposition.HETEROGENEOUS or FleetComposition.HOMOGENEOUS - * - * @deprecated has no effect - * @param fleetComposition - * @return - */ - @Deprecated - public Builder setFleetComposition(FleetComposition fleetComposition){ - this.fleetComposition = fleetComposition; - return this; - } - - /** - * Adds a service to jobList. - * - *
If jobList already contains service, a warning message is printed, and the existing job will be overwritten.
- *
- * @deprecated use addJob(...) instead
- * @param service
- * @return
- */
- @Deprecated
- public Builder addService(Service service){
- coordinates.put(service.getLocationId(), service.getCoord());
- if(jobs.containsKey(service.getId())){ logger.warn("service " + service + " already in job list. overrides existing job."); }
- jobs.put(service.getId(),service);
- services.add(service);
- return this;
- }
-
/**
* Adds a job which is either a service or a shipment.
*
@@ -302,32 +258,6 @@ public class VehicleRoutingProblem {
return this;
}
- /**
- * Adds a vehicleType.
- *
- * @deprecated use add vehicle instead
- * @param type
- * @return builder
- */
- @Deprecated
- public Builder addVehicleType(VehicleType type){
- vehicleTypes.add(type);
- return this;
- }
-
- /**
- * Sets the neighborhood.
- *
- * @deprecated use HardRoute- or ActivityLevelConstraint instead
- * @param neighborhood
- * @return
- */
- @Deprecated
- public Builder setNeighborhood(Neighborhood neighborhood){
- this.neighborhood = neighborhood;
- return this;
- }
-
/**
* Sets the activityCostFunction that considers also activities on a vehicle-route.
*
@@ -398,8 +328,15 @@ public class VehicleRoutingProblem {
return Collections.unmodifiableCollection(vehicles);
}
- public void addConstraint(jsprit.core.problem.constraint.Constraint constraint){
+ /**
+ * Adds constraint to problem.
+ *
+ * @param constraint
+ * @return
+ */
+ public Builder addConstraint(jsprit.core.problem.constraint.Constraint constraint){
constraints.add(constraint);
+ return this;
}
/**
@@ -414,6 +351,75 @@ public class VehicleRoutingProblem {
public Collection FleetComposition is either FleetComposition.HETEROGENEOUS or FleetComposition.HOMOGENEOUS
+ *
+ * @deprecated has no effect
+ * @param fleetComposition
+ * @return
+ */
+ @Deprecated
+ public Builder setFleetComposition(FleetComposition fleetComposition){
+ this.fleetComposition = fleetComposition;
+ return this;
+ }
+
+ /**
+ * Adds a service to jobList.
+ *
+ * If jobList already contains service, a warning message is printed, and the existing job will be overwritten.
+ *
+ * @deprecated use addJob(...) instead
+ * @param service
+ * @return
+ */
+ @Deprecated
+ public Builder addService(Service service){
+ coordinates.put(service.getLocationId(), service.getCoord());
+ if(jobs.containsKey(service.getId())){ logger.warn("service " + service + " already in job list. overrides existing job."); }
+ jobs.put(service.getId(),service);
+ services.add(service);
+ return this;
+ }
+
+ /**
+ * Adds a vehicleType.
+ *
+ * @deprecated use add vehicle instead
+ * @param type
+ * @return builder
+ */
+ @Deprecated
+ public Builder addVehicleType(VehicleType type){
+ vehicleTypes.add(type);
+ return this;
+ }
+
+ /**
+ * Sets the neighborhood.
+ *
+ * @deprecated use HardRoute- or ActivityLevelConstraint instead
+ * @param neighborhood
+ * @return
+ */
+ @Deprecated
+ public Builder setNeighborhood(Neighborhood neighborhood){
+ this.neighborhood = neighborhood;
+ return this;
+ }
+
+ /**
+ *
+ * @deprecated use .addConstraint(new ServiceDeliveriesFirstConstraint())
+ * @param constraint
+ */
+ @Deprecated
+ public void addProblemConstraint(Constraint constraint){
+ if(!problemConstraints.contains(constraint)) problemConstraints.add(constraint);
+ }
}
/**
@@ -493,8 +499,10 @@ public class VehicleRoutingProblem {
}
/**
+ * @deprecated see builder.setNeighborhood(...). addConstraint(...) instead.
* @return the neighborhood
*/
+ @Deprecated
public Neighborhood getNeighborhood() {
return neighborhood;
}
@@ -531,8 +539,10 @@ public class VehicleRoutingProblem {
/**
* Returns unmodifiable collection of problem-constraints.
*
+ * @deprecated use .getConstraints() and builder.add
* @return
*/
+ @Deprecated
public Collection