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

additionalFixedCost (#61)

* additionalFixedCost

* test fix
This commit is contained in:
kandelirina 2018-08-23 11:31:48 +03:00 committed by GitHub
parent 7cc8cf1838
commit 550e633d0b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 9 deletions

View file

@ -101,7 +101,9 @@ final class VehicleTypeDependentJobInsertionCalculator implements JobInsertionCo
InsertionData bestIData = new InsertionData.NoInsertionFound();
double bestKnownCost_ = bestKnownCost;
Collection<Vehicle> relevantVehicles = new ArrayList<Vehicle>();
double currentVehicleFixedCost = .0;
if (!(selectedVehicle instanceof VehicleImpl.NoVehicle)) {
currentVehicleFixedCost = selectedVehicle.getType().getVehicleCostParams().fix;
relevantVehicles.add(selectedVehicle);
if (vehicleSwitchAllowed && !isVehicleWithInitialRoute(selectedVehicle)) {
relevantVehicles.addAll(fleetManager.getAvailableVehicles(selectedVehicle));
@ -118,17 +120,13 @@ final class VehicleTypeDependentJobInsertionCalculator implements JobInsertionCo
bestIData.getFailedConstraintNames().addAll(iData.getFailedConstraintNames());
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;
bestKnownCost_ = iData.getInsertionCost();
}
}
if (bestIData.getSelectedVehicle() != null) {
bestIData.setInsertionCost(bestIData.getInsertionCost() - bestIData.getSelectedVehicle().getType().getVehicleCostParams().fix);
}
return bestIData;
}

View file

@ -112,10 +112,10 @@ public class CalcVehicleTypeDependentServiceInsertionTest {
JobInsertionCostsCalculator calc = mock(JobInsertionCostsCalculator.class);
InsertionData iDataVeh1 = new InsertionData(insertionCost1, InsertionData.NO_INDEX, 1, veh1, 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, 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);
when(vrp.getInitialVehicleRoutes()).thenReturn(Collections.<VehicleRoute>emptyList());
VehicleTypeDependentJobInsertionCalculator insertion = new VehicleTypeDependentJobInsertionCalculator(vrp, fleetManager, calc);