mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
Merge pull request #7 from bringg/add-driver-cost-for-new-route
add driver cost for new route
This commit is contained in:
commit
7251733803
6 changed files with 19 additions and 5 deletions
|
|
@ -75,9 +75,15 @@ public abstract class AbstractInsertionStrategy implements InsertionStrategy {
|
||||||
|
|
||||||
protected VehicleRoutingProblem vrp;
|
protected VehicleRoutingProblem vrp;
|
||||||
|
|
||||||
|
protected double minVehicleCost = Double.POSITIVE_INFINITY;
|
||||||
|
|
||||||
public AbstractInsertionStrategy(VehicleRoutingProblem vrp) {
|
public AbstractInsertionStrategy(VehicleRoutingProblem vrp) {
|
||||||
this.insertionsListeners = new InsertionListeners();
|
this.insertionsListeners = new InsertionListeners();
|
||||||
this.vrp = vrp;
|
this.vrp = vrp;
|
||||||
|
for (Vehicle vehicle : vrp.getVehicles()) {
|
||||||
|
minVehicleCost = Math.min(vehicle.getType().getVehicleCostParams().fix, minVehicleCost);
|
||||||
|
}
|
||||||
|
|
||||||
eventListeners = new EventListeners();
|
eventListeners = new EventListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -85,6 +85,7 @@ public final class BestInsertion extends AbstractInsertionStrategy {
|
||||||
VehicleRoute newRoute = VehicleRoute.emptyRoute();
|
VehicleRoute newRoute = VehicleRoute.emptyRoute();
|
||||||
InsertionData newIData = bestInsertionCostCalculator.getInsertionData(newRoute, unassignedJob, NO_NEW_VEHICLE_YET, NO_NEW_DEPARTURE_TIME_YET, NO_NEW_DRIVER_YET, bestInsertionCost);
|
InsertionData newIData = bestInsertionCostCalculator.getInsertionData(newRoute, unassignedJob, NO_NEW_VEHICLE_YET, NO_NEW_DEPARTURE_TIME_YET, NO_NEW_DRIVER_YET, bestInsertionCost);
|
||||||
if (!(newIData instanceof InsertionData.NoInsertionFound)) {
|
if (!(newIData instanceof InsertionData.NoInsertionFound)) {
|
||||||
|
newIData.setInsertionCost(newIData.getInsertionCost() + minVehicleCost);
|
||||||
if (newIData.getInsertionCost() < bestInsertionCost + noiseMaker.makeNoise()) {
|
if (newIData.getInsertionCost() < bestInsertionCost + noiseMaker.makeNoise()) {
|
||||||
bestInsertion = new Insertion(newRoute, newIData);
|
bestInsertion = new Insertion(newRoute, newIData);
|
||||||
vehicleRoutes.add(newRoute);
|
vehicleRoutes.add(newRoute);
|
||||||
|
|
|
||||||
|
|
@ -138,6 +138,7 @@ public final class BestInsertionConcurrent extends AbstractInsertionStrategy {
|
||||||
}
|
}
|
||||||
VehicleRoute newRoute = VehicleRoute.emptyRoute();
|
VehicleRoute newRoute = VehicleRoute.emptyRoute();
|
||||||
InsertionData newIData = bestInsertionCostCalculator.getInsertionData(newRoute, unassignedJob, NO_NEW_VEHICLE_YET, NO_NEW_DEPARTURE_TIME_YET, NO_NEW_DRIVER_YET, bestInsertionCost);
|
InsertionData newIData = bestInsertionCostCalculator.getInsertionData(newRoute, unassignedJob, NO_NEW_VEHICLE_YET, NO_NEW_DEPARTURE_TIME_YET, NO_NEW_DRIVER_YET, bestInsertionCost);
|
||||||
|
newIData.setInsertionCost(newIData.getInsertionCost() + minVehicleCost);
|
||||||
if (newIData.getInsertionCost() < bestInsertionCost) {
|
if (newIData.getInsertionCost() < bestInsertionCost) {
|
||||||
bestInsertion = new Insertion(newRoute, newIData);
|
bestInsertion = new Insertion(newRoute, newIData);
|
||||||
vehicleRoutes.add(newRoute);
|
vehicleRoutes.add(newRoute);
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ public class InsertionData {
|
||||||
|
|
||||||
static int NO_INDEX = -1;
|
static int NO_INDEX = -1;
|
||||||
|
|
||||||
private final double insertionCost;
|
private double insertionCost;
|
||||||
|
|
||||||
private final int pickupInsertionIndex;
|
private final int pickupInsertionIndex;
|
||||||
|
|
||||||
|
|
@ -172,5 +172,10 @@ public class InsertionData {
|
||||||
this.departureTime = departureTime;
|
this.departureTime = departureTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param insertionCost the insertionCost to set
|
||||||
|
*/
|
||||||
|
public void setInsertionCost(double insertionCost) {
|
||||||
|
this.insertionCost = insertionCost;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,7 @@ public class RegretInsertion extends AbstractInsertionStrategy {
|
||||||
private ScoredJob nextJob(Collection<VehicleRoute> routes, Collection<Job> unassignedJobList, List<ScoredJob> badJobs) {
|
private ScoredJob nextJob(Collection<VehicleRoute> routes, Collection<Job> unassignedJobList, List<ScoredJob> badJobs) {
|
||||||
ScoredJob bestScoredJob = null;
|
ScoredJob bestScoredJob = null;
|
||||||
for (Job unassignedJob : unassignedJobList) {
|
for (Job unassignedJob : unassignedJobList) {
|
||||||
ScoredJob scoredJob = getScoredJob(routes, unassignedJob, insertionCostsCalculator, scoringFunction);
|
ScoredJob scoredJob = getScoredJob(routes, unassignedJob, insertionCostsCalculator, scoringFunction, minVehicleCost);
|
||||||
if (scoredJob instanceof ScoredJob.BadJob) {
|
if (scoredJob instanceof ScoredJob.BadJob) {
|
||||||
badJobs.add(scoredJob);
|
badJobs.add(scoredJob);
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -156,7 +156,7 @@ public class RegretInsertion extends AbstractInsertionStrategy {
|
||||||
return bestScoredJob;
|
return bestScoredJob;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ScoredJob getScoredJob(Collection<VehicleRoute> routes, Job unassignedJob, JobInsertionCostsCalculator insertionCostsCalculator, ScoringFunction scoringFunction) {
|
static ScoredJob getScoredJob(Collection<VehicleRoute> routes, Job unassignedJob, JobInsertionCostsCalculator insertionCostsCalculator, ScoringFunction scoringFunction, double newVehicleCost) {
|
||||||
InsertionData best = null;
|
InsertionData best = null;
|
||||||
InsertionData secondBest = null;
|
InsertionData secondBest = null;
|
||||||
VehicleRoute bestRoute = null;
|
VehicleRoute bestRoute = null;
|
||||||
|
|
@ -186,6 +186,7 @@ public class RegretInsertion extends AbstractInsertionStrategy {
|
||||||
VehicleRoute emptyRoute = VehicleRoute.emptyRoute();
|
VehicleRoute emptyRoute = VehicleRoute.emptyRoute();
|
||||||
InsertionData iData = insertionCostsCalculator.getInsertionData(emptyRoute, unassignedJob, NO_NEW_VEHICLE_YET, NO_NEW_DEPARTURE_TIME_YET, NO_NEW_DRIVER_YET, benchmark);
|
InsertionData iData = insertionCostsCalculator.getInsertionData(emptyRoute, unassignedJob, NO_NEW_VEHICLE_YET, NO_NEW_DEPARTURE_TIME_YET, NO_NEW_DRIVER_YET, benchmark);
|
||||||
if (!(iData instanceof InsertionData.NoInsertionFound)) {
|
if (!(iData instanceof InsertionData.NoInsertionFound)) {
|
||||||
|
iData.setInsertionCost(iData.getInsertionCost() + newVehicleCost);
|
||||||
if (best == null) {
|
if (best == null) {
|
||||||
best = iData;
|
best = iData;
|
||||||
bestRoute = emptyRoute;
|
bestRoute = emptyRoute;
|
||||||
|
|
|
||||||
|
|
@ -139,7 +139,7 @@ public class RegretInsertionConcurrent extends AbstractInsertionStrategy {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ScoredJob call() throws Exception {
|
public ScoredJob call() throws Exception {
|
||||||
return RegretInsertion.getScoredJob(routes, unassignedJob, insertionCostsCalculator, scoringFunction);
|
return RegretInsertion.getScoredJob(routes, unassignedJob, insertionCostsCalculator, scoringFunction, minVehicleCost);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue