mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
made test testing core.problem.io.VrpXMLReader.java to read
initialRoutes working
This commit is contained in:
parent
26ad6addf6
commit
75108ffc90
2 changed files with 32 additions and 12 deletions
|
|
@ -21,8 +21,10 @@ import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import jsprit.core.problem.VehicleRoutingProblem;
|
import jsprit.core.problem.VehicleRoutingProblem;
|
||||||
import jsprit.core.problem.VehicleRoutingProblem.FleetComposition;
|
import jsprit.core.problem.VehicleRoutingProblem.FleetComposition;
|
||||||
|
|
@ -131,6 +133,8 @@ public class VrpXMLReader{
|
||||||
|
|
||||||
private Map<String, Shipment> shipmentMap;
|
private Map<String, Shipment> shipmentMap;
|
||||||
|
|
||||||
|
private Set<String> freezedJobIds = new HashSet<String>();
|
||||||
|
|
||||||
private boolean schemaValidation = true;
|
private boolean schemaValidation = true;
|
||||||
|
|
||||||
private Collection<VehicleRoutingProblemSolution> solutions;
|
private Collection<VehicleRoutingProblemSolution> solutions;
|
||||||
|
|
@ -216,8 +220,22 @@ public class VrpXMLReader{
|
||||||
|
|
||||||
readInitialRoutes(xmlConfig);
|
readInitialRoutes(xmlConfig);
|
||||||
readSolutions(xmlConfig);
|
readSolutions(xmlConfig);
|
||||||
|
|
||||||
|
addJobsAndTheirLocationsToVrp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addJobsAndTheirLocationsToVrp() {
|
||||||
|
for(Service service : serviceMap.values()) {
|
||||||
|
if(!freezedJobIds.contains(service.getId())){
|
||||||
|
vrpBuilder.addJob(service);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(Shipment shipment : shipmentMap.values()){
|
||||||
|
if(!freezedJobIds.contains(shipment.getId())){
|
||||||
|
vrpBuilder.addJob(shipment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
private void readInitialRoutes(XMLConfiguration xmlConfig) {
|
private void readInitialRoutes(XMLConfiguration xmlConfig) {
|
||||||
List<HierarchicalConfiguration> initialRouteConfigs = xmlConfig.configurationsAt("initialRoutes.route");
|
List<HierarchicalConfiguration> initialRouteConfigs = xmlConfig.configurationsAt("initialRoutes.route");
|
||||||
for(HierarchicalConfiguration routeConfig : initialRouteConfigs){
|
for(HierarchicalConfiguration routeConfig : initialRouteConfigs){
|
||||||
|
|
@ -246,15 +264,17 @@ public class VrpXMLReader{
|
||||||
String serviceId = actConfig.getString("serviceId");
|
String serviceId = actConfig.getString("serviceId");
|
||||||
if(serviceId != null) {
|
if(serviceId != null) {
|
||||||
Service service = getService(serviceId);
|
Service service = getService(serviceId);
|
||||||
//!!!
|
if(service==null) throw new IllegalStateException("service to serviceId " + serviceId + " is missing (reference in one of your initial routes). make sure you define the service you refer to here in <services> </services>.");
|
||||||
|
//!!!since job is part of initial route, it does not belong to jobs in problem, i.e. variable jobs that can be assigned/scheduled
|
||||||
|
freezedJobIds.add(serviceId);
|
||||||
routeBuilder.addService(service, arrTime, endTime);
|
routeBuilder.addService(service, arrTime, endTime);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
String shipmentId = actConfig.getString("shipmentId");
|
String shipmentId = actConfig.getString("shipmentId");
|
||||||
if(shipmentId == null) throw new IllegalStateException("either serviceId or shipmentId is missing");
|
if(shipmentId == null) throw new IllegalStateException("either serviceId or shipmentId is missing");
|
||||||
Shipment shipment = getShipment(shipmentId);
|
Shipment shipment = getShipment(shipmentId);
|
||||||
if(shipment == null) throw new IllegalStateException("shipment with id " + shipmentId + " does not exist.");
|
if(shipment == null) throw new IllegalStateException("shipment to shipmentId " + shipmentId + " is missing (reference in one of your initial routes). make sure you define the shipment you refer to here in <shipments> </shipments>.");
|
||||||
|
freezedJobIds.add(shipmentId);
|
||||||
if(type.equals("pickupShipment")){
|
if(type.equals("pickupShipment")){
|
||||||
routeBuilder.addPickup(shipment, arrTime, endTime);
|
routeBuilder.addPickup(shipment, arrTime, endTime);
|
||||||
}
|
}
|
||||||
|
|
@ -397,10 +417,10 @@ public class VrpXMLReader{
|
||||||
if(pickupCoord != null){
|
if(pickupCoord != null){
|
||||||
builder.setPickupCoord(pickupCoord);
|
builder.setPickupCoord(pickupCoord);
|
||||||
if(pickupLocationId != null){
|
if(pickupLocationId != null){
|
||||||
vrpBuilder.addLocation(pickupLocationId,pickupCoord);
|
// vrpBuilder.addLocation(pickupLocationId,pickupCoord);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
vrpBuilder.addLocation(pickupCoord.toString(),pickupCoord);
|
// vrpBuilder.addLocation(pickupCoord.toString(),pickupCoord);
|
||||||
builder.setPickupLocation(pickupCoord.toString());
|
builder.setPickupLocation(pickupCoord.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -428,10 +448,10 @@ public class VrpXMLReader{
|
||||||
if(deliveryCoord != null){
|
if(deliveryCoord != null){
|
||||||
builder.setDeliveryCoord(deliveryCoord);
|
builder.setDeliveryCoord(deliveryCoord);
|
||||||
if(deliveryLocationId != null){
|
if(deliveryLocationId != null){
|
||||||
vrpBuilder.addLocation(deliveryLocationId,deliveryCoord);
|
// vrpBuilder.addLocation(deliveryLocationId,deliveryCoord);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
vrpBuilder.addLocation(deliveryCoord.toString(),deliveryCoord);
|
// vrpBuilder.addLocation(deliveryCoord.toString(),deliveryCoord);
|
||||||
builder.setDeliveryLocation(deliveryCoord.toString());
|
builder.setDeliveryLocation(deliveryCoord.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -449,7 +469,7 @@ public class VrpXMLReader{
|
||||||
|
|
||||||
|
|
||||||
Shipment shipment = builder.build();
|
Shipment shipment = builder.build();
|
||||||
vrpBuilder.addJob(shipment);
|
// vrpBuilder.addJob(shipment);
|
||||||
shipmentMap.put(shipment.getId(),shipment);
|
shipmentMap.put(shipment.getId(),shipment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -500,10 +520,10 @@ public class VrpXMLReader{
|
||||||
if(serviceCoord != null){
|
if(serviceCoord != null){
|
||||||
builder.setCoord(serviceCoord);
|
builder.setCoord(serviceCoord);
|
||||||
if(serviceLocationId != null){
|
if(serviceLocationId != null){
|
||||||
vrpBuilder.addLocation(serviceLocationId,serviceCoord);
|
// vrpBuilder.addLocation(serviceLocationId,serviceCoord);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
vrpBuilder.addLocation(serviceCoord.toString(),serviceCoord);
|
// vrpBuilder.addLocation(serviceCoord.toString(),serviceCoord);
|
||||||
builder.setLocationId(serviceCoord.toString());
|
builder.setLocationId(serviceCoord.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -518,7 +538,7 @@ public class VrpXMLReader{
|
||||||
}
|
}
|
||||||
Service service = builder.build();
|
Service service = builder.build();
|
||||||
serviceMap.put(service.getId(),service);
|
serviceMap.put(service.getId(),service);
|
||||||
vrpBuilder.addJob(service);
|
// vrpBuilder.addJob(service);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -227,7 +227,7 @@
|
||||||
<initialRoutes>
|
<initialRoutes>
|
||||||
<route>
|
<route>
|
||||||
<driverId>noDriver</driverId>
|
<driverId>noDriver</driverId>
|
||||||
<vehicleId>A</vehicleId>
|
<vehicleId>v1</vehicleId>
|
||||||
<start>10.</start>
|
<start>10.</start>
|
||||||
<act type="pickupShipment">
|
<act type="pickupShipment">
|
||||||
<shipmentId>4</shipmentId>
|
<shipmentId>4</shipmentId>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue