mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
parent
d1948fb255
commit
34cc4ef3bb
2 changed files with 7 additions and 9 deletions
|
|
@ -101,7 +101,9 @@ final class VehicleTypeDependentJobInsertionCalculator implements JobInsertionCo
|
||||||
InsertionData bestIData = new InsertionData.NoInsertionFound();
|
InsertionData bestIData = new InsertionData.NoInsertionFound();
|
||||||
double bestKnownCost_ = bestKnownCost;
|
double bestKnownCost_ = bestKnownCost;
|
||||||
Collection<Vehicle> relevantVehicles = new ArrayList<Vehicle>();
|
Collection<Vehicle> relevantVehicles = new ArrayList<Vehicle>();
|
||||||
|
double currentVehicleFixedCost = .0;
|
||||||
if (!(selectedVehicle instanceof VehicleImpl.NoVehicle)) {
|
if (!(selectedVehicle instanceof VehicleImpl.NoVehicle)) {
|
||||||
|
currentVehicleFixedCost = selectedVehicle.getType().getVehicleCostParams().fix;
|
||||||
relevantVehicles.add(selectedVehicle);
|
relevantVehicles.add(selectedVehicle);
|
||||||
if (vehicleSwitchAllowed && !isVehicleWithInitialRoute(selectedVehicle)) {
|
if (vehicleSwitchAllowed && !isVehicleWithInitialRoute(selectedVehicle)) {
|
||||||
relevantVehicles.addAll(fleetManager.getAvailableVehicles(selectedVehicle));
|
relevantVehicles.addAll(fleetManager.getAvailableVehicles(selectedVehicle));
|
||||||
|
|
@ -118,17 +120,13 @@ final class VehicleTypeDependentJobInsertionCalculator implements JobInsertionCo
|
||||||
bestIData.getFailedConstraintNames().addAll(iData.getFailedConstraintNames());
|
bestIData.getFailedConstraintNames().addAll(iData.getFailedConstraintNames());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
iData.setInsertionCost(iData.getInsertionCost() + v.getType().getVehicleCostParams().fix);
|
|
||||||
if (iData.getInsertionCost() < bestKnownCost_) {
|
double additionalFixedCost = v.getType().getVehicleCostParams().fix - currentVehicleFixedCost;
|
||||||
|
if (iData.getInsertionCost() + additionalFixedCost < bestKnownCost_) {
|
||||||
bestIData = iData;
|
bestIData = iData;
|
||||||
bestKnownCost_ = iData.getInsertionCost();
|
bestKnownCost_ = iData.getInsertionCost();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bestIData.getSelectedVehicle() != null) {
|
|
||||||
bestIData.setInsertionCost(bestIData.getInsertionCost() - bestIData.getSelectedVehicle().getType().getVehicleCostParams().fix);
|
|
||||||
}
|
|
||||||
|
|
||||||
return bestIData;
|
return bestIData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -112,10 +112,10 @@ public class CalcVehicleTypeDependentServiceInsertionTest {
|
||||||
JobInsertionCostsCalculator calc = mock(JobInsertionCostsCalculator.class);
|
JobInsertionCostsCalculator calc = mock(JobInsertionCostsCalculator.class);
|
||||||
InsertionData iDataVeh1 = new InsertionData(insertionCost1, InsertionData.NO_INDEX, 1, veh1, null);
|
InsertionData iDataVeh1 = new InsertionData(insertionCost1, InsertionData.NO_INDEX, 1, veh1, null);
|
||||||
InsertionData iDataVeh2 = new InsertionData(insertionCost2, InsertionData.NO_INDEX, 1, veh2, null);
|
InsertionData iDataVeh2 = new InsertionData(insertionCost2, InsertionData.NO_INDEX, 1, veh2, null);
|
||||||
InsertionData iDataVeh1PlusFixed = new InsertionData(insertionCost1 + fixed1, InsertionData.NO_INDEX, 1, veh1, null);
|
InsertionData iDataVeh1WithoutFixed = new InsertionData(insertionCost1, InsertionData.NO_INDEX, 1, veh1, null);
|
||||||
when(calc.getInsertionData(vehicleRoute, service, veh1, veh1.getEarliestDeparture(), null, Double.MAX_VALUE)).thenReturn(iDataVeh1);
|
when(calc.getInsertionData(vehicleRoute, service, veh1, veh1.getEarliestDeparture(), null, Double.MAX_VALUE)).thenReturn(iDataVeh1);
|
||||||
when(calc.getInsertionData(vehicleRoute, service, veh2, veh2.getEarliestDeparture(), null, Double.MAX_VALUE)).thenReturn(iDataVeh2);
|
when(calc.getInsertionData(vehicleRoute, service, veh2, veh2.getEarliestDeparture(), null, Double.MAX_VALUE)).thenReturn(iDataVeh2);
|
||||||
when(calc.getInsertionData(vehicleRoute, service, veh2, veh2.getEarliestDeparture(), null, iDataVeh1PlusFixed.getInsertionCost())).thenReturn(iDataVeh1PlusFixed);
|
when(calc.getInsertionData(vehicleRoute, service, veh2, veh2.getEarliestDeparture(), null, iDataVeh1WithoutFixed.getInsertionCost())).thenReturn(iDataVeh1WithoutFixed);
|
||||||
VehicleRoutingProblem vrp = mock(VehicleRoutingProblem.class);
|
VehicleRoutingProblem vrp = mock(VehicleRoutingProblem.class);
|
||||||
when(vrp.getInitialVehicleRoutes()).thenReturn(Collections.<VehicleRoute>emptyList());
|
when(vrp.getInitialVehicleRoutes()).thenReturn(Collections.<VehicleRoute>emptyList());
|
||||||
VehicleTypeDependentJobInsertionCalculator insertion = new VehicleTypeDependentJobInsertionCalculator(vrp, fleetManager, calc);
|
VehicleTypeDependentJobInsertionCalculator insertion = new VehicleTypeDependentJobInsertionCalculator(vrp, fleetManager, calc);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue