mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
added tests to reproduce bug #104
This commit is contained in:
parent
6ce0ff7ac1
commit
cf5b5fa267
1 changed files with 173 additions and 3 deletions
|
|
@ -4,7 +4,14 @@ import static org.junit.Assert.assertFalse;
|
|||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import jsprit.core.algorithm.state.StateManager;
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.cost.AbstractForwardVehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
import jsprit.core.problem.job.Delivery;
|
||||
import jsprit.core.problem.job.Pickup;
|
||||
import jsprit.core.problem.job.Service;
|
||||
|
|
@ -30,6 +37,21 @@ public class ServiceLoadRouteLevelConstraintTest {
|
|||
|
||||
ServiceLoadRouteLevelConstraint constraint;
|
||||
|
||||
VehicleRoutingTransportCosts routingCosts = new AbstractForwardVehicleRoutingTransportCosts() {
|
||||
|
||||
@Override
|
||||
public double getTransportTime(String fromId, String toId,double departureTime, Driver driver, Vehicle vehicle) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTransportCost(String fromId, String toId,double departureTime, Driver driver, Vehicle vehicle) {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
StateManager stateManager;
|
||||
|
||||
@Before
|
||||
public void doBefore(){
|
||||
VehicleType type = mock(VehicleType.class);
|
||||
|
|
@ -43,10 +65,12 @@ public class ServiceLoadRouteLevelConstraintTest {
|
|||
stateGetter = mock(RouteAndActivityStateGetter.class);
|
||||
when(stateGetter.getRouteState(route, StateFactory.LOAD_AT_BEGINNING, Capacity.class)).thenReturn(currentLoad);
|
||||
when(stateGetter.getRouteState(route, StateFactory.LOAD_AT_END, Capacity.class)).thenReturn(currentLoad);
|
||||
|
||||
|
||||
|
||||
when(stateGetter.getRouteState(route, StateFactory.MAXLOAD, Capacity.class)).thenReturn(currentLoad);
|
||||
|
||||
constraint = new ServiceLoadRouteLevelConstraint(stateGetter);
|
||||
|
||||
stateManager = new StateManager(routingCosts);
|
||||
stateManager.updateLoadStates();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -204,4 +228,150 @@ public class ServiceLoadRouteLevelConstraintTest {
|
|||
|
||||
assertTrue(constraint.fulfilled(iContext));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingAServiceAndNewVehicleDoesNotHaveTheCapacity_itShouldReturnFalse(){
|
||||
Service service = mock(Service.class);
|
||||
when(service.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 2).build());
|
||||
|
||||
Capacity atBeginning = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).addDimension(2, 1).build();
|
||||
Capacity atEnd = Capacity.Builder.newInstance().addDimension(0, 0).addDimension(1, 0).addDimension(2, 0).build();
|
||||
|
||||
RouteAndActivityStateGetter stateGetter = mock(RouteAndActivityStateGetter.class);
|
||||
when(stateGetter.getRouteState(route, StateFactory.LOAD_AT_BEGINNING, Capacity.class)).thenReturn(atBeginning);
|
||||
when(stateGetter.getRouteState(route, StateFactory.LOAD_AT_END, Capacity.class)).thenReturn(atEnd);
|
||||
when(stateGetter.getRouteState(route, StateFactory.MAXLOAD, Capacity.class)).thenReturn(atBeginning);
|
||||
|
||||
JobInsertionContext iContext = mock(JobInsertionContext.class);
|
||||
when(iContext.getJob()).thenReturn(service);
|
||||
when(iContext.getRoute()).thenReturn(route);
|
||||
|
||||
VehicleType type = mock(VehicleType.class);
|
||||
when(type.getCapacityDimensions()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 1).addDimension(2, 2).build());
|
||||
Vehicle vehicle = mock(Vehicle.class);
|
||||
when(vehicle.getType()).thenReturn(type);
|
||||
|
||||
when(iContext.getNewVehicle()).thenReturn(vehicle);
|
||||
|
||||
ServiceLoadRouteLevelConstraint constraint = new ServiceLoadRouteLevelConstraint(stateGetter);
|
||||
assertFalse(constraint.fulfilled(iContext));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingADeliveryAndNewVehicleDoesNotHaveTheCapacity_itShouldReturnFalse(){
|
||||
Service service = mock(Delivery.class);
|
||||
when(service.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 2).build());
|
||||
|
||||
Capacity atBeginning = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).addDimension(2, 1).build();
|
||||
Capacity atEnd = Capacity.Builder.newInstance().addDimension(0, 0).addDimension(1, 0).addDimension(2, 0).build();
|
||||
|
||||
RouteAndActivityStateGetter stateGetter = mock(RouteAndActivityStateGetter.class);
|
||||
when(stateGetter.getRouteState(route, StateFactory.LOAD_AT_BEGINNING, Capacity.class)).thenReturn(atBeginning);
|
||||
when(stateGetter.getRouteState(route, StateFactory.LOAD_AT_END, Capacity.class)).thenReturn(atEnd);
|
||||
when(stateGetter.getRouteState(route, StateFactory.MAXLOAD, Capacity.class)).thenReturn(atBeginning);
|
||||
|
||||
JobInsertionContext iContext = mock(JobInsertionContext.class);
|
||||
when(iContext.getJob()).thenReturn(service);
|
||||
when(iContext.getRoute()).thenReturn(route);
|
||||
|
||||
VehicleType type = mock(VehicleType.class);
|
||||
when(type.getCapacityDimensions()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 1).addDimension(2, 2).build());
|
||||
vehicle = mock(Vehicle.class);
|
||||
when(vehicle.getType()).thenReturn(type);
|
||||
|
||||
when(iContext.getNewVehicle()).thenReturn(vehicle);
|
||||
|
||||
ServiceLoadRouteLevelConstraint constraint = new ServiceLoadRouteLevelConstraint(stateGetter);
|
||||
assertFalse(constraint.fulfilled(iContext));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingAPickupAndNewVehicleDoesNotHaveTheCapacity_itShouldReturnFalse(){
|
||||
Pickup service = mock(Pickup.class);
|
||||
when(service.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 2).build());
|
||||
|
||||
Capacity atBeginning = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).addDimension(2, 1).build();
|
||||
Capacity atEnd = Capacity.Builder.newInstance().addDimension(0, 0).addDimension(1, 0).addDimension(2, 0).build();
|
||||
|
||||
RouteAndActivityStateGetter stateGetter = mock(RouteAndActivityStateGetter.class);
|
||||
when(stateGetter.getRouteState(route, StateFactory.LOAD_AT_BEGINNING, Capacity.class)).thenReturn(atBeginning);
|
||||
when(stateGetter.getRouteState(route, StateFactory.LOAD_AT_END, Capacity.class)).thenReturn(atEnd);
|
||||
when(stateGetter.getRouteState(route, StateFactory.MAXLOAD, Capacity.class)).thenReturn(atBeginning);
|
||||
|
||||
JobInsertionContext iContext = mock(JobInsertionContext.class);
|
||||
when(iContext.getJob()).thenReturn(service);
|
||||
when(iContext.getRoute()).thenReturn(route);
|
||||
|
||||
VehicleType type = mock(VehicleType.class);
|
||||
when(type.getCapacityDimensions()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 1).addDimension(2, 2).build());
|
||||
vehicle = mock(Vehicle.class);
|
||||
when(vehicle.getType()).thenReturn(type);
|
||||
|
||||
when(iContext.getNewVehicle()).thenReturn(vehicle);
|
||||
|
||||
ServiceLoadRouteLevelConstraint constraint = new ServiceLoadRouteLevelConstraint(stateGetter);
|
||||
assertFalse(constraint.fulfilled(iContext));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenNewVehicleCapacityIsNotSufficiant1_returnFalse(){
|
||||
Pickup service = mock(Pickup.class);
|
||||
when(service.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 2).build());
|
||||
|
||||
Service delivery = createDelivery("del1",3);
|
||||
VehicleRoute.Builder routeBuilder = VehicleRoute.Builder.newInstance(vehicle);
|
||||
routeBuilder.addService(delivery);
|
||||
VehicleRoute route = routeBuilder.build();
|
||||
|
||||
stateManager.informInsertionStarts(Arrays.asList(route), null);
|
||||
|
||||
VehicleType type = mock(VehicleType.class);
|
||||
when(type.getCapacityDimensions()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 2).build());
|
||||
Vehicle vehicle = mock(Vehicle.class);
|
||||
when(vehicle.getType()).thenReturn(type);
|
||||
|
||||
JobInsertionContext iContext = mock(JobInsertionContext.class);
|
||||
when(iContext.getJob()).thenReturn(service);
|
||||
when(iContext.getRoute()).thenReturn(route);
|
||||
when(iContext.getNewVehicle()).thenReturn(vehicle);
|
||||
|
||||
assertFalse(new ServiceLoadRouteLevelConstraint(stateManager).fulfilled(iContext));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenNewVehicleCapacityIsNotSufficiant2_returnFalse(){
|
||||
Pickup service = mock(Pickup.class);
|
||||
when(service.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 2).build());
|
||||
|
||||
Service serviceInRoute = createPickup("pick1",3);
|
||||
VehicleRoute.Builder routeBuilder = VehicleRoute.Builder.newInstance(vehicle);
|
||||
routeBuilder.addService(serviceInRoute);
|
||||
VehicleRoute route = routeBuilder.build();
|
||||
|
||||
stateManager.informInsertionStarts(Arrays.asList(route), null);
|
||||
|
||||
VehicleType type = mock(VehicleType.class);
|
||||
when(type.getCapacityDimensions()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 2).build());
|
||||
Vehicle vehicle = mock(Vehicle.class);
|
||||
when(vehicle.getType()).thenReturn(type);
|
||||
|
||||
JobInsertionContext iContext = mock(JobInsertionContext.class);
|
||||
when(iContext.getJob()).thenReturn(service);
|
||||
when(iContext.getRoute()).thenReturn(route);
|
||||
when(iContext.getNewVehicle()).thenReturn(vehicle);
|
||||
|
||||
assertFalse(new ServiceLoadRouteLevelConstraint(stateManager).fulfilled(iContext));
|
||||
}
|
||||
|
||||
|
||||
|
||||
private Service createPickup(String string, int i) {
|
||||
return Pickup.Builder.newInstance(string).addSizeDimension(0, i).setLocationId("loc").build();
|
||||
}
|
||||
|
||||
private Service createDelivery(String string, int i) {
|
||||
return Delivery.Builder.newInstance(string).addSizeDimension(0, i).setLocationId("loc").build();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue