mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
remove Double.MAX_VALUE - related to #286
This commit is contained in:
parent
f8ea447cb9
commit
f924293520
2 changed files with 170 additions and 84 deletions
|
|
@ -35,32 +35,32 @@ final class JobInsertionConsideringFixCostsCalculator implements JobInsertionCos
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(JobInsertionConsideringFixCostsCalculator.class);
|
private static final Logger logger = LoggerFactory.getLogger(JobInsertionConsideringFixCostsCalculator.class);
|
||||||
|
|
||||||
private final JobInsertionCostsCalculator standardServiceInsertion;
|
private final JobInsertionCostsCalculator standardInsertion;
|
||||||
|
|
||||||
private double weight_deltaFixCost = 0.5;
|
private double weightDeltaFixCost = 0.5;
|
||||||
|
|
||||||
private double solution_completeness_ratio = 0.5;
|
private double solutionCompletenessRatio = 0.5;
|
||||||
|
|
||||||
private RouteAndActivityStateGetter stateGetter;
|
private RouteAndActivityStateGetter stateGetter;
|
||||||
|
|
||||||
public JobInsertionConsideringFixCostsCalculator(final JobInsertionCostsCalculator standardInsertionCalculator, RouteAndActivityStateGetter stateGetter) {
|
public JobInsertionConsideringFixCostsCalculator(final JobInsertionCostsCalculator standardCalculator, RouteAndActivityStateGetter stateGetter) {
|
||||||
super();
|
super();
|
||||||
this.standardServiceInsertion = standardInsertionCalculator;
|
this.standardInsertion = standardCalculator;
|
||||||
this.stateGetter = stateGetter;
|
this.stateGetter = stateGetter;
|
||||||
logger.debug("inialise {}", this);
|
logger.debug("initialise {}", this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InsertionData getInsertionData(final VehicleRoute currentRoute, final Job jobToInsert, final Vehicle newVehicle, double newVehicleDepartureTime, final Driver newDriver, final double bestKnownPrice) {
|
public InsertionData getInsertionData(final VehicleRoute currentRoute, final Job jobToInsert, final Vehicle newVehicle, double newVehicleDepartureTime, final Driver newDriver, final double bestKnownPrice) {
|
||||||
double fixcost_contribution = getFixCostContribution(currentRoute, jobToInsert, newVehicle);
|
double fixedCostContribution = getFixCostContribution(currentRoute, jobToInsert, newVehicle);
|
||||||
if (fixcost_contribution > bestKnownPrice) {
|
if (fixedCostContribution > bestKnownPrice) {
|
||||||
return InsertionData.createEmptyInsertionData();
|
return InsertionData.createEmptyInsertionData();
|
||||||
}
|
}
|
||||||
InsertionData iData = standardServiceInsertion.getInsertionData(currentRoute, jobToInsert, newVehicle, newVehicleDepartureTime, newDriver, bestKnownPrice);
|
InsertionData iData = standardInsertion.getInsertionData(currentRoute, jobToInsert, newVehicle, newVehicleDepartureTime, newDriver, bestKnownPrice);
|
||||||
if (iData instanceof InsertionData.NoInsertionFound) {
|
if (iData instanceof InsertionData.NoInsertionFound) {
|
||||||
return iData;
|
return iData;
|
||||||
}
|
}
|
||||||
double totalInsertionCost = iData.getInsertionCost() + fixcost_contribution;
|
double totalInsertionCost = iData.getInsertionCost() + fixedCostContribution;
|
||||||
InsertionData insertionData = new InsertionData(totalInsertionCost, iData.getPickupInsertionIndex(), iData.getDeliveryInsertionIndex(), newVehicle, newDriver);
|
InsertionData insertionData = new InsertionData(totalInsertionCost, iData.getPickupInsertionIndex(), iData.getDeliveryInsertionIndex(), newVehicle, newDriver);
|
||||||
insertionData.setVehicleDepartureTime(newVehicleDepartureTime);
|
insertionData.setVehicleDepartureTime(newVehicleDepartureTime);
|
||||||
insertionData.getEvents().addAll(iData.getEvents());
|
insertionData.getEvents().addAll(iData.getEvents());
|
||||||
|
|
@ -70,55 +70,42 @@ final class JobInsertionConsideringFixCostsCalculator implements JobInsertionCos
|
||||||
private double getFixCostContribution(final VehicleRoute currentRoute, final Job jobToInsert, final Vehicle newVehicle) {
|
private double getFixCostContribution(final VehicleRoute currentRoute, final Job jobToInsert, final Vehicle newVehicle) {
|
||||||
Capacity currentMaxLoadInRoute = getCurrentMaxLoadInRoute(currentRoute);
|
Capacity currentMaxLoadInRoute = getCurrentMaxLoadInRoute(currentRoute);
|
||||||
double relFixCost = getDeltaRelativeFixCost(currentRoute, newVehicle, jobToInsert,currentMaxLoadInRoute);
|
double relFixCost = getDeltaRelativeFixCost(currentRoute, newVehicle, jobToInsert,currentMaxLoadInRoute);
|
||||||
double absFixCost = getDeltaAbsoluteFixCost(currentRoute, newVehicle, jobToInsert,currentMaxLoadInRoute);
|
double absFixCost = getDeltaAbsoluteFixCost(currentRoute, newVehicle);
|
||||||
double deltaFixCost = (1 - solution_completeness_ratio) * relFixCost + solution_completeness_ratio * absFixCost;
|
double deltaFixCost = (1 - solutionCompletenessRatio) * relFixCost + solutionCompletenessRatio * absFixCost;
|
||||||
double fixcost_contribution = weight_deltaFixCost * solution_completeness_ratio * deltaFixCost;
|
return weightDeltaFixCost * solutionCompletenessRatio * deltaFixCost;
|
||||||
return fixcost_contribution;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setWeightOfFixCost(double weight) {
|
public void setWeightOfFixCost(double weight) {
|
||||||
weight_deltaFixCost = weight;
|
weightDeltaFixCost = weight;
|
||||||
logger.debug("set weightOfFixCostSaving to {}", weight);
|
logger.debug("set weightOfFixCostSaving to {}", weight);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "[name=calculatesServiceInsertionConsideringFixCost][weightOfFixedCostSavings=" + weight_deltaFixCost + "]";
|
return "[name=calculatesServiceInsertionConsideringFixCost][weightOfFixedCostSavings=" + weightDeltaFixCost + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSolutionCompletenessRatio(double ratio) {
|
public void setSolutionCompletenessRatio(double ratio) {
|
||||||
solution_completeness_ratio = ratio;
|
solutionCompletenessRatio = ratio;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getSolutionCompletenessRatio() { return solution_completeness_ratio; }
|
public double getSolutionCompletenessRatio() { return solutionCompletenessRatio; }
|
||||||
|
|
||||||
private double getDeltaAbsoluteFixCost(VehicleRoute route, Vehicle newVehicle, Job job, Capacity currentMaxLoadInRoute) {
|
private double getDeltaAbsoluteFixCost(VehicleRoute route, Vehicle newVehicle) {
|
||||||
Capacity load = Capacity.addup(currentMaxLoadInRoute, job.getSize());
|
double currentFix = 0d;
|
||||||
double currentFix = 0.0;
|
if (route.getVehicle() != null && !(route.getVehicle() instanceof VehicleImpl.NoVehicle)) {
|
||||||
if (route.getVehicle() != null) {
|
currentFix = route.getVehicle().getType().getVehicleCostParams().fix;
|
||||||
if (!(route.getVehicle() instanceof VehicleImpl.NoVehicle)) {
|
|
||||||
currentFix += route.getVehicle().getType().getVehicleCostParams().fix;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!newVehicle.getType().getCapacityDimensions().isGreaterOrEqual(load)) {
|
|
||||||
return Double.MAX_VALUE;
|
|
||||||
}
|
}
|
||||||
return newVehicle.getType().getVehicleCostParams().fix - currentFix;
|
return newVehicle.getType().getVehicleCostParams().fix - currentFix;
|
||||||
}
|
}
|
||||||
|
|
||||||
private double getDeltaRelativeFixCost(VehicleRoute route, Vehicle newVehicle, Job job, Capacity currentLoad) {
|
private double getDeltaRelativeFixCost(VehicleRoute route, Vehicle newVehicle, Job job, Capacity currentLoad) {
|
||||||
Capacity load = Capacity.addup(currentLoad, job.getSize());
|
Capacity load = Capacity.addup(currentLoad, job.getSize());
|
||||||
double currentRelFix = 0.0;
|
double currentRelFix = 0d;
|
||||||
if (route.getVehicle() != null) {
|
if (route.getVehicle() != null && !(route.getVehicle() instanceof VehicleImpl.NoVehicle)) {
|
||||||
if (!(route.getVehicle() instanceof VehicleImpl.NoVehicle)) {
|
currentRelFix = route.getVehicle().getType().getVehicleCostParams().fix * Capacity.divide(currentLoad, route.getVehicle().getType().getCapacityDimensions());
|
||||||
currentRelFix += route.getVehicle().getType().getVehicleCostParams().fix * Capacity.divide(currentLoad, route.getVehicle().getType().getCapacityDimensions());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!newVehicle.getType().getCapacityDimensions().isGreaterOrEqual(load)) {
|
return newVehicle.getType().getVehicleCostParams().fix * (Capacity.divide(load, newVehicle.getType().getCapacityDimensions())) - currentRelFix;
|
||||||
return Double.MAX_VALUE;
|
|
||||||
}
|
|
||||||
double relativeFixCost = newVehicle.getType().getVehicleCostParams().fix * (Capacity.divide(load, newVehicle.getType().getCapacityDimensions())) - currentRelFix;
|
|
||||||
return relativeFixCost;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Capacity getCurrentMaxLoadInRoute(VehicleRoute route) {
|
private Capacity getCurrentMaxLoadInRoute(VehicleRoute route) {
|
||||||
|
|
|
||||||
|
|
@ -36,9 +36,11 @@ public class JobInsertionConsideringFixCostsCalculatorTest {
|
||||||
|
|
||||||
private JobInsertionConsideringFixCostsCalculator calc;
|
private JobInsertionConsideringFixCostsCalculator calc;
|
||||||
|
|
||||||
private Vehicle oVehicle;
|
private Vehicle small;
|
||||||
|
|
||||||
private Vehicle nVehicle;
|
private Vehicle medium;
|
||||||
|
|
||||||
|
private Vehicle large;
|
||||||
|
|
||||||
private Job job;
|
private Job job;
|
||||||
|
|
||||||
|
|
@ -52,18 +54,23 @@ public class JobInsertionConsideringFixCostsCalculatorTest {
|
||||||
job = mock(Job.class);
|
job = mock(Job.class);
|
||||||
when(job.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 50).build());
|
when(job.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 50).build());
|
||||||
|
|
||||||
oVehicle = mock(Vehicle.class);
|
small = mock(Vehicle.class);
|
||||||
VehicleType oType = VehicleTypeImpl.Builder.newInstance("otype").addCapacityDimension(0, 50).setFixedCost(50.0).build();
|
VehicleType smallType = VehicleTypeImpl.Builder.newInstance("smallType").addCapacityDimension(0, 50).setFixedCost(50.0).build();
|
||||||
when(oVehicle.getType()).thenReturn(oType);
|
when(small.getType()).thenReturn(smallType);
|
||||||
|
|
||||||
nVehicle = mock(Vehicle.class);
|
medium = mock(Vehicle.class);
|
||||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("type").addCapacityDimension(0, 100).setFixedCost(100.0).build();
|
VehicleType mediumType = VehicleTypeImpl.Builder.newInstance("mediumType").addCapacityDimension(0, 100).setFixedCost(100.0).build();
|
||||||
when(nVehicle.getType()).thenReturn(type);
|
when(medium.getType()).thenReturn(mediumType);
|
||||||
|
|
||||||
InsertionData iData = new InsertionData(0.0, 1, 1, nVehicle, null);
|
large = mock(Vehicle.class);
|
||||||
|
VehicleType largeType = VehicleTypeImpl.Builder.newInstance("largeType").addCapacityDimension(0, 400).setFixedCost(200.0).build();
|
||||||
|
when(large.getType()).thenReturn(largeType);
|
||||||
|
|
||||||
|
InsertionData iData = new InsertionData(0.0, 1, 1, medium, null);
|
||||||
route = mock(VehicleRoute.class);
|
route = mock(VehicleRoute.class);
|
||||||
|
|
||||||
when(jobInsertionCosts.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE)).thenReturn(iData);
|
when(jobInsertionCosts.getInsertionData(route, job, medium, 0.0, null, Double.MAX_VALUE)).thenReturn(iData);
|
||||||
|
when(jobInsertionCosts.getInsertionData(route, job, large, 0.0, null, Double.MAX_VALUE)).thenReturn(new InsertionData(0.0, 1, 1, large, null));
|
||||||
|
|
||||||
stateGetter = mock(RouteAndActivityStateGetter.class);
|
stateGetter = mock(RouteAndActivityStateGetter.class);
|
||||||
when(stateGetter.getRouteState(route, InternalStates.MAXLOAD, Capacity.class)).thenReturn(Capacity.Builder.newInstance().build());
|
when(stateGetter.getRouteState(route, InternalStates.MAXLOAD, Capacity.class)).thenReturn(Capacity.Builder.newInstance().build());
|
||||||
|
|
@ -76,7 +83,7 @@ public class JobInsertionConsideringFixCostsCalculatorTest {
|
||||||
calc.setSolutionCompletenessRatio(1.0);
|
calc.setSolutionCompletenessRatio(1.0);
|
||||||
calc.setWeightOfFixCost(1.0);
|
calc.setWeightOfFixCost(1.0);
|
||||||
//(1.*absFix + 0.*relFix) * completeness * weight = (1.*100. + 0.*50.) * 1. * 1. = 100.
|
//(1.*absFix + 0.*relFix) * completeness * weight = (1.*100. + 0.*50.) * 1. * 1. = 100.
|
||||||
assertEquals(100., calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
assertEquals(100., calc.getInsertionData(route, job, medium, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -84,7 +91,7 @@ public class JobInsertionConsideringFixCostsCalculatorTest {
|
||||||
calc.setSolutionCompletenessRatio(0.0);
|
calc.setSolutionCompletenessRatio(0.0);
|
||||||
calc.setWeightOfFixCost(1.0);
|
calc.setWeightOfFixCost(1.0);
|
||||||
//(0.*absFix + 1.*relFix) * completeness * weight = 0.
|
//(0.*absFix + 1.*relFix) * completeness * weight = 0.
|
||||||
assertEquals(0., calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
assertEquals(0., calc.getInsertionData(route, job, medium, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -92,7 +99,7 @@ public class JobInsertionConsideringFixCostsCalculatorTest {
|
||||||
calc.setSolutionCompletenessRatio(0.5);
|
calc.setSolutionCompletenessRatio(0.5);
|
||||||
calc.setWeightOfFixCost(1.0);
|
calc.setWeightOfFixCost(1.0);
|
||||||
//(0.5*absFix + 0.5*relFix) * 0.5 * 1. = (0.5*100+0.5*50)*0.5*1. = 37.5
|
//(0.5*absFix + 0.5*relFix) * 0.5 * 1. = (0.5*100+0.5*50)*0.5*1. = 37.5
|
||||||
assertEquals(37.5, calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
assertEquals(37.5, calc.getInsertionData(route, job, medium, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -100,7 +107,7 @@ public class JobInsertionConsideringFixCostsCalculatorTest {
|
||||||
calc.setSolutionCompletenessRatio(0.75);
|
calc.setSolutionCompletenessRatio(0.75);
|
||||||
calc.setWeightOfFixCost(1.0);
|
calc.setWeightOfFixCost(1.0);
|
||||||
//(0.75*absFix + 0.25*relFix) * 0.75 * 1.= (0.75*100.+0.25*50.)*0.75*1. = 65.625
|
//(0.75*absFix + 0.25*relFix) * 0.75 * 1.= (0.75*100.+0.25*50.)*0.75*1. = 65.625
|
||||||
assertEquals(65.625, calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
assertEquals(65.625, calc.getInsertionData(route, job, medium, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -108,7 +115,7 @@ public class JobInsertionConsideringFixCostsCalculatorTest {
|
||||||
calc.setSolutionCompletenessRatio(1.0);
|
calc.setSolutionCompletenessRatio(1.0);
|
||||||
calc.setWeightOfFixCost(.5);
|
calc.setWeightOfFixCost(.5);
|
||||||
//(1.*absFix + 0.*relFix) * 1. * 0.5 = (1.*100. + 0.*50.) * 1. * 0.5 = 5.
|
//(1.*absFix + 0.*relFix) * 1. * 0.5 = (1.*100. + 0.*50.) * 1. * 0.5 = 5.
|
||||||
assertEquals(50., calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
assertEquals(50., calc.getInsertionData(route, job, medium, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -116,7 +123,7 @@ public class JobInsertionConsideringFixCostsCalculatorTest {
|
||||||
calc.setSolutionCompletenessRatio(0.0);
|
calc.setSolutionCompletenessRatio(0.0);
|
||||||
calc.setWeightOfFixCost(.5);
|
calc.setWeightOfFixCost(.5);
|
||||||
//(0.*absFix + 1.*relFix) * 0. * .5 = 0.
|
//(0.*absFix + 1.*relFix) * 0. * .5 = 0.
|
||||||
assertEquals(0., calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
assertEquals(0., calc.getInsertionData(route, job, medium, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -124,7 +131,7 @@ public class JobInsertionConsideringFixCostsCalculatorTest {
|
||||||
calc.setSolutionCompletenessRatio(0.5);
|
calc.setSolutionCompletenessRatio(0.5);
|
||||||
calc.setWeightOfFixCost(.5);
|
calc.setWeightOfFixCost(.5);
|
||||||
//(0.5*absFix + 0.5*relFix) * 0.5 * 0.= (0.5*100+0.5*50)*0.5*0.5 = 18.75
|
//(0.5*absFix + 0.5*relFix) * 0.5 * 0.= (0.5*100+0.5*50)*0.5*0.5 = 18.75
|
||||||
assertEquals(18.75, calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
assertEquals(18.75, calc.getInsertionData(route, job, medium, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -132,98 +139,98 @@ public class JobInsertionConsideringFixCostsCalculatorTest {
|
||||||
calc.setSolutionCompletenessRatio(0.75);
|
calc.setSolutionCompletenessRatio(0.75);
|
||||||
calc.setWeightOfFixCost(0.5);
|
calc.setWeightOfFixCost(0.5);
|
||||||
//(0.75*absFix + 0.25*relFix) * 0.75 * 0.5 = (0.75*100.+0.25*50.)*0.75*0.5 = 32.8125
|
//(0.75*absFix + 0.25*relFix) * 0.75 * 0.5 = (0.75*100.+0.25*50.)*0.75*0.5 = 32.8125
|
||||||
assertEquals(32.8125, calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
assertEquals(32.8125, calc.getInsertionData(route, job, medium, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenOldVehicleIsNotNullAndSolutionComplete_itShouldReturnHalfOfFixedCostsOfNewVehicle() {
|
public void whenOldVehicleIsNotNullAndSolutionComplete_itShouldReturnHalfOfFixedCostsOfNewVehicle() {
|
||||||
calc.setSolutionCompletenessRatio(1.0);
|
calc.setSolutionCompletenessRatio(1.0);
|
||||||
calc.setWeightOfFixCost(1.0);
|
calc.setWeightOfFixCost(1.0);
|
||||||
when(route.getVehicle()).thenReturn(oVehicle);
|
when(route.getVehicle()).thenReturn(small);
|
||||||
//(1.*absFix + 0.*relFix) * completeness * weight = (1.*(100.-50.) + 0.*(50.-0.)) * 1. * 1. = 50.
|
//(1.*absFix + 0.*relFix) * completeness * weight = (1.*(100.-50.) + 0.*(50.-0.)) * 1. * 1. = 50.
|
||||||
assertEquals(50., calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
assertEquals(50., calc.getInsertionData(route, job, medium, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenOldVehicleIsNotNullAndSolutionIs0PercentComplete_itShouldReturnNoFixedCosts() {
|
public void whenOldVehicleIsNotNullAndSolutionIs0PercentComplete_itShouldReturnNoFixedCosts() {
|
||||||
calc.setSolutionCompletenessRatio(0.0);
|
calc.setSolutionCompletenessRatio(0.0);
|
||||||
calc.setWeightOfFixCost(1.0);
|
calc.setWeightOfFixCost(1.0);
|
||||||
when(route.getVehicle()).thenReturn(oVehicle);
|
when(route.getVehicle()).thenReturn(small);
|
||||||
//(0.*absFix + 1.*relFix) * completeness * weight = 0.
|
//(0.*absFix + 1.*relFix) * completeness * weight = 0.
|
||||||
assertEquals(0., calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
assertEquals(0., calc.getInsertionData(route, job, medium, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenOldVehicleIsNotNullAndSolutionIs50PercentComplete_itShouldCorrectVal() {
|
public void whenOldVehicleIsNotNullAndSolutionIs50PercentComplete_itShouldCorrectVal() {
|
||||||
calc.setSolutionCompletenessRatio(0.5);
|
calc.setSolutionCompletenessRatio(0.5);
|
||||||
calc.setWeightOfFixCost(1.0);
|
calc.setWeightOfFixCost(1.0);
|
||||||
when(route.getVehicle()).thenReturn(oVehicle);
|
when(route.getVehicle()).thenReturn(small);
|
||||||
//(0.5*absFix + 0.5*relFix) * 0.5 * 1. = (0.5*(100-50)+0.5*(50-0))*0.5*1. = 25.
|
//(0.5*absFix + 0.5*relFix) * 0.5 * 1. = (0.5*(100-50)+0.5*(50-0))*0.5*1. = 25.
|
||||||
assertEquals(25., calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
assertEquals(25., calc.getInsertionData(route, job, medium, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenOldVehicleIsNotNullAndSolutionIs75PercentComplete_itShouldReturnCorrectVal() {
|
public void whenOldVehicleIsNotNullAndSolutionIs75PercentComplete_itShouldReturnCorrectVal() {
|
||||||
calc.setSolutionCompletenessRatio(0.75);
|
calc.setSolutionCompletenessRatio(0.75);
|
||||||
calc.setWeightOfFixCost(1.0);
|
calc.setWeightOfFixCost(1.0);
|
||||||
when(route.getVehicle()).thenReturn(oVehicle);
|
when(route.getVehicle()).thenReturn(small);
|
||||||
//(0.75*absFix + 0.25*relFix) * 0.75 * 1.= (0.75*(100.-50.)+0.25*(50.-0.))*0.75*1. = 37.5
|
//(0.75*absFix + 0.25*relFix) * 0.75 * 1.= (0.75*(100.-50.)+0.25*(50.-0.))*0.75*1. = 37.5
|
||||||
assertEquals(37.5, calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
assertEquals(37.5, calc.getInsertionData(route, job, medium, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenOldVehicleIsNotNullAndSolutionCompleteAndWeightIs05_itShouldReturnCorrectVal() {
|
public void whenOldVehicleIsNotNullAndSolutionCompleteAndWeightIs05_itShouldReturnCorrectVal() {
|
||||||
calc.setSolutionCompletenessRatio(1.0);
|
calc.setSolutionCompletenessRatio(1.0);
|
||||||
calc.setWeightOfFixCost(.5);
|
calc.setWeightOfFixCost(.5);
|
||||||
when(route.getVehicle()).thenReturn(oVehicle);
|
when(route.getVehicle()).thenReturn(small);
|
||||||
//(1.*absFix + 0.*relFix) * 1. * 0.5 = (1.*(100.-50.) + 0.*(50.-0.)) * 1. * 0.5 = 25.
|
//(1.*absFix + 0.*relFix) * 1. * 0.5 = (1.*(100.-50.) + 0.*(50.-0.)) * 1. * 0.5 = 25.
|
||||||
assertEquals(25., calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
assertEquals(25., calc.getInsertionData(route, job, medium, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenOldVehicleIsNotNullAndSolutionIs0PercentCompleteAndWeightIs05_itShouldReturnCorrectVal() {
|
public void whenOldVehicleIsNotNullAndSolutionIs0PercentCompleteAndWeightIs05_itShouldReturnCorrectVal() {
|
||||||
calc.setSolutionCompletenessRatio(0.0);
|
calc.setSolutionCompletenessRatio(0.0);
|
||||||
calc.setWeightOfFixCost(.5);
|
calc.setWeightOfFixCost(.5);
|
||||||
when(route.getVehicle()).thenReturn(oVehicle);
|
when(route.getVehicle()).thenReturn(small);
|
||||||
//(0.*absFix + 1.*relFix) * 0. * .5 = 0.
|
//(0.*absFix + 1.*relFix) * 0. * .5 = 0.
|
||||||
assertEquals(0., calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
assertEquals(0., calc.getInsertionData(route, job, medium, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenOldVehicleIsNotNullAndSolutionIs50PercentCompleteAndWeightIs05_itShouldReturnCorrectVal() {
|
public void whenOldVehicleIsNotNullAndSolutionIs50PercentCompleteAndWeightIs05_itShouldReturnCorrectVal() {
|
||||||
calc.setSolutionCompletenessRatio(0.5);
|
calc.setSolutionCompletenessRatio(0.5);
|
||||||
calc.setWeightOfFixCost(.5);
|
calc.setWeightOfFixCost(.5);
|
||||||
when(route.getVehicle()).thenReturn(oVehicle);
|
when(route.getVehicle()).thenReturn(small);
|
||||||
//(0.5*absFix + 0.5*relFix) * 0.5 * 0.= (0.5*(100-50)+0.5*(50-0))*0.5*0.5 = 12.5
|
//(0.5*absFix + 0.5*relFix) * 0.5 * 0.= (0.5*(100-50)+0.5*(50-0))*0.5*0.5 = 12.5
|
||||||
assertEquals(12.5, calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
assertEquals(12.5, calc.getInsertionData(route, job, medium, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenOldVehicleIsNotNullAndSolutionIs75PercentCompleteAndWeightIs05_itShouldReturnCorrectVal() {
|
public void whenOldVehicleIsNotNullAndSolutionIs75PercentCompleteAndWeightIs05_itShouldReturnCorrectVal() {
|
||||||
calc.setSolutionCompletenessRatio(0.75);
|
calc.setSolutionCompletenessRatio(0.75);
|
||||||
calc.setWeightOfFixCost(0.5);
|
calc.setWeightOfFixCost(0.5);
|
||||||
when(route.getVehicle()).thenReturn(oVehicle);
|
when(route.getVehicle()).thenReturn(small);
|
||||||
//(0.75*absFix + 0.25*relFix) * 0.75 * 0.5 = (0.75*(100.-50.)+0.25*(50.-0.))*0.75*0.5 = 18.75
|
//(0.75*absFix + 0.25*relFix) * 0.75 * 0.5 = (0.75*(100.-50.)+0.25*(50.-0.))*0.75*0.5 = 18.75
|
||||||
assertEquals(18.75, calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
assertEquals(18.75, calc.getInsertionData(route, job, medium, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenOldVehicleIsNotNullAndCurrentLoadIs25AndSolutionIs50PercentCompleteAndWeightIs05_itShouldReturnCorrectVal() {
|
public void whenOldVehicleIsNotNullAndCurrentLoadIs25AndSolutionIs50PercentCompleteAndWeightIs05_itShouldReturnCorrectVal() {
|
||||||
calc.setSolutionCompletenessRatio(0.5);
|
calc.setSolutionCompletenessRatio(0.5);
|
||||||
calc.setWeightOfFixCost(.5);
|
calc.setWeightOfFixCost(.5);
|
||||||
when(route.getVehicle()).thenReturn(oVehicle);
|
when(route.getVehicle()).thenReturn(small);
|
||||||
when(stateGetter.getRouteState(route, InternalStates.MAXLOAD, Capacity.class)).thenReturn(Capacity.Builder.newInstance().addDimension(0, 25).build());
|
when(stateGetter.getRouteState(route, InternalStates.MAXLOAD, Capacity.class)).thenReturn(Capacity.Builder.newInstance().addDimension(0, 25).build());
|
||||||
//(0.5*absFix + 0.5*relFix) * 0.5 * 0.= (0.5*(100-50)+0.5*(75-25))*0.5*0.5 = 12.5
|
//(0.5*absFix + 0.5*relFix) * 0.5 * 0.= (0.5*(100-50)+0.5*(75-25))*0.5*0.5 = 12.5
|
||||||
assertEquals(12.5, calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
assertEquals(12.5, calc.getInsertionData(route, job, medium, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenOldVehicleIsNotNullAndCurrentLoadIs25AndSolutionIs75PercentCompleteAndWeightIs05_itShouldReturnCorrectVal() {
|
public void whenOldVehicleIsNotNullAndCurrentLoadIs25AndSolutionIs75PercentCompleteAndWeightIs05_itShouldReturnCorrectVal() {
|
||||||
calc.setSolutionCompletenessRatio(0.75);
|
calc.setSolutionCompletenessRatio(0.75);
|
||||||
calc.setWeightOfFixCost(0.5);
|
calc.setWeightOfFixCost(0.5);
|
||||||
when(route.getVehicle()).thenReturn(oVehicle);
|
when(route.getVehicle()).thenReturn(small);
|
||||||
//(0.75*absFix + 0.25*relFix) * 0.75 * 0.5 = (0.75*(100.-50.)+0.25*(75.-25.))*0.75*0.5 = 18.75
|
//(0.75*absFix + 0.25*relFix) * 0.75 * 0.5 = (0.75*(100.-50.)+0.25*(75.-25.))*0.75*0.5 = 18.75
|
||||||
assertEquals(18.75, calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
assertEquals(18.75, calc.getInsertionData(route, job, medium, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -234,12 +241,12 @@ public class JobInsertionConsideringFixCostsCalculatorTest {
|
||||||
when(job.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 50).addDimension(1, 0).build());
|
when(job.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 50).addDimension(1, 0).build());
|
||||||
|
|
||||||
VehicleType oType = VehicleTypeImpl.Builder.newInstance("otype").addCapacityDimension(0, 50).addCapacityDimension(1, 100).setFixedCost(50.0).build();
|
VehicleType oType = VehicleTypeImpl.Builder.newInstance("otype").addCapacityDimension(0, 50).addCapacityDimension(1, 100).setFixedCost(50.0).build();
|
||||||
when(oVehicle.getType()).thenReturn(oType);
|
when(small.getType()).thenReturn(oType);
|
||||||
|
|
||||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("type").addCapacityDimension(0, 100).addCapacityDimension(1, 400).setFixedCost(100.0).build();
|
VehicleType type = VehicleTypeImpl.Builder.newInstance("type").addCapacityDimension(0, 100).addCapacityDimension(1, 400).setFixedCost(100.0).build();
|
||||||
when(nVehicle.getType()).thenReturn(type);
|
when(medium.getType()).thenReturn(type);
|
||||||
|
|
||||||
when(route.getVehicle()).thenReturn(oVehicle);
|
when(route.getVehicle()).thenReturn(small);
|
||||||
when(stateGetter.getRouteState(route, InternalStates.MAXLOAD, Capacity.class)).thenReturn(Capacity.Builder.newInstance().addDimension(0, 25).addDimension(1, 100).build());
|
when(stateGetter.getRouteState(route, InternalStates.MAXLOAD, Capacity.class)).thenReturn(Capacity.Builder.newInstance().addDimension(0, 25).addDimension(1, 100).build());
|
||||||
//(0.5*absFix + 0.5*relFix) * 0.5 * 0.= (0.5*(100-50)+0.5*(75-25))*0.5*0.5 = 12.5
|
//(0.5*absFix + 0.5*relFix) * 0.5 * 0.= (0.5*(100-50)+0.5*(75-25))*0.5*0.5 = 12.5
|
||||||
/*
|
/*
|
||||||
|
|
@ -249,7 +256,99 @@ public class JobInsertionConsideringFixCostsCalculatorTest {
|
||||||
* = (0.5*(100-50)+0.5*((75/100+100/400)/2.*100 - ((25/50+100/100)/2.*50.)))*0.5*0.5
|
* = (0.5*(100-50)+0.5*((75/100+100/400)/2.*100 - ((25/50+100/100)/2.*50.)))*0.5*0.5
|
||||||
* = (0.5*(100-50)+0.5*12.5)*0.5*0.5 = 7.8125
|
* = (0.5*(100-50)+0.5*12.5)*0.5*0.5 = 7.8125
|
||||||
*/
|
*/
|
||||||
assertEquals(7.8125, calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
assertEquals(7.8125, calc.getInsertionData(route, job, medium, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenOldVehicleIsMoreExpensive() {
|
||||||
|
calc.setSolutionCompletenessRatio(1);
|
||||||
|
calc.setWeightOfFixCost(1);
|
||||||
|
|
||||||
|
when(job.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 50).addDimension(1, 0).build());
|
||||||
|
|
||||||
|
VehicleType oType = VehicleTypeImpl.Builder.newInstance("otype").addCapacityDimension(0, 50).addCapacityDimension(1, 100).setFixedCost(50.0).build();
|
||||||
|
when(medium.getType()).thenReturn(oType);
|
||||||
|
|
||||||
|
VehicleType type = VehicleTypeImpl.Builder.newInstance("type").addCapacityDimension(0, 100).addCapacityDimension(1, 400).setFixedCost(100.0).build();
|
||||||
|
when(small.getType()).thenReturn(type);
|
||||||
|
|
||||||
|
|
||||||
|
when(route.getVehicle()).thenReturn(small);
|
||||||
|
when(stateGetter.getRouteState(route, InternalStates.MAXLOAD, Capacity.class)).thenReturn(Capacity.Builder.newInstance().addDimension(0, 25).addDimension(1, 100).build());
|
||||||
|
//(0.5*absFix + 0.5*relFix) * 0.5 * 0.= (0.5*(100-50)+0.5*(75-25))*0.5*0.5 = 12.5
|
||||||
|
/*
|
||||||
|
* (0.5*(100-50)+0.5*(
|
||||||
|
* relFixNew - relFixOld = (75/100+100/400)/2.*100 - ((25/50+100/100)/2.*50.) =
|
||||||
|
* )*0.5*0.5
|
||||||
|
* = (0.5*(100-50)+0.5*((75/100+100/400)/2.*100 - ((25/50+100/100)/2.*50.)))*0.5*0.5
|
||||||
|
* = (0.5*(100-50)+0.5*12.5)*0.5*0.5 = 7.8125
|
||||||
|
*/
|
||||||
|
double insertionCost = calc.getInsertionData(route, job, medium, 0.0, null, Double.MAX_VALUE).getInsertionCost();
|
||||||
|
assertEquals(-50d, insertionCost, 0.01);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void smallVSMediumAbsCosts() {
|
||||||
|
calc.setSolutionCompletenessRatio(1);
|
||||||
|
calc.setWeightOfFixCost(1);
|
||||||
|
when(route.getVehicle()).thenReturn(small);
|
||||||
|
double insertionCost = calc.getInsertionData(route, job, medium, 0.0, null, Double.MAX_VALUE).getInsertionCost();
|
||||||
|
assertEquals(50d, insertionCost, 0.01);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void smallVSLargeAbsCosts() {
|
||||||
|
calc.setSolutionCompletenessRatio(1);
|
||||||
|
calc.setWeightOfFixCost(1);
|
||||||
|
when(route.getVehicle()).thenReturn(small);
|
||||||
|
double insertionCost = calc.getInsertionData(route, job, large, 0.0, null, Double.MAX_VALUE).getInsertionCost();
|
||||||
|
assertEquals(150d, insertionCost, 0.01);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void largeVSMediumAbsCosts() {
|
||||||
|
calc.setSolutionCompletenessRatio(1);
|
||||||
|
calc.setWeightOfFixCost(1);
|
||||||
|
when(route.getVehicle()).thenReturn(large);
|
||||||
|
double insertionCost = calc.getInsertionData(route, job, medium, 0.0, null, Double.MAX_VALUE).getInsertionCost();
|
||||||
|
assertEquals(-100d, insertionCost, 0.01);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mediumVSLargeAbsCosts() {
|
||||||
|
calc.setSolutionCompletenessRatio(1);
|
||||||
|
calc.setWeightOfFixCost(1);
|
||||||
|
when(route.getVehicle()).thenReturn(medium);
|
||||||
|
double insertionCost = calc.getInsertionData(route, job, large, 0.0, null, Double.MAX_VALUE).getInsertionCost();
|
||||||
|
assertEquals(100d, insertionCost, 0.01);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenOldVehicleIsMoreExpensive2() {
|
||||||
|
calc.setSolutionCompletenessRatio(0.1);
|
||||||
|
calc.setWeightOfFixCost(1);
|
||||||
|
|
||||||
|
when(job.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 50).addDimension(1, 0).build());
|
||||||
|
|
||||||
|
VehicleType oType = VehicleTypeImpl.Builder.newInstance("otype").addCapacityDimension(0, 50).addCapacityDimension(1, 100).setFixedCost(50.0).build();
|
||||||
|
when(medium.getType()).thenReturn(oType);
|
||||||
|
|
||||||
|
VehicleType type = VehicleTypeImpl.Builder.newInstance("type").addCapacityDimension(0, 100).addCapacityDimension(1, 400).setFixedCost(100.0).build();
|
||||||
|
when(small.getType()).thenReturn(type);
|
||||||
|
|
||||||
|
|
||||||
|
when(route.getVehicle()).thenReturn(small);
|
||||||
|
when(stateGetter.getRouteState(route, InternalStates.MAXLOAD, Capacity.class)).thenReturn(Capacity.Builder.newInstance().addDimension(0, 25).addDimension(1, 100).build());
|
||||||
|
//(0.5*absFix + 0.5*relFix) * 0.5 * 0.= (0.5*(100-50)+0.5*(75-25))*0.5*0.5 = 12.5
|
||||||
|
/*
|
||||||
|
* (0.5*(100-50)+0.5*(
|
||||||
|
* relFixNew - relFixOld = (75/100+100/400)/2.*100 - ((25/50+100/100)/2.*50.) =
|
||||||
|
* )*0.5*0.5
|
||||||
|
* = (0.5*(100-50)+0.5*((75/100+100/400)/2.*100 - ((25/50+100/100)/2.*50.)))*0.5*0.5
|
||||||
|
* = (0.5*(100-50)+0.5*12.5)*0.5*0.5 = 7.8125
|
||||||
|
*/
|
||||||
|
double insertionCost = calc.getInsertionData(route, job, medium, 0.0, null, Double.MAX_VALUE).getInsertionCost();
|
||||||
|
assertEquals(-50d, insertionCost, 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -259,16 +358,16 @@ public class JobInsertionConsideringFixCostsCalculatorTest {
|
||||||
when(job.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 50).addDimension(1, 0).build());
|
when(job.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 50).addDimension(1, 0).build());
|
||||||
|
|
||||||
VehicleType oType = VehicleTypeImpl.Builder.newInstance("otype").addCapacityDimension(0, 50).addCapacityDimension(1, 100).setFixedCost(50.0).build();
|
VehicleType oType = VehicleTypeImpl.Builder.newInstance("otype").addCapacityDimension(0, 50).addCapacityDimension(1, 100).setFixedCost(50.0).build();
|
||||||
when(oVehicle.getType()).thenReturn(oType);
|
when(small.getType()).thenReturn(oType);
|
||||||
|
|
||||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("type").addCapacityDimension(0, 100).addCapacityDimension(1, 400).setFixedCost(100.0).build();
|
VehicleType type = VehicleTypeImpl.Builder.newInstance("type").addCapacityDimension(0, 100).addCapacityDimension(1, 400).setFixedCost(100.0).build();
|
||||||
when(nVehicle.getType()).thenReturn(type);
|
when(medium.getType()).thenReturn(type);
|
||||||
|
|
||||||
when(route.getVehicle()).thenReturn(oVehicle);
|
when(route.getVehicle()).thenReturn(small);
|
||||||
when(stateGetter.getRouteState(route, InternalStates.MAXLOAD, Capacity.class)).thenReturn(Capacity.Builder.newInstance().addDimension(0, 25).addDimension(1, 100).build());
|
when(stateGetter.getRouteState(route, InternalStates.MAXLOAD, Capacity.class)).thenReturn(Capacity.Builder.newInstance().addDimension(0, 25).addDimension(1, 100).build());
|
||||||
//(0.75*absFix + 0.25*relFix) * 0.75 * 0.5 = (0.75*(100.-50.)+0.25*12.5)*0.75*0.5 = 15.234375
|
//(0.75*absFix + 0.25*relFix) * 0.75 * 0.5 = (0.75*(100.-50.)+0.25*12.5)*0.75*0.5 = 15.234375
|
||||||
|
|
||||||
assertEquals(15.234375, calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
assertEquals(15.234375, calc.getInsertionData(route, job, medium, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue