mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
finalize test with open-routes
This commit is contained in:
parent
cf9d3c0779
commit
b52a103ae5
8 changed files with 192 additions and 178 deletions
|
|
@ -0,0 +1,103 @@
|
|||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import jsprit.core.problem.cost.VehicleRoutingActivityCosts;
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.solution.route.activity.End;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestAuxilliaryCostCalculator {
|
||||
|
||||
private VehicleRoutingTransportCosts routingCosts;
|
||||
|
||||
private VehicleRoutingActivityCosts actCosts;
|
||||
|
||||
private Vehicle vehicle;
|
||||
|
||||
@Before
|
||||
public void doBefore(){
|
||||
vehicle = mock(Vehicle.class);
|
||||
|
||||
routingCosts = mock(VehicleRoutingTransportCosts.class);
|
||||
actCosts = mock(VehicleRoutingActivityCosts.class);
|
||||
|
||||
when(routingCosts.getTransportCost("i", "j", 0.0, null, vehicle)).thenReturn(2.0);
|
||||
when(routingCosts.getTransportTime("i", "j", 0.0, null, vehicle)).thenReturn(0.0);
|
||||
when(routingCosts.getTransportCost("i", "k", 0.0, null, vehicle)).thenReturn(3.0);
|
||||
when(routingCosts.getTransportTime("i", "k", 0.0, null, vehicle)).thenReturn(0.0);
|
||||
when(routingCosts.getTransportCost("k", "j", 0.0, null, vehicle)).thenReturn(3.0);
|
||||
when(routingCosts.getTransportTime("k", "j", 0.0, null, vehicle)).thenReturn(0.0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRouteIsClosed_itCalculatesCostUpToEnd_v1(){
|
||||
TourActivity prevAct = mock(TourActivity.class);
|
||||
when(prevAct.getLocationId()).thenReturn("i");
|
||||
TourActivity nextAct = mock(TourActivity.class);
|
||||
when(nextAct.getLocationId()).thenReturn("j");
|
||||
TourActivity newAct = mock(TourActivity.class);
|
||||
when(newAct.getLocationId()).thenReturn("k");
|
||||
|
||||
when(vehicle.isReturnToDepot()).thenReturn(true);
|
||||
|
||||
AuxilliaryCostCalculator aCalc = new AuxilliaryCostCalculator(routingCosts, actCosts);
|
||||
double costs = aCalc.costOfPath(Arrays.asList(prevAct,newAct,nextAct), 0.0, null, vehicle);
|
||||
assertEquals(6.0,costs,0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRouteIsClosed_itCalculatesCostUpToEnd_v2(){
|
||||
TourActivity prevAct = mock(TourActivity.class);
|
||||
when(prevAct.getLocationId()).thenReturn("i");
|
||||
End nextAct = End.newInstance("j", 0.0, 0.0);
|
||||
TourActivity newAct = mock(TourActivity.class);
|
||||
when(newAct.getLocationId()).thenReturn("k");
|
||||
|
||||
when(vehicle.isReturnToDepot()).thenReturn(true);
|
||||
|
||||
AuxilliaryCostCalculator aCalc = new AuxilliaryCostCalculator(routingCosts, actCosts);
|
||||
double costs = aCalc.costOfPath(Arrays.asList(prevAct,newAct,nextAct), 0.0, null, vehicle);
|
||||
assertEquals(6.0,costs,0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRouteIsOpen_itCalculatesCostUpToEnd_v1(){
|
||||
TourActivity prevAct = mock(TourActivity.class);
|
||||
when(prevAct.getLocationId()).thenReturn("i");
|
||||
TourActivity nextAct = mock(TourActivity.class);
|
||||
when(nextAct.getLocationId()).thenReturn("j");
|
||||
TourActivity newAct = mock(TourActivity.class);
|
||||
when(newAct.getLocationId()).thenReturn("k");
|
||||
|
||||
when(vehicle.isReturnToDepot()).thenReturn(false);
|
||||
|
||||
AuxilliaryCostCalculator aCalc = new AuxilliaryCostCalculator(routingCosts, actCosts);
|
||||
double costs = aCalc.costOfPath(Arrays.asList(prevAct,newAct,nextAct), 0.0, null, vehicle);
|
||||
assertEquals(6.0,costs,0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRouteIsOpen_itCalculatesCostUpToEnd_v2(){
|
||||
TourActivity prevAct = mock(TourActivity.class);
|
||||
when(prevAct.getLocationId()).thenReturn("i");
|
||||
End nextAct = End.newInstance("j", 0.0, 0.0);
|
||||
TourActivity newAct = mock(TourActivity.class);
|
||||
when(newAct.getLocationId()).thenReturn("k");
|
||||
|
||||
when(vehicle.isReturnToDepot()).thenReturn(false);
|
||||
|
||||
AuxilliaryCostCalculator aCalc = new AuxilliaryCostCalculator(routingCosts, actCosts);
|
||||
double costs = aCalc.costOfPath(Arrays.asList(prevAct,newAct,nextAct), 0.0, null, vehicle);
|
||||
assertEquals(3.0,costs,0.01);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -83,12 +83,14 @@ public class TestCalculatesServiceInsertionOnRouteLevel {
|
|||
when(vehicle.getLocationId()).thenReturn("0,0");
|
||||
when(vehicle.getEarliestDeparture()).thenReturn(0.0);
|
||||
when(vehicle.getLatestArrival()).thenReturn(100.0);
|
||||
when(vehicle.isReturnToDepot()).thenReturn(true);
|
||||
|
||||
newVehicle = mock(Vehicle.class);
|
||||
when(newVehicle.getCapacity()).thenReturn(1000);
|
||||
when(newVehicle.getLocationId()).thenReturn("0,0");
|
||||
when(newVehicle.getEarliestDeparture()).thenReturn(0.0);
|
||||
when(newVehicle.getLatestArrival()).thenReturn(100.0);
|
||||
when(newVehicle.isReturnToDepot()).thenReturn(true);
|
||||
|
||||
driver = DriverImpl.noDriver();
|
||||
|
||||
|
|
@ -240,10 +242,5 @@ public class TestCalculatesServiceInsertionOnRouteLevel {
|
|||
assertEquals(2, iData.getDeliveryInsertionIndex());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenInsertingAndRouteIsOpen(){
|
||||
assertTrue(false);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,16 @@
|
|||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import jsprit.core.algorithm.recreate.ActivityInsertionCostsCalculator.ActivityInsertionCosts;
|
||||
import jsprit.core.problem.cost.VehicleRoutingActivityCosts;
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.misc.JobInsertionContext;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.End;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
|
@ -15,28 +23,91 @@ public class TestLocalActivityInsertionCostsCalculator {
|
|||
|
||||
LocalActivityInsertionCostsCalculator calc;
|
||||
|
||||
Vehicle vehicle;
|
||||
|
||||
VehicleRoute route;
|
||||
|
||||
JobInsertionContext jic;
|
||||
|
||||
@Before
|
||||
public void doBefore(){
|
||||
|
||||
vehicle = mock(Vehicle.class);
|
||||
route = mock(VehicleRoute.class);
|
||||
when(route.isEmpty()).thenReturn(false);
|
||||
when(route.getVehicle()).thenReturn(vehicle);
|
||||
|
||||
jic = mock(JobInsertionContext.class);
|
||||
when(jic.getRoute()).thenReturn(route);
|
||||
when(jic.getNewVehicle()).thenReturn(vehicle);
|
||||
|
||||
tpCosts = mock(VehicleRoutingTransportCosts.class);
|
||||
when(tpCosts.getTransportCost("i", "j", 0.0, null, vehicle)).thenReturn(2.0);
|
||||
when(tpCosts.getTransportTime("i", "j", 0.0, null, vehicle)).thenReturn(0.0);
|
||||
when(tpCosts.getTransportCost("i", "k", 0.0, null, vehicle)).thenReturn(3.0);
|
||||
when(tpCosts.getTransportTime("i", "k", 0.0, null, vehicle)).thenReturn(0.0);
|
||||
when(tpCosts.getTransportCost("k", "j", 0.0, null, vehicle)).thenReturn(3.0);
|
||||
when(tpCosts.getTransportTime("k", "j", 0.0, null, vehicle)).thenReturn(0.0);
|
||||
|
||||
actCosts = mock(VehicleRoutingActivityCosts.class);
|
||||
calc = new LocalActivityInsertionCostsCalculator(tpCosts, actCosts);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenInsertingActBetweenTwoRouteActs_itCalcsMarginalTpCosts(){
|
||||
VehicleRoutingTransportCosts tpCosts = mock(VehicleRoutingTransportCosts.class);
|
||||
VehicleRoutingActivityCosts actCosts = mock(VehicleRoutingActivityCosts.class);
|
||||
TourActivity prevAct = mock(TourActivity.class);
|
||||
when(prevAct.getLocationId()).thenReturn("i");
|
||||
TourActivity nextAct = mock(TourActivity.class);
|
||||
when(nextAct.getLocationId()).thenReturn("j");
|
||||
TourActivity newAct = mock(TourActivity.class);
|
||||
when(newAct.getLocationId()).thenReturn("k");
|
||||
|
||||
LocalActivityInsertionCostsCalculator calc = new LocalActivityInsertionCostsCalculator(tpCosts, actCosts);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenInsertingActBeforeEndANDRouteIsOpen_itReturnsTransportCostsToLastAct(){
|
||||
when(vehicle.isReturnToDepot()).thenReturn(true);
|
||||
|
||||
ActivityInsertionCosts costs = calc.getCosts(jic, prevAct, nextAct, newAct, 0.0);
|
||||
assertEquals(4.0,costs.getAdditionalCosts(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenInsertingActBeforeEndANDRouteIsClosed_itReturnsMarginalTpCosts(){
|
||||
public void whenInsertingActBetweenLastActAndEnd_itCalcsMarginalTpCosts(){
|
||||
TourActivity prevAct = mock(TourActivity.class);
|
||||
when(prevAct.getLocationId()).thenReturn("i");
|
||||
End nextAct = End.newInstance("j", 0.0, 0.0);
|
||||
TourActivity newAct = mock(TourActivity.class);
|
||||
when(newAct.getLocationId()).thenReturn("k");
|
||||
|
||||
when(vehicle.isReturnToDepot()).thenReturn(true);
|
||||
|
||||
ActivityInsertionCosts costs = calc.getCosts(jic, prevAct, nextAct, newAct, 0.0);
|
||||
assertEquals(4.0,costs.getAdditionalCosts(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenInsertingActBetweenTwoRouteActsAndRouteIsOpen_itCalcsMarginalTpCosts(){
|
||||
TourActivity prevAct = mock(TourActivity.class);
|
||||
when(prevAct.getLocationId()).thenReturn("i");
|
||||
TourActivity nextAct = mock(TourActivity.class);
|
||||
when(nextAct.getLocationId()).thenReturn("j");
|
||||
TourActivity newAct = mock(TourActivity.class);
|
||||
when(newAct.getLocationId()).thenReturn("k");
|
||||
|
||||
when(vehicle.isReturnToDepot()).thenReturn(false);
|
||||
|
||||
ActivityInsertionCosts costs = calc.getCosts(jic, prevAct, nextAct, newAct, 0.0);
|
||||
assertEquals(4.0,costs.getAdditionalCosts(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenInsertingActBetweenLastActAndEndAndRouteIsOpen_itCalculatesTpCostsFromPrevToNewAct(){
|
||||
TourActivity prevAct = mock(TourActivity.class);
|
||||
when(prevAct.getLocationId()).thenReturn("i");
|
||||
End nextAct = End.newInstance("j", 0.0, 0.0);
|
||||
TourActivity newAct = mock(TourActivity.class);
|
||||
when(newAct.getLocationId()).thenReturn("k");
|
||||
|
||||
when(vehicle.isReturnToDepot()).thenReturn(false);
|
||||
|
||||
ActivityInsertionCosts costs = calc.getCosts(jic, prevAct, nextAct, newAct, 0.0);
|
||||
assertEquals(3.0,costs.getAdditionalCosts(),0.01);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +0,0 @@
|
|||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
public class TestRouteLevelActivityInsertionCostsCalculator {
|
||||
|
||||
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue