mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
tested VrpXMLWriter to write multiple cap-dims
This commit is contained in:
parent
7ca1665dfb
commit
89025693c8
2 changed files with 125 additions and 58 deletions
|
|
@ -119,6 +119,32 @@ public class VrpWriterV2Test {
|
||||||
assertEquals(2.0,s1_read.getServiceDuration(),0.01);
|
assertEquals(2.0,s1_read.getServiceDuration(),0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenWritingServicesWithSeveralCapacityDimensions_itWritesThemCorrectly(){
|
||||||
|
Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||||
|
|
||||||
|
Service s1 = Service.Builder.newInstance("1")
|
||||||
|
.addCapacityDimension(0, 20)
|
||||||
|
.addCapacityDimension(1, 200)
|
||||||
|
.setLocationId("loc").setServiceTime(2.0).build();
|
||||||
|
Service s2 = Service.Builder.newInstance("2", 1).setLocationId("loc2").setServiceTime(4.0).build();
|
||||||
|
|
||||||
|
VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build();
|
||||||
|
new VrpXMLWriter(vrp, null).write(infileName);
|
||||||
|
|
||||||
|
VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||||
|
new VrpXMLReader(vrpToReadBuilder, null).read(infileName);
|
||||||
|
VehicleRoutingProblem readVrp = vrpToReadBuilder.build();
|
||||||
|
assertEquals(2,readVrp.getJobs().size());
|
||||||
|
|
||||||
|
Service s1_read = (Service) vrp.getJobs().get("1");
|
||||||
|
|
||||||
|
assertEquals(2, s1_read.getCapacity().getNuOfDimensions());
|
||||||
|
assertEquals(20, s1_read.getCapacity().get(0));
|
||||||
|
assertEquals(200, s1_read.getCapacity().get(1));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenWritingShipments_readingThemAgainMustReturnTheWrittenLocationIdsOfS1(){
|
public void whenWritingShipments_readingThemAgainMustReturnTheWrittenLocationIdsOfS1(){
|
||||||
Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||||
|
|
@ -306,6 +332,36 @@ public class VrpWriterV2Test {
|
||||||
assertEquals(6.0,((Shipment)readVrp.getJobs().get("1")).getDeliveryCoord().getY(),0.01);
|
assertEquals(6.0,((Shipment)readVrp.getJobs().get("1")).getDeliveryCoord().getY(),0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenWritingShipmentWithSeveralCapacityDimension_itShouldWriteAndReadItCorrectly(){
|
||||||
|
Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||||
|
|
||||||
|
Shipment s1 = Shipment.Builder.newInstance("1")
|
||||||
|
.setPickupCoord(Coordinate.newInstance(1, 2)).setDeliveryCoord(Coordinate.newInstance(5, 6)).setDeliveryLocation("delLoc").setPickupTimeWindow(TimeWindow.newInstance(1, 2))
|
||||||
|
.setDeliveryTimeWindow(TimeWindow.newInstance(3, 4)).setPickupServiceTime(100).setDeliveryServiceTime(50)
|
||||||
|
.addCapacityDimension(0, 10)
|
||||||
|
.addCapacityDimension(2, 100)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Shipment s2 = Shipment.Builder.newInstance("2", 20).setPickupLocation("pickLocation").setDeliveryLocation("delLocation").setPickupTimeWindow(TimeWindow.newInstance(5, 6))
|
||||||
|
.setDeliveryTimeWindow(TimeWindow.newInstance(7, 8)).build();
|
||||||
|
|
||||||
|
VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build();
|
||||||
|
new VrpXMLWriter(vrp, null).write(infileName);
|
||||||
|
|
||||||
|
VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||||
|
new VrpXMLReader(vrpToReadBuilder, null).read(infileName);
|
||||||
|
VehicleRoutingProblem readVrp = vrpToReadBuilder.build();
|
||||||
|
|
||||||
|
assertEquals(3,((Shipment)readVrp.getJobs().get("1")).getCapacity().getNuOfDimensions());
|
||||||
|
assertEquals(10,((Shipment)readVrp.getJobs().get("1")).getCapacity().get(0));
|
||||||
|
assertEquals(0,((Shipment)readVrp.getJobs().get("1")).getCapacity().get(1));
|
||||||
|
assertEquals(100,((Shipment)readVrp.getJobs().get("1")).getCapacity().get(2));
|
||||||
|
|
||||||
|
assertEquals(1,((Shipment)readVrp.getJobs().get("2")).getCapacity().getNuOfDimensions());
|
||||||
|
assertEquals(20,((Shipment)readVrp.getJobs().get("2")).getCapacity().get(0));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenWritingVehicleV1_itsStartLocationMustBeWrittenCorrectly(){
|
public void whenWritingVehicleV1_itsStartLocationMustBeWrittenCorrectly(){
|
||||||
Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||||
|
|
@ -473,6 +529,61 @@ public class VrpWriterV2Test {
|
||||||
assertEquals(5.0,v.getEndLocationCoordinate().getY(),0.01);
|
assertEquals(5.0,v.getEndLocationCoordinate().getY(),0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenWritingVehicleWithSeveralCapacityDimensions_itShouldBeWrittenAndRereadCorrectly(){
|
||||||
|
Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||||
|
|
||||||
|
VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("type", 200)
|
||||||
|
.addCapacityDimension(0, 100)
|
||||||
|
.addCapacityDimension(1, 1000)
|
||||||
|
.addCapacityDimension(2, 10000)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Vehicle v2 = VehicleImpl.Builder.newInstance("v").setStartLocationId("startLoc").setStartLocationCoordinate(Coordinate.newInstance(1, 2))
|
||||||
|
.setEndLocationId("endLoc").setEndLocationCoordinate(Coordinate.newInstance(4, 5)).setType(type2).build();
|
||||||
|
builder.addVehicle(v2);
|
||||||
|
|
||||||
|
VehicleRoutingProblem vrp = builder.build();
|
||||||
|
new VrpXMLWriter(vrp, null).write(infileName);
|
||||||
|
|
||||||
|
VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||||
|
new VrpXMLReader(vrpToReadBuilder, null).read(infileName);
|
||||||
|
VehicleRoutingProblem readVrp = vrpToReadBuilder.build();
|
||||||
|
|
||||||
|
Vehicle v = getVehicle("v",readVrp.getVehicles());
|
||||||
|
assertEquals(3,v.getType().getCapacityDimensions().getNuOfDimensions());
|
||||||
|
assertEquals(100,v.getType().getCapacityDimensions().get(0));
|
||||||
|
assertEquals(1000,v.getType().getCapacityDimensions().get(1));
|
||||||
|
assertEquals(10000,v.getType().getCapacityDimensions().get(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenWritingVehicleWithSeveralCapacityDimensions_itShouldBeWrittenAndRereadCorrectlyV2(){
|
||||||
|
Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||||
|
|
||||||
|
VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("type", 200)
|
||||||
|
.addCapacityDimension(0, 100)
|
||||||
|
.addCapacityDimension(1, 1000)
|
||||||
|
.addCapacityDimension(10, 10000)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Vehicle v2 = VehicleImpl.Builder.newInstance("v").setStartLocationId("startLoc").setStartLocationCoordinate(Coordinate.newInstance(1, 2))
|
||||||
|
.setEndLocationId("endLoc").setEndLocationCoordinate(Coordinate.newInstance(4, 5)).setType(type2).build();
|
||||||
|
builder.addVehicle(v2);
|
||||||
|
|
||||||
|
VehicleRoutingProblem vrp = builder.build();
|
||||||
|
new VrpXMLWriter(vrp, null).write(infileName);
|
||||||
|
|
||||||
|
VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||||
|
new VrpXMLReader(vrpToReadBuilder, null).read(infileName);
|
||||||
|
VehicleRoutingProblem readVrp = vrpToReadBuilder.build();
|
||||||
|
|
||||||
|
Vehicle v = getVehicle("v",readVrp.getVehicles());
|
||||||
|
assertEquals(11,v.getType().getCapacityDimensions().getNuOfDimensions());
|
||||||
|
assertEquals(0,v.getType().getCapacityDimensions().get(9));
|
||||||
|
assertEquals(10000,v.getType().getCapacityDimensions().get(10));
|
||||||
|
}
|
||||||
|
|
||||||
private Vehicle getVehicle(String string, Collection<Vehicle> vehicles) {
|
private Vehicle getVehicle(String string, Collection<Vehicle> vehicles) {
|
||||||
for(Vehicle v : vehicles) if(string.equals(v.getId())) return v;
|
for(Vehicle v : vehicles) if(string.equals(v.getId())) return v;
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -7,23 +7,8 @@
|
||||||
</problemType>
|
</problemType>
|
||||||
<vehicles>
|
<vehicles>
|
||||||
<vehicle>
|
<vehicle>
|
||||||
<id>v1</id>
|
<id>v</id>
|
||||||
<typeId>vehType</typeId>
|
<typeId>type</typeId>
|
||||||
<startLocation>
|
|
||||||
<id>loc</id>
|
|
||||||
</startLocation>
|
|
||||||
<endLocation>
|
|
||||||
<id>loc</id>
|
|
||||||
</endLocation>
|
|
||||||
<timeSchedule>
|
|
||||||
<start>0.0</start>
|
|
||||||
<end>1.7976931348623157E308</end>
|
|
||||||
</timeSchedule>
|
|
||||||
<returnToDepot>false</returnToDepot>
|
|
||||||
</vehicle>
|
|
||||||
<vehicle>
|
|
||||||
<id>v2</id>
|
|
||||||
<typeId>vehType2</typeId>
|
|
||||||
<startLocation>
|
<startLocation>
|
||||||
<id>startLoc</id>
|
<id>startLoc</id>
|
||||||
<coord x="1.0" y="2.0"/>
|
<coord x="1.0" y="2.0"/>
|
||||||
|
|
@ -41,20 +26,19 @@
|
||||||
</vehicles>
|
</vehicles>
|
||||||
<vehicleTypes>
|
<vehicleTypes>
|
||||||
<type>
|
<type>
|
||||||
<id>vehType</id>
|
<id>type</id>
|
||||||
<capacity-dimensions>
|
<capacity-dimensions>
|
||||||
<dimension index="0">20</dimension>
|
<dimension index="0">100</dimension>
|
||||||
</capacity-dimensions>
|
<dimension index="1">1000</dimension>
|
||||||
<costs>
|
<dimension index="2">0</dimension>
|
||||||
<fixed>0.0</fixed>
|
<dimension index="3">0</dimension>
|
||||||
<distance>1.0</distance>
|
<dimension index="4">0</dimension>
|
||||||
<time>0.0</time>
|
<dimension index="5">0</dimension>
|
||||||
</costs>
|
<dimension index="6">0</dimension>
|
||||||
</type>
|
<dimension index="7">0</dimension>
|
||||||
<type>
|
<dimension index="8">0</dimension>
|
||||||
<id>vehType2</id>
|
<dimension index="9">0</dimension>
|
||||||
<capacity-dimensions>
|
<dimension index="10">10000</dimension>
|
||||||
<dimension index="0">200</dimension>
|
|
||||||
</capacity-dimensions>
|
</capacity-dimensions>
|
||||||
<costs>
|
<costs>
|
||||||
<fixed>0.0</fixed>
|
<fixed>0.0</fixed>
|
||||||
|
|
@ -63,32 +47,4 @@
|
||||||
</costs>
|
</costs>
|
||||||
</type>
|
</type>
|
||||||
</vehicleTypes>
|
</vehicleTypes>
|
||||||
<services>
|
|
||||||
<service id="2" type="service">
|
|
||||||
<locationId>loc2</locationId>
|
|
||||||
<capacity-dimensions>
|
|
||||||
<dimension index="0">1</dimension>
|
|
||||||
</capacity-dimensions>
|
|
||||||
<duration>4.0</duration>
|
|
||||||
<timeWindows>
|
|
||||||
<timeWindow>
|
|
||||||
<start>0.0</start>
|
|
||||||
<end>1.7976931348623157E308</end>
|
|
||||||
</timeWindow>
|
|
||||||
</timeWindows>
|
|
||||||
</service>
|
|
||||||
<service id="1" type="service">
|
|
||||||
<locationId>loc</locationId>
|
|
||||||
<capacity-dimensions>
|
|
||||||
<dimension index="0">1</dimension>
|
|
||||||
</capacity-dimensions>
|
|
||||||
<duration>2.0</duration>
|
|
||||||
<timeWindows>
|
|
||||||
<timeWindow>
|
|
||||||
<start>0.0</start>
|
|
||||||
<end>1.7976931348623157E308</end>
|
|
||||||
</timeWindow>
|
|
||||||
</timeWindows>
|
|
||||||
</service>
|
|
||||||
</services>
|
|
||||||
</problem>
|
</problem>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue