1
0
Fork 0
mirror of https://github.com/graphhopper/jsprit.git synced 2020-01-24 07:45:05 +01:00

added multiple caps

This commit is contained in:
oblonski 2014-02-14 15:40:46 +01:00
parent cec4e4235e
commit 8da2d1e1c5
13 changed files with 147 additions and 40 deletions

View file

@ -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;i<service.getCapacity().getNuOfDimensions();i++){
xmlConfig.setProperty(shipmentPathString + "("+counter+").capacity-dimensions.dimension("+i+")[@index]", i);
xmlConfig.setProperty(shipmentPathString + "("+counter+").capacity-dimensions.dimension("+i+")", service.getCapacity().get(i));
}
xmlConfig.setProperty(shipmentPathString + "("+counter+").duration", service.getServiceDuration());
xmlConfig.setProperty(shipmentPathString + "("+counter+").timeWindows.timeWindow(0).start", service.getTimeWindow().getStart());
xmlConfig.setProperty(shipmentPathString + "("+counter+").timeWindows.timeWindow(0).end", service.getTimeWindow().getEnd());
@ -212,8 +215,10 @@ public class VrpXMLWriter {
xmlConfig.setProperty(shipmentPathString + "("+counter+").delivery.timeWindows.timeWindow(0).start", shipment.getDeliveryTimeWindow().getStart());
xmlConfig.setProperty(shipmentPathString + "("+counter+").delivery.timeWindows.timeWindow(0).end", shipment.getDeliveryTimeWindow().getEnd());
xmlConfig.setProperty(shipmentPathString + "("+counter+").capacity-demand", shipment.getCapacityDemand());
for(int i=0;i<shipment.getCapacity().getNuOfDimensions();i++){
xmlConfig.setProperty(shipmentPathString + "("+counter+").capacity-dimensions.dimension("+i+")[@index]", i);
xmlConfig.setProperty(shipmentPathString + "("+counter+").capacity-dimensions.dimension("+i+")", shipment.getCapacity().get(i));
}
counter++;
}
}
@ -262,7 +267,12 @@ public class VrpXMLWriter {
xmlConfig.setProperty(typePathString + "("+typeCounter+")[@penaltyFactor]", ((PenaltyVehicleType)type).getPenaltyFactor());
}
xmlConfig.setProperty(typePathString + "("+typeCounter+").id", type.getTypeId());
xmlConfig.setProperty(typePathString + "("+typeCounter+").capacity", type.getCapacity());
for(int i=0;i<type.getCapacityDimensions().getNuOfDimensions();i++){
xmlConfig.setProperty(typePathString + "("+typeCounter+").capacity-dimensions.dimension("+i+")[@index]", i);
xmlConfig.setProperty(typePathString + "("+typeCounter+").capacity-dimensions.dimension("+i+")", type.getCapacityDimensions().get(i));
}
xmlConfig.setProperty(typePathString + "("+typeCounter+").costs.fixed", type.getVehicleCostParams().fix);
xmlConfig.setProperty(typePathString + "("+typeCounter+").costs.distance", type.getVehicleCostParams().perDistanceUnit);
xmlConfig.setProperty(typePathString + "("+typeCounter+").costs.time", type.getVehicleCostParams().perTimeUnit);

View file

@ -39,7 +39,7 @@ public interface Job {
*
* <p>It determines how much capacity this job consumes of vehicle/transport unit.
*
* @deprecated use getCapacity() instead
* @deprecated use <code>.getCapacity()</code> instead
* @return
*/
@Deprecated

View file

@ -44,11 +44,16 @@ public class Service implements Job {
/**
* Returns a new instance of service-builder.
*
* <p>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 <code>.newInstance(String id)</code> 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 <code>.getCapacity()</code> 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 + "]";
}

View file

@ -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.
*
* <p>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 <code>.newInstance(String id)</code> 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 <code>.getCapacity()</code> 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);
}
/**

View file

@ -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 <code>VehicleTypeImpl.Builder.newInstance(...).addCapacityDimension(...)</code> then this method returns the
* dimension with index=0.
*/
@Deprecated
public abstract int getCapacity();
/**

View file

@ -372,6 +372,7 @@ public class VehicleImpl implements Vehicle {
}
@Override
@Deprecated
public int getCapacity() {
return type.getCapacity();
}

View file

@ -39,8 +39,12 @@ public interface VehicleType {
*
* <p>In future versions there will be a capacity-object with an arbitrary number of capacity dimensions. (stefan,11.01.14)
*
*
* @deprecated use <code>.getCapacityDimensions()</code> - 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();
/**

View file

@ -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)

View file

@ -84,8 +84,8 @@
<xs:element name="capacity" type="xs:integer" minOccurs="0" maxOccurs="1" default="0"/>
<xs:element name="capacity-dimensions" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:all>
<xs:element name="dimension" minOccurs="1">
<xs:sequence>
<xs:element name="dimension" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:integer">
@ -94,7 +94,7 @@
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:all>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="costs">
@ -126,8 +126,8 @@
<xs:element name="capacity-demand" type="xs:integer" minOccurs="0" maxOccurs="1" default="0"/>
<xs:element name="capacity-dimensions" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:all>
<xs:element name="dimension" minOccurs="1">
<xs:sequence>
<xs:element name="dimension" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:integer">
@ -136,7 +136,7 @@
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:all>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="duration" type="xs:decimal" minOccurs="0" maxOccurs="1" default="0.0"/>
@ -195,11 +195,11 @@
</xs:all>
</xs:complexType>
</xs:element>
<xs:element name="capacity-demand" type="xs:integer" minOccurs="1" maxOccurs="1"/>
<xs:element name="capacity-demand" type="xs:integer" minOccurs="0" maxOccurs="1"/>
<xs:element name="capacity-dimensions" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:all>
<xs:element name="dimension" minOccurs="1">
<xs:sequence>
<xs:element name="dimension" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:integer">
@ -208,7 +208,7 @@
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:all>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>

View file

@ -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));
}
}

View file

@ -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();

View file

@ -85,12 +85,28 @@
<end>1000.0</end>
</timeSchedule>
</vehicle>
<vehicle>
<id>v5</id>
<location>
<id>startLoc</id>
<coord x="10.0" y="100.0"/>
</location>
<endLocation>
<id>endLoc</id>
<coord x="1000.0" y="2000.0"/>
</endLocation>
<typeId>vehType3</typeId>
<timeSchedule>
<start>0.0</start>
<end>1000.0</end>
</timeSchedule>
</vehicle>
</vehicles>
<vehicleTypes>
<type>
<id>vehType</id>
<capacity-dimensions>
<dimension index="1">20</dimension>
<dimension index="0">20</dimension>
</capacity-dimensions>
<costs>
<fixed>0.0</fixed>
@ -107,6 +123,20 @@
<time>0.0</time>
</costs>
</type>
<type>
<id>vehType3</id>
<capacity-dimensions>
<dimension index="0">100</dimension>
<dimension index="1">1000</dimension>
<dimension index="2">10000</dimension>
<dimension index="10">100000</dimension>
</capacity-dimensions>
<costs>
<fixed>0.0</fixed>
<distance>0.0</distance>
<time>0.0</time>
</costs>
</type>
</vehicleTypes>
<services>
@ -114,7 +144,7 @@
<locationId>j(1,5)</locationId>
<coord x="10.0" y="10.0"/>
<capacity-dimensions>
<dimension index="1">1</dimension>
<dimension index="0">1</dimension>
</capacity-dimensions>
<duration>10.0</duration>
<timeWindows>
@ -187,7 +217,9 @@
</timeWindow>
</timeWindows>
</delivery>
<capacity-demand>10</capacity-demand>
<capacity-dimensions>
<dimension index="0">10</dimension>
</capacity-dimensions>
</shipment>
</shipments>

View file

@ -42,7 +42,9 @@
<vehicleTypes>
<type>
<id>vehType</id>
<capacity>20</capacity>
<capacity-dimensions>
<dimension index="0">20</dimension>
</capacity-dimensions>
<costs>
<fixed>0.0</fixed>
<distance>1.0</distance>
@ -51,7 +53,9 @@
</type>
<type>
<id>vehType2</id>
<capacity>200</capacity>
<capacity-dimensions>
<dimension index="0">200</dimension>
</capacity-dimensions>
<costs>
<fixed>0.0</fixed>
<distance>1.0</distance>
@ -62,7 +66,9 @@
<services>
<service id="2" type="service">
<locationId>loc2</locationId>
<capacity-demand>1</capacity-demand>
<capacity-dimensions>
<dimension index="0">1</dimension>
</capacity-dimensions>
<duration>4.0</duration>
<timeWindows>
<timeWindow>
@ -73,7 +79,9 @@
</service>
<service id="1" type="service">
<locationId>loc</locationId>
<capacity-demand>1</capacity-demand>
<capacity-dimensions>
<dimension index="0">1</dimension>
</capacity-dimensions>
<duration>2.0</duration>
<timeWindows>
<timeWindow>