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

Multi TimeWindows support in XML

This commit is contained in:
braktar 2016-04-07 12:19:54 +02:00
parent 3ea3cc06ee
commit b2b527d7c3
3 changed files with 60 additions and 29 deletions

View file

@ -390,11 +390,11 @@ public class VrpXMLReader {
if (pickupServiceTime != null) builder.setPickupServiceTime(Double.parseDouble(pickupServiceTime));
//pickup-tw
String pickupTWStart = shipmentConfig.getString("pickup.timeWindows.timeWindow(0).start");
String pickupTWEnd = shipmentConfig.getString("pickup.timeWindows.timeWindow(0).end");
if (pickupTWStart != null && pickupTWEnd != null) {
TimeWindow pickupTW = TimeWindow.newInstance(Double.parseDouble(pickupTWStart), Double.parseDouble(pickupTWEnd));
builder.setPickupTimeWindow(pickupTW);
List<HierarchicalConfiguration> pickupTWConfigs = shipmentConfig.configurationsAt("pickup.timeWindows.timeWindow");
if (!pickupTWConfigs.isEmpty()) {
for (HierarchicalConfiguration pu_twConfig : pickupTWConfigs) {
builder.addPickupTimeWindow(TimeWindow.newInstance(pu_twConfig.getDouble("start"), pu_twConfig.getDouble("end")));
}
}
//delivery location
@ -424,11 +424,11 @@ public class VrpXMLReader {
if (deliveryServiceTime != null) builder.setDeliveryServiceTime(Double.parseDouble(deliveryServiceTime));
//delivery-tw
String delTWStart = shipmentConfig.getString("delivery.timeWindows.timeWindow(0).start");
String delTWEnd = shipmentConfig.getString("delivery.timeWindows.timeWindow(0).end");
if (delTWStart != null && delTWEnd != null) {
TimeWindow delTW = TimeWindow.newInstance(Double.parseDouble(delTWStart), Double.parseDouble(delTWEnd));
builder.setDeliveryTimeWindow(delTW);
List<HierarchicalConfiguration> deliveryTWConfigs = shipmentConfig.configurationsAt("delivery.timeWindows.timeWindow");
if (!deliveryTWConfigs.isEmpty()) {
for (HierarchicalConfiguration dl_twConfig : deliveryTWConfigs) {
builder.addDeliveryTimeWindow(TimeWindow.newInstance(dl_twConfig.getDouble("start"), dl_twConfig.getDouble("end")));
}
}
//read skills
@ -514,7 +514,7 @@ public class VrpXMLReader {
List<HierarchicalConfiguration> deliveryTWConfigs = serviceConfig.configurationsAt("timeWindows.timeWindow");
if (!deliveryTWConfigs.isEmpty()) {
for (HierarchicalConfiguration twConfig : deliveryTWConfigs) {
builder.setTimeWindow(TimeWindow.newInstance(twConfig.getDouble("start"), twConfig.getDouble("end")));
builder.addTimeWindow(TimeWindow.newInstance(twConfig.getDouble("start"), twConfig.getDouble("end")));
}
}
@ -673,13 +673,16 @@ public class VrpXMLReader {
}
// read break
String breakStartString = vehicleConfig.getString("breaks.timeWindow.start");
String breakEndString = vehicleConfig.getString("breaks.timeWindow.end");
String breakDurationString = vehicleConfig.getString("breaks.duration");
if(breakStartString!=null && breakEndString!=null && breakDurationString!=null )
builder.setBreak(Break.Builder.newInstance(vehicleId)
.addTimeWindow(Double.parseDouble(breakStartString), Double.parseDouble(breakEndString))
.setServiceTime(Double.parseDouble(breakDurationString)).build());
List<HierarchicalConfiguration> breakTWConfigs = vehicleConfig.configurationsAt("break.timeWindows.timeWindow");
if (!breakTWConfigs.isEmpty()) {
String breakDurationString = vehicleConfig.getString("breaks.duration");
Break.Builder current_break = Break.Builder.newInstance(vehicleId);
current_break.setServiceTime(Double.parseDouble(breakDurationString));
for (HierarchicalConfiguration twConfig : breakTWConfigs) {
current_break.addTimeWindow(TimeWindow.newInstance(twConfig.getDouble("start"), twConfig.getDouble("end")));
}
builder.setBreak(current_break.build());
}
//build vehicle

View file

@ -25,6 +25,7 @@ import com.graphhopper.jsprit.core.problem.job.Service;
import com.graphhopper.jsprit.core.problem.job.Shipment;
import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolution;
import com.graphhopper.jsprit.core.problem.solution.route.VehicleRoute;
import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow;
import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity;
import com.graphhopper.jsprit.core.problem.vehicle.Vehicle;
import com.graphhopper.jsprit.core.problem.vehicle.VehicleType;
@ -229,9 +230,15 @@ public class VrpXMLWriter {
xmlConfig.setProperty(shipmentPathString + "(" + counter + ").capacity-dimensions.dimension(" + i + ")[@index]", i);
xmlConfig.setProperty(shipmentPathString + "(" + counter + ").capacity-dimensions.dimension(" + i + ")", service.getSize().get(i));
}
Collection<TimeWindow> tws = service.getTimeWindows();
int index = 0;
xmlConfig.setProperty(shipmentPathString + "(" + counter + ").duration", service.getServiceDuration());
xmlConfig.setProperty(shipmentPathString + "(" + counter + ").timeWindows.timeWindow(0).start", service.getTimeWindow().getStart());
xmlConfig.setProperty(shipmentPathString + "(" + counter + ").timeWindows.timeWindow(0).end", service.getTimeWindow().getEnd());
for(TimeWindow tw : tws) {
xmlConfig.setProperty(shipmentPathString + "(" + counter + ").timeWindows.timeWindow(" + index + ").start", tw.getStart());
xmlConfig.setProperty(shipmentPathString + "(" + counter + ").timeWindows.timeWindow(" + index + ").end", tw.getEnd());
++index;
}
//skills
String skillString = getSkillString(service);
@ -265,10 +272,14 @@ public class VrpXMLWriter {
xmlConfig.setProperty(shipmentPathString + "(" + counter + ").pickup.location.index", shipment.getPickupLocation().getIndex());
}
Collection<TimeWindow> pu_tws = shipment.getPickupTimeWindows();
int index = 0;
xmlConfig.setProperty(shipmentPathString + "(" + counter + ").pickup.duration", shipment.getPickupServiceTime());
xmlConfig.setProperty(shipmentPathString + "(" + counter + ").pickup.timeWindows.timeWindow(0).start", shipment.getPickupTimeWindow().getStart());
xmlConfig.setProperty(shipmentPathString + "(" + counter + ").pickup.timeWindows.timeWindow(0).end", shipment.getPickupTimeWindow().getEnd());
for(TimeWindow tw : pu_tws) {
xmlConfig.setProperty(shipmentPathString + "(" + counter + ").pickup.timeWindows.timeWindow(" + index + ").start", tw.getStart());
xmlConfig.setProperty(shipmentPathString + "(" + counter + ").pickup.timeWindows.timeWindow(" + index + ").end", tw.getEnd());
++index;
}
if (shipment.getDeliveryLocation().getId() != null)
xmlConfig.setProperty(shipmentPathString + "(" + counter + ").delivery.location.id", shipment.getDeliveryLocation().getId());
@ -280,9 +291,14 @@ public class VrpXMLWriter {
xmlConfig.setProperty(shipmentPathString + "(" + counter + ").delivery.location.index", shipment.getDeliveryLocation().getIndex());
}
xmlConfig.setProperty(shipmentPathString + "(" + counter + ").delivery.duration", shipment.getDeliveryServiceTime());
xmlConfig.setProperty(shipmentPathString + "(" + counter + ").delivery.timeWindows.timeWindow(0).start", shipment.getDeliveryTimeWindow().getStart());
xmlConfig.setProperty(shipmentPathString + "(" + counter + ").delivery.timeWindows.timeWindow(0).end", shipment.getDeliveryTimeWindow().getEnd());
Collection<TimeWindow> del_tws = shipment.getDeliveryTimeWindows();
xmlConfig.setProperty(shipmentPathString + "(" + counter + ").delivery.duration", shipment.getDeliveryServiceTime());
index = 0;
for(TimeWindow tw : del_tws) {
xmlConfig.setProperty(shipmentPathString + "(" + counter + ").delivery.timeWindows.timeWindow(" + index + ").start", tw.getStart());
xmlConfig.setProperty(shipmentPathString + "(" + counter + ").delivery.timeWindows.timeWindow(" + index + ").end", tw.getEnd());
++index;
}
for (int i = 0; i < shipment.getSize().getNuOfDimensions(); i++) {
xmlConfig.setProperty(shipmentPathString + "(" + counter + ").capacity-dimensions.dimension(" + i + ")[@index]", i);
@ -336,9 +352,14 @@ public class VrpXMLWriter {
xmlConfig.setProperty(vehiclePathString + "(" + counter + ").timeSchedule.end", vehicle.getLatestArrival());
if (vehicle.getBreak() != null) {
xmlConfig.setProperty(vehiclePathString + "(" + counter + ").break.timeWindow.start", vehicle.getBreak().getTimeWindow().getStart());
xmlConfig.setProperty(vehiclePathString + "(" + counter + ").break.timeWindow.end", vehicle.getBreak().getTimeWindow().getEnd());
Collection<TimeWindow> tws = vehicle.getBreak().getTimeWindows();
int index = 0;
xmlConfig.setProperty(vehiclePathString + "(" + counter + ").break.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());
++index;
}
}
xmlConfig.setProperty(vehiclePathString + "(" + counter + ").returnToDepot", vehicle.isReturnToDepot());

View file

@ -371,7 +371,14 @@
<xs:complexType name="breaksType">
<xs:sequence>
<xs:element name="timeWindow" type="timeWindowType" minOccurs="1" maxOccurs="1"/>
<xs:element name="timeWindows" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="timeWindow" type="timeWindowType" minOccurs="1"
maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="duration" type="xs:double" minOccurs="1" maxOccurs="1" default="0.0"/>
</xs:sequence>
</xs:complexType>