mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
add tests verifying open-routes
This commit is contained in:
parent
d526ce0080
commit
cf9d3c0779
7 changed files with 1461 additions and 11 deletions
|
|
@ -267,9 +267,6 @@ public class TestCalculatesServiceInsertion {
|
|||
assertEquals(2, iData.getDeliveryInsertionIndex());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenInsertingAndRouteIsOpen(){
|
||||
assertTrue(false);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,122 @@
|
|||
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.listener.InsertionListeners;
|
||||
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 org.junit.Test;
|
||||
|
||||
public class TestInserter {
|
||||
|
||||
|
||||
@Test
|
||||
public void whenInsertingServiceAndRouteIsClosed_itInsertsCorrectly(){
|
||||
Service service = mock(Service.class);
|
||||
Vehicle vehicle = mock(Vehicle.class);
|
||||
when(vehicle.getLocationId()).thenReturn("vehLoc");
|
||||
when(vehicle.isReturnToDepot()).thenReturn(true);
|
||||
when(vehicle.getId()).thenReturn("vehId");
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addService(service).build();
|
||||
//start - pick(shipment) - del(shipment) - end
|
||||
Service serviceToInsert = mock(Service.class);
|
||||
when(serviceToInsert.getLocationId()).thenReturn("delLoc");
|
||||
|
||||
InsertionData iData = mock(InsertionData.class);
|
||||
when(iData.getDeliveryInsertionIndex()).thenReturn(1);
|
||||
when(iData.getSelectedVehicle()).thenReturn(vehicle);
|
||||
|
||||
Inserter inserter = new Inserter(mock(InsertionListeners.class));
|
||||
inserter.insertJob(serviceToInsert, iData, route);
|
||||
|
||||
assertEquals(2,route.getTourActivities().getActivities().size());
|
||||
assertEquals(route.getTourActivities().getActivities().get(1).getLocationId(),serviceToInsert.getLocationId());
|
||||
assertEquals(route.getEnd().getLocationId(),vehicle.getLocationId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenInsertingServiceAndRouteIsOpen_itInsertsCorrectlyAndSwitchesEndLocation(){
|
||||
Service service = mock(Service.class);
|
||||
Vehicle vehicle = mock(Vehicle.class);
|
||||
when(vehicle.getLocationId()).thenReturn("vehLoc");
|
||||
when(vehicle.isReturnToDepot()).thenReturn(false);
|
||||
when(vehicle.getId()).thenReturn("vehId");
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addService(service).build();
|
||||
Service serviceToInsert = mock(Service.class);
|
||||
when(serviceToInsert.getLocationId()).thenReturn("delLoc");
|
||||
|
||||
InsertionData iData = mock(InsertionData.class);
|
||||
when(iData.getDeliveryInsertionIndex()).thenReturn(1);
|
||||
when(iData.getSelectedVehicle()).thenReturn(vehicle);
|
||||
|
||||
Inserter inserter = new Inserter(mock(InsertionListeners.class));
|
||||
inserter.insertJob(serviceToInsert, iData, route);
|
||||
|
||||
assertEquals(2,route.getTourActivities().getActivities().size());
|
||||
assertEquals(route.getTourActivities().getActivities().get(1).getLocationId(),serviceToInsert.getLocationId());
|
||||
assertEquals(route.getEnd().getLocationId(),serviceToInsert.getLocationId());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void whenInsertingShipmentAndRouteIsClosed_itInsertsCorrectly(){
|
||||
Shipment shipment = mock(Shipment.class);
|
||||
Vehicle vehicle = mock(Vehicle.class);
|
||||
when(vehicle.getLocationId()).thenReturn("vehLoc");
|
||||
when(vehicle.isReturnToDepot()).thenReturn(true);
|
||||
when(vehicle.getId()).thenReturn("vehId");
|
||||
|
||||
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(vehicle);
|
||||
|
||||
Inserter inserter = new Inserter(mock(InsertionListeners.class));
|
||||
inserter.insertJob(shipmentToInsert, iData, route);
|
||||
|
||||
assertEquals(4,route.getTourActivities().getActivities().size());
|
||||
assertEquals(route.getTourActivities().getActivities().get(2).getLocationId(),shipmentToInsert.getPickupLocation());
|
||||
assertEquals(route.getTourActivities().getActivities().get(3).getLocationId(),shipmentToInsert.getDeliveryLocation());
|
||||
assertEquals(route.getEnd().getLocationId(),vehicle.getLocationId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenInsertingShipmentAndRouteIsOpen_itInsertsCorrectlyAndSwitchesEndLocation(){
|
||||
Shipment shipment = mock(Shipment.class);
|
||||
Vehicle vehicle = mock(Vehicle.class);
|
||||
when(vehicle.getLocationId()).thenReturn("vehLoc");
|
||||
when(vehicle.isReturnToDepot()).thenReturn(false);
|
||||
when(vehicle.getId()).thenReturn("vehId");
|
||||
|
||||
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(vehicle);
|
||||
|
||||
Inserter inserter = new Inserter(mock(InsertionListeners.class));
|
||||
inserter.insertJob(shipmentToInsert, iData, route);
|
||||
|
||||
assertEquals(4,route.getTourActivities().getActivities().size());
|
||||
assertEquals(route.getTourActivities().getActivities().get(2).getLocationId(),shipmentToInsert.getPickupLocation());
|
||||
assertEquals(route.getTourActivities().getActivities().get(3).getLocationId(),shipmentToInsert.getDeliveryLocation());
|
||||
assertEquals(route.getEnd().getLocationId(),shipmentToInsert.getDeliveryLocation());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,42 @@
|
|||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import jsprit.core.problem.cost.VehicleRoutingActivityCosts;
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestLocalActivityInsertionCostsCalculator {
|
||||
|
||||
VehicleRoutingTransportCosts tpCosts;
|
||||
|
||||
VehicleRoutingActivityCosts actCosts;
|
||||
|
||||
LocalActivityInsertionCostsCalculator calc;
|
||||
|
||||
@Before
|
||||
public void doBefore(){
|
||||
tpCosts = mock(VehicleRoutingTransportCosts.class);
|
||||
actCosts = mock(VehicleRoutingActivityCosts.class);
|
||||
calc = new LocalActivityInsertionCostsCalculator(tpCosts, actCosts);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenInsertingActBetweenTwoRouteActs_itCalcsMarginalTpCosts(){
|
||||
VehicleRoutingTransportCosts tpCosts = mock(VehicleRoutingTransportCosts.class);
|
||||
VehicleRoutingActivityCosts actCosts = mock(VehicleRoutingActivityCosts.class);
|
||||
|
||||
LocalActivityInsertionCostsCalculator calc = new LocalActivityInsertionCostsCalculator(tpCosts, actCosts);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenInsertingActBeforeEndANDRouteIsOpen_itReturnsTransportCostsToLastAct(){
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenInsertingActBeforeEndANDRouteIsClosed_itReturnsMarginalTpCosts(){
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
public class TestRouteLevelActivityInsertionCostsCalculator {
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
package jsprit.core.problem.solution.route;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
import jsprit.core.problem.job.Shipment;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
|
|
@ -60,18 +60,73 @@ public class VehicleRouteBuilderTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void whenBuildingOpenRoute(){
|
||||
assertTrue(false);
|
||||
public void whenBuildingClosedRoute_routeEndShouldHaveLocationOfVehicle(){
|
||||
Shipment s = mock(Shipment.class);
|
||||
Shipment s2 = mock(Shipment.class);
|
||||
Vehicle vehicle = mock(Vehicle.class);
|
||||
when(vehicle.isReturnToDepot()).thenReturn(true);
|
||||
when(vehicle.getLocationId()).thenReturn("vehLoc");
|
||||
VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class));
|
||||
builder.addPickup(s);
|
||||
builder.addPickup(s2);
|
||||
builder.addDelivery(s);
|
||||
builder.addDelivery(s2);
|
||||
VehicleRoute route = builder.build();
|
||||
assertEquals(route.getEnd().getLocationId(), vehicle.getLocationId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenBuildingOpenRoute_routeEndShouldHaveLocationOfLastActivity(){
|
||||
Shipment s = mock(Shipment.class);
|
||||
Shipment s2 = mock(Shipment.class);
|
||||
when(s2.getDeliveryLocation()).thenReturn("delLoc");
|
||||
Vehicle vehicle = mock(Vehicle.class);
|
||||
when(vehicle.isReturnToDepot()).thenReturn(false);
|
||||
when(vehicle.getLocationId()).thenReturn("vehLoc");
|
||||
VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class));
|
||||
builder.addPickup(s);
|
||||
builder.addPickup(s2);
|
||||
builder.addDelivery(s);
|
||||
builder.addDelivery(s2);
|
||||
VehicleRoute route = builder.build();
|
||||
assertEquals(route.getEnd().getLocationId(), s2.getDeliveryLocation());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingDepartureTime(){
|
||||
assertTrue(false);
|
||||
Shipment s = mock(Shipment.class);
|
||||
Shipment s2 = mock(Shipment.class);
|
||||
when(s2.getDeliveryLocation()).thenReturn("delLoc");
|
||||
Vehicle vehicle = mock(Vehicle.class);
|
||||
when(vehicle.isReturnToDepot()).thenReturn(false);
|
||||
when(vehicle.getLocationId()).thenReturn("vehLoc");
|
||||
VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class));
|
||||
builder.addPickup(s);
|
||||
builder.addPickup(s2);
|
||||
builder.addDelivery(s);
|
||||
builder.addDelivery(s2);
|
||||
builder.setDepartureTime(100);
|
||||
VehicleRoute route = builder.build();
|
||||
assertEquals(100.0,route.getDepartureTime(),0.01);
|
||||
assertEquals(100.0,route.getStart().getEndTime(),0.01);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void whenSettingEndTime(){
|
||||
assertTrue(false);
|
||||
Shipment s = mock(Shipment.class);
|
||||
Shipment s2 = mock(Shipment.class);
|
||||
when(s2.getDeliveryLocation()).thenReturn("delLoc");
|
||||
Vehicle vehicle = mock(Vehicle.class);
|
||||
when(vehicle.isReturnToDepot()).thenReturn(false);
|
||||
when(vehicle.getLocationId()).thenReturn("vehLoc");
|
||||
VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class));
|
||||
builder.addPickup(s);
|
||||
builder.addPickup(s2);
|
||||
builder.addDelivery(s);
|
||||
builder.addDelivery(s2);
|
||||
builder.setRouteEndArrivalTime(100.0);
|
||||
VehicleRoute route = builder.build();
|
||||
assertEquals(100.0,route.getEnd().getArrTime(),0.01);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue