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

modify io to read and write shipments, add tests to test reader/writer

This commit is contained in:
oblonski 2013-10-30 08:43:01 +01:00
parent d06f6ddc4b
commit 3740225058
14 changed files with 514 additions and 62 deletions

View file

@ -59,7 +59,7 @@ public class TestAlgorithmReader {
config = new XMLConfiguration("src/test/resources/testConfig.xml");
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
solutions = new ArrayList<VehicleRoutingProblemSolution>();
new VrpXMLReader(vrpBuilder,solutions).read("src/test/resources/finiteVrpForReaderV2Test.xml");
new VrpXMLReader(vrpBuilder,solutions).read("src/test/resources/finiteVrp.xml");
vrp = vrpBuilder.build();
}

View file

@ -16,12 +16,21 @@
******************************************************************************/
package basics.io;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import basics.VehicleRoutingProblem;
import basics.VehicleRoutingProblem.Builder;
import basics.VehicleRoutingProblemSolution;
import basics.route.DeliverShipment;
import basics.route.PickupService;
import basics.route.PickupShipment;
import basics.route.TourActivity;
public class ReaderTest {
@ -29,7 +38,24 @@ public class ReaderTest {
@Test
public void testRead_ifReaderIsCalled_itReadsSuccessfully(){
new VrpXMLReader(VehicleRoutingProblem.Builder.newInstance(), new ArrayList<VehicleRoutingProblemSolution>()).read("src/test/resources/lui-shen-solution.xml");
}
@Test
public void testRead_ifReaderIsCalled_itReadsSuccessfullyV2(){
Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
VehicleRoutingProblem vrp = vrpBuilder.build();
ArrayList<VehicleRoutingProblemSolution> solutions = new ArrayList<VehicleRoutingProblemSolution>();
new VrpXMLReader(vrpBuilder, solutions).read("src/test/resources/finiteVrpWithShipmentsAndSolution.xml");
assertEquals(3,vrp.getJobs().size());
assertEquals(1,solutions.size());
assertEquals(1,solutions.get(0).getRoutes().size());
List<TourActivity> activities = solutions.get(0).getRoutes().iterator().next().getTourActivities().getActivities();
assertEquals(4,activities.size());
assertTrue(activities.get(0) instanceof PickupService);
assertTrue(activities.get(1) instanceof PickupService);
assertTrue(activities.get(2) instanceof PickupShipment);
assertTrue(activities.get(3) instanceof DeliverShipment);
}
}

View file

@ -28,7 +28,9 @@ import java.util.List;
import org.junit.Before;
import org.junit.Test;
import basics.Job;
import basics.Service;
import basics.Shipment;
import basics.VehicleRoutingProblem;
import basics.VehicleRoutingProblem.FleetComposition;
import basics.VehicleRoutingProblem.FleetSize;
@ -110,7 +112,25 @@ public class VrpReaderV2Test {
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
new VrpXMLReader(builder, null).read(inFileName);
VehicleRoutingProblem vrp = builder.build();
assertEquals(2, vrp.getJobs().size());
assertEquals(3, vrp.getJobs().size());
int servCounter = 0;
for(Job j : vrp.getJobs().values()){
if(j instanceof Service) servCounter++;
}
assertEquals(2,servCounter);
}
@Test
public void whenReadingShipments_itReadsThemCorrectly(){
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);
}
@Test
@ -122,6 +142,6 @@ public class VrpReaderV2Test {
assertEquals("service",s1.getType());
assertEquals(1,s1.getCapacityDemand());
assertEquals(0.0,s1.getServiceDuration(),0.01);
assertEquals(2, vrp.getJobs().size());
assertEquals(3, vrp.getJobs().size());
}
}

View file

