mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
Refine Breaks XML
This commit is contained in:
parent
ee3b1589ba
commit
aacafa27ba
5 changed files with 88 additions and 45 deletions
|
|
@ -213,27 +213,33 @@ public class VrpXMLReader {
|
||||||
if (endTimeS != null) endTime = Double.parseDouble(endTimeS);
|
if (endTimeS != null) endTime = Double.parseDouble(endTimeS);
|
||||||
|
|
||||||
String serviceId = actConfig.getString("serviceId");
|
String serviceId = actConfig.getString("serviceId");
|
||||||
if (serviceId != null) {
|
if(type.equals("break")) {
|
||||||
Service service = getService(serviceId);
|
Break currentbreak = getBreak(vehicleId);
|
||||||
if (service == null)
|
routeBuilder.addBreak(currentbreak);
|
||||||
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
|
else {
|
||||||
freezedJobIds.add(serviceId);
|
if (serviceId != null) {
|
||||||
routeBuilder.addService(service);
|
Service service = getService(serviceId);
|
||||||
} else {
|
if (service == null)
|
||||||
String shipmentId = actConfig.getString("shipmentId");
|
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>.");
|
||||||
if (shipmentId == null)
|
//!!!since job is part of initial route, it does not belong to jobs in problem, i.e. variable jobs that can be assigned/scheduled
|
||||||
throw new IllegalStateException("either serviceId or shipmentId is missing");
|
freezedJobIds.add(serviceId);
|
||||||
Shipment shipment = getShipment(shipmentId);
|
routeBuilder.addService(service);
|
||||||
if (shipment == null)
|
} else {
|
||||||
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>.");
|
String shipmentId = actConfig.getString("shipmentId");
|
||||||
freezedJobIds.add(shipmentId);
|
if (shipmentId == null)
|
||||||
if (type.equals("pickupShipment")) {
|
throw new IllegalStateException("either serviceId or shipmentId is missing");
|
||||||
routeBuilder.addPickup(shipment);
|
Shipment shipment = getShipment(shipmentId);
|
||||||
} else if (type.equals("deliverShipment")) {
|
if (shipment == null)
|
||||||
routeBuilder.addDelivery(shipment);
|
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>.");
|
||||||
} else
|
freezedJobIds.add(shipmentId);
|
||||||
throw new IllegalStateException("type " + type + " is not supported. Use 'pickupShipment' or 'deliverShipment' here");
|
if (type.equals("pickupShipment")) {
|
||||||
|
routeBuilder.addPickup(shipment);
|
||||||
|
} else if (type.equals("deliverShipment")) {
|
||||||
|
routeBuilder.addDelivery(shipment);
|
||||||
|
} else
|
||||||
|
throw new IllegalStateException("type " + type + " is not supported. Use 'pickupShipment' or 'deliverShipment' here");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
VehicleRoute route = routeBuilder.build();
|
VehicleRoute route = routeBuilder.build();
|
||||||
|
|
@ -276,24 +282,29 @@ public class VrpXMLReader {
|
||||||
if (arrTimeS != null) arrTime = Double.parseDouble(arrTimeS);
|
if (arrTimeS != null) arrTime = Double.parseDouble(arrTimeS);
|
||||||
String endTimeS = actConfig.getString("endTime");
|
String endTimeS = actConfig.getString("endTime");
|
||||||
if (endTimeS != null) endTime = Double.parseDouble(endTimeS);
|
if (endTimeS != null) endTime = Double.parseDouble(endTimeS);
|
||||||
|
if(type.equals("break")) {
|
||||||
String serviceId = actConfig.getString("serviceId");
|
Break currentbreak = getBreak(vehicleId);
|
||||||
if (serviceId != null) {
|
routeBuilder.addBreak(currentbreak);
|
||||||
Service service = getService(serviceId);
|
}
|
||||||
routeBuilder.addService(service);
|
else {
|
||||||
} else {
|
String serviceId = actConfig.getString("serviceId");
|
||||||
String shipmentId = actConfig.getString("shipmentId");
|
if (serviceId != null) {
|
||||||
if (shipmentId == null)
|
Service service = getService(serviceId);
|
||||||
throw new IllegalStateException("either serviceId or shipmentId is missing");
|
routeBuilder.addService(service);
|
||||||
Shipment shipment = getShipment(shipmentId);
|
} else {
|
||||||
if (shipment == null)
|
String shipmentId = actConfig.getString("shipmentId");
|
||||||
throw new IllegalStateException("shipment with id " + shipmentId + " does not exist.");
|
if (shipmentId == null)
|
||||||
if (type.equals("pickupShipment")) {
|
throw new IllegalStateException("either serviceId or shipmentId is missing");
|
||||||
routeBuilder.addPickup(shipment);
|
Shipment shipment = getShipment(shipmentId);
|
||||||
} else if (type.equals("deliverShipment")) {
|
if (shipment == null)
|
||||||
routeBuilder.addDelivery(shipment);
|
throw new IllegalStateException("shipment with id " + shipmentId + " does not exist.");
|
||||||
} else
|
if (type.equals("pickupShipment")) {
|
||||||
throw new IllegalStateException("type " + type + " is not supported. Use 'pickupShipment' or 'deliverShipment' here");
|
routeBuilder.addPickup(shipment);
|
||||||
|
} else if (type.equals("deliverShipment")) {
|
||||||
|
routeBuilder.addDelivery(shipment);
|
||||||
|
} else
|
||||||
|
throw new IllegalStateException("type " + type + " is not supported. Use 'pickupShipment' or 'deliverShipment' here");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
routes.add(routeBuilder.build());
|
routes.add(routeBuilder.build());
|
||||||
|
|
@ -324,6 +335,10 @@ public class VrpXMLReader {
|
||||||
return vehicleMap.get(vehicleId);
|
return vehicleMap.get(vehicleId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Break getBreak(String vehicleId) {
|
||||||
|
return vehicleMap.get(vehicleId).getBreak();
|
||||||
|
}
|
||||||
|
|
||||||
private void readProblemType(XMLConfiguration vrpProblem) {
|
private void readProblemType(XMLConfiguration vrpProblem) {
|
||||||
String fleetSize = vrpProblem.getString("problemType.fleetSize");
|
String fleetSize = vrpProblem.getString("problemType.fleetSize");
|
||||||
if (fleetSize == null) vrpBuilder.setFleetSize(FleetSize.INFINITE);
|
if (fleetSize == null) vrpBuilder.setFleetSize(FleetSize.INFINITE);
|
||||||
|
|
@ -673,7 +688,7 @@ public class VrpXMLReader {
|
||||||
}
|
}
|
||||||
|
|
||||||
// read break
|
// read break
|
||||||
List<HierarchicalConfiguration> breakTWConfigs = vehicleConfig.configurationsAt("break.timeWindows.timeWindow");
|
List<HierarchicalConfiguration> breakTWConfigs = vehicleConfig.configurationsAt("breaks.timeWindows.timeWindow");
|
||||||
if (!breakTWConfigs.isEmpty()) {
|
if (!breakTWConfigs.isEmpty()) {
|
||||||
String breakDurationString = vehicleConfig.getString("breaks.duration");
|
String breakDurationString = vehicleConfig.getString("breaks.duration");
|
||||||
Break.Builder current_break = Break.Builder.newInstance(vehicleId);
|
Break.Builder current_break = Break.Builder.newInstance(vehicleId);
|
||||||
|
|
|
||||||
|
|
@ -354,10 +354,10 @@ public class VrpXMLWriter {
|
||||||
if (vehicle.getBreak() != null) {
|
if (vehicle.getBreak() != null) {
|
||||||
Collection<TimeWindow> tws = vehicle.getBreak().getTimeWindows();
|
Collection<TimeWindow> tws = vehicle.getBreak().getTimeWindows();
|
||||||
int index = 0;
|
int index = 0;
|
||||||
xmlConfig.setProperty(vehiclePathString + "(" + counter + ").break.duration", vehicle.getBreak().getServiceDuration());
|
xmlConfig.setProperty(vehiclePathString + "(" + counter + ").breaks.duration", vehicle.getBreak().getServiceDuration());
|
||||||
for(TimeWindow tw : tws) {
|
for(TimeWindow tw : tws) {
|
||||||
xmlConfig.setProperty(vehiclePathString + "(" + counter + ").break.timeWindows.timeWindow(" + index + ").start", tw.getStart());
|
xmlConfig.setProperty(vehiclePathString + "(" + counter + ").breaks.timeWindows.timeWindow(" + index + ").start", tw.getStart());
|
||||||
xmlConfig.setProperty(vehiclePathString + "(" + counter + ").break.timeWindows.timeWindow(" + index + ").end", tw.getEnd());
|
xmlConfig.setProperty(vehiclePathString + "(" + counter + ").breaks.timeWindows.timeWindow(" + index + ").end", tw.getEnd());
|
||||||
++index;
|
++index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -195,6 +195,16 @@ public class VehicleRoute {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Builder addBreak(Break currentbreak) {
|
||||||
|
if (currentbreak == null) throw new IllegalArgumentException("break must not be null");
|
||||||
|
return addBreak(currentbreak, currentbreak.getTimeWindow());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder addBreak(Break currentbreak, TimeWindow timeWindow) {
|
||||||
|
if (currentbreak == null) throw new IllegalArgumentException("break must not be null");
|
||||||
|
return addService(currentbreak,timeWindow);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a pickup to this route.
|
* Adds a pickup to this route.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package com.graphhopper.jsprit.core.reporting;
|
package com.graphhopper.jsprit.core.reporting;
|
||||||
|
|
||||||
import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
|
import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
|
||||||
|
import com.graphhopper.jsprit.core.problem.job.Break;
|
||||||
import com.graphhopper.jsprit.core.problem.job.Job;
|
import com.graphhopper.jsprit.core.problem.job.Job;
|
||||||
import com.graphhopper.jsprit.core.problem.job.Service;
|
import com.graphhopper.jsprit.core.problem.job.Service;
|
||||||
import com.graphhopper.jsprit.core.problem.job.Shipment;
|
import com.graphhopper.jsprit.core.problem.job.Shipment;
|
||||||
|
|
@ -53,11 +54,13 @@ public class SolutionPrinter {
|
||||||
private static class Jobs {
|
private static class Jobs {
|
||||||
int nServices;
|
int nServices;
|
||||||
int nShipments;
|
int nShipments;
|
||||||
|
int nBreaks;
|
||||||
|
|
||||||
public Jobs(int nServices, int nShipments) {
|
public Jobs(int nServices, int nShipments, int nBreaks) {
|
||||||
super();
|
super();
|
||||||
this.nServices = nServices;
|
this.nServices = nServices;
|
||||||
this.nShipments = nShipments;
|
this.nShipments = nShipments;
|
||||||
|
this.nBreaks = nBreaks;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -113,6 +116,7 @@ public class SolutionPrinter {
|
||||||
Jobs jobs = getNuOfJobs(problem);
|
Jobs jobs = getNuOfJobs(problem);
|
||||||
out.format(leftAlign, "noServices", jobs.nServices);
|
out.format(leftAlign, "noServices", jobs.nServices);
|
||||||
out.format(leftAlign, "noShipments", jobs.nShipments);
|
out.format(leftAlign, "noShipments", jobs.nShipments);
|
||||||
|
out.format(leftAlign, "noBreaks", jobs.nBreaks);
|
||||||
out.format(leftAlign, "fleetsize", problem.getFleetSize().toString());
|
out.format(leftAlign, "fleetsize", problem.getFleetSize().toString());
|
||||||
out.format("+--------------------------+%n");
|
out.format("+--------------------------+%n");
|
||||||
|
|
||||||
|
|
@ -194,6 +198,7 @@ public class SolutionPrinter {
|
||||||
private static Jobs getNuOfJobs(VehicleRoutingProblem problem) {
|
private static Jobs getNuOfJobs(VehicleRoutingProblem problem) {
|
||||||
int nShipments = 0;
|
int nShipments = 0;
|
||||||
int nServices = 0;
|
int nServices = 0;
|
||||||
|
int nBreaks = 0;
|
||||||
for (Job j : problem.getJobs().values()) {
|
for (Job j : problem.getJobs().values()) {
|
||||||
if (j instanceof Shipment) {
|
if (j instanceof Shipment) {
|
||||||
nShipments++;
|
nShipments++;
|
||||||
|
|
@ -201,8 +206,11 @@ public class SolutionPrinter {
|
||||||
if (j instanceof Service) {
|
if (j instanceof Service) {
|
||||||
nServices++;
|
nServices++;
|
||||||
}
|
}
|
||||||
|
if (j instanceof Break) {
|
||||||
|
nBreaks++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return new Jobs(nServices, nShipments);
|
return new Jobs(nServices, nShipments, nBreaks);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -258,6 +258,7 @@
|
||||||
<xs:choice>
|
<xs:choice>
|
||||||
<xs:group ref="serviceActGroup"/>
|
<xs:group ref="serviceActGroup"/>
|
||||||
<xs:group ref="shipmentActGroup"/>
|
<xs:group ref="shipmentActGroup"/>
|
||||||
|
<xs:group ref="breakActGroup"/>
|
||||||
</xs:choice>
|
</xs:choice>
|
||||||
<xs:attribute name="type" type="xs:string" use="required"/>
|
<xs:attribute name="type" type="xs:string" use="required"/>
|
||||||
</xs:complexType>
|
</xs:complexType>
|
||||||
|
|
@ -297,6 +298,7 @@
|
||||||
<xs:choice>
|
<xs:choice>
|
||||||
<xs:group ref="serviceActGroup"/>
|
<xs:group ref="serviceActGroup"/>
|
||||||
<xs:group ref="shipmentActGroup"/>
|
<xs:group ref="shipmentActGroup"/>
|
||||||
|
<xs:group ref="breakActGroup"/>
|
||||||
|
|
||||||
</xs:choice>
|
</xs:choice>
|
||||||
<xs:attribute name="type" type="xs:string"
|
<xs:attribute name="type" type="xs:string"
|
||||||
|
|
@ -354,6 +356,14 @@
|
||||||
</xs:sequence>
|
</xs:sequence>
|
||||||
</xs:group>
|
</xs:group>
|
||||||
|
|
||||||
|
<xs:group name="breakActGroup">
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element name="breakId" type="xs:string" 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:complexType name="timeWindowType">
|
<xs:complexType name="timeWindowType">
|
||||||
<xs:sequence>
|
<xs:sequence>
|
||||||
<xs:element name="start" type="xs:double"/>
|
<xs:element name="start" type="xs:double"/>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue