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

merge multiple time window branch

This commit is contained in:
oblonski 2016-01-13 10:32:12 +01:00
commit 26d03f15e3
123 changed files with 9432 additions and 205 deletions

View file

@ -143,6 +143,8 @@ final class BreakInsertionCalculator implements JobInsertionCostsCalculator {
List<Location> locations = Arrays.asList(prevAct.getLocation(), nextAct.getLocation());
for (Location location : locations) {
breakAct2Insert.setLocation(location);
breakAct2Insert.setTheoreticalEarliestOperationStartTime(breakToInsert.getTimeWindow().getStart());
breakAct2Insert.setTheoreticalLatestOperationStartTime(breakToInsert.getTimeWindow().getEnd());
ConstraintsStatus status = hardActivityLevelConstraint.fulfilled(insertionContext, prevAct, breakAct2Insert, nextAct, prevActStartTime);
if (status.equals(ConstraintsStatus.FULFILLED)) {
//from job2insert induced costs at activity level

View file

@ -27,6 +27,7 @@ import jsprit.core.problem.misc.JobInsertionContext;
import jsprit.core.problem.solution.route.VehicleRoute;
import jsprit.core.problem.solution.route.activity.End;
import jsprit.core.problem.solution.route.activity.Start;
import jsprit.core.problem.solution.route.activity.TimeWindow;
import jsprit.core.problem.solution.route.activity.TourActivity;
import jsprit.core.problem.vehicle.Vehicle;
import jsprit.core.util.CalculationUtils;
@ -108,6 +109,7 @@ final class ServiceInsertionCalculator implements JobInsertionCostsCalculator {
double bestCost = bestKnownCosts;
additionalICostsAtRouteLevel += additionalAccessEgressCalculator.getCosts(insertionContext);
TimeWindow bestTimeWindow = null;
/*
generate new start and end for new vehicle
@ -121,38 +123,46 @@ final class ServiceInsertionCalculator implements JobInsertionCostsCalculator {
int actIndex = 0;
Iterator<TourActivity> activityIterator = currentRoute.getActivities().iterator();
boolean tourEnd = false;
while (!tourEnd) {
while(!tourEnd){
TourActivity nextAct;
if (activityIterator.hasNext()) nextAct = activityIterator.next();
else {
if(activityIterator.hasNext()) nextAct = activityIterator.next();
else{
nextAct = end;
tourEnd = true;
}
ConstraintsStatus status = hardActivityLevelConstraint.fulfilled(insertionContext, prevAct, deliveryAct2Insert, nextAct, prevActStartTime);
if (status.equals(ConstraintsStatus.FULFILLED)) {
//from job2insert induced costs at activity level
double additionalICostsAtActLevel = softActivityConstraint.getCosts(insertionContext, prevAct, deliveryAct2Insert, nextAct, prevActStartTime);
double additionalTransportationCosts = additionalTransportCostsCalculator.getCosts(insertionContext, prevAct, nextAct, deliveryAct2Insert, prevActStartTime);
if (additionalICostsAtRouteLevel + additionalICostsAtActLevel + additionalTransportationCosts < bestCost) {
bestCost = additionalICostsAtRouteLevel + additionalICostsAtActLevel + additionalTransportationCosts;
insertionIndex = actIndex;
boolean not_fulfilled_break = true;
for(TimeWindow timeWindow : service.getTimeWindows()) {
deliveryAct2Insert.setTheoreticalEarliestOperationStartTime(timeWindow.getStart());
deliveryAct2Insert.setTheoreticalLatestOperationStartTime(timeWindow.getEnd());
ConstraintsStatus status = hardActivityLevelConstraint.fulfilled(insertionContext, prevAct, deliveryAct2Insert, nextAct, prevActStartTime);
if (status.equals(ConstraintsStatus.FULFILLED)) {
double additionalICostsAtActLevel = softActivityConstraint.getCosts(insertionContext, prevAct, deliveryAct2Insert, nextAct, prevActStartTime);
double additionalTransportationCosts = additionalTransportCostsCalculator.getCosts(insertionContext, prevAct, nextAct, deliveryAct2Insert, prevActStartTime);
if (additionalICostsAtRouteLevel + additionalICostsAtActLevel + additionalTransportationCosts < bestCost) {
bestCost = additionalICostsAtRouteLevel + additionalICostsAtActLevel + additionalTransportationCosts;
insertionIndex = actIndex;
bestTimeWindow = timeWindow;
}
not_fulfilled_break = false;
} else if (status.equals(ConstraintsStatus.NOT_FULFILLED)) {
not_fulfilled_break = false;
}
} else if (status.equals(ConstraintsStatus.NOT_FULFILLED_BREAK)) {
break;
}
}
if(not_fulfilled_break) break;
double nextActArrTime = prevActStartTime + transportCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), prevActStartTime, newDriver, newVehicle);
prevActStartTime = CalculationUtils.getActivityEndTime(nextActArrTime, nextAct);
prevAct = nextAct;
actIndex++;
}
if (insertionIndex == InsertionData.NO_INDEX) {
if(insertionIndex == InsertionData.NO_INDEX) {
return InsertionData.createEmptyInsertionData();
}
InsertionData insertionData = new InsertionData(bestCost, InsertionData.NO_INDEX, insertionIndex, newVehicle, newDriver);
deliveryAct2Insert.setTheoreticalEarliestOperationStartTime(bestTimeWindow.getStart());
deliveryAct2Insert.setTheoreticalLatestOperationStartTime(bestTimeWindow.getEnd());
insertionData.getEvents().add(new InsertActivity(currentRoute, newVehicle, deliveryAct2Insert, insertionIndex));
insertionData.getEvents().add(new SwitchVehicle(currentRoute, newVehicle, newVehicleDepartureTime));
insertionData.getEvents().add(new SwitchVehicle(currentRoute,newVehicle,newVehicleDepartureTime));
insertionData.setVehicleDepartureTime(newVehicleDepartureTime);
return insertionData;
}
}

View file

@ -28,6 +28,7 @@ import jsprit.core.problem.misc.JobInsertionContext;
import jsprit.core.problem.solution.route.VehicleRoute;
import jsprit.core.problem.solution.route.activity.End;
import jsprit.core.problem.solution.route.activity.Start;
import jsprit.core.problem.solution.route.activity.TimeWindow;
import jsprit.core.problem.solution.route.activity.TourActivity;
import jsprit.core.problem.vehicle.Vehicle;
import jsprit.core.util.CalculationUtils;
@ -108,6 +109,9 @@ final class ShipmentInsertionCalculator implements JobInsertionCostsCalculator {
int pickupInsertionIndex = InsertionData.NO_INDEX;
int deliveryInsertionIndex = InsertionData.NO_INDEX;
TimeWindow bestPickupTimeWindow = null;
TimeWindow bestDeliveryTimeWindow = null;
Start start = new Start(newVehicle.getStartLocation(), newVehicle.getEarliestDeparture(), newVehicle.getLatestArrival());
start.setEndTime(newVehicleDepartureTime);
@ -132,67 +136,83 @@ final class ShipmentInsertionCalculator implements JobInsertionCostsCalculator {
nextAct = end;
tourEnd = true;
}
// logger.info("activity: {}, act-size: {}", i, activities.size());
ConstraintsStatus pickupShipmentConstraintStatus = hardActivityLevelConstraint.fulfilled(insertionContext, prevAct, pickupShipment, nextAct, prevActEndTime);
if (pickupShipmentConstraintStatus.equals(ConstraintsStatus.NOT_FULFILLED)) {
double nextActArrTime = prevActEndTime + transportCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), prevActEndTime, newDriver, newVehicle);
prevActEndTime = CalculationUtils.getActivityEndTime(nextActArrTime, nextAct);
prevAct = nextAct;
i++;
continue;
} else if (pickupShipmentConstraintStatus.equals(ConstraintsStatus.NOT_FULFILLED_BREAK)) {
break;
}
double additionalPickupICosts = softActivityConstraint.getCosts(insertionContext, prevAct, pickupShipment, nextAct, prevActEndTime);
double pickupAIC = calculate(insertionContext, prevAct, pickupShipment, nextAct, prevActEndTime);
TourActivity prevAct_deliveryLoop = pickupShipment;
double shipmentPickupArrTime = prevActEndTime + transportCosts.getTransportTime(prevAct.getLocation(), pickupShipment.getLocation(), prevActEndTime, newDriver, newVehicle);
double shipmentPickupEndTime = CalculationUtils.getActivityEndTime(shipmentPickupArrTime, pickupShipment);
boolean pickupInsertionNotFulfilledBreak = true;
for(TimeWindow pickupTimeWindow : shipment.getPickupTimeWindows()) {
pickupShipment.setTheoreticalEarliestOperationStartTime(pickupTimeWindow.getStart());
pickupShipment.setTheoreticalLatestOperationStartTime(pickupTimeWindow.getEnd());
ConstraintsStatus pickupShipmentConstraintStatus = hardActivityLevelConstraint.fulfilled(insertionContext, prevAct, pickupShipment, nextAct, prevActEndTime);
if (pickupShipmentConstraintStatus.equals(ConstraintsStatus.NOT_FULFILLED)) {
pickupInsertionNotFulfilledBreak = false;
continue;
} else if(pickupShipmentConstraintStatus.equals(ConstraintsStatus.NOT_FULFILLED_BREAK)) {
continue;
}
else if (pickupShipmentConstraintStatus.equals(ConstraintsStatus.FULFILLED)) {
pickupInsertionNotFulfilledBreak = false;
}
double additionalPickupICosts = softActivityConstraint.getCosts(insertionContext, prevAct, pickupShipment, nextAct, prevActEndTime);
double pickupAIC = calculate(insertionContext, prevAct, pickupShipment, nextAct, prevActEndTime);
pickupContext.setArrivalTime(shipmentPickupArrTime);
pickupContext.setEndTime(shipmentPickupEndTime);
pickupContext.setInsertionIndex(i);
insertionContext.setRelatedActivityContext(pickupContext);
TourActivity prevAct_deliveryLoop = pickupShipment;
double shipmentPickupArrTime = prevActEndTime + transportCosts.getTransportTime(prevAct.getLocation(), pickupShipment.getLocation(), prevActEndTime, newDriver, newVehicle);
double shipmentPickupEndTime = CalculationUtils.getActivityEndTime(shipmentPickupArrTime, pickupShipment);
double prevActEndTime_deliveryLoop = shipmentPickupEndTime;
pickupContext.setArrivalTime(shipmentPickupArrTime);
pickupContext.setEndTime(shipmentPickupEndTime);
pickupContext.setInsertionIndex(i);
insertionContext.setRelatedActivityContext(pickupContext);
double prevActEndTime_deliveryLoop = shipmentPickupEndTime;
/*
--------------------------------
*/
//deliverShipmentLoop
int j = i;
boolean tourEnd_deliveryLoop = false;
while (!tourEnd_deliveryLoop) {
// for(int j=i;j<activities.size();j++){
TourActivity nextAct_deliveryLoop;
if (j < activities.size()) {
nextAct_deliveryLoop = activities.get(j);
} else {
nextAct_deliveryLoop = end;
tourEnd_deliveryLoop = true;
}
ConstraintsStatus deliverShipmentConstraintStatus = hardActivityLevelConstraint.fulfilled(insertionContext, prevAct_deliveryLoop, deliverShipment, nextAct_deliveryLoop, prevActEndTime_deliveryLoop);
if (deliverShipmentConstraintStatus.equals(ConstraintsStatus.FULFILLED)) {
double additionalDeliveryICosts = softActivityConstraint.getCosts(insertionContext, prevAct_deliveryLoop, deliverShipment, nextAct_deliveryLoop, prevActEndTime_deliveryLoop);
double deliveryAIC = calculate(insertionContext, prevAct_deliveryLoop, deliverShipment, nextAct_deliveryLoop, prevActEndTime_deliveryLoop);
double totalActivityInsertionCosts = pickupAIC + deliveryAIC
+ additionalICostsAtRouteLevel + additionalPickupICosts + additionalDeliveryICosts;
if (totalActivityInsertionCosts < bestCost) {
bestCost = totalActivityInsertionCosts;
pickupInsertionIndex = i;
deliveryInsertionIndex = j;
//deliverShipmentLoop
int j = i;
boolean tourEnd_deliveryLoop = false;
while (!tourEnd_deliveryLoop) {
TourActivity nextAct_deliveryLoop;
if (j < activities.size()) {
nextAct_deliveryLoop = activities.get(j);
} else {
nextAct_deliveryLoop = end;
tourEnd_deliveryLoop = true;
}
} else if (deliverShipmentConstraintStatus.equals(ConstraintsStatus.NOT_FULFILLED_BREAK)) {
break;
boolean deliveryInsertionNotFulfilledBreak = true;
for (TimeWindow deliveryTimeWindow : shipment.getDeliveryTimeWindows()) {
deliverShipment.setTheoreticalEarliestOperationStartTime(deliveryTimeWindow.getStart());
deliverShipment.setTheoreticalLatestOperationStartTime(deliveryTimeWindow.getEnd());
ConstraintsStatus deliverShipmentConstraintStatus = hardActivityLevelConstraint.fulfilled(insertionContext, prevAct_deliveryLoop, deliverShipment, nextAct_deliveryLoop, prevActEndTime_deliveryLoop);
if (deliverShipmentConstraintStatus.equals(ConstraintsStatus.FULFILLED)) {
double additionalDeliveryICosts = softActivityConstraint.getCosts(insertionContext, prevAct_deliveryLoop, deliverShipment, nextAct_deliveryLoop, prevActEndTime_deliveryLoop);
double deliveryAIC = calculate(insertionContext, prevAct_deliveryLoop, deliverShipment, nextAct_deliveryLoop, prevActEndTime_deliveryLoop);
double totalActivityInsertionCosts = pickupAIC + deliveryAIC
+ additionalICostsAtRouteLevel + additionalPickupICosts + additionalDeliveryICosts;
if (totalActivityInsertionCosts < bestCost) {
bestCost = totalActivityInsertionCosts;
pickupInsertionIndex = i;
deliveryInsertionIndex = j;
bestPickupTimeWindow = pickupTimeWindow;
bestDeliveryTimeWindow = deliveryTimeWindow;
}
deliveryInsertionNotFulfilledBreak = false;
} else if (deliverShipmentConstraintStatus.equals(ConstraintsStatus.NOT_FULFILLED)) {
deliveryInsertionNotFulfilledBreak = false;
}
}
if (deliveryInsertionNotFulfilledBreak) break;
//update prevAct and endTime
double nextActArrTime = prevActEndTime_deliveryLoop + transportCosts.getTransportTime(prevAct_deliveryLoop.getLocation(), nextAct_deliveryLoop.getLocation(), prevActEndTime_deliveryLoop, newDriver, newVehicle);
prevActEndTime_deliveryLoop = CalculationUtils.getActivityEndTime(nextActArrTime, nextAct_deliveryLoop);
prevAct_deliveryLoop = nextAct_deliveryLoop;
j++;
}
//update prevAct and endTime
double nextActArrTime = prevActEndTime_deliveryLoop + transportCosts.getTransportTime(prevAct_deliveryLoop.getLocation(), nextAct_deliveryLoop.getLocation(), prevActEndTime_deliveryLoop, newDriver, newVehicle);
prevActEndTime_deliveryLoop = CalculationUtils.getActivityEndTime(nextActArrTime, nextAct_deliveryLoop);
prevAct_deliveryLoop = nextAct_deliveryLoop;
j++;
}
if(pickupInsertionNotFulfilledBreak){
break;
}
//update prevAct and endTime
double nextActArrTime = prevActEndTime + transportCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), prevActEndTime, newDriver, newVehicle);
@ -204,6 +224,10 @@ final class ShipmentInsertionCalculator implements JobInsertionCostsCalculator {
return InsertionData.createEmptyInsertionData();
}
InsertionData insertionData = new InsertionData(bestCost, pickupInsertionIndex, deliveryInsertionIndex, newVehicle, newDriver);
pickupShipment.setTheoreticalEarliestOperationStartTime(bestPickupTimeWindow.getStart());
pickupShipment.setTheoreticalLatestOperationStartTime(bestPickupTimeWindow.getEnd());
deliverShipment.setTheoreticalEarliestOperationStartTime(bestDeliveryTimeWindow.getStart());
deliverShipment.setTheoreticalLatestOperationStartTime(bestDeliveryTimeWindow.getEnd());
insertionData.setVehicleDepartureTime(newVehicleDepartureTime);
insertionData.getEvents().add(new InsertActivity(currentRoute, newVehicle, deliverShipment, deliveryInsertionIndex));
insertionData.getEvents().add(new InsertActivity(currentRoute, newVehicle, pickupShipment, pickupInsertionIndex));

View file

@ -29,8 +29,8 @@ class NearestNeighborhoodIterator implements Iterator<Job> {
public boolean hasNext() {
if (jobCount < nJobs) {
boolean hasNext = jobIter.hasNext();
if (!hasNext)
log.warn("more jobs are requested then iterator can iterate over. probably the number of neighbors memorized in JobNeighborhoods is too small");
// if (!hasNext)
// log.warn("more jobs are requested then iterator can iterate over. probably the number of neighbors memorized in JobNeighborhoods is too small");
return hasNext;
}
return false;

View file

@ -21,6 +21,7 @@ import jsprit.core.problem.Location;
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
import jsprit.core.problem.solution.route.RouteVisitor;
import jsprit.core.problem.solution.route.VehicleRoute;
import jsprit.core.problem.solution.route.activity.TimeWindow;
import jsprit.core.problem.solution.route.activity.TourActivity;
import jsprit.core.problem.vehicle.Vehicle;
@ -97,6 +98,7 @@ public class UpdateVehicleDependentPracticalTimeWindows implements RouteVisitor,
double potentialLatestArrivalTimeAtCurrAct = latestArrTimeAtPrevAct - transportCosts.getBackwardTransportTime(activity.getLocation(), prevLocation,
latestArrTimeAtPrevAct, route.getDriver(), vehicle) - activity.getOperationTime();
double latestArrivalTime = Math.min(activity.getTheoreticalLatestOperationStartTime(), potentialLatestArrivalTimeAtCurrAct);
// getLatestArrivalTime(activity.getTimeWindows(), potentialLatestArrivalTimeAtCurrAct);
if (latestArrivalTime < activity.getTheoreticalEarliestOperationStartTime()) {
stateManager.putTypedInternalRouteState(route, vehicle, InternalStates.SWITCH_NOT_FEASIBLE, true);
}
@ -107,8 +109,8 @@ public class UpdateVehicleDependentPracticalTimeWindows implements RouteVisitor,
}
public void finish() {
}
public void finish() {}
}

View file

@ -54,14 +54,9 @@ public class VehicleDependentTimeWindowConstraints implements HardActivityConstr
nextActLocation = newAct.getLocation();
}
} else {
//try to get latest_operation_start_time of newVehicle
latestArrTimeAtNextAct = states.getActivityState(nextAct, iFacts.getNewVehicle(), InternalStates.LATEST_OPERATION_START_TIME, Double.class);
// if(latestArrTimeAtNextAct == null) //try to get latest_operation_start_time of currVehicle
// latestArrTimeAtNextAct = states.getActivityState(nextAct, iFacts.getRoute().getVehicle(), StateFactory.LATEST_OPERATION_START_TIME ,Double.class);
if (latestArrTimeAtNextAct == null) {//otherwise set it to theoretical_latest_operation_startTime
latestArrTimeAtNextAct = nextAct.getTheoreticalLatestOperationStartTime();
// throw new IllegalStateException("this is strange and should not be");
//ToDo here, there should be another solution
}
nextActLocation = nextAct.getLocation();
}
@ -73,8 +68,10 @@ public class VehicleDependentTimeWindowConstraints implements HardActivityConstr
* |--- vehicle's operation time ---|
* |--- prevAct or newAct or nextAct ---|
*/
double newAct_theoreticalEarliestOperationStartTime = newAct.getTheoreticalEarliestOperationStartTime();
if (latestVehicleArrival < prevAct.getTheoreticalEarliestOperationStartTime() ||
latestVehicleArrival < newAct.getTheoreticalEarliestOperationStartTime() ||
latestVehicleArrival < newAct_theoreticalEarliestOperationStartTime ||
latestVehicleArrival < nextAct.getTheoreticalEarliestOperationStartTime()) {
return ConstraintsStatus.NOT_FULFILLED_BREAK;
}
@ -85,7 +82,9 @@ public class VehicleDependentTimeWindowConstraints implements HardActivityConstr
* |--- prevAct ---|
* |--- newAct ---|
*/
if (newAct.getTheoreticalLatestOperationStartTime() < prevAct.getTheoreticalEarliestOperationStartTime()) {
double newAct_theoreticalLatestOperationStartTime = newAct.getTheoreticalLatestOperationStartTime();
if (newAct_theoreticalLatestOperationStartTime < prevAct.getTheoreticalEarliestOperationStartTime()) {
return ConstraintsStatus.NOT_FULFILLED_BREAK;
}
@ -103,16 +102,16 @@ public class VehicleDependentTimeWindowConstraints implements HardActivityConstr
* |--- newAct ---|
* |--- nextAct ---|
*/
if (newAct.getTheoreticalEarliestOperationStartTime() > nextAct.getTheoreticalLatestOperationStartTime()) {
if(newAct_theoreticalEarliestOperationStartTime > nextAct.getTheoreticalLatestOperationStartTime()){
return ConstraintsStatus.NOT_FULFILLED;
}
// log.info("check insertion of " + newAct + " between " + prevAct + " and " + nextAct + ". prevActDepTime=" + prevActDepTime);
double arrTimeAtNewAct = prevActDepTime + routingCosts.getTransportTime(prevAct.getLocation(), newAct.getLocation(), prevActDepTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
double endTimeAtNewAct = CalculationUtils.getActivityEndTime(arrTimeAtNewAct, newAct);
double latestArrTimeAtNewAct =
Math.min(newAct.getTheoreticalLatestOperationStartTime(),
Math.min(newAct_theoreticalLatestOperationStartTime,
latestArrTimeAtNextAct -
routingCosts.getBackwardTransportTime(newAct.getLocation(), nextActLocation, latestArrTimeAtNextAct, iFacts.getNewDriver(), iFacts.getNewVehicle())
routingCosts.getBackwardTransportTime(newAct.getLocation(),nextActLocation,latestArrTimeAtNextAct,iFacts.getNewDriver(),iFacts.getNewVehicle())
- newAct.getOperationTime()
);

View file

@ -134,6 +134,174 @@ public class VrpXMLReader {
this.solutions = null;
}
public void read(String filename) {
logger.debug("read vrp: {}", filename);
XMLConfiguration xmlConfig = new XMLConfiguration();
xmlConfig.setFileName(filename);
xmlConfig.setAttributeSplittingDisabled(true);
xmlConfig.setDelimiterParsingDisabled(true);
if (schemaValidation) {
final InputStream resource = Resource.getAsInputStream("vrp_xml_schema.xsd");
if (resource != null) {
EntityResolver resolver = new EntityResolver() {
@Override
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
{
InputSource is = new InputSource(resource);
return is;
}
}
};
xmlConfig.setEntityResolver(resolver);
xmlConfig.setSchemaValidation(true);
} else {
logger.debug("cannot find schema-xsd file (vrp_xml_schema.xsd). try to read xml without xml-file-validation.");
}
}
try {
xmlConfig.load();
} catch (ConfigurationException e) {
throw new RuntimeException(e);
}
readProblemType(xmlConfig);
readVehiclesAndTheirTypes(xmlConfig);
readShipments(xmlConfig);
readServices(xmlConfig);
readInitialRoutes(xmlConfig);
readSolutions(xmlConfig);
addJobsAndTheirLocationsToVrp();
}
private void addJobsAndTheirLocationsToVrp() {
for (Service service : serviceMap.values()) {
if (!freezedJobIds.contains(service.getId())) {
vrpBuilder.addJob(service);
}
}
for (Shipment shipment : shipmentMap.values()) {
if (!freezedJobIds.contains(shipment.getId())) {
vrpBuilder.addJob(shipment);
}
}
}
private void readInitialRoutes(XMLConfiguration xmlConfig) {
List<HierarchicalConfiguration> initialRouteConfigs = xmlConfig.configurationsAt("initialRoutes.route");
for (HierarchicalConfiguration routeConfig : initialRouteConfigs) {
Driver driver = DriverImpl.noDriver();
String vehicleId = routeConfig.getString("vehicleId");
Vehicle vehicle = getVehicle(vehicleId);
if (vehicle == null) throw new IllegalStateException("vehicle is missing.");
String start = routeConfig.getString("start");
if (start == null) throw new IllegalStateException("route start-time is missing.");
double departureTime = Double.parseDouble(start);
VehicleRoute.Builder routeBuilder = VehicleRoute.Builder.newInstance(vehicle, driver);
routeBuilder.setDepartureTime(departureTime);
List<HierarchicalConfiguration> actConfigs = routeConfig.configurationsAt("act");
for (HierarchicalConfiguration actConfig : actConfigs) {
String type = actConfig.getString("[@type]");
if (type == null) throw new IllegalStateException("act[@type] is missing.");
double arrTime = 0.;
double endTime = 0.;
String arrTimeS = actConfig.getString("arrTime");
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);
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();
vrpBuilder.addInitialVehicleRoute(route);
}
}
private void readSolutions(XMLConfiguration vrpProblem) {
if (solutions == null) return;
List<HierarchicalConfiguration> solutionConfigs = vrpProblem.configurationsAt("solutions.solution");
for (HierarchicalConfiguration solutionConfig : solutionConfigs) {
String totalCost = solutionConfig.getString("cost");
double cost = -1;
if (totalCost != null) cost = Double.parseDouble(totalCost);
List<HierarchicalConfiguration> routeConfigs = solutionConfig.configurationsAt("routes.route");
List<VehicleRoute> routes = new ArrayList<VehicleRoute>();
for (HierarchicalConfiguration routeConfig : routeConfigs) {
//! here, driverId is set to noDriver, no matter whats in driverId.
Driver driver = DriverImpl.noDriver();
String vehicleId = routeConfig.getString("vehicleId");
Vehicle vehicle = getVehicle(vehicleId);
if (vehicle == null) throw new IllegalStateException("vehicle is missing.");
String start = routeConfig.getString("start");
if (start == null) throw new IllegalStateException("route start-time is missing.");
double departureTime = Double.parseDouble(start);
String end = routeConfig.getString("end");
if (end == null) throw new IllegalStateException("route end-time is missing.");
VehicleRoute.Builder routeBuilder = VehicleRoute.Builder.newInstance(vehicle, driver);
routeBuilder.setDepartureTime(departureTime);
routeBuilder.setRouteEndArrivalTime(Double.parseDouble(end));
List<HierarchicalConfiguration> actConfigs = routeConfig.configurationsAt("act");
for (HierarchicalConfiguration actConfig : actConfigs) {
String type = actConfig.getString("[@type]");
if (type == null) throw new IllegalStateException("act[@type] is missing.");
double arrTime = 0.;
double endTime = 0.;
String arrTimeS = actConfig.getString("arrTime");
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");
}
}
routes.add(routeBuilder.build());
}
public void read(String filename) {
logger.debug("read vrp: {}", filename);
XMLConfiguration xmlConfig = createXMLConfiguration();

View file

@ -21,8 +21,12 @@ import jsprit.core.problem.Capacity;
import jsprit.core.problem.Location;
import jsprit.core.problem.Skills;
import jsprit.core.problem.solution.route.activity.TimeWindow;
import jsprit.core.problem.solution.route.activity.TimeWindows;
import jsprit.core.problem.solution.route.activity.TimeWindowsImpl;
import jsprit.core.util.Coordinate;
import java.util.Collection;
/**
* Service implementation of a job.
* <p/>
@ -78,9 +82,15 @@ public class Service extends AbstractJob {
protected Location location;
Builder(String id) {
this.id = id;
}
protected TimeWindowsImpl timeWindows;
private boolean twAdded = false;
Builder(String id){
this.id = id;
timeWindows = new TimeWindowsImpl();
timeWindows.add(timeWindow);
}
/**
* Protected method to set the type-name of the service.
@ -137,21 +147,28 @@ public class Service extends AbstractJob {
return this;
}
/**
* Sets the time-window of this service.
* <p/>
* <p>The time-window indicates the time period a service/activity/operation is allowed to start.
*
* @param tw the time-window to be set
* @return builder
* @throws IllegalArgumentException if timeWindow is null
*/
public Builder<T> setTimeWindow(TimeWindow tw) {
if (tw == null) throw new IllegalArgumentException("time-window arg must not be null");
public Builder<T> setTimeWindow(TimeWindow tw){
if(tw == null) throw new IllegalArgumentException("time-window arg must not be null");
this.timeWindow = tw;
this.timeWindows = new TimeWindowsImpl();
timeWindows.add(tw);
return this;
}
public Builder<T> addTimeWindow(TimeWindow timeWindow) {
if(timeWindow == null) throw new IllegalArgumentException("time-window arg must not be null");
if(!twAdded){
timeWindows = new TimeWindowsImpl();
twAdded = true;
}
timeWindows.add(timeWindow);
return this;
}
public Builder<T> addTimeWindow(double earliest, double latest) {
return addTimeWindow(TimeWindow.newInstance(earliest, latest));
}
/**
* Builds the service.
*
@ -191,7 +208,6 @@ public class Service extends AbstractJob {
}
}
private final String id;
private final String type;
@ -208,6 +224,8 @@ public class Service extends AbstractJob {
private final Location location;
private final TimeWindows timeWindowManager;
Service(Builder builder) {
id = builder.id;
serviceTime = builder.serviceTime;
@ -217,7 +235,12 @@ public class Service extends AbstractJob {
skills = builder.skills;
name = builder.name;
location = builder.location;
}
timeWindowManager = builder.timeWindows;
}
public Collection<TimeWindow> getTimeWindows(){
return timeWindowManager.getTimeWindows();
}
@Override
public String getId() {
@ -245,11 +268,13 @@ public class Service extends AbstractJob {
/**
* Returns the time-window a service(-operation) is allowed to start.
* It is recommended to use getTimeWindows() instead. If you still use this, it returns the first time window of getTimeWindows() collection.
*
* @return time window
*
*/
public TimeWindow getTimeWindow() {
return timeWindow;
return timeWindowManager.getTimeWindows().iterator().next();
}
/**

View file

@ -21,6 +21,9 @@ import jsprit.core.problem.Capacity;
import jsprit.core.problem.Location;
import jsprit.core.problem.Skills;
import jsprit.core.problem.solution.route.activity.TimeWindow;
import jsprit.core.problem.solution.route.activity.TimeWindowsImpl;
import java.util.Collection;
/**
@ -42,6 +45,7 @@ import jsprit.core.problem.solution.route.activity.TimeWindow;
public class Shipment extends AbstractJob {
/**
* Builder that builds the shipment.
*
@ -73,6 +77,14 @@ public class Shipment extends AbstractJob {
private Location deliveryLocation_;
protected TimeWindowsImpl deliveryTimeWindows;
private boolean deliveryTimeWindowAdded = false;
private boolean pickupTimeWindowAdded = false;
private TimeWindowsImpl pickupTimeWindows;
/**
* Returns new instance of this builder.
*
@ -86,6 +98,10 @@ public class Shipment extends AbstractJob {
Builder(String id) {
if (id == null) throw new IllegalArgumentException("id must not be null");
this.id = id;
pickupTimeWindows = new TimeWindowsImpl();
pickupTimeWindows.add(pickupTimeWindow);
deliveryTimeWindows = new TimeWindowsImpl();
deliveryTimeWindows.add(deliveryTimeWindow);
}
/**
@ -125,11 +141,15 @@ public class Shipment extends AbstractJob {
* @throws IllegalArgumentException if timeWindow is null
*/
public Builder setPickupTimeWindow(TimeWindow timeWindow) {
if (timeWindow == null) throw new IllegalArgumentException("timeWindow cannot be null");
if (timeWindow == null) throw new IllegalArgumentException("delivery time-window must not be null");
this.pickupTimeWindow = timeWindow;
this.pickupTimeWindows = new TimeWindowsImpl();
this.pickupTimeWindows.add(timeWindow);
return this;
}
/**
* Sets delivery location.
*
@ -169,6 +189,8 @@ public class Shipment extends AbstractJob {
public Builder setDeliveryTimeWindow(TimeWindow timeWindow) {
if (timeWindow == null) throw new IllegalArgumentException("delivery time-window must not be null");
this.deliveryTimeWindow = timeWindow;
this.deliveryTimeWindows = new TimeWindowsImpl();
this.deliveryTimeWindows.add(timeWindow);
return this;
}
@ -212,6 +234,35 @@ public class Shipment extends AbstractJob {
this.name = name;
return this;
}
public Builder addDeliveryTimeWindow(TimeWindow timeWindow) {
if(timeWindow == null) throw new IllegalArgumentException("time-window arg must not be null");
if(!deliveryTimeWindowAdded){
deliveryTimeWindows = new TimeWindowsImpl();
deliveryTimeWindowAdded = true;
}
deliveryTimeWindows.add(timeWindow);
return this;
}
public Builder addDeliveryTimeWindow(double earliest, double latest) {
addDeliveryTimeWindow(TimeWindow.newInstance(earliest, latest));
return this;
}
public Builder addPickupTimeWindow(TimeWindow timeWindow) {
if(timeWindow == null) throw new IllegalArgumentException("time-window arg must not be null");
if(!pickupTimeWindowAdded){
pickupTimeWindows = new TimeWindowsImpl();
pickupTimeWindowAdded = true;
}
pickupTimeWindows.add(timeWindow);
return this;
}
public Builder addPickupTimeWindow(double earliest, double latest) {
return addPickupTimeWindow(TimeWindow.newInstance(earliest, latest));
}
}
private final String id;
@ -234,6 +285,10 @@ public class Shipment extends AbstractJob {
private final Location deliveryLocation_;
private final TimeWindowsImpl deliveryTimeWindows;
private final TimeWindowsImpl pickupTimeWindows;
Shipment(Builder builder) {
this.id = builder.id;
this.pickupServiceTime = builder.pickupServiceTime;
@ -245,6 +300,8 @@ public class Shipment extends AbstractJob {
this.name = builder.name;
this.pickupLocation_ = builder.pickupLocation_;
this.deliveryLocation_ = builder.deliveryLocation_;
this.deliveryTimeWindows = builder.deliveryTimeWindows;
this.pickupTimeWindows = builder.pickupTimeWindows;
}
@Override
@ -286,7 +343,11 @@ public class Shipment extends AbstractJob {
* @return time-window of delivery
*/
public TimeWindow getDeliveryTimeWindow() {
return deliveryTimeWindow;
return deliveryTimeWindows.getTimeWindows().iterator().next();
}
public Collection<TimeWindow> getDeliveryTimeWindows() {
return deliveryTimeWindows.getTimeWindows();
}
/**
@ -295,9 +356,14 @@ public class Shipment extends AbstractJob {
* @return time-window of pickup
*/
public TimeWindow getPickupTimeWindow() {
return pickupTimeWindow;
return pickupTimeWindows.getTimeWindows().iterator().next();
}
public Collection<TimeWindow> getPickupTimeWindows() {
return pickupTimeWindows.getTimeWindows();
}
@Override
public int hashCode() {
final int prime = 31;

View file

@ -212,7 +212,8 @@ public class VehicleRoute {
}
/**
* Adds a service to this route.
* Adds a service to this route. Activity is initialized with .getTimeWindow(). If you want to explicitly set another time window
* use .addService(Service service, TimeWindow timeWindow)
* <p/>
* <p>This implies that for this service a serviceActivity is created with {@link TourActivityFactory} and added to the sequence of tourActivities.
* <p/>
@ -223,9 +224,15 @@ public class VehicleRoute {
* @throws IllegalArgumentException if service is null
*/
public Builder addService(Service service) {
return addService(service,service.getTimeWindow());
}
public Builder addService(Service service, TimeWindow timeWindow) {
if (service == null) throw new IllegalArgumentException("service must not be null");
List<AbstractActivity> acts = jobActivityFactory.createActivities(service);
TourActivity act = acts.get(0);
act.setTheoreticalEarliestOperationStartTime(timeWindow.getStart());
act.setTheoreticalLatestOperationStartTime(timeWindow.getEnd());
tourActivities.addActivity(act);
return this;
}
@ -238,8 +245,12 @@ public class VehicleRoute {
*/
public Builder addPickup(Pickup pickup) {
if (pickup == null) throw new IllegalArgumentException("pickup must not be null");
addService(pickup);
return this;
return addService(pickup);
}
public Builder addPickup(Pickup pickup, TimeWindow timeWindow) {
if (pickup == null) throw new IllegalArgumentException("pickup must not be null");
return addService(pickup,timeWindow);
}
/**
@ -250,8 +261,12 @@ public class VehicleRoute {
*/
public Builder addDelivery(Delivery delivery) {
if (delivery == null) throw new IllegalArgumentException("delivery must not be null");
addService(delivery);
return this;
return addService(delivery);
}
public Builder addDelivery(Delivery delivery, TimeWindow timeWindow) {
if (delivery == null) throw new IllegalArgumentException("delivery must not be null");
return addService(delivery,timeWindow);
}
/**
@ -262,10 +277,16 @@ public class VehicleRoute {
* @throws IllegalStateException if method has already been called with the specified shipment.
*/
public Builder addPickup(Shipment shipment) {
return addPickup(shipment, shipment.getPickupTimeWindow());
}
public Builder addPickup(Shipment shipment, TimeWindow pickupTimeWindow) {
if (openShipments.contains(shipment))
throw new IllegalStateException("shipment has already been added. cannot add it twice.");
List<AbstractActivity> acts = jobActivityFactory.createActivities(shipment);
TourActivity act = acts.get(0);
act.setTheoreticalEarliestOperationStartTime(pickupTimeWindow.getStart());
act.setTheoreticalLatestOperationStartTime(pickupTimeWindow.getEnd());
tourActivities.addActivity(act);
openShipments.add(shipment);
openActivities.put(shipment, acts.get(1));
@ -280,8 +301,14 @@ public class VehicleRoute {
* @throws IllegalStateException if specified shipment has not been picked up yet (i.e. method addPickup(shipment) has not been called yet).
*/
public Builder addDelivery(Shipment shipment) {
return addDelivery(shipment,shipment.getDeliveryTimeWindow());
}
public Builder addDelivery(Shipment shipment, TimeWindow deliveryTimeWindow) {
if (openShipments.contains(shipment)) {
TourActivity act = openActivities.get(shipment);
act.setTheoreticalEarliestOperationStartTime(deliveryTimeWindow.getStart());
act.setTheoreticalLatestOperationStartTime(deliveryTimeWindow.getEnd());
tourActivities.addActivity(act);
openShipments.remove(shipment);
} else {

View file

@ -0,0 +1,12 @@
package jsprit.core.problem.solution.route.activity;
/**
* Created by schroeder on 08/07/15.
*/
public class ActivityStartAsSoonAsArrived implements ActivityStartStrategy {
@Override
public double getActivityStartTime(TourActivity activity, double arrivalTime) {
return arrivalTime;
}
}

View file

@ -0,0 +1,10 @@
package jsprit.core.problem.solution.route.activity;
/**
* Created by schroeder on 08/07/15.
*/
public interface ActivityStartStrategy {
public double getActivityStartTime(TourActivity activity, double arrivalTime);
}

View file

@ -0,0 +1,13 @@
package jsprit.core.problem.solution.route.activity;
/**
* Created by schroeder on 08/07/15.
*/
public class ActivityStartsAsSoonAsTimeWindowOpens implements ActivityStartStrategy {
@Override
public double getActivityStartTime(TourActivity activity, double arrivalTime) {
return Math.max(activity.getTheoreticalEarliestOperationStartTime(),arrivalTime);
}
}

View file

@ -71,6 +71,10 @@ public class BreakActivity extends AbstractActivity implements JobActivity {
private final Break aBreak;
private double earliest = 0;
private double latest = Double.MAX_VALUE;
protected BreakActivity(Break aBreak) {
counter++;
this.aBreak = aBreak;
@ -83,6 +87,8 @@ public class BreakActivity extends AbstractActivity implements JobActivity {
this.endTime = breakActivity.getEndTime();
this.location = breakActivity.getLocation();
setIndex(breakActivity.getIndex());
this.earliest = breakActivity.getTheoreticalEarliestOperationStartTime();
this.latest = breakActivity.getTheoreticalLatestOperationStartTime();
}
@ -118,11 +124,11 @@ public class BreakActivity extends AbstractActivity implements JobActivity {
}
public double getTheoreticalEarliestOperationStartTime() {
return aBreak.getTimeWindow().getStart();
return earliest;
}
public double getTheoreticalLatestOperationStartTime() {
return aBreak.getTimeWindow().getEnd();
return latest;
}
@Override
@ -158,6 +164,16 @@ public class BreakActivity extends AbstractActivity implements JobActivity {
+ "][twEnd=" + Activities.round(getTheoreticalLatestOperationStartTime()) + "]";
}
@Override
public void setTheoreticalEarliestOperationStartTime(double earliest) {
this.earliest = earliest;
}
@Override
public void setTheoreticalLatestOperationStartTime(double latest) {
this.latest = latest;
}
@Override
public String getName() {
return aBreak.getType();

View file

@ -31,6 +31,10 @@ public final class DeliverService extends AbstractActivity implements DeliveryAc
private double endTime;
private double theoreticalEarliest = 0;
private double theoreticalLatest = Double.MAX_VALUE;
public DeliverService(Delivery delivery) {
super();
this.delivery = delivery;
@ -43,6 +47,8 @@ public final class DeliverService extends AbstractActivity implements DeliveryAc
this.endTime = deliveryActivity.getEndTime();
capacity = deliveryActivity.getSize();
setIndex(deliveryActivity.getIndex());
this.theoreticalEarliest = deliveryActivity.getTheoreticalEarliestOperationStartTime();
this.theoreticalLatest = deliveryActivity.getTheoreticalLatestOperationStartTime();
}
@Override
@ -60,14 +66,25 @@ public final class DeliverService extends AbstractActivity implements DeliveryAc
return delivery.getLocation();
}
@Override
public void setTheoreticalEarliestOperationStartTime(double earliest) {
theoreticalEarliest = earliest;
}
@Override
public void setTheoreticalLatestOperationStartTime(double latest) {
theoreticalLatest = latest;
}
@Override
public double getTheoreticalEarliestOperationStartTime() {
return delivery.getTimeWindow().getStart();
return theoreticalEarliest;
}
@Override
public double getTheoreticalLatestOperationStartTime() {
return delivery.getTimeWindow().getEnd();
return theoreticalLatest;
}
@Override

View file

@ -32,6 +32,10 @@ public final class DeliverShipment extends AbstractActivity implements DeliveryA
private Capacity capacity;
private double earliest = 0;
private double latest = Double.MAX_VALUE;
public DeliverShipment(Shipment shipment) {
super();
this.shipment = shipment;
@ -45,6 +49,8 @@ public final class DeliverShipment extends AbstractActivity implements DeliveryA
this.endTime = deliveryShipmentActivity.getEndTime();
this.capacity = deliveryShipmentActivity.getSize();
setIndex(deliveryShipmentActivity.getIndex());
this.earliest = deliveryShipmentActivity.getTheoreticalEarliestOperationStartTime();
this.latest = deliveryShipmentActivity.getTheoreticalLatestOperationStartTime();
}
@Override
@ -52,6 +58,16 @@ public final class DeliverShipment extends AbstractActivity implements DeliveryA
return shipment;
}
@Override
public void setTheoreticalEarliestOperationStartTime(double earliest) {
this.earliest = earliest;
}
@Override
public void setTheoreticalLatestOperationStartTime(double latest) {
this.latest = latest;
}
@Override
public String getName() {
return "deliverShipment";
@ -69,12 +85,12 @@ public final class DeliverShipment extends AbstractActivity implements DeliveryA
@Override
public double getTheoreticalEarliestOperationStartTime() {
return shipment.getDeliveryTimeWindow().getStart();
return earliest;
}
@Override
public double getTheoreticalLatestOperationStartTime() {
return shipment.getDeliveryTimeWindow().getEnd();
return latest;
}
@Override

View file

@ -30,6 +30,10 @@ public final class PickupService extends AbstractActivity implements PickupActiv
private double depTime;
private double theoreticalEarliest = 0;
private double theoreticalLatest = Double.MAX_VALUE;
public PickupService(Pickup pickup) {
super();
this.pickup = pickup;
@ -44,6 +48,8 @@ public final class PickupService extends AbstractActivity implements PickupActiv
this.arrTime = pickupActivity.getArrTime();
this.depTime = pickupActivity.getEndTime();
setIndex(pickupActivity.getIndex());
this.theoreticalEarliest = pickupActivity.getTheoreticalEarliestOperationStartTime();
this.theoreticalLatest = pickupActivity.getTheoreticalLatestOperationStartTime();
}
@Override
@ -63,12 +69,22 @@ public final class PickupService extends AbstractActivity implements PickupActiv
@Override
public double getTheoreticalEarliestOperationStartTime() {
return pickup.getTimeWindow().getStart();
return theoreticalEarliest;
}
@Override
public double getTheoreticalLatestOperationStartTime() {
return pickup.getTimeWindow().getEnd();
return theoreticalLatest;
}
@Override
public void setTheoreticalEarliestOperationStartTime(double earliest) {
this.theoreticalEarliest = earliest;
}
@Override
public void setTheoreticalLatestOperationStartTime(double latest) {
this.theoreticalLatest = latest;
}
@Override

View file

@ -22,7 +22,7 @@ import jsprit.core.problem.Location;
import jsprit.core.problem.job.Job;
import jsprit.core.problem.job.Shipment;
public final class PickupShipment extends AbstractActivity implements PickupActivity {
public final class PickupShipment extends AbstractActivity implements PickupActivity{
private Shipment shipment;
@ -30,6 +30,10 @@ public final class PickupShipment extends AbstractActivity implements PickupActi
private double arrTime;
private double earliest = 0;
private double latest = Double.MAX_VALUE;
public PickupShipment(Shipment shipment) {
super();
this.shipment = shipment;
@ -41,6 +45,8 @@ public final class PickupShipment extends AbstractActivity implements PickupActi
this.arrTime = pickupShipmentActivity.getArrTime();
this.endTime = pickupShipmentActivity.getEndTime();
setIndex(pickupShipmentActivity.getIndex());
this.earliest = pickupShipmentActivity.getTheoreticalEarliestOperationStartTime();
this.latest = pickupShipmentActivity.getTheoreticalLatestOperationStartTime();
}
@Override
@ -48,6 +54,16 @@ public final class PickupShipment extends AbstractActivity implements PickupActi
return shipment;
}
@Override
public void setTheoreticalEarliestOperationStartTime(double earliest) {
this.earliest = earliest;
}
@Override
public void setTheoreticalLatestOperationStartTime(double latest) {
this.latest = latest;
}
@Override
public String getName() {
return "pickupShipment";
@ -65,12 +81,12 @@ public final class PickupShipment extends AbstractActivity implements PickupActi
@Override
public double getTheoreticalEarliestOperationStartTime() {
return shipment.getPickupTimeWindow().getStart();
return earliest;
}
@Override
public double getTheoreticalLatestOperationStartTime() {
return shipment.getPickupTimeWindow().getEnd();
return latest;
}
@Override

View file

@ -22,14 +22,22 @@ import jsprit.core.problem.Location;
import jsprit.core.problem.job.Service;
import jsprit.core.problem.solution.route.activity.TourActivity.JobActivity;
import java.util.ArrayList;
import java.util.List;
public class ServiceActivity extends AbstractActivity implements JobActivity {
@Deprecated
public static int counter = 0;
public double arrTime;
public double endTime;
private double theoreticalEarliest;
private double theoreticalLatest;
/**
* @return the arrTime
*/
@ -80,6 +88,8 @@ public class ServiceActivity extends AbstractActivity implements JobActivity {
this.arrTime = serviceActivity.getArrTime();
this.endTime = serviceActivity.getEndTime();
setIndex(serviceActivity.getIndex());
this.theoreticalEarliest = serviceActivity.getTheoreticalEarliestOperationStartTime();
this.theoreticalLatest = serviceActivity.getTheoreticalLatestOperationStartTime();
}
@ -115,11 +125,21 @@ public class ServiceActivity extends AbstractActivity implements JobActivity {
}
public double getTheoreticalEarliestOperationStartTime() {
return service.getTimeWindow().getStart();
return theoreticalEarliest;
}
public double getTheoreticalLatestOperationStartTime() {
return service.getTimeWindow().getEnd();
return theoreticalLatest;
}
@Override
public void setTheoreticalEarliestOperationStartTime(double earliest) {
theoreticalEarliest = earliest;
}
@Override
public void setTheoreticalLatestOperationStartTime(double latest) {
theoreticalLatest = latest;
}
@Override

View file

@ -97,10 +97,12 @@ public final class Start extends AbstractActivity implements TourActivity {
return theoretical_latestOperationStartTime;
}
@Deprecated
public void setTheoreticalEarliestOperationStartTime(double time) {
this.theoretical_earliestOperationStartTime = time;
}
@Deprecated
public void setTheoreticalLatestOperationStartTime(double time) {
this.theoretical_latestOperationStartTime = time;
}

View file

@ -0,0 +1,12 @@
package jsprit.core.problem.solution.route.activity;
import java.util.Collection;
/**
* Created by schroeder on 20/05/15.
*/
public interface TimeWindows {
public Collection<TimeWindow> getTimeWindows();
}

View file

@ -0,0 +1,33 @@
package jsprit.core.problem.solution.route.activity;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
/**
* Created by schroeder on 26/05/15.
*/
public class TimeWindowsImpl implements TimeWindows {
private Collection<TimeWindow> timeWindows = new ArrayList<TimeWindow>();
public void add(TimeWindow timeWindow){
for(TimeWindow tw : timeWindows){
if(timeWindow.getStart() > tw.getStart() && timeWindow.getStart() < tw.getEnd()){
throw new IllegalStateException("time-windows cannot overlap each other. overlap: " + tw + ", " + timeWindow);
}
if(timeWindow.getEnd() > tw.getStart() && timeWindow.getEnd() < tw.getEnd()){
throw new IllegalStateException("time-windows cannot overlap each other. overlap: " + tw + ", " + timeWindow);
}
if(timeWindow.getStart() <= tw.getStart() && timeWindow.getEnd() >= tw.getEnd()){
throw new IllegalStateException("time-windows cannot overlap each other. overlap: " + tw + ", " + timeWindow);
}
}
timeWindows.add(timeWindow);
}
public Collection<TimeWindow> getTimeWindows() {
return Collections.unmodifiableCollection(timeWindows);
}
}

View file

@ -30,6 +30,10 @@ import jsprit.core.problem.job.Job;
*/
public interface TourActivity extends HasIndex {
public void setTheoreticalEarliestOperationStartTime(double earliest);
public void setTheoreticalLatestOperationStartTime(double latest);
/**
* Basic interface of job-activies.
* <p/>

View file

@ -18,8 +18,7 @@ package jsprit.core.util;
import jsprit.core.problem.cost.ForwardTransportTime;
import jsprit.core.problem.solution.route.VehicleRoute;
import jsprit.core.problem.solution.route.activity.ActivityVisitor;
import jsprit.core.problem.solution.route.activity.TourActivity;
import jsprit.core.problem.solution.route.activity.*;
public class ActivityTimeTracker implements ActivityVisitor {
@ -43,17 +42,27 @@ public class ActivityTimeTracker implements ActivityVisitor {
private double actEndTime;
private ActivityPolicy activityPolicy = ActivityPolicy.AS_SOON_AS_TIME_WINDOW_OPENS;
private ActivityStartStrategy startStrategy;
public ActivityTimeTracker(ForwardTransportTime transportTime) {
super();
this.transportTime = transportTime;
}
public ActivityTimeTracker(ForwardTransportTime transportTime) {
super();
this.transportTime = transportTime;
this.startStrategy = new ActivityStartsAsSoonAsTimeWindowOpens();
}
public ActivityTimeTracker(ForwardTransportTime transportTime, ActivityPolicy activityPolicy) {
super();
this.transportTime = transportTime;
this.activityPolicy = activityPolicy;
if(activityPolicy.equals(ActivityPolicy.AS_SOON_AS_ARRIVED)){
this.startStrategy = new ActivityStartAsSoonAsArrived();
}
else this.startStrategy = new ActivityStartsAsSoonAsTimeWindowOpens();
}
public ActivityTimeTracker(ForwardTransportTime transportTime, ActivityStartStrategy startStrategy) {
super();
this.transportTime = transportTime;
this.startStrategy = startStrategy;
}
public double getActArrTime() {
@ -75,36 +84,22 @@ public class ActivityTimeTracker implements ActivityVisitor {
@Override
public void visit(TourActivity activity) {
if (!beginFirst) throw new IllegalStateException("never called begin. this however is essential here");
if(!beginFirst) throw new IllegalStateException("never called begin. this however is essential here");
double transportTime = this.transportTime.getTransportTime(prevAct.getLocation(), activity.getLocation(), startAtPrevAct, route.getDriver(), route.getVehicle());
double arrivalTimeAtCurrAct = startAtPrevAct + transportTime;
actArrTime = arrivalTimeAtCurrAct;
double operationStartTime;
if (activityPolicy.equals(ActivityPolicy.AS_SOON_AS_TIME_WINDOW_OPENS)) {
operationStartTime = Math.max(activity.getTheoreticalEarliestOperationStartTime(), arrivalTimeAtCurrAct);
} else if (activityPolicy.equals(ActivityPolicy.AS_SOON_AS_ARRIVED)) {
operationStartTime = actArrTime;
} else operationStartTime = actArrTime;
double operationEndTime = operationStartTime + activity.getOperationTime();
double operationEndTime = startStrategy.getActivityStartTime(activity,arrivalTimeAtCurrAct) + activity.getOperationTime();
actEndTime = operationEndTime;
prevAct = activity;
startAtPrevAct = operationEndTime;
}
@Override
public void finish() {
double transportTime = this.transportTime.getTransportTime(prevAct.getLocation(), route.getEnd().getLocation(), startAtPrevAct, route.getDriver(), route.getVehicle());
double arrivalTimeAtCurrAct = startAtPrevAct + transportTime;
actArrTime = arrivalTimeAtCurrAct;
actEndTime = arrivalTimeAtCurrAct;
beginFirst = false;
}

View file

@ -1,3 +1,4 @@
/*******************************************************************************
* Copyright (C) 2014 Stefan Schroeder
*
@ -29,7 +30,7 @@ public class CalculationUtils {
* @param act
* @return
*/
public static double getActivityEndTime(double actArrTime, TourActivity act) {
return Math.max(actArrTime, act.getTheoreticalEarliestOperationStartTime()) + act.getOperationTime();
public static double getActivityEndTime(double actArrTime, TourActivity act){
return Math.max(actArrTime, act.getTheoreticalEarliestOperationStartTime()) + act.getOperationTime();
}
}