mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
merge multiple time window branch
This commit is contained in:
commit
26d03f15e3
123 changed files with 9432 additions and 205 deletions
|
|
@ -0,0 +1,96 @@
|
|||
package jsprit.core.algorithm;
|
||||
|
||||
import jsprit.core.algorithm.box.Jsprit;
|
||||
import jsprit.core.problem.Location;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.job.Break;
|
||||
import jsprit.core.problem.job.Service;
|
||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
import jsprit.core.problem.solution.route.activity.BreakActivity;
|
||||
import jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.vehicle.VehicleImpl;
|
||||
import jsprit.core.problem.vehicle.VehicleType;
|
||||
import jsprit.core.problem.vehicle.VehicleTypeImpl;
|
||||
import jsprit.core.util.Solutions;
|
||||
import junit.framework.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Created by schroeder on 08/01/16.
|
||||
*/
|
||||
public class IgnoreBreakTimeWindowTest {
|
||||
|
||||
@Test
|
||||
public void doNotIgnoreBreakTW(){
|
||||
VehicleTypeImpl.Builder vehicleTypeBuilder = VehicleTypeImpl.Builder.newInstance("vehicleType");
|
||||
VehicleType vehicleType = vehicleTypeBuilder.setCostPerWaitingTime(0.8).build();
|
||||
|
||||
/*
|
||||
* get a vehicle-builder and build a vehicle located at (10,10) with type "vehicleType"
|
||||
*/
|
||||
|
||||
VehicleImpl vehicle2;
|
||||
{
|
||||
VehicleImpl.Builder vehicleBuilder = VehicleImpl.Builder.newInstance("v2");
|
||||
vehicleBuilder.setStartLocation(Location.newInstance(0, 0));
|
||||
vehicleBuilder.setType(vehicleType);
|
||||
vehicleBuilder.setEarliestStart(10).setLatestArrival(50);
|
||||
vehicleBuilder.setBreak(Break.Builder.newInstance("lunch").setTimeWindow(TimeWindow.newInstance(14, 14)).setServiceTime(1.).build());
|
||||
vehicle2 = vehicleBuilder.build();
|
||||
}
|
||||
/*
|
||||
* build services at the required locations, each with a capacity-demand of 1.
|
||||
*/
|
||||
|
||||
|
||||
Service service4 = Service.Builder.newInstance("2").setLocation(Location.newInstance(0, 0))
|
||||
.setServiceTime(1.).setTimeWindow(TimeWindow.newInstance(17,17)).build();
|
||||
|
||||
Service service5 = Service.Builder.newInstance("3").setLocation(Location.newInstance(0, 0))
|
||||
.setServiceTime(1.).setTimeWindow(TimeWindow.newInstance(18, 18)).build();
|
||||
|
||||
Service service7 = Service.Builder.newInstance("4").setLocation(Location.newInstance(0, 0))
|
||||
.setServiceTime(1.).setTimeWindow(TimeWindow.newInstance(10, 10)).build();
|
||||
|
||||
Service service8 = Service.Builder.newInstance("5").setLocation(Location.newInstance(0, 0))
|
||||
.setServiceTime(1.).setTimeWindow(TimeWindow.newInstance(12, 12)).build();
|
||||
|
||||
Service service10 = Service.Builder.newInstance("6").setLocation(Location.newInstance(0, 0))
|
||||
.setServiceTime(1.).setTimeWindow(TimeWindow.newInstance(16, 16)).build();
|
||||
|
||||
Service service11 = Service.Builder.newInstance("7").setLocation(Location.newInstance(0, 0))
|
||||
.setServiceTime(1.).setTimeWindow(TimeWindow.newInstance(13, 13)).build();
|
||||
|
||||
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance()
|
||||
.addVehicle(vehicle2)
|
||||
.addJob(service4)
|
||||
.addJob(service5).addJob(service7)
|
||||
.addJob(service8).addJob(service10).addJob(service11)
|
||||
.setFleetSize(VehicleRoutingProblem.FleetSize.FINITE)
|
||||
.build();
|
||||
|
||||
VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
|
||||
vra.setMaxIterations(50);
|
||||
|
||||
VehicleRoutingProblemSolution solution = Solutions.bestOf(vra.searchSolutions());
|
||||
|
||||
|
||||
Assert.assertTrue(breakShouldBeTime(solution));
|
||||
}
|
||||
|
||||
private boolean breakShouldBeTime(VehicleRoutingProblemSolution solution) {
|
||||
boolean inTime = true;
|
||||
for(TourActivity act : solution.getRoutes().iterator().next().getActivities()){
|
||||
if(act instanceof BreakActivity){
|
||||
if(act.getEndTime() < ((BreakActivity) act).getJob().getTimeWindow().getStart()){
|
||||
inTime = false;
|
||||
}
|
||||
if(act.getArrTime() > ((BreakActivity) act).getJob().getTimeWindow().getEnd()){
|
||||
inTime = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return inTime;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
package jsprit.core.algorithm;
|
||||
|
||||
import jsprit.core.algorithm.box.Jsprit;
|
||||
import jsprit.core.problem.Location;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.job.Service;
|
||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
import jsprit.core.problem.vehicle.VehicleImpl;
|
||||
import jsprit.core.util.Solutions;
|
||||
import junit.framework.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Created by schroeder on 26/05/15.
|
||||
*/
|
||||
public class MultipleTimeWindowsTest {
|
||||
|
||||
@Test
|
||||
public void service2ShouldNotBeInserted(){
|
||||
Service s = Service.Builder.newInstance("s1").setLocation(Location.newInstance(10,0)).build();
|
||||
|
||||
Service s2 = Service.Builder.newInstance("s2")
|
||||
.addTimeWindow(50.,60.)
|
||||
.setLocation(Location.newInstance(20, 0)).build();
|
||||
|
||||
VehicleImpl v = VehicleImpl.Builder.newInstance("v1").setStartLocation(Location.newInstance(0,0))
|
||||
.setEarliestStart(0.).setLatestArrival(40).build();
|
||||
|
||||
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(s).addJob(s2).addVehicle(v).build();
|
||||
VehicleRoutingAlgorithm algorithm = Jsprit.createAlgorithm(vrp);
|
||||
algorithm.setMaxIterations(100);
|
||||
VehicleRoutingProblemSolution solution = Solutions.bestOf(algorithm.searchSolutions());
|
||||
|
||||
Assert.assertEquals(1,solution.getUnassignedJobs().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void service2ShouldBeInsertedIntoNewVehicle(){
|
||||
Service s = Service.Builder.newInstance("s1").setLocation(Location.newInstance(10,0))
|
||||
.addTimeWindow(5.,15.).build();
|
||||
|
||||
Service s2 = Service.Builder.newInstance("s2")
|
||||
.addTimeWindow(50.,60.)
|
||||
.setLocation(Location.newInstance(20, 0)).build();
|
||||
|
||||
VehicleImpl v = VehicleImpl.Builder.newInstance("v1").setStartLocation(Location.newInstance(0,0))
|
||||
.setEarliestStart(0.).setLatestArrival(40).build();
|
||||
|
||||
VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(Location.newInstance(0,0))
|
||||
.setEarliestStart(40.).setLatestArrival(80).build();
|
||||
|
||||
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(s).addJob(s2).addVehicle(v).addVehicle(v2).build();
|
||||
VehicleRoutingAlgorithm algorithm = Jsprit.createAlgorithm(vrp);
|
||||
algorithm.setMaxIterations(100);
|
||||
VehicleRoutingProblemSolution solution = Solutions.bestOf(algorithm.searchSolutions());
|
||||
|
||||
Assert.assertEquals(0,solution.getUnassignedJobs().size());
|
||||
Assert.assertEquals(2, solution.getRoutes().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void service2ShouldBeInserted(){
|
||||
Service s = Service.Builder.newInstance("s1").setLocation(Location.newInstance(10,0)).build();
|
||||
|
||||
Service s2 = Service.Builder.newInstance("s2")
|
||||
.addTimeWindow(50., 60.).addTimeWindow(15., 25)
|
||||
.setLocation(Location.newInstance(20, 0)).build();
|
||||
|
||||
VehicleImpl v = VehicleImpl.Builder.newInstance("v1").setStartLocation(Location.newInstance(0,0))
|
||||
.setEarliestStart(0.).setLatestArrival(40).build();
|
||||
|
||||
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(s).addJob(s2).addVehicle(v).build();
|
||||
VehicleRoutingAlgorithm algorithm = Jsprit.createAlgorithm(vrp);
|
||||
algorithm.setMaxIterations(100);
|
||||
VehicleRoutingProblemSolution solution = Solutions.bestOf(algorithm.searchSolutions());
|
||||
|
||||
Assert.assertEquals(0,solution.getUnassignedJobs().size());
|
||||
}
|
||||
}
|
||||
|
|
@ -124,6 +124,7 @@ public class TestCalculatesServiceInsertion {
|
|||
states.updateLoadStates();
|
||||
states.updateTimeWindowStates();
|
||||
|
||||
|
||||
ConstraintManager cManager = new ConstraintManager(vrp, states);
|
||||
cManager.addLoadConstraint();
|
||||
cManager.addTimeWindowConstraint();
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ 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.TimeWindow;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.problem.vehicle.VehicleImpl;
|
||||
import jsprit.core.problem.vehicle.VehicleType;
|
||||
|
|
@ -53,6 +54,8 @@ public class TestInserter {
|
|||
when(vehicle.isReturnToDepot()).thenReturn(true);
|
||||
when(vehicle.getId()).thenReturn("vehId");
|
||||
|
||||
when(service.getTimeWindow()).thenReturn(mock(TimeWindow.class));
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addService(service).build();
|
||||
//start - pick(shipment) - del(shipment) - end
|
||||
Service serviceToInsert = mock(Service.class);
|
||||
|
|
@ -88,6 +91,8 @@ public class TestInserter {
|
|||
when(vehicle.isReturnToDepot()).thenReturn(false);
|
||||
when(vehicle.getId()).thenReturn("vehId");
|
||||
|
||||
when(service.getTimeWindow()).thenReturn(mock(TimeWindow.class));
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addService(service).build();
|
||||
Service serviceToInsert = mock(Service.class);
|
||||
when(serviceToInsert.getLocation()).thenReturn(Location.Builder.newInstance().setId("delLoc").build());
|
||||
|
|
@ -125,6 +130,9 @@ public class TestInserter {
|
|||
when(vehicle.isReturnToDepot()).thenReturn(true);
|
||||
when(vehicle.getId()).thenReturn("vehId");
|
||||
|
||||
when(shipment.getPickupTimeWindow()).thenReturn(mock(TimeWindow.class));
|
||||
when(shipment.getDeliveryTimeWindow()).thenReturn(mock(TimeWindow.class));
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addPickup(shipment).addDelivery(shipment).build();
|
||||
//start - pick(shipment) - del(shipment) - end
|
||||
Shipment shipmentToInsert = Shipment.Builder.newInstance("s").setDeliveryLocation(Location.newInstance("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
|
|
@ -161,6 +169,9 @@ public class TestInserter {
|
|||
when(vehicle.isReturnToDepot()).thenReturn(false);
|
||||
when(vehicle.getId()).thenReturn("vehId");
|
||||
|
||||
when(shipment.getPickupTimeWindow()).thenReturn(mock(TimeWindow.class));
|
||||
when(shipment.getDeliveryTimeWindow()).thenReturn(mock(TimeWindow.class));
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addPickup(shipment).addDelivery(shipment).build();
|
||||
//start - pick(shipment) - del(shipment) - end
|
||||
Shipment shipmentToInsert = Shipment.Builder.newInstance("s").setDeliveryLocation(Location.newInstance("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
|
|
@ -188,6 +199,9 @@ public class TestInserter {
|
|||
Vehicle vehicle = VehicleImpl.Builder.newInstance("vehId").setStartLocation(Location.newInstance("vehLoc")).setType(mock(VehicleType.class)).build();
|
||||
Vehicle newVehicle = VehicleImpl.Builder.newInstance("newVehId").setStartLocation(Location.newInstance("newVehLoc")).setType(mock(VehicleType.class)).build();
|
||||
|
||||
when(shipment.getPickupTimeWindow()).thenReturn(mock(TimeWindow.class));
|
||||
when(shipment.getDeliveryTimeWindow()).thenReturn(mock(TimeWindow.class));
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addPickup(shipment).addDelivery(shipment).build();
|
||||
//start - pick(shipment) - del(shipment) - end
|
||||
Shipment shipmentToInsert = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).setDeliveryLocation(Location.newInstance("delLoc")).build();
|
||||
|
|
@ -213,6 +227,9 @@ public class TestInserter {
|
|||
Vehicle vehicle = VehicleImpl.Builder.newInstance("vehId").setReturnToDepot(false).setStartLocation(Location.newInstance("vehLoc")).setType(mock(VehicleType.class)).build();
|
||||
Vehicle newVehicle = VehicleImpl.Builder.newInstance("newVehId").setReturnToDepot(false).setStartLocation(Location.newInstance("newVehLoc")).setType(mock(VehicleType.class)).build();
|
||||
|
||||
when(shipment.getPickupTimeWindow()).thenReturn(mock(TimeWindow.class));
|
||||
when(shipment.getDeliveryTimeWindow()).thenReturn(mock(TimeWindow.class));
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addPickup(shipment).addDelivery(shipment).build();
|
||||
//start - pick(shipment) - del(shipment) - end
|
||||
Shipment shipmentToInsert = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).setDeliveryLocation(Location.newInstance("delLoc")).build();
|
||||
|
|
@ -239,6 +256,9 @@ public class TestInserter {
|
|||
Vehicle vehicle = VehicleImpl.Builder.newInstance("vehId").setReturnToDepot(false).setStartLocation(Location.Builder.newInstance().setId("vehLoc").build()).setType(mock(VehicleType.class)).build();
|
||||
Vehicle newVehicle = VehicleImpl.Builder.newInstance("newVehId").setReturnToDepot(false).setStartLocation(Location.Builder.newInstance().setId("newVehLoc").build()).setType(mock(VehicleType.class)).build();
|
||||
|
||||
when(shipment.getPickupTimeWindow()).thenReturn(mock(TimeWindow.class));
|
||||
when(shipment.getDeliveryTimeWindow()).thenReturn(mock(TimeWindow.class));
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addPickup(shipment).addDelivery(shipment).build();
|
||||
//start - pick(shipment) - del(shipment) - end
|
||||
Shipment shipmentToInsert = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).setDeliveryLocation(Location.newInstance("delLoc")).build();
|
||||
|
|
|
|||
|
|
@ -171,6 +171,8 @@ public class TestLocalActivityInsertionCostsCalculator {
|
|||
TourActivity prevAct = vrp.getActivities(prevS).get(0);
|
||||
TourActivity newAct = vrp.getActivities(newS).get(0);
|
||||
TourActivity nextAct = vrp.getActivities(nextS).get(0);
|
||||
nextAct.setTheoreticalEarliestOperationStartTime(40);
|
||||
nextAct.setTheoreticalLatestOperationStartTime(80);
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(v).setJobActivityFactory(vrp.getJobActivityFactory()).addService(prevS).addService(nextS).build();
|
||||
JobInsertionContext context = new JobInsertionContext(route, newS, v, null, 0.);
|
||||
|
|
@ -204,6 +206,9 @@ public class TestLocalActivityInsertionCostsCalculator {
|
|||
Start prevAct = new Start(Location.newInstance(0, 0), 0, 100);
|
||||
TourActivity newAct = vrp.getActivities(newS).get(0);
|
||||
TourActivity nextAct = vrp.getActivities(nextS).get(0);
|
||||
nextAct.setTheoreticalEarliestOperationStartTime(40);
|
||||
nextAct.setTheoreticalLatestOperationStartTime(50);
|
||||
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(v).setJobActivityFactory(vrp.getJobActivityFactory()).addService(nextS).build();
|
||||
JobInsertionContext context = new JobInsertionContext(route, newS, v, null, 0.);
|
||||
|
|
@ -228,6 +233,9 @@ public class TestLocalActivityInsertionCostsCalculator {
|
|||
Start prevAct = new Start(Location.newInstance(0, 0), 0, 100);
|
||||
TourActivity newAct = vrp.getActivities(newS).get(0);
|
||||
TourActivity nextAct = vrp.getActivities(nextS).get(0);
|
||||
nextAct.setTheoreticalEarliestOperationStartTime(140);
|
||||
nextAct.setTheoreticalLatestOperationStartTime(150);
|
||||
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(v2).setJobActivityFactory(vrp.getJobActivityFactory()).addService(nextS).build();
|
||||
JobInsertionContext context = new JobInsertionContext(route, newS, v2, null, 0.);
|
||||
|
|
@ -248,6 +256,9 @@ public class TestLocalActivityInsertionCostsCalculator {
|
|||
|
||||
Start prevAct = new Start(Location.newInstance(0, 0), 0, 100);
|
||||
TourActivity newAct = vrp.getActivities(newS).get(0);
|
||||
newAct.setTheoreticalEarliestOperationStartTime(100);
|
||||
newAct.setTheoreticalLatestOperationStartTime(150);
|
||||
|
||||
End nextAct = new End(Location.newInstance(0, 0), 0, 100);
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(v).setJobActivityFactory(vrp.getJobActivityFactory()).build();
|
||||
|
|
@ -273,6 +284,9 @@ public class TestLocalActivityInsertionCostsCalculator {
|
|||
TourActivity prevAct = vrp.getActivities(prevS).get(0);
|
||||
TourActivity newAct = vrp.getActivities(newS).get(0);
|
||||
TourActivity nextAct = vrp.getActivities(nextS).get(0);
|
||||
nextAct.setTheoreticalEarliestOperationStartTime(40);
|
||||
nextAct.setTheoreticalLatestOperationStartTime(50);
|
||||
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(v).setJobActivityFactory(vrp.getJobActivityFactory()).addService(prevS).addService(nextS).build();
|
||||
JobInsertionContext context = new JobInsertionContext(route, newS, v, null, 0.);
|
||||
|
|
@ -296,7 +310,13 @@ public class TestLocalActivityInsertionCostsCalculator {
|
|||
|
||||
TourActivity prevAct = vrp.getActivities(prevS).get(0);
|
||||
TourActivity newAct = vrp.getActivities(newS).get(0);
|
||||
newAct.setTheoreticalEarliestOperationStartTime(100);
|
||||
newAct.setTheoreticalLatestOperationStartTime(120);
|
||||
|
||||
TourActivity nextAct = vrp.getActivities(nextS).get(0);
|
||||
nextAct.setTheoreticalEarliestOperationStartTime(40);
|
||||
nextAct.setTheoreticalLatestOperationStartTime(500);
|
||||
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(v).setJobActivityFactory(vrp.getJobActivityFactory()).addService(prevS).addService(nextS).build();
|
||||
JobInsertionContext context = new JobInsertionContext(route, newS, v, null, 0.);
|
||||
|
|
@ -323,7 +343,13 @@ public class TestLocalActivityInsertionCostsCalculator {
|
|||
|
||||
TourActivity prevAct = vrp.getActivities(prevS).get(0);
|
||||
TourActivity newAct = vrp.getActivities(newS).get(0);
|
||||
newAct.setTheoreticalEarliestOperationStartTime(100);
|
||||
newAct.setTheoreticalLatestOperationStartTime(120);
|
||||
|
||||
TourActivity nextAct = vrp.getActivities(nextS).get(0);
|
||||
nextAct.setTheoreticalEarliestOperationStartTime(400);
|
||||
nextAct.setTheoreticalLatestOperationStartTime(500);
|
||||
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(v).setJobActivityFactory(vrp.getJobActivityFactory()).addService(prevS).addService(nextS).addService(afterNextS).build();
|
||||
|
||||
|
|
@ -358,7 +384,21 @@ public class TestLocalActivityInsertionCostsCalculator {
|
|||
|
||||
TourActivity prevAct = vrp.getActivities(prevS).get(0);
|
||||
TourActivity newAct = vrp.getActivities(newS).get(0);
|
||||
newAct.setTheoreticalEarliestOperationStartTime(100);
|
||||
newAct.setTheoreticalLatestOperationStartTime(120);
|
||||
|
||||
TourActivity nextAct = vrp.getActivities(nextS).get(0);
|
||||
nextAct.setTheoreticalEarliestOperationStartTime(40);
|
||||
nextAct.setTheoreticalLatestOperationStartTime(500);
|
||||
|
||||
TourActivity afterNextAct = vrp.getActivities(afterNextS).get(0);
|
||||
afterNextAct.setTheoreticalEarliestOperationStartTime(80);
|
||||
afterNextAct.setTheoreticalLatestOperationStartTime(500);
|
||||
|
||||
TourActivity afterAfterNextAct = vrp.getActivities(afterAfterNextS).get(0);
|
||||
afterAfterNextAct.setTheoreticalEarliestOperationStartTime(100);
|
||||
afterAfterNextAct.setTheoreticalLatestOperationStartTime(500);
|
||||
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(v).setJobActivityFactory(vrp.getJobActivityFactory()).addService(prevS).addService(nextS).addService(afterNextS).addService(afterAfterNextS).build();
|
||||
|
||||
|
|
@ -396,7 +436,20 @@ public class TestLocalActivityInsertionCostsCalculator {
|
|||
|
||||
TourActivity prevAct = vrp.getActivities(prevS).get(0);
|
||||
TourActivity newAct = vrp.getActivities(newS).get(0);
|
||||
newAct.setTheoreticalEarliestOperationStartTime(100);
|
||||
newAct.setTheoreticalLatestOperationStartTime(120);
|
||||
|
||||
TourActivity nextAct = vrp.getActivities(nextS).get(0);
|
||||
nextAct.setTheoreticalEarliestOperationStartTime(40);
|
||||
nextAct.setTheoreticalLatestOperationStartTime(500);
|
||||
|
||||
TourActivity afterNextAct = vrp.getActivities(afterNextS).get(0);
|
||||
afterNextAct.setTheoreticalEarliestOperationStartTime(80);
|
||||
afterNextAct.setTheoreticalLatestOperationStartTime(500);
|
||||
|
||||
TourActivity afterAfterNextAct = vrp.getActivities(afterAfterNextS).get(0);
|
||||
afterAfterNextAct.setTheoreticalEarliestOperationStartTime(100);
|
||||
afterAfterNextAct.setTheoreticalLatestOperationStartTime(500);
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(v).setJobActivityFactory(vrp.getJobActivityFactory()).addService(prevS).addService(nextS).addService(afterNextS).addService(afterAfterNextS).build();
|
||||
JobInsertionContext context = new JobInsertionContext(route, newS, v, null, 0.);
|
||||
|
|
@ -438,7 +491,21 @@ public class TestLocalActivityInsertionCostsCalculator {
|
|||
|
||||
TourActivity prevAct = vrp.getActivities(prevS).get(0);
|
||||
TourActivity newAct = vrp.getActivities(newS).get(0);
|
||||
newAct.setTheoreticalEarliestOperationStartTime(100);
|
||||
newAct.setTheoreticalLatestOperationStartTime(120);
|
||||
|
||||
TourActivity nextAct = vrp.getActivities(nextS).get(0);
|
||||
nextAct.setTheoreticalEarliestOperationStartTime(40);
|
||||
nextAct.setTheoreticalLatestOperationStartTime(500);
|
||||
|
||||
TourActivity afterNextAct = vrp.getActivities(afterNextS).get(0);
|
||||
afterNextAct.setTheoreticalEarliestOperationStartTime(80);
|
||||
afterNextAct.setTheoreticalLatestOperationStartTime(500);
|
||||
|
||||
TourActivity afterAfterNextAct = vrp.getActivities(afterAfterNextS).get(0);
|
||||
afterAfterNextAct.setTheoreticalEarliestOperationStartTime(100);
|
||||
afterAfterNextAct.setTheoreticalLatestOperationStartTime(500);
|
||||
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(v).setJobActivityFactory(vrp.getJobActivityFactory()).addService(prevS).addService(nextS).addService(afterNextS).addService(afterAfterNextS).build();
|
||||
JobInsertionContext context = new JobInsertionContext(route, newS, v, null, 0.);
|
||||
|
|
@ -478,13 +545,29 @@ public class TestLocalActivityInsertionCostsCalculator {
|
|||
.addJob(afterNextS).addJob(afterAfterNextS).build();
|
||||
|
||||
TourActivity prevAct = vrp.getActivities(prevS).get(0);
|
||||
|
||||
TourActivity newAct = vrp.getActivities(newS).get(0);
|
||||
newAct.setTheoreticalEarliestOperationStartTime(50);
|
||||
newAct.setTheoreticalLatestOperationStartTime(70);
|
||||
|
||||
TourActivity nextAct = vrp.getActivities(nextS).get(0);
|
||||
nextAct.setTheoreticalEarliestOperationStartTime(40);
|
||||
nextAct.setTheoreticalLatestOperationStartTime(70);
|
||||
|
||||
TourActivity afterNextAct = vrp.getActivities(afterNextS).get(0);
|
||||
afterNextAct.setTheoreticalEarliestOperationStartTime(50);
|
||||
afterNextAct.setTheoreticalEarliestOperationStartTime(100);
|
||||
|
||||
TourActivity afterAfterNextAct = vrp.getActivities(afterAfterNextS).get(0);
|
||||
afterAfterNextAct.setTheoreticalEarliestOperationStartTime(100);
|
||||
afterAfterNextAct.setTheoreticalEarliestOperationStartTime(500);
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(v).setJobActivityFactory(vrp.getJobActivityFactory()).addService(prevS).addService(nextS).addService(afterNextS).addService(afterAfterNextS).build();
|
||||
JobInsertionContext context = new JobInsertionContext(route, newS, v, null, 0.);
|
||||
|
||||
StateManager stateManager = getStateManager(vrp, route);
|
||||
stateManager.updateTimeWindowStates();
|
||||
stateManager.informInsertionStarts(Arrays.asList(route),new ArrayList<Job>());
|
||||
|
||||
LocalActivityInsertionCostsCalculator calc = new LocalActivityInsertionCostsCalculator(CostFactory.createEuclideanCosts(), new WaitingTimeCosts(), stateManager);
|
||||
calc.setSolutionCompletenessRatio(1.);
|
||||
|
|
|
|||
|
|
@ -84,6 +84,15 @@ public class TestRouteLevelActivityInsertionCostEstimator {
|
|||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
final VehicleRoutingProblem vrp = vrpBuilder.addJob(s1).addJob(s2).addJob(s3).build();
|
||||
|
||||
vrp.getActivities(s1).get(0).setTheoreticalEarliestOperationStartTime(10);
|
||||
vrp.getActivities(s1).get(0).setTheoreticalLatestOperationStartTime(10);
|
||||
|
||||
vrp.getActivities(s2).get(0).setTheoreticalEarliestOperationStartTime(20);
|
||||
vrp.getActivities(s2).get(0).setTheoreticalLatestOperationStartTime(20);
|
||||
|
||||
vrp.getActivities(s3).get(0).setTheoreticalEarliestOperationStartTime(30);
|
||||
vrp.getActivities(s3).get(0).setTheoreticalLatestOperationStartTime(30);
|
||||
|
||||
route = VehicleRoute.Builder.newInstance(vehicle).setJobActivityFactory(new JobActivityFactory() {
|
||||
@Override
|
||||
public List<AbstractActivity> createActivities(Job job) {
|
||||
|
|
@ -123,6 +132,9 @@ public class TestRouteLevelActivityInsertionCostEstimator {
|
|||
public void whenNewActWithTWAndServiceTimeInBetweenFirstAndSecond_and_forwardLookingIs0_itShouldReturnCorrectCosts() {
|
||||
Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance("5,0")).setServiceTime(10.).setTimeWindow(TimeWindow.newInstance(5., 5.)).build();
|
||||
PickupActivity pickupService = new PickupService(s4);
|
||||
pickupService.setTheoreticalEarliestOperationStartTime(5);
|
||||
pickupService.setTheoreticalLatestOperationStartTime(5);
|
||||
|
||||
JobInsertionContext context = new JobInsertionContext(route, s4, route.getVehicle(), route.getDriver(), 0.);
|
||||
RouteLevelActivityInsertionCostsEstimator estimator = new RouteLevelActivityInsertionCostsEstimator(routingCosts, activityCosts, stateManager);
|
||||
estimator.setForwardLooking(0);
|
||||
|
|
@ -177,6 +189,8 @@ public class TestRouteLevelActivityInsertionCostEstimator {
|
|||
public void whenNewActWithTWInBetweenSecondAndThird_and_forwardLookingIs3_itShouldReturnCorrectCosts() {
|
||||
Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance("5,0")).setTimeWindow(TimeWindow.newInstance(5., 5.)).build();
|
||||
PickupActivity pickupService = new PickupService(s4);
|
||||
pickupService.setTheoreticalEarliestOperationStartTime(5);
|
||||
pickupService.setTheoreticalLatestOperationStartTime(5);
|
||||
JobInsertionContext context = new JobInsertionContext(route, s4, route.getVehicle(), route.getDriver(), 0.);
|
||||
RouteLevelActivityInsertionCostsEstimator estimator = new RouteLevelActivityInsertionCostsEstimator(routingCosts, activityCosts, stateManager);
|
||||
estimator.setForwardLooking(3);
|
||||
|
|
|
|||
|
|
@ -96,6 +96,15 @@ public class TestRouteLevelServiceInsertionCostEstimator {
|
|||
vrpBuilder.addVehicle(vehicle);
|
||||
vrp = vrpBuilder.build();
|
||||
|
||||
vrp.getActivities(s1).get(0).setTheoreticalEarliestOperationStartTime(10);
|
||||
vrp.getActivities(s1).get(0).setTheoreticalLatestOperationStartTime(10);
|
||||
|
||||
vrp.getActivities(s2).get(0).setTheoreticalEarliestOperationStartTime(20);
|
||||
vrp.getActivities(s2).get(0).setTheoreticalLatestOperationStartTime(20);
|
||||
|
||||
vrp.getActivities(s3).get(0).setTheoreticalEarliestOperationStartTime(30);
|
||||
vrp.getActivities(s3).get(0).setTheoreticalLatestOperationStartTime(30);
|
||||
|
||||
activityFactory = new JobActivityFactory() {
|
||||
@Override
|
||||
public List<AbstractActivity> createActivities(Job job) {
|
||||
|
|
@ -169,7 +178,10 @@ public class TestRouteLevelServiceInsertionCostEstimator {
|
|||
public List<AbstractActivity> createActivities(Job job) {
|
||||
List<AbstractActivity> acts = activityFactory.createActivities(job);
|
||||
if (acts.isEmpty()) {
|
||||
acts.add(new PickupService(s4));
|
||||
PickupService pickupService = new PickupService(s4);
|
||||
pickupService.setTheoreticalEarliestOperationStartTime(5);
|
||||
pickupService.setTheoreticalLatestOperationStartTime(5);
|
||||
acts.add(pickupService);
|
||||
}
|
||||
return acts;
|
||||
}
|
||||
|
|
@ -195,7 +207,10 @@ public class TestRouteLevelServiceInsertionCostEstimator {
|
|||
public List<AbstractActivity> createActivities(Job job) {
|
||||
List<AbstractActivity> acts = activityFactory.createActivities(job);
|
||||
if (acts.isEmpty()) {
|
||||
acts.add(new PickupService(s4));
|
||||
PickupService pickupService = new PickupService(s4);
|
||||
pickupService.setTheoreticalEarliestOperationStartTime(5);
|
||||
pickupService.setTheoreticalLatestOperationStartTime(5);
|
||||
acts.add(pickupService);
|
||||
}
|
||||
return acts;
|
||||
}
|
||||
|
|
@ -220,7 +235,10 @@ public class TestRouteLevelServiceInsertionCostEstimator {
|
|||
public List<AbstractActivity> createActivities(Job job) {
|
||||
List<AbstractActivity> acts = activityFactory.createActivities(job);
|
||||
if (acts.isEmpty()) {
|
||||
acts.add(new PickupService(s4));
|
||||
PickupService pickupService = new PickupService(s4);
|
||||
pickupService.setTheoreticalEarliestOperationStartTime(3);
|
||||
pickupService.setTheoreticalLatestOperationStartTime(3);
|
||||
acts.add(pickupService);
|
||||
}
|
||||
return acts;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
|||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.job.Service;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||
import jsprit.core.problem.vehicle.FiniteFleetManagerFactory;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.problem.vehicle.VehicleFleetManager;
|
||||
|
|
@ -179,4 +180,40 @@ public class UpdateVehicleDependentTimeWindowTest {
|
|||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void twUpdateShouldWorkWithMultipleTWs(){
|
||||
//
|
||||
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("0,0")).setEarliestStart(0.).setLatestArrival(100.).build();
|
||||
Service service = Service.Builder.newInstance("s1").setLocation(Location.newInstance("10,0"))
|
||||
.addTimeWindow(10,20).addTimeWindow(30,40).build();
|
||||
Service service2 = Service.Builder.newInstance("s2")
|
||||
.addTimeWindow(20,30).addTimeWindow(40,60).addTimeWindow(70,80).setLocation(Location.newInstance("20,0")).build();
|
||||
|
||||
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(service).addJob(service2).addVehicle(vehicle)
|
||||
.setRoutingCost(routingCosts).build();
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle).setJobActivityFactory(vrp.getJobActivityFactory())
|
||||
.addService(service).addService(service2, TimeWindow.newInstance(70,80)).build();
|
||||
|
||||
StateManager stateManager = new StateManager(vrp);
|
||||
UpdateVehicleDependentPracticalTimeWindows updater = new UpdateVehicleDependentPracticalTimeWindows(stateManager,routingCosts);
|
||||
updater.setVehiclesToUpdate(new UpdateVehicleDependentPracticalTimeWindows.VehiclesToUpdate() {
|
||||
|
||||
@Override
|
||||
public Collection<Vehicle> get(VehicleRoute route) {
|
||||
Collection<Vehicle> vehicles = new ArrayList<Vehicle>();
|
||||
vehicles.add(route.getVehicle());
|
||||
// vehicles.addAll(fleetManager.getAvailableVehicles(route.getVehicle()));
|
||||
return vehicles;
|
||||
}
|
||||
|
||||
});
|
||||
stateManager.addStateUpdater(updater);
|
||||
stateManager.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
|
||||
|
||||
assertEquals(80.,stateManager.getActivityState(route.getActivities().get(1),vehicle,
|
||||
InternalStates.LATEST_OPERATION_START_TIME, Double.class),0.01);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,7 +90,9 @@ public class SolutionAnalyserTest {
|
|||
Service s3 = Service.Builder.newInstance("s3")
|
||||
.setTimeWindow(TimeWindow.newInstance(10, 20))
|
||||
.setLocation(TestUtils.loc(Coordinate.newInstance(10, 1))).addSizeDimension(0, 2).build();
|
||||
|
||||
Service s4 = Service.Builder.newInstance("s4").setLocation(TestUtils.loc(Coordinate.newInstance(10, 10))).addSizeDimension(0, 3).build();
|
||||
|
||||
Shipment shipment2 = Shipment.Builder.newInstance("ship2").setPickupLocation(TestUtils.loc(Coordinate.newInstance(15, 2)))
|
||||
.setPickupServiceTime(20.).setDeliveryServiceTime(20.)
|
||||
.setDeliveryLocation(TestUtils.loc(Coordinate.newInstance(16, 5))).addSizeDimension(0, 10).build();
|
||||
|
|
@ -120,12 +122,12 @@ public class SolutionAnalyserTest {
|
|||
.setLatestArrival(150.)
|
||||
.build();
|
||||
|
||||
Pickup s1 = (Pickup) Pickup.Builder.newInstance("s1")
|
||||
Pickup s1 = Pickup.Builder.newInstance("s1")
|
||||
.setTimeWindow(TimeWindow.newInstance(10, 20))
|
||||
.setLocation(Location.newInstance(-10, 1))
|
||||
.addSizeDimension(0, 10)
|
||||
.build();
|
||||
Delivery s2 = (Delivery) Delivery.Builder.newInstance("s2")
|
||||
Delivery s2 = Delivery.Builder.newInstance("s2")
|
||||
.setLocation(Location.newInstance(-10, 10))
|
||||
.setTimeWindow(TimeWindow.newInstance(10, 20))
|
||||
.addSizeDimension(0, 20)
|
||||
|
|
@ -137,12 +139,12 @@ public class SolutionAnalyserTest {
|
|||
.setPickupTimeWindow(TimeWindow.newInstance(10, 20)).setDeliveryTimeWindow(TimeWindow.newInstance(10, 20))
|
||||
.build();
|
||||
|
||||
Pickup s3 = (Pickup) Pickup.Builder.newInstance("s3")
|
||||
Pickup s3 = Pickup.Builder.newInstance("s3")
|
||||
.setTimeWindow(TimeWindow.newInstance(10, 20))
|
||||
.setLocation(TestUtils.loc(Coordinate.newInstance(10, 1)))
|
||||
.addSizeDimension(0, 10)
|
||||
.build();
|
||||
Delivery s4 = (Delivery) Delivery.Builder.newInstance("s4").setLocation(Location.newInstance(10, 10))
|
||||
Delivery s4 = Delivery.Builder.newInstance("s4").setLocation(Location.newInstance(10, 10))
|
||||
.addSizeDimension(0, 20)
|
||||
.setTimeWindow(TimeWindow.newInstance(10, 20))
|
||||
.build();
|
||||
|
|
|
|||
|
|
@ -23,7 +23,9 @@ import org.junit.Test;
|
|||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.internal.matchers.IsCollectionContaining.hasItem;
|
||||
|
||||
public class ServiceTest {
|
||||
|
||||
|
|
@ -112,62 +114,86 @@ public class ServiceTest {
|
|||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void whenSettingLocationCoord_itShouldBeSetCorrectly(){
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance(1, 2)).build();
|
||||
assertEquals(1.0,s.getLocation().getCoordinate().getX(),0.01);
|
||||
assertEquals(2.0,s.getLocation().getCoordinate().getY(),0.01);
|
||||
assertEquals(1.0,s.getLocation().getCoordinate().getX(),0.01);
|
||||
assertEquals(2.0,s.getLocation().getCoordinate().getY(),0.01);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalStateException.class)
|
||||
public void whenSettingNeitherLocationIdNorCoord_throwsException(){
|
||||
@SuppressWarnings("unused")
|
||||
Service s = Service.Builder.newInstance("s").build();
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void whenServiceTimeSmallerZero_throwIllegalStateException(){
|
||||
@SuppressWarnings("unused")
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).setServiceTime(-1).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingServiceTime_itShouldBeSetCorrectly(){
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).setServiceTime(1).build();
|
||||
assertEquals(1.0,s.getServiceDuration(),0.01);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void whenTimeWindowIsNull_throwException(){
|
||||
@SuppressWarnings("unused")
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).setTimeWindow(null).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingTimeWindow_itShouldBeSetCorrectly(){
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).setTimeWindow(TimeWindow.newInstance(1.0, 2.0)).build();
|
||||
assertEquals(1.0,s.getTimeWindow().getStart(),0.01);
|
||||
assertEquals(2.0,s.getTimeWindow().getEnd(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingSkills_theyShouldBeAddedCorrectly(){
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addRequiredSkill("drill").addRequiredSkill("screwdriver").build();
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertTrue(s.getRequiredSkills().containsSkill("ScrewDriver"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly(){
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build();
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drilL"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingLocationCoord_itShouldBeSetCorrectly() {
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance(1, 2)).build();
|
||||
assertEquals(1.0, s.getLocation().getCoordinate().getX(), 0.01);
|
||||
assertEquals(2.0, s.getLocation().getCoordinate().getY(), 0.01);
|
||||
assertEquals(1.0, s.getLocation().getCoordinate().getX(), 0.01);
|
||||
assertEquals(2.0, s.getLocation().getCoordinate().getY(), 0.01);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void whenSettingNeitherLocationIdNorCoord_throwsException() {
|
||||
@SuppressWarnings("unused")
|
||||
Service s = Service.Builder.newInstance("s").build();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenServiceTimeSmallerZero_throwIllegalStateException() {
|
||||
@SuppressWarnings("unused")
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).setServiceTime(-1).build();
|
||||
public void whenAddingSeveralTimeWindows_itShouldBeSetCorrectly(){
|
||||
TimeWindow tw1 = TimeWindow.newInstance(1.0, 2.0);
|
||||
TimeWindow tw2 = TimeWindow.newInstance(3.0, 5.0);
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addTimeWindow(tw1)
|
||||
.addTimeWindow(tw2)
|
||||
.build();
|
||||
assertEquals(2, s.getTimeWindows().size());
|
||||
assertThat(s.getTimeWindows(),hasItem(is(tw1)));
|
||||
assertThat(s.getTimeWindows(),hasItem(is(tw2)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingServiceTime_itShouldBeSetCorrectly() {
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).setServiceTime(1).build();
|
||||
assertEquals(1.0, s.getServiceDuration(), 0.01);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenTimeWindowIsNull_throwException() {
|
||||
@SuppressWarnings("unused")
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).setTimeWindow(null).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingTimeWindow_itShouldBeSetCorrectly() {
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).setTimeWindow(TimeWindow.newInstance(1.0, 2.0)).build();
|
||||
public void whenAddingTimeWindow_itShouldBeSetCorrectly(){
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addTimeWindow(TimeWindow.newInstance(1.0, 2.0)).build();
|
||||
assertEquals(1.0, s.getTimeWindow().getStart(), 0.01);
|
||||
assertEquals(2.0, s.getTimeWindow().getEnd(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingSkills_theyShouldBeAddedCorrectly() {
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addRequiredSkill("drill").addRequiredSkill("screwdriver").build();
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertTrue(s.getRequiredSkills().containsSkill("ScrewDriver"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly() {
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build();
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drilL"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly() {
|
||||
|
|
@ -184,4 +210,28 @@ public class ServiceTest {
|
|||
assertEquals("name", s.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldKnowMultipleTimeWindows(){
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addTimeWindow(TimeWindow.newInstance(0., 10.)).addTimeWindow(TimeWindow.newInstance(20., 30.))
|
||||
.setName("name").build();
|
||||
assertEquals(2,s.getTimeWindows().size());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void whenMultipleTWOverlap_throwEx(){
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addTimeWindow(TimeWindow.newInstance(0.,10.))
|
||||
.addTimeWindow(TimeWindow.newInstance(5., 30.))
|
||||
.setName("name").build();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void whenMultipleTWOverlap2_throwEx(){
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addTimeWindow(TimeWindow.newInstance(20., 30.))
|
||||
.addTimeWindow(TimeWindow.newInstance(0., 25.))
|
||||
.setName("name").build();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,9 @@ import jsprit.core.util.Coordinate;
|
|||
import jsprit.core.util.TestUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.internal.matchers.IsCollectionContaining.hasItem;
|
||||
|
||||
public class ShipmentTest {
|
||||
|
||||
|
|
@ -223,6 +225,80 @@ public class ShipmentTest {
|
|||
assertEquals(2.0, s.getDeliveryTimeWindow().getEnd(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenUsingAddDeliveryTimeWindow_itShouldBeDoneCorrectly() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").addDeliveryTimeWindow(TimeWindow.newInstance(1, 2))
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(1.0, s.getDeliveryTimeWindow().getStart(), 0.01);
|
||||
assertEquals(2.0, s.getDeliveryTimeWindow().getEnd(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenUsingAddDeliveryTimeWindow2_itShouldBeDoneCorrectly() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").addDeliveryTimeWindow(1, 2)
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(1.0, s.getDeliveryTimeWindow().getStart(), 0.01);
|
||||
assertEquals(2.0, s.getDeliveryTimeWindow().getEnd(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingMultipleDeliveryTimeWindows_itShouldBeDoneCorrectly() {
|
||||
TimeWindow tw1 = TimeWindow.newInstance(1,2);
|
||||
TimeWindow tw2 = TimeWindow.newInstance(4,5);
|
||||
Shipment s = Shipment.Builder.newInstance("s").addDeliveryTimeWindow(tw1).addDeliveryTimeWindow(tw2)
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(s.getDeliveryTimeWindows().size(),2);
|
||||
assertThat(s.getDeliveryTimeWindows(),hasItem(is(tw1)));
|
||||
assertThat(s.getDeliveryTimeWindows(),hasItem(is(tw2)));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void whenAddingMultipleOverlappingDeliveryTimeWindows_itShouldThrowException() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").addDeliveryTimeWindow(1, 3).addDeliveryTimeWindow(2,5)
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(1.0, s.getDeliveryTimeWindow().getStart(), 0.01);
|
||||
assertEquals(2.0, s.getDeliveryTimeWindow().getEnd(), 0.01);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void whenUsingAddPickupTimeWindow_itShouldBeDoneCorrectly() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").addPickupTimeWindow(TimeWindow.newInstance(1, 2))
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(1.0, s.getPickupTimeWindow().getStart(), 0.01);
|
||||
assertEquals(2.0, s.getPickupTimeWindow().getEnd(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenUsingAddPickupTimeWindow2_itShouldBeDoneCorrectly() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").addPickupTimeWindow(1, 2)
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(1.0, s.getPickupTimeWindow().getStart(), 0.01);
|
||||
assertEquals(2.0, s.getPickupTimeWindow().getEnd(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingMultiplePickupTimeWindows_itShouldBeDoneCorrectly() {
|
||||
TimeWindow tw1 = TimeWindow.newInstance(1,2);
|
||||
TimeWindow tw2 = TimeWindow.newInstance(4,5);
|
||||
Shipment s = Shipment.Builder.newInstance("s").addPickupTimeWindow(tw1).addPickupTimeWindow(tw2)
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(s.getPickupTimeWindows().size(),2);
|
||||
assertThat(s.getPickupTimeWindows(), hasItem(is(tw1)));
|
||||
assertThat(s.getPickupTimeWindows(), hasItem(is(tw2)));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void whenAddingMultipleOverlappingPickupTimeWindows_itShouldThrowException() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").addPickupTimeWindow(1, 3).addPickupTimeWindow(2,5)
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(1.0, s.getPickupTimeWindow().getStart(), 0.01);
|
||||
assertEquals(2.0, s.getPickupTimeWindow().getEnd(), 0.01);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenShipmentHasNegativeCapacityVal_throwIllegalStateExpception() {
|
||||
@SuppressWarnings("unused")
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ import jsprit.core.problem.Capacity;
|
|||
import jsprit.core.problem.Location;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
import jsprit.core.problem.job.Shipment;
|
||||
import jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||
import jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.problem.vehicle.VehicleImpl;
|
||||
import org.junit.Test;
|
||||
|
|
@ -42,6 +44,7 @@ public class VehicleRouteBuilderTest {
|
|||
public void whenPickupIsAddedTwice_throwsException() {
|
||||
Shipment s = mock(Shipment.class);
|
||||
when(s.getSize()).thenReturn(Capacity.Builder.newInstance().build());
|
||||
when(s.getPickupTimeWindow()).thenReturn(TimeWindow.newInstance(0., 10.));
|
||||
VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(mock(Vehicle.class), mock(Driver.class));
|
||||
builder.addPickup(s);
|
||||
builder.addPickup(s);
|
||||
|
|
@ -52,6 +55,8 @@ public class VehicleRouteBuilderTest {
|
|||
Shipment s = mock(Shipment.class);
|
||||
Capacity capacity = Capacity.Builder.newInstance().build();
|
||||
when(s.getSize()).thenReturn(capacity);
|
||||
when(s.getPickupTimeWindow()).thenReturn(TimeWindow.newInstance(0.,10.));
|
||||
when(s.getDeliveryTimeWindow()).thenReturn(TimeWindow.newInstance(0.,10.));
|
||||
VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(mock(Vehicle.class), mock(Driver.class));
|
||||
builder.addPickup(s);
|
||||
builder.addDelivery(s);
|
||||
|
|
@ -65,6 +70,10 @@ public class VehicleRouteBuilderTest {
|
|||
Shipment s2 = mock(Shipment.class);
|
||||
when(s2.getSize()).thenReturn(capacity);
|
||||
when(s.getSize()).thenReturn(capacity);
|
||||
when(s2.getPickupTimeWindow()).thenReturn(TimeWindow.newInstance(0.,10.));
|
||||
when(s2.getDeliveryTimeWindow()).thenReturn(TimeWindow.newInstance(0.,10.));
|
||||
when(s.getPickupTimeWindow()).thenReturn(TimeWindow.newInstance(0.,10.));
|
||||
when(s.getDeliveryTimeWindow()).thenReturn(TimeWindow.newInstance(0.,10.));
|
||||
VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(mock(Vehicle.class), mock(Driver.class));
|
||||
builder.addPickup(s);
|
||||
builder.addPickup(s2);
|
||||
|
|
@ -79,6 +88,10 @@ public class VehicleRouteBuilderTest {
|
|||
Capacity capacity = Capacity.Builder.newInstance().build();
|
||||
when(s.getSize()).thenReturn(capacity);
|
||||
when(s2.getSize()).thenReturn(capacity);
|
||||
when(s2.getPickupTimeWindow()).thenReturn(TimeWindow.newInstance(0.,10.));
|
||||
when(s2.getDeliveryTimeWindow()).thenReturn(TimeWindow.newInstance(0.,10.));
|
||||
when(s.getPickupTimeWindow()).thenReturn(TimeWindow.newInstance(0.,10.));
|
||||
when(s.getDeliveryTimeWindow()).thenReturn(TimeWindow.newInstance(0.,10.));
|
||||
VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(mock(Vehicle.class), mock(Driver.class));
|
||||
builder.addPickup(s);
|
||||
builder.addPickup(s2);
|
||||
|
|
@ -95,6 +108,10 @@ public class VehicleRouteBuilderTest {
|
|||
Capacity capacity = Capacity.Builder.newInstance().build();
|
||||
when(s.getSize()).thenReturn(capacity);
|
||||
when(s2.getSize()).thenReturn(capacity);
|
||||
when(s2.getPickupTimeWindow()).thenReturn(TimeWindow.newInstance(0.,10.));
|
||||
when(s2.getDeliveryTimeWindow()).thenReturn(TimeWindow.newInstance(0.,10.));
|
||||
when(s.getPickupTimeWindow()).thenReturn(TimeWindow.newInstance(0.,10.));
|
||||
when(s.getDeliveryTimeWindow()).thenReturn(TimeWindow.newInstance(0.,10.));
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("vehLoc")).setEndLocation(Location.newInstance("vehLoc"))
|
||||
.build();
|
||||
|
||||
|
|
@ -115,6 +132,10 @@ public class VehicleRouteBuilderTest {
|
|||
when(s.getSize()).thenReturn(capacity);
|
||||
when(s2.getSize()).thenReturn(capacity);
|
||||
when(s2.getDeliveryLocation()).thenReturn(loc("delLoc"));
|
||||
when(s.getPickupTimeWindow()).thenReturn(TimeWindow.newInstance(0.,10.));
|
||||
when(s.getDeliveryTimeWindow()).thenReturn(TimeWindow.newInstance(0.,10.));
|
||||
when(s2.getPickupTimeWindow()).thenReturn(TimeWindow.newInstance(0.,10.));
|
||||
when(s2.getDeliveryTimeWindow()).thenReturn(TimeWindow.newInstance(0.,10.));
|
||||
Vehicle vehicle = mock(Vehicle.class);
|
||||
when(vehicle.isReturnToDepot()).thenReturn(false);
|
||||
when(vehicle.getStartLocation()).thenReturn(loc("vehLoc"));
|
||||
|
|
@ -139,6 +160,10 @@ public class VehicleRouteBuilderTest {
|
|||
when(s.getSize()).thenReturn(capacity);
|
||||
when(s2.getSize()).thenReturn(capacity);
|
||||
when(s2.getDeliveryLocation()).thenReturn(Location.Builder.newInstance().setId("delLoc").build());
|
||||
when(s.getPickupTimeWindow()).thenReturn(TimeWindow.newInstance(0.,10.));
|
||||
when(s.getDeliveryTimeWindow()).thenReturn(TimeWindow.newInstance(0.,10.));
|
||||
when(s2.getPickupTimeWindow()).thenReturn(TimeWindow.newInstance(0., 10.));
|
||||
when(s2.getDeliveryTimeWindow()).thenReturn(TimeWindow.newInstance(0.,10.));
|
||||
Vehicle vehicle = mock(Vehicle.class);
|
||||
when(vehicle.isReturnToDepot()).thenReturn(false);
|
||||
when(vehicle.getStartLocation()).thenReturn(Location.Builder.newInstance().setId("vehLoc").build());
|
||||
|
|
@ -162,6 +187,10 @@ public class VehicleRouteBuilderTest {
|
|||
when(s.getSize()).thenReturn(capacity);
|
||||
when(s2.getSize()).thenReturn(capacity);
|
||||
when(s2.getDeliveryLocation()).thenReturn(Location.Builder.newInstance().setId("delLoc").build());
|
||||
when(s2.getPickupTimeWindow()).thenReturn(TimeWindow.newInstance(0.,10.));
|
||||
when(s2.getDeliveryTimeWindow()).thenReturn(TimeWindow.newInstance(0.,10.));
|
||||
when(s.getPickupTimeWindow()).thenReturn(TimeWindow.newInstance(0., 10.));
|
||||
when(s.getDeliveryTimeWindow()).thenReturn(TimeWindow.newInstance(0.,10.));
|
||||
Vehicle vehicle = mock(Vehicle.class);
|
||||
when(vehicle.isReturnToDepot()).thenReturn(false);
|
||||
when(vehicle.getStartLocation()).thenReturn(Location.Builder.newInstance().setId("vehLoc").build());
|
||||
|
|
|
|||
|
|
@ -33,9 +33,11 @@ public class BreakActivityTest {
|
|||
|
||||
@Before
|
||||
public void doBefore() {
|
||||
service = (Break) Break.Builder.newInstance("service")
|
||||
service = Break.Builder.newInstance("service")
|
||||
.setTimeWindow(TimeWindow.newInstance(1., 2.)).setServiceTime(3).build();
|
||||
serviceActivity = BreakActivity.newInstance(service);
|
||||
serviceActivity.setTheoreticalEarliestOperationStartTime(service.getTimeWindow().getStart());
|
||||
serviceActivity.setTheoreticalLatestOperationStartTime(service.getTimeWindow().getEnd());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -32,10 +32,12 @@ public class DeliverServiceTest {
|
|||
|
||||
@Before
|
||||
public void doBefore() {
|
||||
service = (Delivery) Delivery.Builder.newInstance("service").setLocation(Location.newInstance("loc")).
|
||||
service = Delivery.Builder.newInstance("service").setLocation(Location.newInstance("loc")).
|
||||
setTimeWindow(TimeWindow.newInstance(1., 2.)).
|
||||
addSizeDimension(0, 10).addSizeDimension(1, 100).addSizeDimension(2, 1000).build();
|
||||
deliver = new DeliverService(service);
|
||||
deliver.setTheoreticalEarliestOperationStartTime(service.getTimeWindow().getStart());
|
||||
deliver.setTheoreticalLatestOperationStartTime(service.getTimeWindow().getEnd());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -36,6 +36,8 @@ public class DeliverShipmentTest {
|
|||
.setDeliveryTimeWindow(TimeWindow.newInstance(3., 4.))
|
||||
.addSizeDimension(0, 10).addSizeDimension(1, 100).addSizeDimension(2, 1000).build();
|
||||
deliver = new DeliverShipment(shipment);
|
||||
deliver.setTheoreticalEarliestOperationStartTime(shipment.getDeliveryTimeWindow().getStart());
|
||||
deliver.setTheoreticalLatestOperationStartTime(shipment.getDeliveryTimeWindow().getEnd());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -36,6 +36,8 @@ public class PickupServiceTest {
|
|||
setTimeWindow(TimeWindow.newInstance(1., 2.)).
|
||||
addSizeDimension(0, 10).addSizeDimension(1, 100).addSizeDimension(2, 1000).build();
|
||||
pickup = new PickupService(service);
|
||||
pickup.setTheoreticalEarliestOperationStartTime(service.getTimeWindow().getStart());
|
||||
pickup.setTheoreticalLatestOperationStartTime(service.getTimeWindow().getEnd());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -36,6 +36,8 @@ public class PickupShipmentTest {
|
|||
.setDeliveryTimeWindow(TimeWindow.newInstance(3., 4.))
|
||||
.addSizeDimension(0, 10).addSizeDimension(1, 100).addSizeDimension(2, 1000).build();
|
||||
pickup = new PickupShipment(shipment);
|
||||
pickup.setTheoreticalEarliestOperationStartTime(shipment.getPickupTimeWindow().getStart());
|
||||
pickup.setTheoreticalLatestOperationStartTime(shipment.getPickupTimeWindow().getEnd());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -36,6 +36,8 @@ public class ServiceActivityTest {
|
|||
setTimeWindow(TimeWindow.newInstance(1., 2.)).
|
||||
addSizeDimension(0, 10).addSizeDimension(1, 100).addSizeDimension(2, 1000).build();
|
||||
serviceActivity = ServiceActivity.newInstance(service);
|
||||
serviceActivity.setTheoreticalEarliestOperationStartTime(service.getTimeWindow().getStart());
|
||||
serviceActivity.setTheoreticalLatestOperationStartTime(service.getTimeWindow().getEnd());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
package jsprit.core.problem.solution.route.activity;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Created by schroeder on 18/12/15.
|
||||
*/
|
||||
public class TimeWindowsImplTest {
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void overlappingTW_shouldThrowException(){
|
||||
TimeWindowsImpl tws = new TimeWindowsImpl();
|
||||
tws.add(TimeWindow.newInstance(50, 100));
|
||||
tws.add(TimeWindow.newInstance(90,150));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void overlappingTW2_shouldThrowException(){
|
||||
TimeWindowsImpl tws = new TimeWindowsImpl();
|
||||
tws.add(TimeWindow.newInstance(50, 100));
|
||||
tws.add(TimeWindow.newInstance(40,150));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void overlappingTW3_shouldThrowException(){
|
||||
TimeWindowsImpl tws = new TimeWindowsImpl();
|
||||
tws.add(TimeWindow.newInstance(50, 100));
|
||||
tws.add(TimeWindow.newInstance(50, 100));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue