1
0
Fork 0
mirror of https://github.com/graphhopper/jsprit.git synced 2020-01-24 07:45:05 +01:00
This commit is contained in:
Stefan Schroeder 2013-12-05 18:19:01 +01:00
parent d00f159404
commit aff324fb3f
4 changed files with 98 additions and 12 deletions

View file

@ -4,11 +4,14 @@ import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import jsprit.core.algorithm.recreate.listener.InsertionListeners;
import jsprit.core.algorithm.state.UpdateEndLocationIfRouteIsOpen;
import jsprit.core.problem.driver.Driver;
import jsprit.core.problem.job.Service;
import jsprit.core.problem.job.Shipment;
import jsprit.core.problem.solution.route.VehicleRoute;
import jsprit.core.problem.vehicle.Vehicle;
import jsprit.core.problem.vehicle.VehicleImpl;
import jsprit.core.problem.vehicle.VehicleType;
import org.junit.Test;
@ -118,5 +121,78 @@ public class TestInserter {
assertEquals(route.getTourActivities().getActivities().get(3).getLocationId(),shipmentToInsert.getDeliveryLocation());
assertEquals(route.getEnd().getLocationId(),shipmentToInsert.getDeliveryLocation());
}
@Test
public void whenSwitchingVehicleAndRouteIsClosed_newStartAndEndShouldBeTheLocationOfNewVehicle(){
Shipment shipment = mock(Shipment.class);
Vehicle vehicle = VehicleImpl.Builder.newInstance("vehId").setLocationId("vehLoc").setType(mock(VehicleType.class)).build();
Vehicle newVehicle = VehicleImpl.Builder.newInstance("newVehId").setLocationId("newVehLoc").setType(mock(VehicleType.class)).build();
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addPickup(shipment).addDelivery(shipment).build();
//start - pick(shipment) - del(shipment) - end
Shipment shipmentToInsert = mock(Shipment.class);
when(shipmentToInsert.getDeliveryLocation()).thenReturn("delLoc");
when(shipmentToInsert.getPickupLocation()).thenReturn("pickLoc");
InsertionData iData = mock(InsertionData.class);
when(iData.getPickupInsertionIndex()).thenReturn(2);
when(iData.getDeliveryInsertionIndex()).thenReturn(2);
when(iData.getSelectedVehicle()).thenReturn(newVehicle);
Inserter inserter = new Inserter(mock(InsertionListeners.class));
inserter.insertJob(shipmentToInsert, iData, route);
assertEquals(newVehicle.getLocationId(),route.getEnd().getLocationId());
}
@Test
public void whenSwitchingVehicleAndRouteIsOpen_endLocationShouldBeTheLocationOfTheLastActivity(){
Shipment shipment = mock(Shipment.class);
Vehicle vehicle = VehicleImpl.Builder.newInstance("vehId").setReturnToDepot(false).setLocationId("vehLoc").setType(mock(VehicleType.class)).build();
Vehicle newVehicle = VehicleImpl.Builder.newInstance("newVehId").setReturnToDepot(false).setLocationId("newVehLoc").setType(mock(VehicleType.class)).build();
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addPickup(shipment).addDelivery(shipment).build();
//start - pick(shipment) - del(shipment) - end
Shipment shipmentToInsert = mock(Shipment.class);
when(shipmentToInsert.getDeliveryLocation()).thenReturn("delLoc");
when(shipmentToInsert.getPickupLocation()).thenReturn("pickLoc");
InsertionData iData = mock(InsertionData.class);
when(iData.getPickupInsertionIndex()).thenReturn(2);
when(iData.getDeliveryInsertionIndex()).thenReturn(2);
when(iData.getSelectedVehicle()).thenReturn(newVehicle);
Inserter inserter = new Inserter(mock(InsertionListeners.class));
inserter.insertJob(shipmentToInsert, iData, route);
assertEquals("delLoc",route.getEnd().getLocationId());
}
@Test
public void whenInsertingShipmentAtBeginningAndSwitchingVehicleAndRouteIsOpen_endLocationShouldBeTheLocationOfTheLastActivity(){
Shipment shipment = mock(Shipment.class);
when(shipment.getDeliveryLocation()).thenReturn("oldShipmentDelLoc");
Vehicle vehicle = VehicleImpl.Builder.newInstance("vehId").setReturnToDepot(false).setLocationId("vehLoc").setType(mock(VehicleType.class)).build();
Vehicle newVehicle = VehicleImpl.Builder.newInstance("newVehId").setReturnToDepot(false).setLocationId("newVehLoc").setType(mock(VehicleType.class)).build();
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addPickup(shipment).addDelivery(shipment).build();
//start - pick(shipment) - del(shipment) - end
Shipment shipmentToInsert = mock(Shipment.class);
when(shipmentToInsert.getDeliveryLocation()).thenReturn("delLoc");
when(shipmentToInsert.getPickupLocation()).thenReturn("pickLoc");
InsertionData iData = mock(InsertionData.class);
when(iData.getPickupInsertionIndex()).thenReturn(0);
when(iData.getDeliveryInsertionIndex()).thenReturn(0);
when(iData.getSelectedVehicle()).thenReturn(newVehicle);
Inserter inserter = new Inserter(mock(InsertionListeners.class));
inserter.insertJob(shipmentToInsert, iData, route);
UpdateEndLocationIfRouteIsOpen updateEnd = new UpdateEndLocationIfRouteIsOpen();
updateEnd.visit(route);
assertEquals("oldShipmentDelLoc",route.getEnd().getLocationId());
}
}