@ -129,7 +129,7 @@ public class VrpWriterV2Test {
VehicleRoutingProblem vrp = builder.addService(s1).addService(s2).build();
new VrpXMLWriter(vrp, null).write(infileName);
VehicleRoutingProblem.Builder vrpToReadBuilder = builder;
VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance();
new VrpXMLReader(vrpToReadBuilder, null).read(infileName);
VehicleRoutingProblem readVrp = vrpToReadBuilder.build();
assertEquals(2,readVrp.getJobs().size());

View file

@ -0,0 +1,89 @@
<?xml version="1.0" encoding="UTF-8"?>
<problem xmlns="http://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd">
<problemType>
<fleetSize>FINITE</fleetSize>
<fleetComposition>HETEROGENEOUS</fleetComposition>
</problemType>
<vehicles>
<vehicle>
<id>v1</id>
<location>
<id>depotLoc2</id>
<coord x="100.0" y="100.0"/>
</location>
<typeId>vehType</typeId>
<timeSchedule>
<start>0.0</start>
<end>1000.0</end>
</timeSchedule>
</vehicle>
<vehicle>
<id>v2</id>
<location>
<id>depotLoc</id>
<coord x="10.0" y="100.0"/>
</location>
<typeId>vehType2</typeId>
<timeSchedule>
<start>0.0</start>
<end>1000.0</end>
</timeSchedule>
</vehicle>
</vehicles>
<vehicleTypes>
<type>
<id>vehType</id>
<capacity>20</capacity>
<costs>
<fixed>0.0</fixed>
<distance>0.0</distance>
<time>0.0</time>
</costs>
</type>
<type>
<id>vehType2</id>
<capacity>200</capacity>
<costs>
<fixed>0.0</fixed>
<distance>0.0</distance>
<time>0.0</time>
</costs>
</type>
</vehicleTypes>
<services>
<service id="1" type="service">
<locationId>j(1,5)</locationId>
<coord x="10.0" y="10.0"/>
<capacity-demand>1</capacity-demand>
<duration>0.0</duration>
<timeWindows>
<timeWindow>
<start>0.0</start>
<end>4000.0</end>
</timeWindow>
</timeWindows>
</service>
<service id="2" type="service">
<locationId>i(3,9)</locationId>
<coord x="10.0" y="10.0"/>
<capacity-demand>1</capacity-demand>
<duration>0.0</duration>
<timeWindows>
<timeWindow>
<start>0.0</start>
<end>4000.0</end>
</timeWindow>
</timeWindows>
</service>
</services>
</problem>

View file

@ -102,5 +102,33 @@
</service>
</services>
<shipments>
<shipment id="3">
<pickup>
<locationId>i(3,9)</locationId>
<coord x="10.0" y="10.0"/>
<duration>0.0</duration>
<timeWindows>
<timeWindow>
<start>0.0</start>
<end>4000.0</end>
</timeWindow>
</timeWindows>
</pickup>
<delivery>
<locationId>i(9,9)</locationId>
<coord x="10.0" y="0.0"/>
<duration>0.0</duration>
<timeWindows>
<timeWindow>
<start>0.0</start>
<end>4000.0</end>
</timeWindow>
</timeWindows>
</delivery>
<capacity-demand>1</capacity-demand>
</shipment>
</shipments>
</problem>

View file

@ -0,0 +1,149 @@
<?xml version="1.0" encoding="UTF-8"?>
<problem xmlns="http://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd">
<problemType>
<fleetSize>FINITE</fleetSize>
<fleetComposition>HETEROGENEOUS</fleetComposition>
</problemType>
<vehicles>
<vehicle>
<id>v1</id>
<location>
<id>depotLoc2</id>
<coord x="100.0" y="100.0"/>
</location>
<typeId>vehType</typeId>
<timeSchedule>
<start>0.0</start>
<end>1000.0</end>
</timeSchedule>
</vehicle>
<vehicle>
<id>v2</id>
<location>
<id>depotLoc</id>
<coord x="10.0" y="100.0"/>
</location>
<typeId>vehType2</typeId>
<timeSchedule>
<start>0.0</start>
<end>1000.0</end>
</timeSchedule>
</vehicle>
</vehicles>
<vehicleTypes>
<type>
<id>vehType</id>
<capacity>20</capacity>
<costs>
<fixed>0.0</fixed>
<distance>0.0</distance>
<time>0.0</time>
</costs>
</type>
<type>
<id>vehType2</id>
<capacity>200</capacity>
<costs>
<fixed>0.0</fixed>
<distance>0.0</distance>
<time>0.0</time>
</costs>
</type>
</vehicleTypes>
<services>
<service id="1" type="service">
<locationId>j(1,5)</locationId>
<coord x="10.0" y="10.0"/>
<capacity-demand>1</capacity-demand>
<duration>0.0</duration>
<timeWindows>
<timeWindow>
<start>0.0</start>
<end>4000.0</end>
</timeWindow>
</timeWindows>
</service>
<service id="2" type="service">
<locationId>i(3,9)</locationId>
<coord x="10.0" y="10.0"/>
<capacity-demand>1</capacity-demand>
<duration>0.0</duration>
<timeWindows>
<timeWindow>
<start>0.0</start>
<end>4000.0</end>
</timeWindow>
</timeWindows>
</service>
</services>
<shipments>
<shipment id="3">
<pickup>
<locationId>i(3,9)</locationId>
<coord x="10.0" y="10.0"/>
<duration>0.0</duration>
<timeWindows>
<timeWindow>
<start>0.0</start>
<end>4000.0</end>
</timeWindow>
</timeWindows>
</pickup>
<delivery>
<locationId>i(9,9)</locationId>
<coord x="10.0" y="0.0"/>
<duration>0.0</duration>
<timeWindows>
<timeWindow>
<start>0.0</start>
<end>4000.0</end>
</timeWindow>
</timeWindows>
</delivery>
<capacity-demand>1</capacity-demand>
</shipment>
</shipments>
<solutions>
<solution>
<cost>100.0</cost>
<routes>
<route>
<cost>0.0</cost>
<driverId>noDriver</driverId>
<vehicleId>v1</vehicleId>
<start>10.0</start>
<act type="service">
<serviceId>1</serviceId>
<arrTime>20.0</arrTime>
<endTime>30.0</endTime>
</act>
<act type="service">
<serviceId>2</serviceId>
<arrTime>40.0</arrTime>
<endTime>80.0</endTime>
</act>
<act type="pickupShipment">
<shipmentId>3</shipmentId>
<arrTime>40.0</arrTime>
<endTime>80.0</endTime>
</act>
<act type="deliverShipment">
<shipmentId>3</shipmentId>
<arrTime>40.0</arrTime>
<endTime>80.0</endTime>
</act>
<end>100.0</end>
</route>
</routes>
</solution>
</solutions>
</problem>