mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
add option for vehicles to take over a whole route or not
This commit is contained in:
parent
76da6aef59
commit
cc23fa446f
4 changed files with 37 additions and 12 deletions
|
|
@ -53,7 +53,6 @@ public class BestInsertionBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
public BestInsertionBuilder setRouteLevel(int forwardLooking, int memory){
|
public BestInsertionBuilder setRouteLevel(int forwardLooking, int memory){
|
||||||
|
|
||||||
local = false;
|
local = false;
|
||||||
this.forwaredLooking = forwardLooking;
|
this.forwaredLooking = forwardLooking;
|
||||||
this.memory = memory;
|
this.memory = memory;
|
||||||
|
|
|
||||||
|
|
@ -30,8 +30,6 @@ import jsprit.core.problem.vehicle.VehicleImpl.NoVehicle;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
final class VehicleTypeDependentJobInsertionCalculator implements JobInsertionCostsCalculator{
|
final class VehicleTypeDependentJobInsertionCalculator implements JobInsertionCostsCalculator{
|
||||||
|
|
||||||
private Logger logger = Logger.getLogger(VehicleTypeDependentJobInsertionCalculator.class);
|
private Logger logger = Logger.getLogger(VehicleTypeDependentJobInsertionCalculator.class);
|
||||||
|
|
@ -40,6 +38,16 @@ final class VehicleTypeDependentJobInsertionCalculator implements JobInsertionCo
|
||||||
|
|
||||||
private final JobInsertionCostsCalculator insertionCalculator;
|
private final JobInsertionCostsCalculator insertionCalculator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* true if a vehicle(-type) is allowed to take over the whole route that was previously served by another vehicle
|
||||||
|
*
|
||||||
|
* <p>vehicleSwitch allowed makes sense if fleet consists of vehicles with different capacities such that one
|
||||||
|
* can start with a small vehicle, but as the number of customers grows bigger vehicles can be operated, i.e.
|
||||||
|
* bigger vehicles can take over the route that was previously served by a small vehicle.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private boolean vehicleSwitchAllowed = false;
|
||||||
|
|
||||||
public VehicleTypeDependentJobInsertionCalculator(final VehicleFleetManager fleetManager, final JobInsertionCostsCalculator jobInsertionCalc) {
|
public VehicleTypeDependentJobInsertionCalculator(final VehicleFleetManager fleetManager, final JobInsertionCostsCalculator jobInsertionCalc) {
|
||||||
this.fleetManager = fleetManager;
|
this.fleetManager = fleetManager;
|
||||||
this.insertionCalculator = jobInsertionCalc;
|
this.insertionCalculator = jobInsertionCalc;
|
||||||
|
|
@ -51,6 +59,22 @@ final class VehicleTypeDependentJobInsertionCalculator implements JobInsertionCo
|
||||||
return "[name=vehicleTypeDependentServiceInsertion]";
|
return "[name=vehicleTypeDependentServiceInsertion]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the vehicleSwitchAllowed
|
||||||
|
*/
|
||||||
|
public boolean isVehicleSwitchAllowed() {
|
||||||
|
return vehicleSwitchAllowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* default is true
|
||||||
|
*
|
||||||
|
* @param vehicleSwitchAllowed the vehicleSwitchAllowed to set
|
||||||
|
*/
|
||||||
|
public void setVehicleSwitchAllowed(boolean vehicleSwitchAllowed) {
|
||||||
|
this.vehicleSwitchAllowed = vehicleSwitchAllowed;
|
||||||
|
}
|
||||||
|
|
||||||
public InsertionData getInsertionData(final VehicleRoute currentRoute, final Job jobToInsert, final Vehicle vehicle, double newVehicleDepartureTime, final Driver driver, final double bestKnownCost) {
|
public InsertionData getInsertionData(final VehicleRoute currentRoute, final Job jobToInsert, final Vehicle vehicle, double newVehicleDepartureTime, final Driver driver, final double bestKnownCost) {
|
||||||
Vehicle selectedVehicle = currentRoute.getVehicle();
|
Vehicle selectedVehicle = currentRoute.getVehicle();
|
||||||
Driver selectedDriver = currentRoute.getDriver();
|
Driver selectedDriver = currentRoute.getDriver();
|
||||||
|
|
@ -59,7 +83,9 @@ final class VehicleTypeDependentJobInsertionCalculator implements JobInsertionCo
|
||||||
Collection<Vehicle> relevantVehicles = new ArrayList<Vehicle>();
|
Collection<Vehicle> relevantVehicles = new ArrayList<Vehicle>();
|
||||||
if(!(selectedVehicle instanceof NoVehicle)) {
|
if(!(selectedVehicle instanceof NoVehicle)) {
|
||||||
relevantVehicles.add(selectedVehicle);
|
relevantVehicles.add(selectedVehicle);
|
||||||
relevantVehicles.addAll(fleetManager.getAvailableVehicles(selectedVehicle.getType().getTypeId(),selectedVehicle.getLocationId()));
|
if(vehicleSwitchAllowed){
|
||||||
|
relevantVehicles.addAll(fleetManager.getAvailableVehicles(selectedVehicle.getType().getTypeId(),selectedVehicle.getLocationId()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
relevantVehicles.addAll(fleetManager.getAvailableVehicles());
|
relevantVehicles.addAll(fleetManager.getAvailableVehicles());
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@
|
||||||
<modules>
|
<modules>
|
||||||
<module name="ruin_and_recreate">
|
<module name="ruin_and_recreate">
|
||||||
<ruin name="randomRuin">
|
<ruin name="randomRuin">
|
||||||
<share>0.5</share>
|
<share>0.4</share>
|
||||||
</ruin>
|
</ruin>
|
||||||
<insertion name="bestInsertion"/>
|
<insertion name="bestInsertion"/>
|
||||||
</module>
|
</module>
|
||||||
|
|
|
||||||
|
|
@ -241,7 +241,7 @@ public class BicycleMessenger {
|
||||||
//if you want, terminate it after 1000 iterations with no change
|
//if you want, terminate it after 1000 iterations with no change
|
||||||
// algorithm.setPrematureAlgorithmTermination(new IterationWithoutImprovementTermination(1000));
|
// algorithm.setPrematureAlgorithmTermination(new IterationWithoutImprovementTermination(1000));
|
||||||
algorithm.addListener(new AlgorithmSearchProgressChartListener("output/progress.png"));
|
algorithm.addListener(new AlgorithmSearchProgressChartListener("output/progress.png"));
|
||||||
algorithm.setNuOfIterations(2000);
|
algorithm.setNuOfIterations(1000);
|
||||||
Collection<VehicleRoutingProblemSolution> solutions = algorithm.searchSolutions();
|
Collection<VehicleRoutingProblemSolution> solutions = algorithm.searchSolutions();
|
||||||
|
|
||||||
//this is just to ensure that solution meet the above constraints
|
//this is just to ensure that solution meet the above constraints
|
||||||
|
|
@ -256,19 +256,19 @@ public class BicycleMessenger {
|
||||||
|
|
||||||
//and the problem as well as the solution
|
//and the problem as well as the solution
|
||||||
Plotter plotter1 = new Plotter(bicycleMessengerProblem, Solutions.bestOf(solutions));
|
Plotter plotter1 = new Plotter(bicycleMessengerProblem, Solutions.bestOf(solutions));
|
||||||
plotter1.plotShipments(true);
|
plotter1.plotShipments(false);
|
||||||
plotter1.setShowFirstActivity(true);
|
plotter1.setShowFirstActivity(true);
|
||||||
// plotter1.setBoundingBox(5000, 45500, 25000, 66500);
|
// plotter1.setBoundingBox(5000, 45500, 25000, 66500);
|
||||||
plotter1.plot("output/bicycleMessengerSolution.png", "bicycleMessenger");
|
plotter1.plot("output/bicycleMessengerSolution.png", "bicycleMessenger");
|
||||||
|
|
||||||
//and write out your solution in xml
|
//and write out your solution in xml
|
||||||
new VrpXMLWriter(bicycleMessengerProblem, solutions).write("output/bicycleMessenger.xml");
|
// new VrpXMLWriter(bicycleMessengerProblem, solutions).write("output/bicycleMessenger.xml");
|
||||||
|
|
||||||
SolutionPrinter.print(bicycleMessengerProblem, Solutions.bestOf(solutions), Print.VERBOSE);
|
SolutionPrinter.print(bicycleMessengerProblem, Solutions.bestOf(solutions), Print.VERBOSE);
|
||||||
|
|
||||||
new GraphStreamViewer(bicycleMessengerProblem).labelWith(Label.ID).setRenderShipments(true).setRenderDelay(150).display();
|
// new GraphStreamViewer(bicycleMessengerProblem).labelWith(Label.ID).setRenderShipments(true).setRenderDelay(150).display();
|
||||||
|
//
|
||||||
new GraphStreamViewer(bicycleMessengerProblem, Solutions.bestOf(solutions)).setGraphStreamFrameScalingFactor(1.5).setCameraView(12500, 55000, 0.25).labelWith(Label.ACTIVITY).setRenderShipments(true).setRenderDelay(150).display();
|
// new GraphStreamViewer(bicycleMessengerProblem, Solutions.bestOf(solutions)).setGraphStreamFrameScalingFactor(1.5).setCameraView(12500, 55000, 0.25).labelWith(Label.ACTIVITY).setRenderShipments(true).setRenderDelay(150).display();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue