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

add option 'allowVehicleSwitch'

it determines whether a route served by vehicle A can be taken over
entirely by vehicle B.
This commit is contained in:
Stefan Schroeder 2014-01-10 15:17:23 +01:00
parent 37197de191
commit 5593671e7a
5 changed files with 23 additions and 12 deletions

View file

@ -95,11 +95,15 @@ class InsertionFactory {
if(timeSliceString != null && neighbors != null){
iBuilder.experimentalTimeScheduler(Double.parseDouble(timeSliceString),Integer.parseInt(neighbors));
}
String allowVehicleSwitch = config.getString("allowVehicleSwitch");
if(allowVehicleSwitch != null){
iBuilder.setAllowVehicleSwitch(Boolean.parseBoolean(allowVehicleSwitch));
}
if(insertionName.equals("bestInsertion")){
insertionStrategy = iBuilder.build();
}
else throw new IllegalStateException("currently only 'bestInsertion' is supported");
for(InsertionListener l : insertionListeners) insertionStrategy.addListener(l);
algorithmListeners.addAll(algoListeners);

View file

@ -857,14 +857,6 @@ public class VehicleRoutingAlgorithms {
}
else if(ruin_name.equals("radialRuin")){
JobDistance jobDistance = new AvgServiceAndShipmentDistance(vrp.getTransportCosts());
// if(ruin_distance == null) jobDistance
// else {
// if(ruin_distance.equals("euclidean")){
// jobDistance = new EuclideanServiceDistance();
// }
// else throw new IllegalStateException("does not know ruin.distance " + ruin_distance + ". either ommit ruin.distance then the "
// + "default is used or use 'euclidean'");
// }
ruin = getRadialRuin(vrp, routeStates, definedClasses, ruinKey, shareToRuin, jobDistance);
}
else throw new IllegalStateException("ruin[@name] " + ruin_name + " is not known. Use either randomRuin or radialRuin.");

View file

@ -44,6 +44,8 @@ public class BestInsertionBuilder {
private boolean timeScheduling=false;
private boolean allowVehicleSwitch=true;
public BestInsertionBuilder(VehicleRoutingProblem vrp, VehicleFleetManager vehicleFleetManager, StateManager stateManager, ConstraintManager constraintManager) {
super();
this.vrp = vrp;
@ -103,6 +105,7 @@ public class BestInsertionBuilder {
if(timeScheduling){
calcBuilder.experimentalTimeScheduler(timeSlice, nNeighbors);
}
calcBuilder.setAllowVehicleSwitch(allowVehicleSwitch);
JobInsertionCostsCalculator jobInsertions = calcBuilder.build();
InsertionStrategy bestInsertion;
if(executor == null){
@ -130,6 +133,10 @@ public class BestInsertionBuilder {
timeScheduling=true;
}
public void setAllowVehicleSwitch(boolean allowVehicleSwitch) {
this.allowVehicleSwitch = allowVehicleSwitch;
}

View file

@ -91,6 +91,8 @@ class CalculatorBuilder {
private ActivityInsertionCostsCalculator activityInsertionCostCalculator = null;
private boolean allowVehicleSwitch = true;
/**
* Constructs the builder.
*
@ -297,13 +299,19 @@ class CalculatorBuilder {
}
private JobInsertionCostsCalculator createFinalInsertion(VehicleFleetManager fleetManager, JobInsertionCostsCalculator baseCalc, RouteAndActivityStateGetter activityStates2){
return new VehicleTypeDependentJobInsertionCalculator(fleetManager, baseCalc);
VehicleTypeDependentJobInsertionCalculator vehicleTypeDependentJobInsertionCalculator = new VehicleTypeDependentJobInsertionCalculator(fleetManager, baseCalc);
vehicleTypeDependentJobInsertionCalculator.setVehicleSwitchAllowed(allowVehicleSwitch);
return vehicleTypeDependentJobInsertionCalculator;
}
public void setConstraintManager(ConstraintManager constraintManager) {
this.constraintManager = constraintManager;
}
public void setAllowVehicleSwitch(boolean allowVehicleSwitch) {
this.allowVehicleSwitch = allowVehicleSwitch;
}
}

View file

@ -72,6 +72,7 @@ final class VehicleTypeDependentJobInsertionCalculator implements JobInsertionCo
* @param vehicleSwitchAllowed the vehicleSwitchAllowed to set
*/
public void setVehicleSwitchAllowed(boolean vehicleSwitchAllowed) {
logger.info("set vehicleSwitchAllowed to " + vehicleSwitchAllowed);
this.vehicleSwitchAllowed = vehicleSwitchAllowed;
}
@ -87,10 +88,9 @@ final class VehicleTypeDependentJobInsertionCalculator implements JobInsertionCo
relevantVehicles.addAll(fleetManager.getAvailableVehicles(selectedVehicle.getType().getTypeId(),selectedVehicle.getLocationId()));
}
}
else{
else{ //if no vehicle has been assigned, i.e. it is an empty route
relevantVehicles.addAll(fleetManager.getAvailableVehicles());
}
for(Vehicle v : relevantVehicles){
double depTime = v.getEarliestDeparture();
InsertionData iData = insertionCalculator.getInsertionData(currentRoute, jobToInsert, v, depTime, selectedDriver, bestKnownCost_);