diff --git a/jsprit-core/src/main/java/jsprit/core/problem/io/VrpXMLWriter.java b/jsprit-core/src/main/java/jsprit/core/problem/io/VrpXMLWriter.java index 01bba935..eaf7574a 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/io/VrpXMLWriter.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/io/VrpXMLWriter.java @@ -174,7 +174,10 @@ public class VrpXMLWriter { xmlConfig.setProperty(shipmentPathString + "("+counter+").coord[@x]", service.getCoord().getX()); xmlConfig.setProperty(shipmentPathString + "("+counter+").coord[@y]", service.getCoord().getY()); } - xmlConfig.setProperty(shipmentPathString + "("+counter+").capacity-demand", service.getCapacityDemand()); + for(int i=0;iIt determines how much capacity this job consumes of vehicle/transport unit. * - * @deprecated use getCapacity() instead + * @deprecated use .getCapacity() instead * @return */ @Deprecated diff --git a/jsprit-core/src/main/java/jsprit/core/problem/job/Service.java b/jsprit-core/src/main/java/jsprit/core/problem/job/Service.java index 6b97bd3a..ee65c97e 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/job/Service.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/job/Service.java @@ -44,11 +44,16 @@ public class Service implements Job { /** * Returns a new instance of service-builder. * + *

Note that if you use this builder, size is assigned to capacity-dimension with index=0. + * * @param id of service * @param size of capacity-demand * @return builder * @throws IllegalArgumentException if size < 0 or id is null + * @deprecated use .newInstance(String id) instead, and add a capacity dimension + * with dimensionIndex='your index' and and dimsionValue=size to the returned builder */ + @Deprecated public static Builder newInstance(String id, int size){ Builder builder = new Builder(id,size); builder.addCapacityDimension(0, size); @@ -71,7 +76,6 @@ public class Service implements Job { protected TimeWindow timeWindow = TimeWindow.newInstance(0.0, Double.MAX_VALUE); - protected int demand; protected Capacity.Builder capacityBuilder = Capacity.Builder.newInstance(); protected Capacity capacity; @@ -86,7 +90,6 @@ public class Service implements Job { if(size < 0) throw new IllegalArgumentException("size must be greater than or equal to zero"); if(id == null) throw new IllegalArgumentException("id must not be null"); this.id = id; - this.demand = size; } Builder(String id){ @@ -144,7 +147,13 @@ public class Service implements Job { return this; } - + /** + * Adds capacity dimension. + * + * @param dimensionIndex + * @param dimensionValue + * @return the builder + */ public Builder addCapacityDimension(int dimensionIndex, int dimensionValue){ capacityBuilder.addDimension(dimensionIndex, dimensionValue); return this; @@ -196,7 +205,7 @@ public class Service implements Job { private final TimeWindow timeWindow; - private final int demand; +// private final int demand; private final Capacity capacity; @@ -206,7 +215,6 @@ public class Service implements Job { coord = builder.coord; serviceTime = builder.serviceTime; timeWindow = builder.timeWindow; - demand = builder.demand; type = builder.type; capacity = builder.capacity; } @@ -252,9 +260,15 @@ public class Service implements Job { return timeWindow; } + /** + * @Deprecated use .getCapacity() instead. if you still use this method, it returns the + * capacity dimension with index=0. + * + */ @Override + @Deprecated public int getCapacityDemand() { - return demand; + return capacity.get(0); } /** @@ -271,7 +285,7 @@ public class Service implements Job { */ @Override public String toString() { - return "[id=" + id + "][type="+type+"][locationId=" + locationId + "][coord="+coord+"][size=" + demand + "][serviceTime=" + serviceTime + "][timeWindow=" + timeWindow + "]"; + return "[id=" + id + "][type="+type+"][locationId=" + locationId + "][coord="+coord+"][capacity=" + capacity + "][serviceTime=" + serviceTime + "][timeWindow=" + timeWindow + "]"; } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/job/Shipment.java b/jsprit-core/src/main/java/jsprit/core/problem/job/Shipment.java index 005d0ba2..e2b7adb0 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/job/Shipment.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/job/Shipment.java @@ -31,8 +31,6 @@ public class Shipment implements Job{ */ public static class Builder { - private int demand; - private String id; private String pickupLocation; @@ -58,11 +56,16 @@ public class Shipment implements Job{ /** * Returns a new instance of this builder. * + *

Note that if you use this builder, size is assigned to capacity-dimension with index=0. + * * @param id * @param size * @return builder * @throws IllegalArgumentException if size < 0 or id is null + * @deprecated use .newInstance(String id) instead, and add a capacity dimension + * with dimensionIndex='your index' and and dimsionValue=size to the returned builder */ + @Deprecated public static Builder newInstance(String id, int size){ Builder builder = new Builder(id,size); builder.addCapacityDimension(0, size); @@ -84,7 +87,6 @@ public class Shipment implements Job{ if(size < 0) throw new IllegalArgumentException("size must be greater than or equal to zero"); if(id == null) throw new IllegalArgumentException("id must not be null"); this.id = id; - this.demand = size; } Builder(String id){ @@ -241,8 +243,6 @@ public class Shipment implements Job{ } - private final int demand; - private final String id; private final String pickupLocation; @@ -271,7 +271,6 @@ public class Shipment implements Job{ */ Shipment(Builder builder){ this.id = builder.id; - this.demand = builder.demand; this.pickupLocation = builder.pickupLocation; this.pickupCoord = builder.pickupCoord; this.pickupServiceTime = builder.pickupServiceTime; @@ -288,9 +287,14 @@ public class Shipment implements Job{ return id; } + /** + * @Deprecated use .getCapacity() instead. if you still use this method, it returns the + * capacity dimension with index=0. + */ + @Deprecated @Override public int getCapacityDemand() { - return demand; + return capacity.get(0); } /** diff --git a/jsprit-core/src/main/java/jsprit/core/problem/vehicle/Vehicle.java b/jsprit-core/src/main/java/jsprit/core/problem/vehicle/Vehicle.java index c73cfb24..0f44343f 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/vehicle/Vehicle.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/vehicle/Vehicle.java @@ -81,7 +81,11 @@ public interface Vehicle { * Returns the capacity of this vehicle. * * @return capacity + * @deprecated use .getType().getCapacityDimensions() - if you still use this method, + * but set capacity-dimensions via VehicleTypeImpl.Builder.newInstance(...).addCapacityDimension(...) then this method returns the + * dimension with index=0. */ + @Deprecated public abstract int getCapacity(); /** diff --git a/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleImpl.java b/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleImpl.java index 92e69358..3c3abf9d 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleImpl.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleImpl.java @@ -372,6 +372,7 @@ public class VehicleImpl implements Vehicle { } @Override + @Deprecated public int getCapacity() { return type.getCapacity(); } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleType.java b/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleType.java index f2464aaf..7580513b 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleType.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleType.java @@ -39,8 +39,12 @@ public interface VehicleType { * *

In future versions there will be a capacity-object with an arbitrary number of capacity dimensions. (stefan,11.01.14) * + * + * @deprecated use .getCapacityDimensions() - if you still use it, but set CapacityDimensions rather + * than setCapacity(...) it will return the capacity.dimension with index=0 * @return cap */ + @Deprecated public int getCapacity(); /** diff --git a/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleTypeImpl.java b/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleTypeImpl.java index a1e1bda2..f0c6cae3 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleTypeImpl.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleTypeImpl.java @@ -187,6 +187,13 @@ public class VehicleTypeImpl implements VehicleType { return new VehicleTypeImpl(this); } + /** + * Adds a capacity dimension. + * + * @param dimIndex + * @param dimVal + * @return the builder + */ public Builder addCapacityDimension(int dimIndex, int dimVal) { capacityBuilder.addDimension(dimIndex,dimVal); return this; @@ -285,8 +292,9 @@ public class VehicleTypeImpl implements VehicleType { * @see basics.route.VehicleType#getCapacity() */ @Override + @Deprecated public int getCapacity() { - return capacity; + return capacityDimensions.get(0); } /* (non-Javadoc) diff --git a/jsprit-core/src/main/resources/vrp_xml_schema.xsd b/jsprit-core/src/main/resources/vrp_xml_schema.xsd index 4022bacd..c687aa05 100644 --- a/jsprit-core/src/main/resources/vrp_xml_schema.xsd +++ b/jsprit-core/src/main/resources/vrp_xml_schema.xsd @@ -84,8 +84,8 @@ - - + + @@ -94,7 +94,7 @@ - + @@ -126,8 +126,8 @@ - - + + @@ -136,7 +136,7 @@ - + @@ -195,11 +195,11 @@ - + - - + + @@ -208,7 +208,7 @@ - + diff --git a/jsprit-core/src/test/java/jsprit/core/problem/io/VrpReaderV2Test.java b/jsprit-core/src/test/java/jsprit/core/problem/io/VrpReaderV2Test.java index 19f29541..4767c197 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/io/VrpReaderV2Test.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/io/VrpReaderV2Test.java @@ -59,10 +59,11 @@ public class VrpReaderV2Test { VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); new VrpXMLReader(builder, null).read(inFileName); VehicleRoutingProblem vrp = builder.build(); - assertEquals(4,vrp.getVehicles().size()); + assertEquals(5,vrp.getVehicles().size()); assertTrue(idsInCollection(Arrays.asList("v1","v2"),vrp.getVehicles())); } + @SuppressWarnings("deprecation") @Test public void whenReadingVrp_vehiclesAreReadCorrectly2(){ VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); @@ -70,6 +71,7 @@ public class VrpReaderV2Test { VehicleRoutingProblem vrp = builder.build(); Vehicle v1 = getVehicle("v1",vrp.getVehicles()); assertEquals(20,v1.getCapacity()); + assertEquals(20,v1.getType().getCapacityDimensions().get(0)); assertEquals(100.0,v1.getStartLocationCoordinate().getX(),0.01); assertEquals(0.0,v1.getEarliestDeparture(),0.01); assertEquals("depotLoc2",v1.getStartLocationId()); @@ -96,7 +98,7 @@ public class VrpReaderV2Test { VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); new VrpXMLReader(builder, null).read(inFileName); VehicleRoutingProblem vrp = builder.build(); - assertEquals(2,vrp.getTypes().size()); + assertEquals(3,vrp.getTypes().size()); } @Test @@ -139,6 +141,7 @@ public class VrpReaderV2Test { assertEquals(2,shipCounter); } + @SuppressWarnings("deprecation") @Test public void whenReadingServices_capOfService1IsReadCorrectly(){ VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); @@ -146,6 +149,7 @@ public class VrpReaderV2Test { VehicleRoutingProblem vrp = builder.build(); Service s1 = (Service) vrp.getJobs().get("1"); assertEquals(1,s1.getCapacityDemand()); + assertEquals(1,s1.getCapacity().get(0)); } @Test @@ -299,6 +303,7 @@ public class VrpReaderV2Test { assertEquals("startLoc",v.getStartLocationId()); } + @SuppressWarnings("deprecation") @Test public void whenReadingJobs_capOfShipment3IsReadCorrectly(){ VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); @@ -306,6 +311,7 @@ public class VrpReaderV2Test { VehicleRoutingProblem vrp = builder.build(); Shipment s = (Shipment) vrp.getJobs().get("3"); assertEquals(10,s.getCapacityDemand()); + assertEquals(10,s.getCapacity().get(0)); } @Test @@ -419,5 +425,20 @@ public class VrpReaderV2Test { Shipment s = (Shipment) vrp.getJobs().get("4"); assertEquals(100.0,s.getDeliveryServiceTime(),0.01); } + + @Test + public void whenReadingFile_v5AndItsTypeHasTheCorrectCapacityDimensionValues(){ + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder, null).read(inFileName); + VehicleRoutingProblem vrp = builder.build(); + Vehicle v = getVehicle("v5",vrp.getVehicles()); +// assertEquals(100, v.getType().getCapacityDimensions().get(0)); + assertEquals(1000, v.getType().getCapacityDimensions().get(1)); +// assertEquals(10000, v.getType().getCapacityDimensions().get(2)); +// assertEquals(0, v.getType().getCapacityDimensions().get(3)); +// assertEquals(0, v.getType().getCapacityDimensions().get(5)); +// assertEquals(100000, v.getType().getCapacityDimensions().get(10)); + + } } diff --git a/jsprit-core/src/test/java/jsprit/core/problem/io/VrpWriterV2Test.java b/jsprit-core/src/test/java/jsprit/core/problem/io/VrpWriterV2Test.java index 6954f1ed..f029647c 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/io/VrpWriterV2Test.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/io/VrpWriterV2Test.java @@ -35,7 +35,7 @@ import jsprit.core.util.Coordinate; import org.junit.Before; import org.junit.Test; - +@SuppressWarnings("deprecation") public class VrpWriterV2Test { private String infileName; @@ -100,6 +100,7 @@ public class VrpWriterV2Test { builder.addVehicle(v1); builder.addVehicle(v2); + Service s1 = Service.Builder.newInstance("1", 1).setLocationId("loc").setServiceTime(2.0).build(); Service s2 = Service.Builder.newInstance("2", 1).setLocationId("loc2").setServiceTime(4.0).build(); diff --git a/jsprit-core/src/test/resources/finiteVrpForReaderV2Test.xml b/jsprit-core/src/test/resources/finiteVrpForReaderV2Test.xml index c94d7cf9..844f0c4a 100644 --- a/jsprit-core/src/test/resources/finiteVrpForReaderV2Test.xml +++ b/jsprit-core/src/test/resources/finiteVrpForReaderV2Test.xml @@ -85,12 +85,28 @@ 1000.0 + + v5 + + startLoc + + + + endLoc + + + vehType3 + + 0.0 + 1000.0 + + vehType - 20 + 20 0.0 @@ -107,6 +123,20 @@ + + vehType3 + + 100 + 1000 + 10000 + 100000 + + + 0.0 + 0.0 + + + @@ -114,7 +144,7 @@ j(1,5) - 1 + 1 10.0 @@ -187,7 +217,9 @@ - 10 + + 10 + diff --git a/jsprit-core/src/test/resources/infiniteWriterV2Test.xml b/jsprit-core/src/test/resources/infiniteWriterV2Test.xml index 11e1b5cf..aef90bc9 100644 --- a/jsprit-core/src/test/resources/infiniteWriterV2Test.xml +++ b/jsprit-core/src/test/resources/infiniteWriterV2Test.xml @@ -42,7 +42,9 @@ vehType - 20 + + 20 + 0.0 1.0 @@ -51,7 +53,9 @@ vehType2 - 200 + + 200 + 0.0 1.0 @@ -62,7 +66,9 @@ loc2 - 1 + + 1 + 4.0 @@ -73,7 +79,9 @@ loc - 1 + + 1 + 2.0