mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
added indeces to main elements
This commit is contained in:
parent
aa1b7214ae
commit
4f2689529f
33 changed files with 512 additions and 243 deletions
|
|
@ -18,11 +18,6 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import jsprit.core.algorithm.recreate.listener.InsertionListeners;
|
||||
import jsprit.core.algorithm.state.StateManager;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
|
|
@ -38,6 +33,7 @@ import jsprit.core.problem.job.Pickup;
|
|||
import jsprit.core.problem.job.Shipment;
|
||||
import jsprit.core.problem.misc.JobInsertionContext;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.DeliverService;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
|
|
@ -45,10 +41,17 @@ import jsprit.core.problem.vehicle.VehicleImpl;
|
|||
import jsprit.core.problem.vehicle.VehicleType;
|
||||
import jsprit.core.problem.vehicle.VehicleTypeImpl;
|
||||
import jsprit.core.util.CostFactory;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
|
||||
public class ServiceInsertionAndLoadConstraintsTest {
|
||||
|
||||
|
|
@ -83,6 +86,8 @@ public class ServiceInsertionAndLoadConstraintsTest {
|
|||
ActivityInsertionCostsCalculator activityInsertionCostsCalculator;
|
||||
|
||||
ShipmentInsertionCalculator insertionCalculator;
|
||||
|
||||
VehicleRoutingProblem vehicleRoutingProblem;
|
||||
|
||||
Vehicle vehicle;
|
||||
|
||||
|
|
@ -93,6 +98,7 @@ public class ServiceInsertionAndLoadConstraintsTest {
|
|||
vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("0,0").setType(type).build();
|
||||
activityInsertionCostsCalculator = new LocalActivityInsertionCostsCalculator(routingCosts, activityCosts);
|
||||
createInsertionCalculator(hardRouteLevelConstraint);
|
||||
vehicleRoutingProblem = mock(VehicleRoutingProblem.class);
|
||||
}
|
||||
|
||||
private void createInsertionCalculator(HardRouteStateLevelConstraint hardRouteLevelConstraint) {
|
||||
|
|
@ -112,8 +118,10 @@ public class ServiceInsertionAndLoadConstraintsTest {
|
|||
VehicleRoute route = VehicleRoute.emptyRoute();
|
||||
route.setVehicleAndDepartureTime(vehicle, 0.0);
|
||||
|
||||
Inserter inserter = new Inserter(new InsertionListeners());
|
||||
|
||||
Inserter inserter = new Inserter(new InsertionListeners(), vehicleRoutingProblem);
|
||||
List<TourActivity> acts = new ArrayList<TourActivity>();
|
||||
acts.add(new DeliverService(delivery));
|
||||
when(vehicleRoutingProblem.copyAndGetActivities(delivery)).thenReturn(acts);
|
||||
inserter.insertJob(delivery, new InsertionData(0,0,0,vehicle,null), route);
|
||||
|
||||
VehicleRoutingProblem vrp = mock(VehicleRoutingProblem.class);
|
||||
|
|
|
|||
|
|
@ -18,21 +18,11 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import jsprit.core.algorithm.recreate.listener.InsertionListeners;
|
||||
import jsprit.core.algorithm.state.StateManager;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.constraint.ConstraintManager;
|
||||
import jsprit.core.problem.constraint.*;
|
||||
import jsprit.core.problem.constraint.ConstraintManager.Priority;
|
||||
import jsprit.core.problem.constraint.HardActivityStateLevelConstraint;
|
||||
import jsprit.core.problem.constraint.HardRouteStateLevelConstraint;
|
||||
import jsprit.core.problem.constraint.PickupAndDeliverShipmentLoadActivityLevelConstraint;
|
||||
import jsprit.core.problem.constraint.ShipmentPickupsFirstConstraint;
|
||||
import jsprit.core.problem.cost.VehicleRoutingActivityCosts;
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
|
|
@ -42,6 +32,8 @@ import jsprit.core.problem.job.Service;
|
|||
import jsprit.core.problem.job.Shipment;
|
||||
import jsprit.core.problem.misc.JobInsertionContext;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.DeliverShipment;
|
||||
import jsprit.core.problem.solution.route.activity.PickupShipment;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
|
|
@ -49,14 +41,24 @@ import jsprit.core.problem.vehicle.VehicleImpl;
|
|||
import jsprit.core.problem.vehicle.VehicleType;
|
||||
import jsprit.core.problem.vehicle.VehicleTypeImpl;
|
||||
import jsprit.core.util.CostFactory;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
|
||||
public class ShipmentInsertionCalculatorTest {
|
||||
|
||||
VehicleRoutingTransportCosts routingCosts;
|
||||
|
||||
VehicleRoutingProblem vehicleRoutingProblem;
|
||||
|
||||
VehicleRoutingActivityCosts activityCosts = new VehicleRoutingActivityCosts(){
|
||||
|
||||
|
|
@ -97,6 +99,7 @@ public class ShipmentInsertionCalculatorTest {
|
|||
vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("0,0").setType(type).build();
|
||||
activityInsertionCostsCalculator = new LocalActivityInsertionCostsCalculator(routingCosts, activityCosts);
|
||||
createInsertionCalculator(hardRouteLevelConstraint);
|
||||
vehicleRoutingProblem = mock(VehicleRoutingProblem.class);
|
||||
}
|
||||
|
||||
private void createInsertionCalculator(HardRouteStateLevelConstraint hardRouteLevelConstraint) {
|
||||
|
|
@ -119,20 +122,31 @@ public class ShipmentInsertionCalculatorTest {
|
|||
Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation("0,10").setDeliveryLocation("10,0").build();
|
||||
Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation("10,10").setDeliveryLocation("0,0").build();
|
||||
VehicleRoute route = VehicleRoute.emptyRoute();
|
||||
new Inserter(new InsertionListeners()).insertJob(shipment, new InsertionData(0,0,0,vehicle,null), route);
|
||||
when(vehicleRoutingProblem.copyAndGetActivities(shipment)).thenReturn(getTourActivities(shipment));
|
||||
new Inserter(new InsertionListeners(), vehicleRoutingProblem).insertJob(shipment, new InsertionData(0,0,0,vehicle,null), route);
|
||||
|
||||
InsertionData iData = insertionCalculator.getInsertionData(route, shipment2, vehicle, 0.0, null, Double.MAX_VALUE);
|
||||
assertEquals(0.0,iData.getInsertionCost(),0.05);
|
||||
assertEquals(1,iData.getPickupInsertionIndex());
|
||||
assertEquals(2,iData.getDeliveryInsertionIndex());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
private List<TourActivity> getTourActivities(Shipment shipment) {
|
||||
List<TourActivity> acts = new ArrayList<TourActivity>();
|
||||
PickupShipment pick = new PickupShipment(shipment);
|
||||
DeliverShipment del = new DeliverShipment(shipment);
|
||||
acts.add(pick);
|
||||
acts.add(del);
|
||||
return acts;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenInsertingShipmentInRouteWithNotEnoughCapacity_itShouldReturnNoInsertion(){
|
||||
Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation("0,10").setDeliveryLocation("10,0").build();
|
||||
Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation("10,10").setDeliveryLocation("0,0").build();
|
||||
VehicleRoute route = VehicleRoute.emptyRoute();
|
||||
new Inserter(new InsertionListeners()).insertJob(shipment, new InsertionData(0,0,0,vehicle,null), route);
|
||||
when(vehicleRoutingProblem.copyAndGetActivities(shipment)).thenReturn(getTourActivities(shipment));
|
||||
new Inserter(new InsertionListeners(), vehicleRoutingProblem).insertJob(shipment, new InsertionData(0,0,0,vehicle,null), route);
|
||||
createInsertionCalculator(new HardRouteStateLevelConstraint() {
|
||||
|
||||
@Override
|
||||
|
|
@ -154,7 +168,9 @@ public class ShipmentInsertionCalculatorTest {
|
|||
Shipment shipment3 = Shipment.Builder.newInstance("s3").addSizeDimension(0, 1).setPickupLocation("0,0").setDeliveryLocation("9,10").build();
|
||||
|
||||
VehicleRoute route = VehicleRoute.emptyRoute();
|
||||
Inserter inserter = new Inserter(new InsertionListeners());
|
||||
when(vehicleRoutingProblem.copyAndGetActivities(shipment)).thenReturn(getTourActivities(shipment));
|
||||
when(vehicleRoutingProblem.copyAndGetActivities(shipment2)).thenReturn(getTourActivities(shipment2));
|
||||
Inserter inserter = new Inserter(new InsertionListeners(),vehicleRoutingProblem );
|
||||
inserter.insertJob(shipment, new InsertionData(0,0,0,vehicle,null), route);
|
||||
inserter.insertJob(shipment2, new InsertionData(0,1,2,vehicle,null),route);
|
||||
|
||||
|
|
@ -169,9 +185,10 @@ public class ShipmentInsertionCalculatorTest {
|
|||
Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation("0,10").setDeliveryLocation("10,0").build();
|
||||
Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation("10,10").setDeliveryLocation("0,0").build();
|
||||
Shipment shipment3 = Shipment.Builder.newInstance("s3").addSizeDimension(0, 1).setPickupLocation("0,0").setDeliveryLocation("9,9").build();
|
||||
|
||||
when(vehicleRoutingProblem.copyAndGetActivities(shipment)).thenReturn(getTourActivities(shipment));
|
||||
when(vehicleRoutingProblem.copyAndGetActivities(shipment2)).thenReturn(getTourActivities(shipment2));
|
||||
VehicleRoute route = VehicleRoute.emptyRoute();
|
||||
Inserter inserter = new Inserter(new InsertionListeners());
|
||||
Inserter inserter = new Inserter(new InsertionListeners(), vehicleRoutingProblem);
|
||||
inserter.insertJob(shipment, new InsertionData(0,0,0,vehicle,null), route);
|
||||
inserter.insertJob(shipment2, new InsertionData(0,1,2,vehicle,null),route);
|
||||
|
||||
|
|
@ -186,13 +203,14 @@ public class ShipmentInsertionCalculatorTest {
|
|||
Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation("0,10").setDeliveryLocation("10,0").build();
|
||||
Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation("10,10").setDeliveryLocation("0,0").build();
|
||||
Shipment shipment3 = Shipment.Builder.newInstance("s3").addSizeDimension(0, 1).setPickupLocation("0,0").setDeliveryLocation("9,9").build();
|
||||
|
||||
|
||||
|
||||
VehicleRoute route = VehicleRoute.emptyRoute();
|
||||
|
||||
when(vehicleRoutingProblem.copyAndGetActivities(shipment)).thenReturn(getTourActivities(shipment));
|
||||
when(vehicleRoutingProblem.copyAndGetActivities(shipment2)).thenReturn(getTourActivities(shipment2));
|
||||
|
||||
VehicleRoute route = VehicleRoute.emptyRoute();
|
||||
route.setVehicleAndDepartureTime(vehicle, 0.0);
|
||||
|
||||
Inserter inserter = new Inserter(new InsertionListeners());
|
||||
Inserter inserter = new Inserter(new InsertionListeners(), vehicleRoutingProblem);
|
||||
|
||||
inserter.insertJob(shipment, new InsertionData(0,0,0,vehicle,null), route);
|
||||
inserter.insertJob(shipment2, new InsertionData(0,1,2,vehicle,null), route);
|
||||
|
|
@ -222,12 +240,12 @@ public class ShipmentInsertionCalculatorTest {
|
|||
Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation("10,10").setDeliveryLocation("0,0").build();
|
||||
VehicleRoute route = VehicleRoute.emptyRoute();
|
||||
route.setVehicleAndDepartureTime(vehicle, 0.0);
|
||||
|
||||
Inserter inserter = new Inserter(new InsertionListeners());
|
||||
when(vehicleRoutingProblem.copyAndGetActivities(shipment)).thenReturn(getTourActivities(shipment));
|
||||
when(vehicleRoutingProblem.copyAndGetActivities(shipment2)).thenReturn(getTourActivities(shipment2));
|
||||
Inserter inserter = new Inserter(new InsertionListeners(), vehicleRoutingProblem);
|
||||
|
||||
inserter.insertJob(shipment, new InsertionData(0,0,0,vehicle,null), route);
|
||||
inserter.insertJob(shipment2, new InsertionData(0,1,2,vehicle,null), route);
|
||||
// inserter.insertJob(shipment2, new InsertionData(0,1,2,vehicle,null), route);
|
||||
|
||||
VehicleRoutingProblem vrp = mock(VehicleRoutingProblem.class);
|
||||
|
||||
|
|
@ -237,8 +255,6 @@ public class ShipmentInsertionCalculatorTest {
|
|||
|
||||
ConstraintManager constraintManager = new ConstraintManager(vrp,stateManager);
|
||||
constraintManager.addLoadConstraint();
|
||||
// constraintManager.addConstraint(new PickupAndDeliverShipmentLoadActivityLevelConstraint(stateManager),Priority.CRITICAL);
|
||||
// constraintManager.addConstraint(new ShipmentPickupsFirstConstraint(),Priority.CRITICAL);
|
||||
|
||||
stateManager.informInsertionStarts(Arrays.asList(route), null);
|
||||
|
||||
|
|
|
|||
|
|
@ -16,17 +16,10 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import jsprit.core.algorithm.ExampleActivityCostFunction;
|
||||
import jsprit.core.algorithm.state.StateManager;
|
||||
import jsprit.core.algorithm.state.UpdateVariableCosts;
|
||||
import jsprit.core.problem.AbstractVehicle;
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.constraint.ConstraintManager;
|
||||
|
|
@ -45,12 +38,19 @@ import jsprit.core.problem.vehicle.Vehicle;
|
|||
import jsprit.core.problem.vehicle.VehicleType;
|
||||
import jsprit.core.util.Coordinate;
|
||||
import jsprit.core.util.ManhattanDistanceCalculator;
|
||||
|
||||
import org.apache.log4j.Level;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -60,9 +60,9 @@ public class TestCalculatesServiceInsertionOnRouteLevel {
|
|||
|
||||
VehicleRoutingTransportCosts costs;
|
||||
|
||||
Vehicle vehicle;
|
||||
AbstractVehicle vehicle;
|
||||
|
||||
Vehicle newVehicle;
|
||||
AbstractVehicle newVehicle;
|
||||
|
||||
private Service first;
|
||||
|
||||
|
|
@ -79,7 +79,7 @@ public class TestCalculatesServiceInsertionOnRouteLevel {
|
|||
Logger.getRootLogger().setLevel(Level.DEBUG);
|
||||
|
||||
costs = mock(VehicleRoutingTransportCosts.class);
|
||||
vehicle = mock(Vehicle.class);
|
||||
vehicle = mock(AbstractVehicle.class);
|
||||
VehicleType type = mock(VehicleType.class);
|
||||
|
||||
when(type.getCapacityDimensions()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1000).build());
|
||||
|
|
@ -91,7 +91,7 @@ public class TestCalculatesServiceInsertionOnRouteLevel {
|
|||
when(vehicle.getLatestArrival()).thenReturn(100.0);
|
||||
when(vehicle.isReturnToDepot()).thenReturn(true);
|
||||
|
||||
newVehicle = mock(Vehicle.class);
|
||||
newVehicle = mock(AbstractVehicle.class);
|
||||
when(newVehicle.getType()).thenReturn(type);
|
||||
when(newVehicle.getStartLocationId()).thenReturn("0,0");
|
||||
when(newVehicle.getEndLocationId()).thenReturn("0,0");
|
||||
|
|
|
|||
|
|
@ -18,25 +18,34 @@
|
|||
******************************************************************************/
|
||||
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.algorithm.state.UpdateEndLocationIfRouteIsOpen;
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
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.solution.route.activity.DeliverShipment;
|
||||
import jsprit.core.problem.solution.route.activity.PickupService;
|
||||
import jsprit.core.problem.solution.route.activity.PickupShipment;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.problem.vehicle.VehicleImpl;
|
||||
import jsprit.core.problem.vehicle.VehicleType;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class TestInserter {
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void whenInsertingServiceAndRouteIsClosed_itInsertsCorrectly(){
|
||||
Service service = mock(Service.class);
|
||||
|
|
@ -54,8 +63,13 @@ public class TestInserter {
|
|||
InsertionData iData = mock(InsertionData.class);
|
||||
when(iData.getDeliveryInsertionIndex()).thenReturn(1);
|
||||
when(iData.getSelectedVehicle()).thenReturn(vehicle);
|
||||
|
||||
Inserter inserter = new Inserter(mock(InsertionListeners.class));
|
||||
|
||||
VehicleRoutingProblem vehicleRoutingProblem = mock(VehicleRoutingProblem.class);
|
||||
List<TourActivity> acts = new ArrayList<TourActivity>();
|
||||
PickupService act = new PickupService(serviceToInsert);
|
||||
acts.add(act);
|
||||
when(vehicleRoutingProblem.copyAndGetActivities(serviceToInsert)).thenReturn(acts);
|
||||
Inserter inserter = new Inserter(mock(InsertionListeners.class), vehicleRoutingProblem);
|
||||
inserter.insertJob(serviceToInsert, iData, route);
|
||||
|
||||
assertEquals(2,route.getTourActivities().getActivities().size());
|
||||
|
|
@ -79,17 +93,26 @@ public class TestInserter {
|
|||
InsertionData iData = mock(InsertionData.class);
|
||||
when(iData.getDeliveryInsertionIndex()).thenReturn(1);
|
||||
when(iData.getSelectedVehicle()).thenReturn(vehicle);
|
||||
|
||||
Inserter inserter = new Inserter(mock(InsertionListeners.class));
|
||||
|
||||
VehicleRoutingProblem vehicleRoutingProblem = mock(VehicleRoutingProblem.class);
|
||||
when(vehicleRoutingProblem.copyAndGetActivities(serviceToInsert)).thenReturn(getTourActivities(serviceToInsert));
|
||||
|
||||
Inserter inserter = new Inserter(mock(InsertionListeners.class),vehicleRoutingProblem);
|
||||
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
|
||||
|
||||
private List<TourActivity> getTourActivities(Service serviceToInsert) {
|
||||
List<TourActivity> acts = new ArrayList<TourActivity>();
|
||||
acts.add(new PickupService(serviceToInsert));
|
||||
return acts;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void whenInsertingShipmentAndRouteIsClosed_itInsertsCorrectly(){
|
||||
Shipment shipment = mock(Shipment.class);
|
||||
Capacity capacity = Capacity.Builder.newInstance().build();
|
||||
|
|
@ -102,16 +125,20 @@ public class TestInserter {
|
|||
|
||||
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.getSize()).thenReturn(capacity);
|
||||
when(shipmentToInsert.getDeliveryLocation()).thenReturn("delLoc");
|
||||
when(shipmentToInsert.getPickupLocation()).thenReturn("pickLoc");
|
||||
Shipment shipmentToInsert = Shipment.Builder.newInstance("s").setDeliveryLocation("delLoc").setPickupLocation("pickLoc").build();
|
||||
// Shipment shipmentToInsert = mock(Shipment.class);
|
||||
// when(shipmentToInsert.getSize()).thenReturn(capacity);
|
||||
// when(shipmentToInsert.getDeliveryLocation()).thenReturn("delLoc");
|
||||
// when(shipmentToInsert.getPickupLocation()).thenReturn("pickLoc");
|
||||
// when(shipmentToInsert.getSize()).thenReturn(Capacity.Builder.newInstance().build());
|
||||
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));
|
||||
|
||||
VehicleRoutingProblem vehicleRoutingProblem = mock(VehicleRoutingProblem.class);
|
||||
when(vehicleRoutingProblem.copyAndGetActivities(shipmentToInsert)).thenReturn(getTourActivities(shipmentToInsert));
|
||||
Inserter inserter = new Inserter(mock(InsertionListeners.class), vehicleRoutingProblem);
|
||||
inserter.insertJob(shipmentToInsert, iData, route);
|
||||
|
||||
assertEquals(4,route.getTourActivities().getActivities().size());
|
||||
|
|
@ -119,8 +146,15 @@ public class TestInserter {
|
|||
assertEquals(route.getTourActivities().getActivities().get(3).getLocationId(),shipmentToInsert.getDeliveryLocation());
|
||||
assertEquals(route.getEnd().getLocationId(),vehicle.getEndLocationId());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
private List<TourActivity> getTourActivities(Shipment shipmentToInsert) {
|
||||
List<TourActivity> acts = new ArrayList<TourActivity>();
|
||||
acts.add(new PickupShipment(shipmentToInsert));
|
||||
acts.add(new DeliverShipment(shipmentToInsert));
|
||||
return acts;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenInsertingShipmentAndRouteIsOpen_itInsertsCorrectlyAndSwitchesEndLocation(){
|
||||
Shipment shipment = mock(Shipment.class);
|
||||
Capacity capacity = Capacity.Builder.newInstance().build();
|
||||
|
|
@ -131,16 +165,15 @@ public class TestInserter {
|
|||
|
||||
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.getSize()).thenReturn(capacity);
|
||||
when(shipmentToInsert.getDeliveryLocation()).thenReturn("delLoc");
|
||||
when(shipmentToInsert.getPickupLocation()).thenReturn("pickLoc");
|
||||
Shipment shipmentToInsert = Shipment.Builder.newInstance("s").setDeliveryLocation("delLoc").setPickupLocation("pickLoc").build();
|
||||
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));
|
||||
|
||||
VehicleRoutingProblem vehicleRoutingProblem = mock(VehicleRoutingProblem.class);
|
||||
when(vehicleRoutingProblem.copyAndGetActivities(shipmentToInsert)).thenReturn(getTourActivities(shipmentToInsert));
|
||||
Inserter inserter = new Inserter(mock(InsertionListeners.class), vehicleRoutingProblem);
|
||||
inserter.insertJob(shipmentToInsert, iData, route);
|
||||
|
||||
assertEquals(4,route.getTourActivities().getActivities().size());
|
||||
|
|
@ -159,17 +192,16 @@ public class TestInserter {
|
|||
|
||||
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.getSize()).thenReturn(capacity);
|
||||
when(shipmentToInsert.getDeliveryLocation()).thenReturn("delLoc");
|
||||
when(shipmentToInsert.getPickupLocation()).thenReturn("pickLoc");
|
||||
Shipment shipmentToInsert = Shipment.Builder.newInstance("s").setPickupLocation("pickLoc").setDeliveryLocation("delLoc").build();
|
||||
|
||||
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));
|
||||
|
||||
VehicleRoutingProblem vehicleRoutingProblem = mock(VehicleRoutingProblem.class);
|
||||
when(vehicleRoutingProblem.copyAndGetActivities(shipmentToInsert)).thenReturn(getTourActivities(shipmentToInsert));
|
||||
Inserter inserter = new Inserter(mock(InsertionListeners.class), vehicleRoutingProblem);
|
||||
inserter.insertJob(shipmentToInsert, iData, route);
|
||||
|
||||
assertEquals(route.getEnd().getLocationId(),newVehicle.getEndLocationId());
|
||||
|
|
@ -185,17 +217,16 @@ public class TestInserter {
|
|||
|
||||
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.getSize()).thenReturn(capacity);
|
||||
when(shipmentToInsert.getDeliveryLocation()).thenReturn("delLoc");
|
||||
when(shipmentToInsert.getPickupLocation()).thenReturn("pickLoc");
|
||||
|
||||
InsertionData iData = mock(InsertionData.class);
|
||||
Shipment shipmentToInsert = Shipment.Builder.newInstance("s").setPickupLocation("pickLoc").setDeliveryLocation("delLoc").build();
|
||||
|
||||
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));
|
||||
|
||||
VehicleRoutingProblem vehicleRoutingProblem = mock(VehicleRoutingProblem.class);
|
||||
when(vehicleRoutingProblem.copyAndGetActivities(shipmentToInsert)).thenReturn(getTourActivities(shipmentToInsert));
|
||||
Inserter inserter = new Inserter(mock(InsertionListeners.class),vehicleRoutingProblem );
|
||||
inserter.insertJob(shipmentToInsert, iData, route);
|
||||
|
||||
assertEquals("delLoc",route.getEnd().getLocationId());
|
||||
|
|
@ -212,17 +243,16 @@ public class TestInserter {
|
|||
|
||||
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.getSize()).thenReturn(capacity);
|
||||
when(shipmentToInsert.getDeliveryLocation()).thenReturn("delLoc");
|
||||
when(shipmentToInsert.getPickupLocation()).thenReturn("pickLoc");
|
||||
|
||||
InsertionData iData = mock(InsertionData.class);
|
||||
Shipment shipmentToInsert = Shipment.Builder.newInstance("s").setPickupLocation("pickLoc").setDeliveryLocation("delLoc").build();
|
||||
|
||||
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));
|
||||
|
||||
VehicleRoutingProblem vehicleRoutingProblem = mock(VehicleRoutingProblem.class);
|
||||
when(vehicleRoutingProblem.copyAndGetActivities(shipmentToInsert)).thenReturn(getTourActivities(shipmentToInsert));
|
||||
Inserter inserter = new Inserter(mock(InsertionListeners.class),vehicleRoutingProblem );
|
||||
inserter.insertJob(shipmentToInsert, iData, route);
|
||||
|
||||
UpdateEndLocationIfRouteIsOpen updateEnd = new UpdateEndLocationIfRouteIsOpen();
|
||||
|
|
|
|||
|
|
@ -16,37 +16,27 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.problem;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
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.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import jsprit.core.problem.VehicleRoutingProblem.FleetSize;
|
||||
import jsprit.core.problem.constraint.Constraint;
|
||||
import jsprit.core.problem.cost.AbstractForwardVehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.cost.VehicleRoutingActivityCosts;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
import jsprit.core.problem.driver.DriverImpl;
|
||||
import jsprit.core.problem.job.Delivery;
|
||||
import jsprit.core.problem.job.Pickup;
|
||||
import jsprit.core.problem.job.Service;
|
||||
import jsprit.core.problem.job.Shipment;
|
||||
import jsprit.core.problem.job.*;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.vehicle.PenaltyVehicleType;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.problem.vehicle.VehicleImpl;
|
||||
import jsprit.core.problem.vehicle.VehicleType;
|
||||
import jsprit.core.problem.vehicle.VehicleTypeImpl;
|
||||
import jsprit.core.problem.vehicle.*;
|
||||
import jsprit.core.util.Coordinate;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
|
||||
public class VehicleRoutingProblemTest {
|
||||
|
||||
|
|
@ -186,9 +176,11 @@ public class VehicleRoutingProblemTest {
|
|||
public void whenDelivieriesAreAdded_vrpShouldContainThem(){
|
||||
Delivery s1 = mock(Delivery.class);
|
||||
when(s1.getId()).thenReturn("s1");
|
||||
when(s1.getSize()).thenReturn(Capacity.Builder.newInstance().build());
|
||||
Delivery s2 = mock(Delivery.class);
|
||||
when(s2.getId()).thenReturn("s2");
|
||||
|
||||
when(s2.getSize()).thenReturn(Capacity.Builder.newInstance().build());
|
||||
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
vrpBuilder.addJob(s1).addJob(s2);
|
||||
|
||||
|
|
@ -203,9 +195,11 @@ public class VehicleRoutingProblemTest {
|
|||
public void whenDelivieriesAreAddedAllAtOnce_vrpShouldContainThem(){
|
||||
Delivery s1 = mock(Delivery.class);
|
||||
when(s1.getId()).thenReturn("s1");
|
||||
when(s1.getSize()).thenReturn(Capacity.Builder.newInstance().build());
|
||||
Delivery s2 = mock(Delivery.class);
|
||||
when(s2.getId()).thenReturn("s2");
|
||||
|
||||
when(s2.getSize()).thenReturn(Capacity.Builder.newInstance().build());
|
||||
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
vrpBuilder.addAllJobs(Arrays.asList(s1,s2));
|
||||
|
||||
|
|
@ -541,4 +535,33 @@ public class VehicleRoutingProblemTest {
|
|||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
assertFalse(vrp.getJobs().containsKey("myService"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingTwoJobs_theyShouldHaveProperIndeces(){
|
||||
Job service = Service.Builder.newInstance("myService").setLocationId("loc").build();
|
||||
Job shipment = Shipment.Builder.newInstance("shipment").setPickupLocation("pick").setDeliveryLocation("del").build();
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
vrpBuilder.addJob(service);
|
||||
vrpBuilder.addJob(shipment);
|
||||
vrpBuilder.build();
|
||||
|
||||
assertEquals(0,service.getIndex());
|
||||
assertEquals(1,shipment.getIndex());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingTwoVehicles_theyShouldHaveProperIndeces(){
|
||||
Vehicle veh1 = VehicleImpl.Builder.newInstance("v1").setStartLocationId("start").setStartLocationCoordinate(Coordinate.newInstance(0, 1)).setEndLocationId("end").build();
|
||||
Vehicle veh2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("start").setStartLocationCoordinate(Coordinate.newInstance(0, 1)).setEndLocationId("end").build();
|
||||
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
vrpBuilder.addVehicle(veh1);
|
||||
vrpBuilder.addVehicle(veh2);
|
||||
vrpBuilder.build();
|
||||
|
||||
assertEquals(0,veh1.getIndex());
|
||||
assertEquals(1,veh2.getIndex());
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue