mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
adjusted examples to multiple cap dims
This commit is contained in:
parent
d74831b38c
commit
794ce90e6a
2 changed files with 11 additions and 9 deletions
|
|
@ -91,7 +91,7 @@ public class BicycleMessenger {
|
||||||
public ConstraintsStatus fulfilled(JobInsertionContext iFacts,TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) {
|
public ConstraintsStatus fulfilled(JobInsertionContext iFacts,TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) {
|
||||||
//make sure vehicle can manage direct path
|
//make sure vehicle can manage direct path
|
||||||
double directArr_at_next = prevActDepTime + routingCosts.getTransportTime(prevAct.getLocationId(), nextAct.getLocationId(), prevActDepTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
double directArr_at_next = prevActDepTime + routingCosts.getTransportTime(prevAct.getLocationId(), nextAct.getLocationId(), prevActDepTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||||
if(directArr_at_next > stateManager.getActivityState(nextAct, StateFactory.createId("latest-act-arrival-time")).toDouble()){
|
if(directArr_at_next > stateManager.getActivityState(nextAct, StateFactory.createId("latest-act-arrival-time"),Double.class)){
|
||||||
return ConstraintsStatus.NOT_FULFILLED_BREAK;
|
return ConstraintsStatus.NOT_FULFILLED_BREAK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -108,7 +108,7 @@ public class BicycleMessenger {
|
||||||
double departureTime_at_newAct = arrivalTime_at_newAct + newAct.getOperationTime();
|
double departureTime_at_newAct = arrivalTime_at_newAct + newAct.getOperationTime();
|
||||||
double arrTimeAtNextAct = departureTime_at_newAct + routingCosts.getTransportTime(newAct.getLocationId(), nextAct.getLocationId(), departureTime_at_newAct, iFacts.getNewDriver(), iFacts.getNewVehicle());;
|
double arrTimeAtNextAct = departureTime_at_newAct + routingCosts.getTransportTime(newAct.getLocationId(), nextAct.getLocationId(), departureTime_at_newAct, iFacts.getNewDriver(), iFacts.getNewVehicle());;
|
||||||
//here you need an activity state
|
//here you need an activity state
|
||||||
if(arrTimeAtNextAct > stateManager.getActivityState(nextAct, StateFactory.createId("latest-act-arrival-time")).toDouble()){
|
if(arrTimeAtNextAct > stateManager.getActivityState(nextAct, StateFactory.createId("latest-act-arrival-time"),Double.class)){
|
||||||
return ConstraintsStatus.NOT_FULFILLED;
|
return ConstraintsStatus.NOT_FULFILLED;
|
||||||
}
|
}
|
||||||
return ConstraintsStatus.FULFILLED;
|
return ConstraintsStatus.FULFILLED;
|
||||||
|
|
@ -190,7 +190,7 @@ public class BicycleMessenger {
|
||||||
double potentialLatestArrivalTimeAtCurrAct =
|
double potentialLatestArrivalTimeAtCurrAct =
|
||||||
latestArrivalTime_at_prevAct - routingCosts.getBackwardTransportTime(activity.getLocationId(), prevAct.getLocationId(), latestArrivalTime_at_prevAct, route.getDriver(),route.getVehicle()) - activity.getOperationTime();
|
latestArrivalTime_at_prevAct - routingCosts.getBackwardTransportTime(activity.getLocationId(), prevAct.getLocationId(), latestArrivalTime_at_prevAct, route.getDriver(),route.getVehicle()) - activity.getOperationTime();
|
||||||
double latestArrivalTime_at_activity = Math.min(3*timeOfNearestMessenger, potentialLatestArrivalTimeAtCurrAct);
|
double latestArrivalTime_at_activity = Math.min(3*timeOfNearestMessenger, potentialLatestArrivalTimeAtCurrAct);
|
||||||
stateManager.putActivityState(activity, StateFactory.createId("latest-act-arrival-time"), StateFactory.createState(latestArrivalTime_at_activity));
|
stateManager.putTypedActivityState(activity, StateFactory.createId("latest-act-arrival-time"), Double.class, latestArrivalTime_at_activity);
|
||||||
assert activity.getArrTime() <= latestArrivalTime_at_activity : "this must not be since it breaks condition; actArrTime: " + activity.getArrTime() + " latestArrTime: " + latestArrivalTime_at_activity + " vehicle: " + route.getVehicle().getId();
|
assert activity.getArrTime() <= latestArrivalTime_at_activity : "this must not be since it breaks condition; actArrTime: " + activity.getArrTime() + " latestArrTime: " + latestArrivalTime_at_activity + " vehicle: " + route.getVehicle().getId();
|
||||||
latestArrivalTime_at_prevAct = latestArrivalTime_at_activity;
|
latestArrivalTime_at_prevAct = latestArrivalTime_at_activity;
|
||||||
prevAct = activity;
|
prevAct = activity;
|
||||||
|
|
@ -221,7 +221,7 @@ public class BicycleMessenger {
|
||||||
//define stateManager to update the required activity-state: "latest-activity-start-time"
|
//define stateManager to update the required activity-state: "latest-activity-start-time"
|
||||||
StateManager stateManager = new StateManager(routingCosts);
|
StateManager stateManager = new StateManager(routingCosts);
|
||||||
//default states makes it more comfortable since state has a value and cannot be null (thus u dont need to check nulls)
|
//default states makes it more comfortable since state has a value and cannot be null (thus u dont need to check nulls)
|
||||||
stateManager.addDefaultActivityState(StateFactory.createId("latest-act-arrival-time"), StateFactory.createState(Double.MAX_VALUE));
|
stateManager.addDefaultActivityState(StateFactory.createId("latest-act-arrival-time"), Double.class, Double.MAX_VALUE);
|
||||||
|
|
||||||
//add the above problem-constraints
|
//add the above problem-constraints
|
||||||
problemBuilder.addConstraint(new ThreeTimesLessThanBestDirectRouteConstraint(nearestMessengers, routingCosts, stateManager));
|
problemBuilder.addConstraint(new ThreeTimesLessThanBestDirectRouteConstraint(nearestMessengers, routingCosts, stateManager));
|
||||||
|
|
@ -317,7 +317,7 @@ public class BicycleMessenger {
|
||||||
if(firstLine) { firstLine = false; continue; }
|
if(firstLine) { firstLine = false; continue; }
|
||||||
String[] tokens = line.split("\\s+");
|
String[] tokens = line.split("\\s+");
|
||||||
//define your envelope which is basically a shipment from A to B
|
//define your envelope which is basically a shipment from A to B
|
||||||
Shipment envelope = Shipment.Builder.newInstance(tokens[1], 1).setPickupCoord(Coordinate.newInstance(Double.parseDouble(tokens[2]), Double.parseDouble(tokens[3])))
|
Shipment envelope = Shipment.Builder.newInstance(tokens[1]).addSizeDimension(0, 1).setPickupCoord(Coordinate.newInstance(Double.parseDouble(tokens[2]), Double.parseDouble(tokens[3])))
|
||||||
.setDeliveryCoord(Coordinate.newInstance(Double.parseDouble(tokens[4]), Double.parseDouble(tokens[5]))).build();
|
.setDeliveryCoord(Coordinate.newInstance(Double.parseDouble(tokens[4]), Double.parseDouble(tokens[5]))).build();
|
||||||
problemBuilder.addJob(envelope);
|
problemBuilder.addJob(envelope);
|
||||||
}
|
}
|
||||||
|
|
@ -328,7 +328,7 @@ public class BicycleMessenger {
|
||||||
BufferedReader reader = new BufferedReader(new FileReader(new File("input/bicycle_messenger_supply.txt")));
|
BufferedReader reader = new BufferedReader(new FileReader(new File("input/bicycle_messenger_supply.txt")));
|
||||||
String line = null;
|
String line = null;
|
||||||
boolean firstLine = true;
|
boolean firstLine = true;
|
||||||
VehicleType messengerType = VehicleTypeImpl.Builder.newInstance("messengerType", 15).setCostPerDistance(1).build();
|
VehicleType messengerType = VehicleTypeImpl.Builder.newInstance("messengerType").addCapacityDimension(0, 15).setCostPerDistance(1).build();
|
||||||
/*
|
/*
|
||||||
* the algo requires some time and space to search for a valid solution. if you ommit a penalty-type, it probably throws an Exception once it cannot insert an envelope anymore
|
* the algo requires some time and space to search for a valid solution. if you ommit a penalty-type, it probably throws an Exception once it cannot insert an envelope anymore
|
||||||
* thus, give it space by defining a penalty/shadow vehicle with higher variable and fixed costs to up the pressure to find solutions without penalty type
|
* thus, give it space by defining a penalty/shadow vehicle with higher variable and fixed costs to up the pressure to find solutions without penalty type
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import java.util.Collection;
|
||||||
|
|
||||||
import jsprit.analysis.toolbox.GraphStreamViewer;
|
import jsprit.analysis.toolbox.GraphStreamViewer;
|
||||||
import jsprit.analysis.toolbox.GraphStreamViewer.Label;
|
import jsprit.analysis.toolbox.GraphStreamViewer.Label;
|
||||||
|
import jsprit.analysis.toolbox.Plotter;
|
||||||
import jsprit.analysis.toolbox.SolutionPrinter;
|
import jsprit.analysis.toolbox.SolutionPrinter;
|
||||||
import jsprit.core.algorithm.VehicleRoutingAlgorithm;
|
import jsprit.core.algorithm.VehicleRoutingAlgorithm;
|
||||||
import jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
|
import jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
|
||||||
|
|
@ -173,9 +174,10 @@ public class TransportOfDisabledPeople {
|
||||||
/*
|
/*
|
||||||
* plot problem without solution
|
* plot problem without solution
|
||||||
*/
|
*/
|
||||||
// Plotter problemPlotter = new Plotter(problem);
|
Plotter problemPlotter = new Plotter(problem);
|
||||||
// problemPlotter.plotShipments(true);
|
problemPlotter.plotShipments(true);
|
||||||
// problemPlotter.plot("output/enRoutePickupAndDeliveryWithMultipleLocationsExample_problem.png", "en-route pickup and delivery");
|
problemPlotter.setLabel(jsprit.analysis.toolbox.Plotter.Label.SIZE);
|
||||||
|
problemPlotter.plot("output/transportOfDisabledPeopleExample_problem.png", "disabled people tp");
|
||||||
//
|
//
|
||||||
// /*
|
// /*
|
||||||
// * plot problem with solution
|
// * plot problem with solution
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue