mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
made core.problem.io.VrpXMLReader.java read initialRoutes
This commit is contained in:
parent
a2ae693544
commit
26ad6addf6
3 changed files with 92 additions and 15 deletions
|
|
@ -214,9 +214,61 @@ public class VrpXMLReader{
|
|||
readShipments(xmlConfig);
|
||||
readServices(xmlConfig);
|
||||
|
||||
readInitialRoutes(xmlConfig);
|
||||
readSolutions(xmlConfig);
|
||||
}
|
||||
|
||||
private void readInitialRoutes(XMLConfiguration xmlConfig) {
|
||||
List<HierarchicalConfiguration> initialRouteConfigs = xmlConfig.configurationsAt("initialRoutes.route");
|
||||
for(HierarchicalConfiguration routeConfig : initialRouteConfigs){
|
||||
Driver driver = DriverImpl.noDriver();
|
||||
String vehicleId = routeConfig.getString("vehicleId");
|
||||
Vehicle vehicle = getVehicle(vehicleId);
|
||||
if(vehicle == null) throw new IllegalStateException("vehicle is missing.");
|
||||
String start = routeConfig.getString("start");
|
||||
if(start == null) throw new IllegalStateException("route start-time is missing.");
|
||||
double departureTime = Double.parseDouble(start);
|
||||
|
||||
VehicleRoute.Builder routeBuilder = VehicleRoute.Builder.newInstance(vehicle, driver);
|
||||
routeBuilder.setDepartureTime(departureTime);
|
||||
|
||||
List<HierarchicalConfiguration> actConfigs = routeConfig.configurationsAt("act");
|
||||
for(HierarchicalConfiguration actConfig : actConfigs){
|
||||
String type = actConfig.getString("[@type]");
|
||||
if(type == null) throw new IllegalStateException("act[@type] is missing.");
|
||||
double arrTime = 0.;
|
||||
double endTime = 0.;
|
||||
String arrTimeS = actConfig.getString("arrTime");
|
||||
if(arrTimeS!=null) arrTime=Double.parseDouble(arrTimeS);
|
||||
String endTimeS = actConfig.getString("endTime");
|
||||
if(endTimeS!=null) endTime=Double.parseDouble(endTimeS);
|
||||
|
||||
String serviceId = actConfig.getString("serviceId");
|
||||
if(serviceId != null) {
|
||||
Service service = getService(serviceId);
|
||||
//!!!
|
||||
|
||||
routeBuilder.addService(service, arrTime, endTime);
|
||||
}
|
||||
else{
|
||||
String shipmentId = actConfig.getString("shipmentId");
|
||||
if(shipmentId == null) throw new IllegalStateException("either serviceId or shipmentId is missing");
|
||||
Shipment shipment = getShipment(shipmentId);
|
||||
if(shipment == null) throw new IllegalStateException("shipment with id " + shipmentId + " does not exist.");
|
||||
if(type.equals("pickupShipment")){
|
||||
routeBuilder.addPickup(shipment, arrTime, endTime);
|
||||
}
|
||||
else if(type.equals("deliverShipment")){
|
||||
routeBuilder.addDelivery(shipment, arrTime, endTime);
|
||||
}
|
||||
else throw new IllegalStateException("type " + type + " is not supported. Use 'pickupShipment' or 'deliverShipment' here");
|
||||
}
|
||||
}
|
||||
VehicleRoute route = routeBuilder.build();
|
||||
vrpBuilder.addInitialVehicleRoute(route);
|
||||
}
|
||||
|
||||
}
|
||||
private void readSolutions(XMLConfiguration vrpProblem) {
|
||||
if(solutions == null) return;
|
||||
List<HierarchicalConfiguration> solutionConfigs = vrpProblem.configurationsAt("solutions.solution");
|
||||
|
|
@ -246,13 +298,13 @@ public class VrpXMLReader{
|
|||
for(HierarchicalConfiguration actConfig : actConfigs){
|
||||
String type = actConfig.getString("[@type]");
|
||||
if(type == null) throw new IllegalStateException("act[@type] is missing.");
|
||||
|
||||
double arrTime = 0.;
|
||||
double endTime = 0.;
|
||||
String arrTimeS = actConfig.getString("arrTime");
|
||||
if(arrTimeS == null) throw new IllegalStateException("act.arrTime is missing.");
|
||||
if(arrTimeS!=null) arrTime=Double.parseDouble(arrTimeS);
|
||||
String endTimeS = actConfig.getString("endTime");
|
||||
if(endTimeS == null) throw new IllegalStateException("act.endTime is missing.");
|
||||
double arrTime = Double.parseDouble(arrTimeS);
|
||||
double endTime = Double.parseDouble(endTimeS);
|
||||
if(endTimeS!=null) endTime=Double.parseDouble(endTimeS);
|
||||
|
||||
String serviceId = actConfig.getString("serviceId");
|
||||
if(serviceId != null) {
|
||||
Service service = getService(serviceId);
|
||||
|
|
@ -271,7 +323,6 @@ public class VrpXMLReader{
|
|||
}
|
||||
else throw new IllegalStateException("type " + type + " is not supported. Use 'pickupShipment' or 'deliverShipment' here");
|
||||
}
|
||||
|
||||
}
|
||||
routes.add(routeBuilder.build());
|
||||
}
|
||||
|
|
@ -399,7 +450,7 @@ public class VrpXMLReader{
|
|||
|
||||
Shipment shipment = builder.build();
|
||||
vrpBuilder.addJob(shipment);
|
||||
shipmentMap .put(shipment.getId(),shipment);
|
||||
shipmentMap.put(shipment.getId(),shipment);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -219,6 +219,32 @@
|
|||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:element name="initialRoutes" minOccurs="0" maxOccurs="1">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="route" minOccurs="0" maxOccurs="unbounded">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="driverId" type="xs:string" minOccurs="1" maxOccurs="1"/>
|
||||
<xs:element name="vehicleId" type="xs:string" minOccurs="1" maxOccurs="1"/>
|
||||
<xs:element name="start" type="xs:double" minOccurs="1" maxOccurs="1"/>
|
||||
<xs:element name="act" minOccurs="0" maxOccurs="unbounded">
|
||||
<xs:complexType>
|
||||
<xs:choice>
|
||||
<xs:group ref="serviceActGroup"/>
|
||||
<xs:group ref="shipmentActGroup"/>
|
||||
</xs:choice>
|
||||
<xs:attribute name="type" type="xs:string" use="required"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="end" type="xs:anySimpleType" minOccurs="1" maxOccurs="1"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:element name="solutions" minOccurs="0" maxOccurs="1">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
|
|
@ -272,16 +298,16 @@
|
|||
<xs:group name="serviceActGroup">
|
||||
<xs:sequence>
|
||||
<xs:element name="serviceId" type="xs:string" minOccurs="1" maxOccurs="1"/>
|
||||
<xs:element name="arrTime" type="xs:double" minOccurs="1" maxOccurs="1"/>
|
||||
<xs:element name="endTime" type="xs:double" minOccurs="1" maxOccurs="1"/>
|
||||
<xs:element name="arrTime" type="xs:double" minOccurs="0" maxOccurs="1"/>
|
||||
<xs:element name="endTime" type="xs:double" minOccurs="0" maxOccurs="1"/>
|
||||
</xs:sequence>
|
||||
</xs:group>
|
||||
|
||||
<xs:group name="shipmentActGroup">
|
||||
<xs:sequence>
|
||||
<xs:element name="shipmentId" type="xs:string" minOccurs="1" maxOccurs="1"/>
|
||||
<xs:element name="arrTime" type="xs:double" minOccurs="1" maxOccurs="1"/>
|
||||
<xs:element name="endTime" type="xs:double" minOccurs="1" maxOccurs="1"/>
|
||||
<xs:element name="arrTime" type="xs:double" minOccurs="0" maxOccurs="1"/>
|
||||
<xs:element name="endTime" type="xs:double" minOccurs="0" maxOccurs="1"/>
|
||||
</xs:sequence>
|
||||
</xs:group>
|
||||
|
||||
|
|
|
|||
|
|
@ -449,7 +449,7 @@ public class VrpXMLReaderTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInitialRouteWithDepTime10_departureTimeOfRouteShouldBeReadCorrectly(){ //i.e. these jobs should not be part of the problem
|
||||
public void whenReadingInitialRouteWithDepTime10_departureTimeOfRouteShouldBeReadCorrectly(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrpXMLReader(builder).read("src/test/resources/finiteVrpWithInitialSolutionForReaderTest.xml");
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
|
|
@ -457,7 +457,7 @@ public class VrpXMLReaderTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInitialRoute_nuInitialRoutesShouldBeCorrect(){ //i.e. these jobs should not be part of the problem
|
||||
public void whenReadingInitialRoute_nuInitialRoutesShouldBeCorrect(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrpXMLReader(builder, null).read("src/test/resources/finiteVrpWithInitialSolutionForReaderTest.xml");
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
|
|
@ -465,7 +465,7 @@ public class VrpXMLReaderTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInitialRoute_nuActivitiesShouldBeCorrect(){ //i.e. these jobs should not be part of the problem
|
||||
public void whenReadingInitialRoute_nuActivitiesShouldBeCorrect(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrpXMLReader(builder, null).read("src/test/resources/finiteVrpWithInitialSolutionForReaderTest.xml");
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue