mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
hard-coded constraint that a vehicle having an initial route cannot be
switched
This commit is contained in:
parent
cea63fd5cc
commit
5327cf11ba
2 changed files with 23 additions and 3 deletions
|
|
@ -329,7 +329,7 @@ class CalculatorBuilder {
|
|||
}
|
||||
|
||||
private JobInsertionCostsCalculator createFinalInsertion(VehicleFleetManager fleetManager, JobInsertionCostsCalculator baseCalc, RouteAndActivityStateGetter activityStates2){
|
||||
VehicleTypeDependentJobInsertionCalculator vehicleTypeDependentJobInsertionCalculator = new VehicleTypeDependentJobInsertionCalculator(fleetManager, baseCalc);
|
||||
VehicleTypeDependentJobInsertionCalculator vehicleTypeDependentJobInsertionCalculator = new VehicleTypeDependentJobInsertionCalculator(vrp, fleetManager, baseCalc);
|
||||
vehicleTypeDependentJobInsertionCalculator.setVehicleSwitchAllowed(allowVehicleSwitch);
|
||||
return vehicleTypeDependentJobInsertionCalculator;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,8 +18,11 @@ package jsprit.core.algorithm.recreate;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import jsprit.core.algorithm.recreate.InsertionData.NoInsertionFound;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
|
|
@ -38,6 +41,10 @@ final class VehicleTypeDependentJobInsertionCalculator implements JobInsertionCo
|
|||
|
||||
private final JobInsertionCostsCalculator insertionCalculator;
|
||||
|
||||
private final VehicleRoutingProblem vrp;
|
||||
|
||||
private Set<String> initialVehicleIds = new HashSet<String>();
|
||||
|
||||
/**
|
||||
* true if a vehicle(-type) is allowed to take over the whole route that was previously served by another vehicle
|
||||
*
|
||||
|
|
@ -48,12 +55,20 @@ final class VehicleTypeDependentJobInsertionCalculator implements JobInsertionCo
|
|||
*/
|
||||
private boolean vehicleSwitchAllowed = false;
|
||||
|
||||
public VehicleTypeDependentJobInsertionCalculator(final VehicleFleetManager fleetManager, final JobInsertionCostsCalculator jobInsertionCalc) {
|
||||
public VehicleTypeDependentJobInsertionCalculator(final VehicleRoutingProblem vrp, final VehicleFleetManager fleetManager, final JobInsertionCostsCalculator jobInsertionCalc) {
|
||||
this.fleetManager = fleetManager;
|
||||
this.insertionCalculator = jobInsertionCalc;
|
||||
this.vrp = vrp;
|
||||
getInitialVehicleIds();
|
||||
logger.info("inialise " + this);
|
||||
}
|
||||
|
||||
private void getInitialVehicleIds() {
|
||||
for(VehicleRoute initialRoute : vrp.getInitialVehicleRoutes()){
|
||||
initialVehicleIds.add(initialRoute.getVehicle().getId());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[name=vehicleTypeDependentServiceInsertion]";
|
||||
|
|
@ -84,7 +99,7 @@ final class VehicleTypeDependentJobInsertionCalculator implements JobInsertionCo
|
|||
Collection<Vehicle> relevantVehicles = new ArrayList<Vehicle>();
|
||||
if(!(selectedVehicle instanceof NoVehicle)) {
|
||||
relevantVehicles.add(selectedVehicle);
|
||||
if(vehicleSwitchAllowed){
|
||||
if(vehicleSwitchAllowed && !isVehicleWithInitialRoute(selectedVehicle)){
|
||||
relevantVehicles.addAll(fleetManager.getAvailableVehicles(selectedVehicle));
|
||||
}
|
||||
}
|
||||
|
|
@ -106,4 +121,9 @@ final class VehicleTypeDependentJobInsertionCalculator implements JobInsertionCo
|
|||
return bestIData;
|
||||
}
|
||||
|
||||
private boolean isVehicleWithInitialRoute(Vehicle selectedVehicle) {
|
||||
if(initialVehicleIds.contains(selectedVehicle.getId())) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue