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 1f9e3d9e..9bad6b39 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
@@ -316,11 +316,14 @@ public class VrpXMLReader{
int cap = getCap(shipmentConfig);
Shipment.Builder builder = Shipment.Builder.newInstance(id, cap);
+ //pickup-locationId
String pickupLocationId = shipmentConfig.getString("pickup.locationId");
- builder.setPickupLocation(pickupLocationId);
+ if(pickupLocationId != null){
+ builder.setPickupLocation(pickupLocationId);
+ }
+ //pickup-coord
Coordinate pickupCoord = getCoord(shipmentConfig,"pickup.");
-
if(pickupCoord != null){
builder.setPickupCoord(pickupCoord);
if(pickupLocationId != null){
@@ -331,17 +334,27 @@ public class VrpXMLReader{
builder.setPickupLocation(pickupCoord.toString());
}
}
+ //pickup-serviceTime
+ String pickupServiceTime = shipmentConfig.getString("pickup.duration");
+ if(pickupServiceTime != null) builder.setPickupServiceTime(Double.parseDouble(pickupServiceTime));
+ //pickup-tw
String pickupTWStart = shipmentConfig.getString("pickup.timeWindows.timeWindow(0).start");
String pickupTWEnd = shipmentConfig.getString("pickup.timeWindows.timeWindow(0).end");
- TimeWindow pickupTW = TimeWindow.newInstance(Double.parseDouble(pickupTWStart), Double.parseDouble(pickupTWEnd));
- builder.setPickupTimeWindow(pickupTW);
+ if(pickupTWStart != null && pickupTWEnd != null){
+ TimeWindow pickupTW = TimeWindow.newInstance(Double.parseDouble(pickupTWStart), Double.parseDouble(pickupTWEnd));
+ builder.setPickupTimeWindow(pickupTW);
+ }
+
+ //delivery-locationId
String deliveryLocationId = shipmentConfig.getString("delivery.locationId");
- builder.setDeliveryLocation(deliveryLocationId);
+ if(deliveryLocationId != null){
+ builder.setDeliveryLocation(deliveryLocationId);
+ }
+ //delivery-coord
Coordinate deliveryCoord = getCoord(shipmentConfig,"delivery.");
-
if(deliveryCoord != null){
builder.setDeliveryCoord(deliveryCoord);
if(deliveryLocationId != null){
@@ -349,14 +362,21 @@ public class VrpXMLReader{
}
else{
vrpBuilder.addLocation(deliveryCoord.toString(),deliveryCoord);
- builder.setPickupLocation(deliveryCoord.toString());
+ builder.setDeliveryLocation(deliveryCoord.toString());
}
}
+ //delivery-serviceTime
+ String deliveryServiceTime = shipmentConfig.getString("delivery.duration");
+ if(deliveryServiceTime != null) builder.setDeliveryServiceTime(Double.parseDouble(deliveryServiceTime));
+ //delivery-tw
String delTWStart = shipmentConfig.getString("delivery.timeWindows.timeWindow(0).start");
String delTWEnd = shipmentConfig.getString("delivery.timeWindows.timeWindow(0).end");
- TimeWindow delTW = TimeWindow.newInstance(Double.parseDouble(delTWStart), Double.parseDouble(delTWEnd));
- builder.setDeliveryTimeWindow(delTW);
+ if(delTWStart != null && delTWEnd != null){
+ TimeWindow delTW = TimeWindow.newInstance(Double.parseDouble(delTWStart), Double.parseDouble(delTWEnd));
+ builder.setDeliveryTimeWindow(delTW);
+ }
+
Shipment shipment = builder.build();
vrpBuilder.addJob(shipment);
@@ -391,7 +411,7 @@ public class VrpXMLReader{
int cap = getCap(serviceConfig);
Service.Builder builder = serviceBuilderFactory.createBuilder(type, id, cap);
String serviceLocationId = serviceConfig.getString("locationId");
- builder.setLocationId(serviceLocationId);
+ if(serviceLocationId != null) builder.setLocationId(serviceLocationId);
Coordinate serviceCoord = getCoord(serviceConfig,"");
if(serviceCoord != null){
builder.setCoord(serviceCoord);
diff --git a/jsprit-core/src/main/resources/vrp_xml_schema.xsd b/jsprit-core/src/main/resources/vrp_xml_schema.xsd
index 565aa509..b0452e62 100644
--- a/jsprit-core/src/main/resources/vrp_xml_schema.xsd
+++ b/jsprit-core/src/main/resources/vrp_xml_schema.xsd
@@ -40,15 +40,16 @@
-
+
+
-
+
@@ -56,7 +57,7 @@
-
+
@@ -105,7 +106,7 @@
-
+
@@ -135,7 +136,7 @@
-
+
@@ -151,7 +152,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 005e9a17..aec2da95 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
@@ -107,12 +107,19 @@ public class VrpReaderV2Test {
assertEquals(FleetSize.FINITE,vrp.getFleetSize());
}
+ @Test
+ public void whenReadingJobs_nuOfJobsIsReadThemCorrectly(){
+ VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
+ new VrpXMLReader(builder, null).read(inFileName);
+ VehicleRoutingProblem vrp = builder.build();
+ assertEquals(4, vrp.getJobs().size());
+ }
+
@Test
public void whenReadingServices_itReadsThemCorrectly(){
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
new VrpXMLReader(builder, null).read(inFileName);
VehicleRoutingProblem vrp = builder.build();
- assertEquals(3, vrp.getJobs().size());
int servCounter = 0;
for(Job j : vrp.getJobs().values()){
if(j instanceof Service) servCounter++;
@@ -125,24 +132,48 @@ public class VrpReaderV2Test {
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
new VrpXMLReader(builder, null).read(inFileName);
VehicleRoutingProblem vrp = builder.build();
- assertEquals(3, vrp.getJobs().size());
int shipCounter = 0;
for(Job j : vrp.getJobs().values()){
if(j instanceof Shipment) shipCounter++;
}
- assertEquals(1,shipCounter);
+ assertEquals(2,shipCounter);
}
@Test
- public void whenReadingServices_servicesAreBuiltCorrectly(){
+ public void whenReadingServices_capOfService1IsReadCorrectly(){
+ VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
+ new VrpXMLReader(builder, null).read(inFileName);
+ VehicleRoutingProblem vrp = builder.build();
+ Service s1 = (Service) vrp.getJobs().get("1");
+ assertEquals(1,s1.getCapacityDemand());
+ }
+
+ @Test
+ public void whenReadingServices_durationOfService1IsReadCorrectly(){
+ VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
+ new VrpXMLReader(builder, null).read(inFileName);
+ VehicleRoutingProblem vrp = builder.build();
+ Service s1 = (Service) vrp.getJobs().get("1");
+ assertEquals(10.0,s1.getServiceDuration(),0.01);
+ }
+
+ @Test
+ public void whenReadingServices_twOfService1IsReadCorrectly(){
+ VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
+ new VrpXMLReader(builder, null).read(inFileName);
+ VehicleRoutingProblem vrp = builder.build();
+ Service s1 = (Service) vrp.getJobs().get("1");
+ assertEquals(0.0,s1.getTimeWindow().getStart(),0.01);
+ assertEquals(4000.0,s1.getTimeWindow().getEnd(),0.01);
+ }
+
+ @Test
+ public void whenReadingServices_typeOfService1IsReadCorrectly(){
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
new VrpXMLReader(builder, null).read(inFileName);
VehicleRoutingProblem vrp = builder.build();
Service s1 = (Service) vrp.getJobs().get("1");
assertEquals("service",s1.getType());
- assertEquals(1,s1.getCapacityDemand());
- assertEquals(0.0,s1.getServiceDuration(),0.01);
- assertEquals(3, vrp.getJobs().size());
}
@Test
@@ -267,4 +298,126 @@ public class VrpReaderV2Test {
Vehicle v = getVehicle("v4",vrp.getVehicles());
assertEquals("startLoc",v.getStartLocationId());
}
+
+ @Test
+ public void whenReadingJobs_capOfShipment3IsReadCorrectly(){
+ VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
+ new VrpXMLReader(builder, null).read(inFileName);
+ VehicleRoutingProblem vrp = builder.build();
+ Shipment s = (Shipment) vrp.getJobs().get("3");
+ assertEquals(10,s.getCapacityDemand());
+ }
+
+ @Test
+ public void whenReadingJobs_pickupServiceTimeOfShipment3IsReadCorrectly(){
+ VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
+ new VrpXMLReader(builder, null).read(inFileName);
+ VehicleRoutingProblem vrp = builder.build();
+ Shipment s = (Shipment) vrp.getJobs().get("3");
+ assertEquals(10.0,s.getPickupServiceTime(),0.01);
+ }
+
+ @Test
+ public void whenReadingJobs_pickupTimeWindowOfShipment3IsReadCorrectly(){
+ VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
+ new VrpXMLReader(builder, null).read(inFileName);
+ VehicleRoutingProblem vrp = builder.build();
+ Shipment s = (Shipment) vrp.getJobs().get("3");
+ assertEquals(1000.0,s.getPickupTimeWindow().getStart(),0.01);
+ assertEquals(4000.0,s.getPickupTimeWindow().getEnd(),0.01);
+ }
+
+ @Test
+ public void whenReadingJobs_deliveryTimeWindowOfShipment3IsReadCorrectly(){
+ VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
+ new VrpXMLReader(builder, null).read(inFileName);
+ VehicleRoutingProblem vrp = builder.build();
+ Shipment s = (Shipment) vrp.getJobs().get("3");
+ assertEquals(6000.0,s.getDeliveryTimeWindow().getStart(),0.01);
+ assertEquals(10000.0,s.getDeliveryTimeWindow().getEnd(),0.01);
+ }
+
+ @Test
+ public void whenReadingJobs_deliveryServiceTimeOfShipment3IsReadCorrectly(){
+ VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
+ new VrpXMLReader(builder, null).read(inFileName);
+ VehicleRoutingProblem vrp = builder.build();
+ Shipment s = (Shipment) vrp.getJobs().get("3");
+ assertEquals(100.0,s.getDeliveryServiceTime(),0.01);
+ }
+
+ @Test
+ public void whenReadingJobs_deliveryCoordShipment3IsReadCorrectly(){
+ VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
+ new VrpXMLReader(builder, null).read(inFileName);
+ VehicleRoutingProblem vrp = builder.build();
+ Shipment s = (Shipment) vrp.getJobs().get("3");
+ assertEquals(10.0,s.getDeliveryCoord().getX(),0.01);
+ assertEquals(0.0,s.getDeliveryCoord().getY(),0.01);
+ }
+
+ @Test
+ public void whenReadingJobs_pickupCoordShipment3IsReadCorrectly(){
+ VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
+ new VrpXMLReader(builder, null).read(inFileName);
+ VehicleRoutingProblem vrp = builder.build();
+ Shipment s = (Shipment) vrp.getJobs().get("3");
+ assertEquals(10.0,s.getPickupCoord().getX(),0.01);
+ assertEquals(10.0,s.getPickupCoord().getY(),0.01);
+ }
+
+ @Test
+ public void whenReadingJobs_deliveryIdShipment3IsReadCorrectly(){
+ VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
+ new VrpXMLReader(builder, null).read(inFileName);
+ VehicleRoutingProblem vrp = builder.build();
+ Shipment s = (Shipment) vrp.getJobs().get("3");
+ assertEquals("i(9,9)",s.getDeliveryLocation());
+ }
+
+ @Test
+ public void whenReadingJobs_pickupIdShipment3IsReadCorrectly(){
+ VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
+ new VrpXMLReader(builder, null).read(inFileName);
+ VehicleRoutingProblem vrp = builder.build();
+ Shipment s = (Shipment) vrp.getJobs().get("3");
+ assertEquals("i(3,9)",s.getPickupLocation());
+ }
+
+ @Test
+ public void whenReadingJobs_pickupLocationIdShipment4IsReadCorrectly(){
+ VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
+ new VrpXMLReader(builder, null).read(inFileName);
+ VehicleRoutingProblem vrp = builder.build();
+ Shipment s = (Shipment) vrp.getJobs().get("4");
+ assertEquals("[x=10.0][y=10.0]",s.getPickupLocation());
+ }
+
+ @Test
+ public void whenReadingJobs_deliveryLocationIdShipment4IsReadCorrectly(){
+ VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
+ new VrpXMLReader(builder, null).read(inFileName);
+ VehicleRoutingProblem vrp = builder.build();
+ Shipment s = (Shipment) vrp.getJobs().get("4");
+ assertEquals("[x=10.0][y=0.0]",s.getDeliveryLocation());
+ }
+
+ @Test
+ public void whenReadingJobs_pickupServiceTimeOfShipment4IsReadCorrectly(){
+ VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
+ new VrpXMLReader(builder, null).read(inFileName);
+ VehicleRoutingProblem vrp = builder.build();
+ Shipment s = (Shipment) vrp.getJobs().get("4");
+ assertEquals(0.0,s.getPickupServiceTime(),0.01);
+ }
+
+ @Test
+ public void whenReadingJobs_deliveryServiceTimeOfShipment4IsReadCorrectly(){
+ VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
+ new VrpXMLReader(builder, null).read(inFileName);
+ VehicleRoutingProblem vrp = builder.build();
+ Shipment s = (Shipment) vrp.getJobs().get("4");
+ assertEquals(100.0,s.getDeliveryServiceTime(),0.01);
+ }
+
}
diff --git a/jsprit-core/src/test/resources/finiteVrpForReaderV2Test.xml b/jsprit-core/src/test/resources/finiteVrpForReaderV2Test.xml
index 83606e39..6a1b7236 100644
--- a/jsprit-core/src/test/resources/finiteVrpForReaderV2Test.xml
+++ b/jsprit-core/src/test/resources/finiteVrpForReaderV2Test.xml
@@ -112,7 +112,7 @@
j(1,5)
1
- 0.0
+ 10.0
0.0
@@ -141,10 +141,10 @@
i(3,9)
- 0.0
+ 10.0
- 0.0
+ 1000.0
4000.0
@@ -152,16 +152,40 @@
i(9,9)
- 0.0
+ 100.0
- 0.0
- 4000.0
+ 6000.0
+ 10000.0
- 1
+ 10
+
+
+
+
+
+
+ 1000.0
+ 4000.0
+
+
+
+
+
+ 100.0
+
+
+ 6000.0
+ 10000.0
+
+
+
+ 10
+
+