mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
Merge branch 'master' into relaxAPI
Conflicts: jsprit-core/src/main/java/algorithms/StateUpdates.java jsprit-core/src/main/java/algorithms/VehicleRoutingAlgorithms.java jsprit-core/src/test/java/algorithms/GendreauPostOptTest.java
This commit is contained in:
commit
b0d0736c22
4 changed files with 294 additions and 4 deletions
|
|
@ -62,6 +62,7 @@ class StateUpdates {
|
|||
// for(VehicleRoute route : vehicleRoutes){
|
||||
// forwardInTime.visit(route);
|
||||
// }
|
||||
|
||||
//
|
||||
// }
|
||||
//
|
||||
|
|
@ -345,6 +346,276 @@ class StateUpdates {
|
|||
//
|
||||
// }
|
||||
//
|
||||
//=======
|
||||
//
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// static class UpdateActivityTimes implements ActivityVisitor{
|
||||
//
|
||||
// private Logger log = Logger.getLogger(UpdateActivityTimes.class);
|
||||
//
|
||||
// private ActivityTimeTracker timeTracker;
|
||||
//
|
||||
// private VehicleRoute route;
|
||||
//
|
||||
// public UpdateActivityTimes(ForwardTransportTime transportTime) {
|
||||
// super();
|
||||
// timeTracker = new ActivityTimeTracker(transportTime);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void begin(VehicleRoute route) {
|
||||
// timeTracker.begin(route);
|
||||
// this.route = route;
|
||||
// route.getStart().setEndTime(timeTracker.getActEndTime());
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void visit(TourActivity activity) {
|
||||
// timeTracker.visit(activity);
|
||||
// activity.setArrTime(timeTracker.getActArrTime());
|
||||
// activity.setEndTime(timeTracker.getActEndTime());
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void finish() {
|
||||
// timeTracker.finish();
|
||||
// route.getEnd().setArrTime(timeTracker.getActArrTime());
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// static class UpdateCostsAtAllLevels implements ActivityVisitor{
|
||||
//
|
||||
// private static Logger log = Logger.getLogger(UpdateCostsAtAllLevels.class);
|
||||
//
|
||||
// private VehicleRoutingActivityCosts activityCost;
|
||||
//
|
||||
// private ForwardTransportCost transportCost;
|
||||
//
|
||||
// private StateManagerImpl states;
|
||||
//
|
||||
// private double totalOperationCost = 0.0;
|
||||
//
|
||||
// private VehicleRoute vehicleRoute = null;
|
||||
//
|
||||
// private TourActivity prevAct = null;
|
||||
//
|
||||
// private double startTimeAtPrevAct = 0.0;
|
||||
//
|
||||
// private ActivityTimeTracker timeTracker;
|
||||
//
|
||||
// public UpdateCostsAtAllLevels(VehicleRoutingActivityCosts activityCost, VehicleRoutingTransportCosts transportCost, StateManagerImpl states) {
|
||||
// super();
|
||||
// this.activityCost = activityCost;
|
||||
// this.transportCost = transportCost;
|
||||
// this.states = states;
|
||||
// timeTracker = new ActivityTimeTracker(transportCost);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void begin(VehicleRoute route) {
|
||||
// vehicleRoute = route;
|
||||
// vehicleRoute.getVehicleRouteCostCalculator().reset();
|
||||
// timeTracker.begin(route);
|
||||
// prevAct = route.getStart();
|
||||
// startTimeAtPrevAct = timeTracker.getActEndTime();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void visit(TourActivity act) {
|
||||
// timeTracker.visit(act);
|
||||
//
|
||||
// double transportCost = this.transportCost.getTransportCost(prevAct.getLocationId(), act.getLocationId(), startTimeAtPrevAct, vehicleRoute.getDriver(), vehicleRoute.getVehicle());
|
||||
// double actCost = activityCost.getActivityCost(act, timeTracker.getActArrTime(), vehicleRoute.getDriver(), vehicleRoute.getVehicle());
|
||||
//
|
||||
// vehicleRoute.getVehicleRouteCostCalculator().addTransportCost(transportCost);
|
||||
// vehicleRoute.getVehicleRouteCostCalculator().addActivityCost(actCost);
|
||||
//
|
||||
// totalOperationCost += transportCost;
|
||||
// totalOperationCost += actCost;
|
||||
//
|
||||
// states.putActivityState(act, StateTypes.COSTS, new StateImpl(totalOperationCost));
|
||||
//
|
||||
// prevAct = act;
|
||||
// startTimeAtPrevAct = timeTracker.getActEndTime();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void finish() {
|
||||
// timeTracker.finish();
|
||||
// double transportCost = this.transportCost.getTransportCost(prevAct.getLocationId(), vehicleRoute.getEnd().getLocationId(), startTimeAtPrevAct, vehicleRoute.getDriver(), vehicleRoute.getVehicle());
|
||||
// double actCost = activityCost.getActivityCost(vehicleRoute.getEnd(), timeTracker.getActEndTime(), vehicleRoute.getDriver(), vehicleRoute.getVehicle());
|
||||
//
|
||||
// vehicleRoute.getVehicleRouteCostCalculator().addTransportCost(transportCost);
|
||||
// vehicleRoute.getVehicleRouteCostCalculator().addActivityCost(actCost);
|
||||
//
|
||||
// totalOperationCost += transportCost;
|
||||
// totalOperationCost += actCost;
|
||||
//// totalOperationCost += getFixCosts();
|
||||
//
|
||||
// states.putRouteState(vehicleRoute, StateTypes.COSTS, new StateImpl(totalOperationCost));
|
||||
//
|
||||
//// this is rather strange and likely to change
|
||||
// vehicleRoute.getVehicleRouteCostCalculator().price(vehicleRoute.getDriver());
|
||||
// vehicleRoute.getVehicleRouteCostCalculator().price(vehicleRoute.getVehicle());
|
||||
// vehicleRoute.getVehicleRouteCostCalculator().finish();
|
||||
//
|
||||
// startTimeAtPrevAct = 0.0;
|
||||
// prevAct = null;
|
||||
// vehicleRoute = null;
|
||||
// totalOperationCost = 0.0;
|
||||
// }
|
||||
//
|
||||
// private double getFixCosts() {
|
||||
// Vehicle vehicle = vehicleRoute.getVehicle();
|
||||
// if(vehicle == null) return 0.0;
|
||||
// VehicleType type = vehicle.getType();
|
||||
// if(type == null) return 0.0;
|
||||
// return type.getVehicleCostParams().fix;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// static class UpdateEarliestStartTimeWindowAtActLocations implements ActivityVisitor{
|
||||
//
|
||||
// private StateManagerImpl states;
|
||||
//
|
||||
// private ActivityTimeTracker timeTracker;
|
||||
//
|
||||
// public UpdateEarliestStartTimeWindowAtActLocations(StateManagerImpl states, VehicleRoutingTransportCosts transportCosts) {
|
||||
// super();
|
||||
// this.states = states;
|
||||
// timeTracker = new ActivityTimeTracker(transportCosts);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void begin(VehicleRoute route) {
|
||||
// timeTracker.begin(route);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void visit(TourActivity activity) {
|
||||
// timeTracker.visit(activity);
|
||||
// states.putActivityState(activity, StateTypes.EARLIEST_OPERATION_START_TIME, new StateImpl(Math.max(timeTracker.getActArrTime(), activity.getTheoreticalEarliestOperationStartTime())));
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void finish() {}
|
||||
//
|
||||
// }
|
||||
//
|
||||
// static class UpdateLatestOperationStartTimeAtActLocations implements ReverseActivityVisitor{
|
||||
//
|
||||
// private static Logger log = Logger.getLogger(UpdateLatestOperationStartTimeAtActLocations.class);
|
||||
//
|
||||
// private StateManagerImpl states;
|
||||
//
|
||||
// private VehicleRoute route;
|
||||
//
|
||||
// private VehicleRoutingTransportCosts transportCosts;
|
||||
//
|
||||
// private double latestArrTimeAtPrevAct;
|
||||
//
|
||||
// private TourActivity prevAct;
|
||||
//
|
||||
// public UpdateLatestOperationStartTimeAtActLocations(StateManagerImpl states, VehicleRoutingTransportCosts tpCosts) {
|
||||
// super();
|
||||
// this.states = states;
|
||||
// this.transportCosts = tpCosts;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void begin(VehicleRoute route) {
|
||||
// this.route = route;
|
||||
// latestArrTimeAtPrevAct = route.getEnd().getTheoreticalLatestOperationStartTime();
|
||||
// prevAct = route.getEnd();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void visit(TourActivity activity) {
|
||||
// double potentialLatestArrivalTimeAtCurrAct = latestArrTimeAtPrevAct - transportCosts.getBackwardTransportTime(activity.getLocationId(), prevAct.getLocationId(), latestArrTimeAtPrevAct, route.getDriver(),route.getVehicle()) - activity.getOperationTime();
|
||||
// double latestArrivalTime = Math.min(activity.getTheoreticalLatestOperationStartTime(), potentialLatestArrivalTimeAtCurrAct);
|
||||
//
|
||||
// states.putActivityState(activity, StateTypes.LATEST_OPERATION_START_TIME, new StateImpl(latestArrivalTime));
|
||||
//
|
||||
// latestArrTimeAtPrevAct = latestArrivalTime;
|
||||
// prevAct = activity;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void finish() {}
|
||||
// }
|
||||
//
|
||||
// static class UpdateLoadAtAllLevels implements ActivityVisitor{
|
||||
//
|
||||
// private double load = 0.0;
|
||||
//
|
||||
// private StateManagerImpl states;
|
||||
//
|
||||
// private VehicleRoute vehicleRoute;
|
||||
//
|
||||
// public UpdateLoadAtAllLevels(StateManagerImpl states) {
|
||||
// super();
|
||||
// this.states = states;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void begin(VehicleRoute route) {
|
||||
// vehicleRoute = route;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void visit(TourActivity activity) {
|
||||
// load += (double)activity.getCapacityDemand();
|
||||
// states.putActivityState(activity, StateTypes.LOAD, new StateImpl(load));
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void finish() {
|
||||
// states.putRouteState(vehicleRoute, StateTypes.LOAD, new StateImpl(load));
|
||||
// load=0;
|
||||
// vehicleRoute = null;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// static class UpdateLoadAtRouteLevel implements JobInsertedListener, InsertionStartsListener{
|
||||
//
|
||||
// private StateManagerImpl states;
|
||||
//
|
||||
// public UpdateLoadAtRouteLevel(StateManagerImpl states) {
|
||||
// super();
|
||||
// this.states = states;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void informJobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime) {
|
||||
// if(!(job2insert instanceof Service)){
|
||||
// return;
|
||||
// }
|
||||
// double oldLoad = states.getRouteState(inRoute, StateTypes.LOAD).toDouble();
|
||||
// states.putRouteState(inRoute, StateTypes.LOAD, new StateImpl(oldLoad + job2insert.getCapacityDemand()));
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void informInsertionStarts(Collection<VehicleRoute> vehicleRoutes, Collection<Job> unassignedJobs) {
|
||||
// for(VehicleRoute route : vehicleRoutes){
|
||||
// int load = 0;
|
||||
// for(Job j : route.getTourActivities().getJobs()){
|
||||
// load += j.getCapacityDemand();
|
||||
// }
|
||||
// states.putRouteState(route, StateTypes.LOAD, new StateImpl(load));
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
//>>>>>>> refs/heads/master
|
||||
static class UpdateStates implements JobInsertedListener, RuinListener{
|
||||
|
||||
private RouteActivityVisitor routeActivityVisitor;
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ public class UpdateCostsAtAllLevels implements ActivityVisitor{
|
|||
|
||||
totalOperationCost += transportCost;
|
||||
totalOperationCost += actCost;
|
||||
totalOperationCost += getFixCosts(vehicleRoute.getVehicle());
|
||||
// totalOperationCost += getFixCosts(vehicleRoute.getVehicle());
|
||||
|
||||
states.putRouteState(vehicleRoute, StateIdFactory.COSTS, new StateImpl(totalOperationCost));
|
||||
|
||||
|
|
|
|||
|
|
@ -70,6 +70,7 @@ import basics.algo.VehicleRoutingAlgorithmListeners.PrioritizedVRAListener;
|
|||
import basics.algo.VehicleRoutingAlgorithmListeners.Priority;
|
||||
import basics.io.AlgorithmConfig;
|
||||
import basics.io.AlgorithmConfigXmlReader;
|
||||
import basics.route.Vehicle;
|
||||
import basics.route.VehicleRoute;
|
||||
|
||||
|
||||
|
|
@ -552,10 +553,18 @@ public class VehicleRoutingAlgorithms {
|
|||
public void calculateCosts(VehicleRoutingProblemSolution solution) {
|
||||
double costs = 0.0;
|
||||
for(VehicleRoute route : solution.getRoutes()){
|
||||
costs += stateManager.getRouteState(route, StateIdFactory.COSTS).toDouble();
|
||||
|
||||
costs += stateManager.getRouteState(route, StateIdFactory.COSTS).toDouble() + getFixedCosts(route.getVehicle());
|
||||
|
||||
}
|
||||
solution.setCost(costs);
|
||||
}
|
||||
|
||||
private double getFixedCosts(Vehicle vehicle) {
|
||||
if(vehicle == null) return 0.0;
|
||||
if(vehicle.getType() == null) return 0.0;
|
||||
return vehicle.getType().getVehicleCostParams().fix;
|
||||
}
|
||||
};
|
||||
return calc;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -187,7 +187,9 @@ public class GendreauPostOptTest {
|
|||
// routes.add(new VehicleRoute(getEmptyTour(),getDriver(),getNoVehicle()));
|
||||
// routes.add(new VehicleRoute(getEmptyTour(),getDriver(),getNoVehicle()));
|
||||
|
||||
VehicleRoutingProblemSolution sol = new VehicleRoutingProblemSolution(routes, states.getRouteState(route, StateIdFactory.COSTS).toDouble());
|
||||
|
||||
VehicleRoutingProblemSolution sol = new VehicleRoutingProblemSolution(routes, states.getRouteState(route, StateIdFactory.COSTS).toDouble() + getFixedCosts(routes));
|
||||
|
||||
|
||||
assertEquals(110.0, sol.getCost(), 0.5);
|
||||
|
||||
|
|
@ -209,10 +211,18 @@ public class GendreauPostOptTest {
|
|||
assertEquals(80.0,newSolution.getCost(),0.5);
|
||||
}
|
||||
|
||||
private double getFixedCosts(Collection<VehicleRoute> routes) {
|
||||
double c = 0.0;
|
||||
for(VehicleRoute r : routes){ c += r.getVehicle().getType().getVehicleCostParams().fix; }
|
||||
return c;
|
||||
}
|
||||
|
||||
private double getCosts(VehicleRoutingProblemSolution newSolution, StateManagerImpl states) {
|
||||
double c = 0.0;
|
||||
for(VehicleRoute r : newSolution.getRoutes()){
|
||||
c += states.getRouteState(r, StateIdFactory.COSTS).toDouble();
|
||||
|
||||
c += states.getRouteState(r, StateIdFactory.COSTS).toDouble() + r.getVehicle().getType().getVehicleCostParams().fix;
|
||||
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue