1
0
Fork 0
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:
braktar 2016-05-19 11:07:13 +02:00
parent ee3b1589ba
commit aacafa27ba
5 changed files with 88 additions and 45 deletions

View file

@ -213,6 +213,11 @@ 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(type.equals("break")) {
Break currentbreak = getBreak(vehicleId);
routeBuilder.addBreak(currentbreak);
}
else {
if (serviceId != null) { if (serviceId != null) {
Service service = getService(serviceId); Service service = getService(serviceId);
if (service == null) if (service == null)
@ -236,6 +241,7 @@ public class VrpXMLReader {
throw new IllegalStateException("type " + type + " is not supported. Use 'pickupShipment' or 'deliverShipment' here"); throw new IllegalStateException("type " + type + " is not supported. Use 'pickupShipment' or 'deliverShipment' here");
} }
} }
}
VehicleRoute route = routeBuilder.build(); VehicleRoute route = routeBuilder.build();
vrpBuilder.addInitialVehicleRoute(route); vrpBuilder.addInitialVehicleRoute(route);
} }
@ -276,7 +282,11 @@ 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")) {
Break currentbreak = getBreak(vehicleId);
routeBuilder.addBreak(currentbreak);
}
else {
String serviceId = actConfig.getString("serviceId"); String serviceId = actConfig.getString("serviceId");
if (serviceId != null) { if (serviceId != null) {
Service service = getService(serviceId); Service service = getService(serviceId);
@ -296,6 +306,7 @@ public class VrpXMLReader {
throw new IllegalStateException("type " + type + " is not supported. Use 'pickupShipment' or 'deliverShipment' here"); throw new IllegalStateException("type " + type + " is not supported. Use 'pickupShipment' or 'deliverShipment' here");
} }
} }
}
routes.add(routeBuilder.build()); routes.add(routeBuilder.build());
} }
VehicleRoutingProblemSolution solution = new VehicleRoutingProblemSolution(routes, cost); VehicleRoutingProblemSolution solution = new VehicleRoutingProblemSolution(routes, cost);
@ -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);

View file

@ -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;
} }
} }

View file

@ -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.
* *

View file

@ -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);
} }
} }

View file

@ -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"/>