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:
parent
3ea3cc06ee
commit
b2b527d7c3
3 changed files with 60 additions and 29 deletions
|
|
@ -390,11 +390,11 @@ public class VrpXMLReader {
|
||||||
if (pickupServiceTime != null) builder.setPickupServiceTime(Double.parseDouble(pickupServiceTime));
|
if (pickupServiceTime != null) builder.setPickupServiceTime(Double.parseDouble(pickupServiceTime));
|
||||||
|
|
||||||
//pickup-tw
|
//pickup-tw
|
||||||
String pickupTWStart = shipmentConfig.getString("pickup.timeWindows.timeWindow(0).start");
|
List<HierarchicalConfiguration> pickupTWConfigs = shipmentConfig.configurationsAt("pickup.timeWindows.timeWindow");
|
||||||
String pickupTWEnd = shipmentConfig.getString("pickup.timeWindows.timeWindow(0).end");
|
if (!pickupTWConfigs.isEmpty()) {
|
||||||
if (pickupTWStart != null && pickupTWEnd != null) {
|
for (HierarchicalConfiguration pu_twConfig : pickupTWConfigs) {
|
||||||
TimeWindow pickupTW = TimeWindow.newInstance(Double.parseDouble(pickupTWStart), Double.parseDouble(pickupTWEnd));
|
builder.addPickupTimeWindow(TimeWindow.newInstance(pu_twConfig.getDouble("start"), pu_twConfig.getDouble("end")));
|
||||||
builder.setPickupTimeWindow(pickupTW);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//delivery location
|
//delivery location
|
||||||
|
|
@ -424,11 +424,11 @@ public class VrpXMLReader {
|
||||||
if (deliveryServiceTime != null) builder.setDeliveryServiceTime(Double.parseDouble(deliveryServiceTime));
|
if (deliveryServiceTime != null) builder.setDeliveryServiceTime(Double.parseDouble(deliveryServiceTime));
|
||||||
|
|
||||||
//delivery-tw
|
//delivery-tw
|
||||||
String delTWStart = shipmentConfig.getString("delivery.timeWindows.timeWindow(0).start");
|
List<HierarchicalConfiguration> deliveryTWConfigs = shipmentConfig.configurationsAt("delivery.timeWindows.timeWindow");
|
||||||
String delTWEnd = shipmentConfig.getString("delivery.timeWindows.timeWindow(0).end");
|
if (!deliveryTWConfigs.isEmpty()) {
|
||||||
if (delTWStart != null && delTWEnd != null) {
|
for (HierarchicalConfiguration dl_twConfig : deliveryTWConfigs) {
|
||||||
TimeWindow delTW = TimeWindow.newInstance(Double.parseDouble(delTWStart), Double.parseDouble(delTWEnd));
|
builder.addDeliveryTimeWindow(TimeWindow.newInstance(dl_twConfig.getDouble("start"), dl_twConfig.getDouble("end")));
|
||||||
builder.setDeliveryTimeWindow(delTW);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//read skills
|
//read skills
|
||||||
|
|
@ -514,7 +514,7 @@ public class VrpXMLReader {
|
||||||
List<HierarchicalConfiguration> deliveryTWConfigs = serviceConfig.configurationsAt("timeWindows.timeWindow");
|
List<HierarchicalConfiguration> deliveryTWConfigs = serviceConfig.configurationsAt("timeWindows.timeWindow");
|
||||||
if (!deliveryTWConfigs.isEmpty()) {
|
if (!deliveryTWConfigs.isEmpty()) {
|
||||||
for (HierarchicalConfiguration twConfig : deliveryTWConfigs) {
|
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
|
// read break
|
||||||
String breakStartString = vehicleConfig.getString("breaks.timeWindow.start");
|
List<HierarchicalConfiguration> breakTWConfigs = vehicleConfig.configurationsAt("break.timeWindows.timeWindow");
|
||||||
String breakEndString = vehicleConfig.getString("breaks.timeWindow.end");
|
if (!breakTWConfigs.isEmpty()) {
|
||||||
String breakDurationString = vehicleConfig.getString("breaks.duration");
|
String breakDurationString = vehicleConfig.getString("breaks.duration");
|
||||||
if(breakStartString!=null && breakEndString!=null && breakDurationString!=null )
|
Break.Builder current_break = Break.Builder.newInstance(vehicleId);
|
||||||
builder.setBreak(Break.Builder.newInstance(vehicleId)
|
current_break.setServiceTime(Double.parseDouble(breakDurationString));
|
||||||
.addTimeWindow(Double.parseDouble(breakStartString), Double.parseDouble(breakEndString))
|
for (HierarchicalConfiguration twConfig : breakTWConfigs) {
|
||||||
.setServiceTime(Double.parseDouble(breakDurationString)).build());
|
current_break.addTimeWindow(TimeWindow.newInstance(twConfig.getDouble("start"), twConfig.getDouble("end")));
|
||||||
|
}
|
||||||
|
builder.setBreak(current_break.build());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//build vehicle
|
//build vehicle
|
||||||
|
|
|
||||||
|
|
@ -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.job.Shipment;
|
||||||
import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
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.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.solution.route.activity.TourActivity;
|
||||||
import com.graphhopper.jsprit.core.problem.vehicle.Vehicle;
|
import com.graphhopper.jsprit.core.problem.vehicle.Vehicle;
|
||||||
import com.graphhopper.jsprit.core.problem.vehicle.VehicleType;
|
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 + ")[@index]", i);
|
||||||
xmlConfig.setProperty(shipmentPathString + "(" + counter + ").capacity-dimensions.dimension(" + i + ")", service.getSize().get(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 + ").duration", service.getServiceDuration());
|
||||||
xmlConfig.setProperty(shipmentPathString + "(" + counter + ").timeWindows.timeWindow(0).start", service.getTimeWindow().getStart());
|
for(TimeWindow tw : tws) {
|
||||||
xmlConfig.setProperty(shipmentPathString + "(" + counter + ").timeWindows.timeWindow(0).end", service.getTimeWindow().getEnd());
|
xmlConfig.setProperty(shipmentPathString + "(" + counter + ").timeWindows.timeWindow(" + index + ").start", tw.getStart());
|
||||||
|
xmlConfig.setProperty(shipmentPathString + "(" + counter + ").timeWindows.timeWindow(" + index + ").end", tw.getEnd());
|
||||||
|
++index;
|
||||||
|
}
|
||||||
|
|
||||||
//skills
|
//skills
|
||||||
String skillString = getSkillString(service);
|
String skillString = getSkillString(service);
|
||||||
|
|
@ -265,10 +272,14 @@ public class VrpXMLWriter {
|
||||||
xmlConfig.setProperty(shipmentPathString + "(" + counter + ").pickup.location.index", shipment.getPickupLocation().getIndex());
|
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.duration", shipment.getPickupServiceTime());
|
||||||
xmlConfig.setProperty(shipmentPathString + "(" + counter + ").pickup.timeWindows.timeWindow(0).start", shipment.getPickupTimeWindow().getStart());
|
for(TimeWindow tw : pu_tws) {
|
||||||
xmlConfig.setProperty(shipmentPathString + "(" + counter + ").pickup.timeWindows.timeWindow(0).end", shipment.getPickupTimeWindow().getEnd());
|
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)
|
if (shipment.getDeliveryLocation().getId() != null)
|
||||||
xmlConfig.setProperty(shipmentPathString + "(" + counter + ").delivery.location.id", shipment.getDeliveryLocation().getId());
|
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.location.index", shipment.getDeliveryLocation().getIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Collection<TimeWindow> del_tws = shipment.getDeliveryTimeWindows();
|
||||||
xmlConfig.setProperty(shipmentPathString + "(" + counter + ").delivery.duration", shipment.getDeliveryServiceTime());
|
xmlConfig.setProperty(shipmentPathString + "(" + counter + ").delivery.duration", shipment.getDeliveryServiceTime());
|
||||||
xmlConfig.setProperty(shipmentPathString + "(" + counter + ").delivery.timeWindows.timeWindow(0).start", shipment.getDeliveryTimeWindow().getStart());
|
index = 0;
|
||||||
xmlConfig.setProperty(shipmentPathString + "(" + counter + ").delivery.timeWindows.timeWindow(0).end", shipment.getDeliveryTimeWindow().getEnd());
|
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++) {
|
for (int i = 0; i < shipment.getSize().getNuOfDimensions(); i++) {
|
||||||
xmlConfig.setProperty(shipmentPathString + "(" + counter + ").capacity-dimensions.dimension(" + i + ")[@index]", 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());
|
xmlConfig.setProperty(vehiclePathString + "(" + counter + ").timeSchedule.end", vehicle.getLatestArrival());
|
||||||
|
|
||||||
if (vehicle.getBreak() != null) {
|
if (vehicle.getBreak() != null) {
|
||||||
xmlConfig.setProperty(vehiclePathString + "(" + counter + ").break.timeWindow.start", vehicle.getBreak().getTimeWindow().getStart());
|
Collection<TimeWindow> tws = vehicle.getBreak().getTimeWindows();
|
||||||
xmlConfig.setProperty(vehiclePathString + "(" + counter + ").break.timeWindow.end", vehicle.getBreak().getTimeWindow().getEnd());
|
int index = 0;
|
||||||
xmlConfig.setProperty(vehiclePathString + "(" + counter + ").break.duration", vehicle.getBreak().getServiceDuration());
|
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());
|
xmlConfig.setProperty(vehiclePathString + "(" + counter + ").returnToDepot", vehicle.isReturnToDepot());
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -371,7 +371,14 @@
|
||||||
|
|
||||||
<xs:complexType name="breaksType">
|
<xs:complexType name="breaksType">
|
||||||
<xs:sequence>
|
<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:element name="duration" type="xs:double" minOccurs="1" maxOccurs="1" default="0.0"/>
|
||||||
</xs:sequence>
|
</xs:sequence>
|
||||||
</xs:complexType>
|
</xs:complexType>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue