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

Merge remote-tracking branch 'origin/master'

This commit is contained in:
oblonski 2016-05-25 10:18:29 +02:00
commit 18ccdf3396
5 changed files with 88 additions and 45 deletions

View file

@ -213,27 +213,33 @@ public class VrpXMLReader {
if (endTimeS != null) endTime = Double.parseDouble(endTimeS);
String serviceId = actConfig.getString("serviceId");
if (serviceId != null) {
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);
} 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 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")) {
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");
if(type.equals("break")) {
Break currentbreak = getBreak(vehicleId);
routeBuilder.addBreak(currentbreak);
}
else {
if (serviceId != null) {
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);
} 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 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")) {
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();
@ -276,24 +282,29 @@ public class VrpXMLReader {
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);
} 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);
} else if (type.equals("deliverShipment")) {
routeBuilder.addDelivery(shipment);
} else
throw new IllegalStateException("type " + type + " is not supported. Use 'pickupShipment' or 'deliverShipment' here");
if(type.equals("break")) {
Break currentbreak = getBreak(vehicleId);
routeBuilder.addBreak(currentbreak);
}
else {
String serviceId = actConfig.getString("serviceId");
if (serviceId != null) {
Service service = getService(serviceId);
routeBuilder.addService(service);
} 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);
} 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());
@ -324,6 +335,10 @@ public class VrpXMLReader {
return vehicleMap.get(vehicleId);
}
private Break getBreak(String vehicleId) {
return vehicleMap.get(vehicleId).getBreak();
}
private void readProblemType(XMLConfiguration vrpProblem) {
String fleetSize = vrpProblem.getString("problemType.fleetSize");
if (fleetSize == null) vrpBuilder.setFleetSize(FleetSize.INFINITE);
@ -673,7 +688,7 @@ public class VrpXMLReader {
}
// read break
List<HierarchicalConfiguration> breakTWConfigs = vehicleConfig.configurationsAt("break.timeWindows.timeWindow");
List<HierarchicalConfiguration> breakTWConfigs = vehicleConfig.configurationsAt("breaks.timeWindows.timeWindow");
if (!breakTWConfigs.isEmpty()) {
String breakDurationString = vehicleConfig.getString("breaks.duration");
Break.Builder current_break = Break.Builder.newInstance(vehicleId);

View file

@ -354,10 +354,10 @@ public class VrpXMLWriter {
if (vehicle.getBreak() != null) {
Collection<TimeWindow> tws = vehicle.getBreak().getTimeWindows();
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) {
xmlConfig.setProperty(vehiclePathString + "(" + counter + ").break.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 + ").start", tw.getStart());
xmlConfig.setProperty(vehiclePathString + "(" + counter + ").breaks.timeWindows.timeWindow(" + index + ").end", tw.getEnd());
++index;
}
}

View file

@ -195,6 +195,16 @@ public class VehicleRoute {
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.
*

View file

@ -17,6 +17,7 @@
package com.graphhopper.jsprit.core.reporting;
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.Service;
import com.graphhopper.jsprit.core.problem.job.Shipment;
@ -53,11 +54,13 @@ public class SolutionPrinter {
private static class Jobs {
int nServices;
int nShipments;
int nBreaks;
public Jobs(int nServices, int nShipments) {
public Jobs(int nServices, int nShipments, int nBreaks) {
super();
this.nServices = nServices;
this.nShipments = nShipments;
this.nBreaks = nBreaks;
}
}
@ -113,6 +116,7 @@ public class SolutionPrinter {
Jobs jobs = getNuOfJobs(problem);
out.format(leftAlign, "noServices", jobs.nServices);
out.format(leftAlign, "noShipments", jobs.nShipments);
out.format(leftAlign, "noBreaks", jobs.nBreaks);
out.format(leftAlign, "fleetsize", problem.getFleetSize().toString());
out.format("+--------------------------+%n");
@ -194,6 +198,7 @@ public class SolutionPrinter {
private static Jobs getNuOfJobs(VehicleRoutingProblem problem) {
int nShipments = 0;
int nServices = 0;
int nBreaks = 0;
for (Job j : problem.getJobs().values()) {
if (j instanceof Shipment) {
nShipments++;
@ -201,8 +206,11 @@ public class SolutionPrinter {
if (j instanceof Service) {
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:group ref="serviceActGroup"/>
<xs:group ref="shipmentActGroup"/>
<xs:group ref="breakActGroup"/>
</xs:choice>
<xs:attribute name="type" type="xs:string" use="required"/>
</xs:complexType>
@ -297,6 +298,7 @@
<xs:choice>
<xs:group ref="serviceActGroup"/>
<xs:group ref="shipmentActGroup"/>
<xs:group ref="breakActGroup"/>
</xs:choice>
<xs:attribute name="type" type="xs:string"
@ -354,6 +356,14 @@
</xs:sequence>
</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:sequence>
<xs:element name="start" type="xs:double"/>