mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
bugfix #186
This commit is contained in:
parent
e5ada2f6d9
commit
e543665da2
6 changed files with 43 additions and 2 deletions
|
|
@ -25,6 +25,7 @@ import jsprit.core.algorithm.recreate.VehicleSwitched;
|
||||||
import jsprit.core.algorithm.state.*;
|
import jsprit.core.algorithm.state.*;
|
||||||
import jsprit.core.problem.VehicleRoutingProblem;
|
import jsprit.core.problem.VehicleRoutingProblem;
|
||||||
import jsprit.core.problem.constraint.ConstraintManager;
|
import jsprit.core.problem.constraint.ConstraintManager;
|
||||||
|
import jsprit.core.problem.constraint.SwitchNotFeasible;
|
||||||
import jsprit.core.problem.solution.SolutionCostCalculator;
|
import jsprit.core.problem.solution.SolutionCostCalculator;
|
||||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||||
|
|
@ -89,6 +90,7 @@ public class PrettyAlgorithmBuilder {
|
||||||
constraintManager.addTimeWindowConstraint();
|
constraintManager.addTimeWindowConstraint();
|
||||||
constraintManager.addLoadConstraint();
|
constraintManager.addLoadConstraint();
|
||||||
constraintManager.addSkillsConstraint();
|
constraintManager.addSkillsConstraint();
|
||||||
|
constraintManager.addConstraint(new SwitchNotFeasible(stateManager));
|
||||||
stateManager.updateLoadStates();
|
stateManager.updateLoadStates();
|
||||||
stateManager.updateTimeWindowStates();
|
stateManager.updateTimeWindowStates();
|
||||||
UpdateVehicleDependentPracticalTimeWindows twUpdater = new UpdateVehicleDependentPracticalTimeWindows(stateManager, vrp.getTransportCosts());
|
UpdateVehicleDependentPracticalTimeWindows twUpdater = new UpdateVehicleDependentPracticalTimeWindows(stateManager, vrp.getTransportCosts());
|
||||||
|
|
|
||||||
|
|
@ -49,4 +49,6 @@ public class InternalStates {
|
||||||
public static final StateId FUTURE_WAITING = new StateFactory.StateIdImpl("future_waiting", 13);
|
public static final StateId FUTURE_WAITING = new StateFactory.StateIdImpl("future_waiting", 13);
|
||||||
|
|
||||||
public static final StateId EARLIEST_WITHOUT_WAITING = new StateFactory.StateIdImpl("earliest_without_waiting", 14);
|
public static final StateId EARLIEST_WITHOUT_WAITING = new StateFactory.StateIdImpl("earliest_without_waiting", 14);
|
||||||
|
|
||||||
|
public static final StateId SWITCH_NOT_FEASIBLE = new StateFactory.StateIdImpl("switch_not_feasible", 15);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -97,6 +97,9 @@ public class UpdateVehicleDependentPracticalTimeWindows implements RouteVisitor,
|
||||||
double potentialLatestArrivalTimeAtCurrAct = latestArrTimeAtPrevAct - transportCosts.getBackwardTransportTime(activity.getLocation(), prevLocation,
|
double potentialLatestArrivalTimeAtCurrAct = latestArrTimeAtPrevAct - transportCosts.getBackwardTransportTime(activity.getLocation(), prevLocation,
|
||||||
latestArrTimeAtPrevAct, route.getDriver(), vehicle) - activity.getOperationTime();
|
latestArrTimeAtPrevAct, route.getDriver(), vehicle) - activity.getOperationTime();
|
||||||
double latestArrivalTime = Math.min(activity.getTheoreticalLatestOperationStartTime(), potentialLatestArrivalTimeAtCurrAct);
|
double latestArrivalTime = Math.min(activity.getTheoreticalLatestOperationStartTime(), potentialLatestArrivalTimeAtCurrAct);
|
||||||
|
if(latestArrivalTime < activity.getTheoreticalEarliestOperationStartTime()){
|
||||||
|
stateManager.putTypedInternalRouteState(route,vehicle,InternalStates.SWITCH_NOT_FEASIBLE,true);
|
||||||
|
}
|
||||||
stateManager.putInternalTypedActivityState(activity, vehicle, InternalStates.LATEST_OPERATION_START_TIME, latestArrivalTime);
|
stateManager.putInternalTypedActivityState(activity, vehicle, InternalStates.LATEST_OPERATION_START_TIME, latestArrivalTime);
|
||||||
latest_arrTimes_at_prevAct[vehicle.getVehicleTypeIdentifier().getIndex()] = latestArrivalTime;
|
latest_arrTimes_at_prevAct[vehicle.getVehicleTypeIdentifier().getIndex()] = latestArrivalTime;
|
||||||
location_of_prevAct[vehicle.getVehicleTypeIdentifier().getIndex()] = activity.getLocation();
|
location_of_prevAct[vehicle.getVehicleTypeIdentifier().getIndex()] = activity.getLocation();
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
package jsprit.core.problem.constraint;
|
||||||
|
|
||||||
|
import jsprit.core.algorithm.state.InternalStates;
|
||||||
|
import jsprit.core.algorithm.state.StateManager;
|
||||||
|
import jsprit.core.problem.misc.JobInsertionContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by schroeder on 19/09/15.
|
||||||
|
*/
|
||||||
|
public class SwitchNotFeasible implements HardRouteConstraint{
|
||||||
|
|
||||||
|
private StateManager stateManager;
|
||||||
|
|
||||||
|
public SwitchNotFeasible(StateManager stateManager) {
|
||||||
|
this.stateManager = stateManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean fulfilled(JobInsertionContext insertionContext) {
|
||||||
|
Boolean notFeasible = stateManager.getRouteState(insertionContext.getRoute(),insertionContext.getNewVehicle(), InternalStates.SWITCH_NOT_FEASIBLE,Boolean.class);
|
||||||
|
if(notFeasible == null) return true;
|
||||||
|
else return !notFeasible;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -114,6 +114,14 @@ public class FastVehicleRoutingTransportCostsMatrix extends AbstractForwardVehic
|
||||||
matrix = builder.matrix;
|
matrix = builder.matrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* First dim is from, second to and third indicates whether it is a distance value (index=0) or time value (index=1).
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public double[][][] getMatrix(){
|
||||||
|
return matrix;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getTransportTime(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) {
|
public double getTransportTime(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package jsprit.core.algorithm;
|
package jsprit.core.algorithm;
|
||||||
|
|
||||||
import jsprit.core.IntegrationTest;
|
import jsprit.core.IntegrationTest;
|
||||||
import jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
|
import jsprit.core.algorithm.box.Jsprit;
|
||||||
import jsprit.core.problem.VehicleRoutingProblem;
|
import jsprit.core.problem.VehicleRoutingProblem;
|
||||||
import jsprit.core.problem.io.VrpXMLReader;
|
import jsprit.core.problem.io.VrpXMLReader;
|
||||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||||
|
|
@ -25,7 +25,8 @@ public class Solomon_IT {
|
||||||
new VrpXMLReader(vrpBuilder).read("src/test/resources/solomon_c101.xml");
|
new VrpXMLReader(vrpBuilder).read("src/test/resources/solomon_c101.xml");
|
||||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||||
|
|
||||||
VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfig.xml");
|
VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
|
||||||
|
// VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfig.xml");
|
||||||
vra.setMaxIterations(500);
|
vra.setMaxIterations(500);
|
||||||
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
||||||
assertEquals(828.94, Solutions.bestOf(solutions).getCost(), 0.01);
|
assertEquals(828.94, Solutions.bestOf(solutions).getCost(), 0.01);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue