mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
Merge branch 'routes-with-specified-start-and-end' into
access-egress-costs-merged-with-routes-with-spec-start-end Conflicts: jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestCalculatesServiceInsertion.java jsprit-examples/src/main/java/jsprit/examples/MultipleDepotExampleWithPenaltyVehicles.java jsprit-examples/src/main/java/jsprit/examples/SolomonExample.java jsprit-examples/src/main/java/jsprit/examples/SolomonOpenExample.java
This commit is contained in:
commit
6dbcd7431a
75 changed files with 4281 additions and 525 deletions
|
|
@ -142,7 +142,7 @@ public class RefuseCollectionWithCostsHigherThanTimesAndFiniteFleet_IT {
|
|||
VehicleTypeImpl bigType = typeBuilder.build();
|
||||
|
||||
VehicleImpl.Builder vehicleBuilder = VehicleImpl.Builder.newInstance("vehicle");
|
||||
vehicleBuilder.setLocationId("1");
|
||||
vehicleBuilder.setStartLocationId("1");
|
||||
vehicleBuilder.setType(bigType);
|
||||
vehicleBuilder.setLatestArrival(220);
|
||||
Vehicle bigVehicle = vehicleBuilder.build();
|
||||
|
|
|
|||
|
|
@ -155,7 +155,7 @@ public class RefuseCollection_IT {
|
|||
VehicleTypeImpl bigType = typeBuilder.build();
|
||||
|
||||
VehicleImpl.Builder vehicleBuilder = VehicleImpl.Builder.newInstance("vehicle");
|
||||
vehicleBuilder.setLocationId("1");
|
||||
vehicleBuilder.setStartLocationId("1");
|
||||
vehicleBuilder.setType(bigType);
|
||||
Vehicle bigVehicle = vehicleBuilder.build();
|
||||
|
||||
|
|
|
|||
|
|
@ -53,8 +53,8 @@ public class CalcVehicleTypeDependentServiceInsertionTest {
|
|||
veh2 = mock(Vehicle.class);
|
||||
when(veh1.getType()).thenReturn(VehicleTypeImpl.Builder.newInstance("type1", 0).build());
|
||||
when(veh2.getType()).thenReturn(VehicleTypeImpl.Builder.newInstance("type2", 0).build());
|
||||
when(veh1.getLocationId()).thenReturn("loc1");
|
||||
when(veh2.getLocationId()).thenReturn("loc2");
|
||||
when(veh1.getStartLocationId()).thenReturn("loc1");
|
||||
when(veh2.getStartLocationId()).thenReturn("loc2");
|
||||
fleetManager = mock(VehicleFleetManager.class);
|
||||
service = mock(Service.class);
|
||||
vehicleRoute = mock(VehicleRoute.class);
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ public class CalcWithTimeSchedulingTest {
|
|||
public void timeScheduler(){
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("myVehicle").setEarliestStart(0.0).setLatestArrival(100.0).
|
||||
setLocationCoord(Coordinate.newInstance(0, 0)).setLocationId("0,0")
|
||||
setStartLocationCoordinate(Coordinate.newInstance(0, 0)).setStartLocationId("0,0")
|
||||
.setType(VehicleTypeImpl.Builder.newInstance("myType", 20).setCostPerDistance(1.0).build()).build();
|
||||
vrpBuilder.addVehicle(vehicle);
|
||||
vrpBuilder.addJob(Service.Builder.newInstance("myService", 2).setLocationId("0,20").setCoord(Coordinate.newInstance(0, 20)).build());
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ public class ServiceInsertionAndLoadConstraintsTest {
|
|||
};
|
||||
routingCosts = new ManhattanCosts(locations);
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("t", 2).setCostPerDistance(1).build();
|
||||
vehicle = VehicleImpl.Builder.newInstance("v").setLocationId("0,0").setType(type).build();
|
||||
vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("0,0").setType(type).build();
|
||||
activityInsertionCostsCalculator = new LocalActivityInsertionCostsCalculator(routingCosts, activityCosts);
|
||||
createInsertionCalculator(hardRouteLevelConstraint);
|
||||
}
|
||||
|
|
@ -109,10 +109,10 @@ public class ServiceInsertionAndLoadConstraintsTest {
|
|||
Pickup pickup = (Pickup) Pickup.Builder.newInstance("pick", 15).setLocationId("0,10").build();
|
||||
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("t", 50).setCostPerDistance(1).build();
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setLocationId("0,0").setType(type).build();
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("0,0").setType(type).build();
|
||||
|
||||
VehicleRoute route = VehicleRoute.emptyRoute();
|
||||
route.setVehicle(vehicle, 0.0);
|
||||
route.setVehicleAndDepartureTime(vehicle, 0.0);
|
||||
|
||||
Inserter inserter = new Inserter(new InsertionListeners());
|
||||
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ public class ShipmentInsertionCalculatorTest {
|
|||
};
|
||||
routingCosts = new ManhattanCosts(locations);
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("t", 2).setCostPerDistance(1).build();
|
||||
vehicle = VehicleImpl.Builder.newInstance("v").setLocationId("0,0").setType(type).build();
|
||||
vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("0,0").setType(type).build();
|
||||
activityInsertionCostsCalculator = new LocalActivityInsertionCostsCalculator(routingCosts, activityCosts);
|
||||
createInsertionCalculator(hardRouteLevelConstraint);
|
||||
}
|
||||
|
|
@ -184,7 +184,7 @@ public class ShipmentInsertionCalculatorTest {
|
|||
|
||||
|
||||
VehicleRoute route = VehicleRoute.emptyRoute();
|
||||
route.setVehicle(vehicle, 0.0);
|
||||
route.setVehicleAndDepartureTime(vehicle, 0.0);
|
||||
|
||||
Inserter inserter = new Inserter(new InsertionListeners());
|
||||
|
||||
|
|
@ -215,7 +215,7 @@ public class ShipmentInsertionCalculatorTest {
|
|||
Shipment shipment = Shipment.Builder.newInstance("s", 1).setPickupLocation("0,10").setDeliveryLocation("0,0").build();
|
||||
Shipment shipment2 = Shipment.Builder.newInstance("s2", 1).setPickupLocation("10,10").setDeliveryLocation("0,0").build();
|
||||
VehicleRoute route = VehicleRoute.emptyRoute();
|
||||
route.setVehicle(vehicle, 0.0);
|
||||
route.setVehicleAndDepartureTime(vehicle, 0.0);
|
||||
|
||||
Inserter inserter = new Inserter(new InsertionListeners());
|
||||
|
||||
|
|
|
|||
|
|
@ -39,9 +39,7 @@ import jsprit.core.problem.job.Job;
|
|||
import jsprit.core.problem.job.Service;
|
||||
import jsprit.core.problem.misc.JobInsertionContext;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.ServiceActivity;
|
||||
import jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivities;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.problem.vehicle.VehicleImpl;
|
||||
|
|
@ -72,10 +70,10 @@ public class TestCalculatesServiceInsertion {
|
|||
|
||||
private Service first;
|
||||
|
||||
private Service second;
|
||||
|
||||
private Service third;
|
||||
|
||||
private Service second;
|
||||
|
||||
private StateManager states;
|
||||
|
||||
private NoDriver driver;
|
||||
|
|
@ -86,18 +84,11 @@ public class TestCalculatesServiceInsertion {
|
|||
public void setup(){
|
||||
Logger.getRootLogger().setLevel(Level.DEBUG);
|
||||
|
||||
costs = mock(VehicleRoutingTransportCosts.class);
|
||||
vehicle = mock(Vehicle.class);
|
||||
when(vehicle.getCapacity()).thenReturn(1000);
|
||||
when(vehicle.getLocationId()).thenReturn("0,0");
|
||||
when(vehicle.getEarliestDeparture()).thenReturn(0.0);
|
||||
when(vehicle.getLatestArrival()).thenReturn(100.0);
|
||||
when(vehicle.isReturnToDepot()).thenReturn(true);
|
||||
VehicleType t1 = VehicleTypeImpl.Builder.newInstance("t1", 1000).setCostPerDistance(1.0).build();
|
||||
vehicle = VehicleImpl.Builder.newInstance("vehicle").setLatestArrival(100.0).setLocationId("0,0").setType(t1).build();
|
||||
vehicle = VehicleImpl.Builder.newInstance("vehicle").setLatestArrival(100.0).setStartLocationId("0,0").setType(t1).build();
|
||||
|
||||
VehicleType t2 = VehicleTypeImpl.Builder.newInstance("t2", 1000).setCostPerDistance(2.0).build();
|
||||
newVehicle = VehicleImpl.Builder.newInstance("newVehicle").setLatestArrival(100.0).setLocationId("0,0").setType(t2).build();
|
||||
newVehicle = VehicleImpl.Builder.newInstance("newVehicle").setLatestArrival(100.0).setStartLocationId("0,0").setType(t2).build();
|
||||
|
||||
driver = DriverImpl.noDriver();
|
||||
|
||||
|
|
@ -127,12 +118,13 @@ public class TestCalculatesServiceInsertion {
|
|||
|
||||
|
||||
first = Service.Builder.newInstance("1", 0).setLocationId("0,10").setTimeWindow(TimeWindow.newInstance(0.0, 100.0)).build();
|
||||
second = Service.Builder.newInstance("3", 0).setLocationId("10,0").setTimeWindow(TimeWindow.newInstance(0.0, 100.0)).build();
|
||||
third = Service.Builder.newInstance("2", 0).setLocationId("10,10").setTimeWindow(TimeWindow.newInstance(0.0, 100.0)).build();
|
||||
second = Service.Builder.newInstance("2", 0).setLocationId("10,10").setTimeWindow(TimeWindow.newInstance(0.0, 100.0)).build();
|
||||
third = Service.Builder.newInstance("3", 0).setLocationId("10,0").setTimeWindow(TimeWindow.newInstance(0.0, 100.0)).build();
|
||||
|
||||
Collection<Job> jobs = new ArrayList<Job>();
|
||||
jobs.add(first);
|
||||
jobs.add(second);
|
||||
jobs.add(third);
|
||||
jobs.add(second);
|
||||
|
||||
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addAllJobs(jobs).addVehicle(vehicle).setRoutingCost(costs).build();
|
||||
|
||||
|
|
@ -158,11 +150,9 @@ public class TestCalculatesServiceInsertion {
|
|||
|
||||
@Test
|
||||
public void whenInsertingTheFirstJobInAnEmptyTourWithVehicle_itCalculatesMarginalCostChanges(){
|
||||
TourActivities tour = new TourActivities();
|
||||
|
||||
VehicleRoute route = VehicleRoute.newInstance(tour,driver,vehicle);
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).build();
|
||||
states.informInsertionStarts(Arrays.asList(route), null);
|
||||
|
||||
|
||||
InsertionData iData = serviceInsertion.getInsertionData(route, first, vehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE);
|
||||
assertEquals(20.0, iData.getInsertionCost(), 0.2);
|
||||
assertEquals(0, iData.getDeliveryInsertionIndex());
|
||||
|
|
@ -170,70 +160,53 @@ public class TestCalculatesServiceInsertion {
|
|||
|
||||
@Test
|
||||
public void whenInsertingTheSecondJobInAnNonEmptyTourWithVehicle_itCalculatesMarginalCostChanges(){
|
||||
TourActivities tour = new TourActivities();
|
||||
tour.addActivity(ServiceActivity.newInstance(first));
|
||||
|
||||
VehicleRoute route = VehicleRoute.newInstance(tour,driver,vehicle);
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).addService(first).build();
|
||||
states.informInsertionStarts(Arrays.asList(route), null);
|
||||
|
||||
InsertionData iData = serviceInsertion.getInsertionData(route, second, vehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE);
|
||||
InsertionData iData = serviceInsertion.getInsertionData(route, third, vehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE);
|
||||
assertEquals(20.0, iData.getInsertionCost(), 0.2);
|
||||
assertEquals(0, iData.getDeliveryInsertionIndex());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenInsertingThirdJobWithVehicle_itCalculatesMarginalCostChanges(){
|
||||
TourActivities tour = new TourActivities();
|
||||
tour.addActivity(ServiceActivity.newInstance(first));
|
||||
tour.addActivity(ServiceActivity.newInstance(second));
|
||||
|
||||
VehicleRoute route = VehicleRoute.newInstance(tour,driver,vehicle);
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).addService(first).addService(third).build();
|
||||
states.informInsertionStarts(Arrays.asList(route), null);
|
||||
|
||||
InsertionData iData = serviceInsertion.getInsertionData(route, third, vehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE);
|
||||
InsertionData iData = serviceInsertion.getInsertionData(route, second, vehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE);
|
||||
assertEquals(0.0, iData.getInsertionCost(), 0.2);
|
||||
assertEquals(1, iData.getDeliveryInsertionIndex());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenInsertingThirdJobWithNewVehicle_itCalculatesMarginalCostChanges(){
|
||||
TourActivities tour = new TourActivities();
|
||||
tour.addActivity(ServiceActivity.newInstance(first));
|
||||
tour.addActivity(ServiceActivity.newInstance(second));
|
||||
|
||||
VehicleRoute route = VehicleRoute.newInstance(tour,driver,vehicle);
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).addService(first).addService(third).build();
|
||||
states.informInsertionStarts(Arrays.asList(route), null);
|
||||
|
||||
InsertionData iData = serviceInsertion.getInsertionData(route, third, newVehicle, newVehicle.getEarliestDeparture(), null, Double.MAX_VALUE);
|
||||
assertEquals(20.0, iData.getInsertionCost(), 0.2);
|
||||
InsertionData iData = serviceInsertion.getInsertionData(route, second, newVehicle, newVehicle.getEarliestDeparture(), null, Double.MAX_VALUE);
|
||||
assertEquals(40.0, iData.getInsertionCost(), 0.2);
|
||||
assertEquals(1, iData.getDeliveryInsertionIndex());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenInsertingASecondJobWithAVehicle_itCalculatesLocalMarginalCostChanges(){
|
||||
TourActivities tour = new TourActivities();
|
||||
tour.addActivity(ServiceActivity.newInstance(first));
|
||||
tour.addActivity(ServiceActivity.newInstance(third));
|
||||
|
||||
VehicleRoute route = VehicleRoute.newInstance(tour,driver,vehicle);
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).addService(first).addService(second).build();
|
||||
states.informInsertionStarts(Arrays.asList(route), null);
|
||||
|
||||
InsertionData iData = serviceInsertion.getInsertionData(route, second, vehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE);
|
||||
InsertionData iData = serviceInsertion.getInsertionData(route, third, vehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE);
|
||||
assertEquals(0.0, iData.getInsertionCost(), 0.2);
|
||||
assertEquals(2, iData.getDeliveryInsertionIndex());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenInsertingASecondJobWithANewVehicle_itCalculatesLocalMarginalCostChanges(){
|
||||
TourActivities tour = new TourActivities();
|
||||
tour.addActivity(ServiceActivity.newInstance(first));
|
||||
tour.addActivity(ServiceActivity.newInstance(third));
|
||||
|
||||
VehicleRoute route = VehicleRoute.newInstance(tour,driver,vehicle);
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).addService(first).addService(second).build();
|
||||
|
||||
states.informInsertionStarts(Arrays.asList(route), null);
|
||||
|
||||
InsertionData iData = serviceInsertion.getInsertionData(route, second, newVehicle, newVehicle.getEarliestDeparture(), null, Double.MAX_VALUE);
|
||||
assertEquals(20.0, iData.getInsertionCost(), 0.2);
|
||||
InsertionData iData = serviceInsertion.getInsertionData(route, third, newVehicle, newVehicle.getEarliestDeparture(), null, Double.MAX_VALUE);
|
||||
assertEquals(50.0, iData.getInsertionCost(), 0.2);
|
||||
assertEquals(2, iData.getDeliveryInsertionIndex());
|
||||
}
|
||||
|
||||
|
|
@ -276,13 +249,13 @@ public class TestCalculatesServiceInsertion {
|
|||
return EuclideanDistanceCalculator.calculateDistance(coords.get(fromId), coords.get(toId));
|
||||
}
|
||||
};
|
||||
Vehicle oldVehicle = VehicleImpl.Builder.newInstance("oldV").setLocationId("oldV").build();
|
||||
Vehicle oldVehicle = VehicleImpl.Builder.newInstance("oldV").setStartLocationId("oldV").build();
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(oldVehicle, DriverImpl.noDriver())
|
||||
.addService(Service.Builder.newInstance("service", 0).setLocationId("service").build())
|
||||
.build();
|
||||
|
||||
Vehicle newVehicle = VehicleImpl.Builder.newInstance("newV").setLocationId("newV").build();
|
||||
Vehicle newVehicle = VehicleImpl.Builder.newInstance("newV").setStartLocationId("newV").build();
|
||||
|
||||
AdditionalAccessEgressCalculator accessEgressCalc = new AdditionalAccessEgressCalculator(routingCosts);
|
||||
Job job = Service.Builder.newInstance("service2", 0).setLocationId("service").build();
|
||||
|
|
|
|||
|
|
@ -79,14 +79,16 @@ public class TestCalculatesServiceInsertionOnRouteLevel {
|
|||
costs = mock(VehicleRoutingTransportCosts.class);
|
||||
vehicle = mock(Vehicle.class);
|
||||
when(vehicle.getCapacity()).thenReturn(1000);
|
||||
when(vehicle.getLocationId()).thenReturn("0,0");
|
||||
when(vehicle.getStartLocationId()).thenReturn("0,0");
|
||||
when(vehicle.getEndLocationId()).thenReturn("0,0");
|
||||
when(vehicle.getEarliestDeparture()).thenReturn(0.0);
|
||||
when(vehicle.getLatestArrival()).thenReturn(100.0);
|
||||
when(vehicle.isReturnToDepot()).thenReturn(true);
|
||||
|
||||
newVehicle = mock(Vehicle.class);
|
||||
when(newVehicle.getCapacity()).thenReturn(1000);
|
||||
when(newVehicle.getLocationId()).thenReturn("0,0");
|
||||
when(newVehicle.getStartLocationId()).thenReturn("0,0");
|
||||
when(newVehicle.getEndLocationId()).thenReturn("0,0");
|
||||
when(newVehicle.getEarliestDeparture()).thenReturn(0.0);
|
||||
when(newVehicle.getLatestArrival()).thenReturn(100.0);
|
||||
when(newVehicle.isReturnToDepot()).thenReturn(true);
|
||||
|
|
@ -175,9 +177,7 @@ public class TestCalculatesServiceInsertionOnRouteLevel {
|
|||
|
||||
@Test
|
||||
public void whenInsertingTheFirstJobInAnEmptyTourWithVehicle_itCalculatesMarginalCostChanges(){
|
||||
TourActivities tour = new TourActivities();
|
||||
|
||||
VehicleRoute route = VehicleRoute.newInstance(tour,driver,vehicle);
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).build();
|
||||
states.informInsertionStarts(Arrays.asList(route), null);
|
||||
|
||||
InsertionData iData = serviceInsertion.getInsertionData(route, first, vehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE);
|
||||
|
|
@ -191,7 +191,7 @@ public class TestCalculatesServiceInsertionOnRouteLevel {
|
|||
tour.addActivity(ServiceActivity.newInstance(first));
|
||||
tour.addActivity(ServiceActivity.newInstance(second));
|
||||
|
||||
VehicleRoute route = VehicleRoute.newInstance(tour,driver,vehicle);
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).addService(first).addService(second).build();
|
||||
states.informInsertionStarts(Arrays.asList(route), null);
|
||||
|
||||
InsertionData iData = serviceInsertion.getInsertionData(route, third, vehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE);
|
||||
|
|
@ -205,7 +205,7 @@ public class TestCalculatesServiceInsertionOnRouteLevel {
|
|||
tour.addActivity(ServiceActivity.newInstance(first));
|
||||
tour.addActivity(ServiceActivity.newInstance(second));
|
||||
|
||||
VehicleRoute route = VehicleRoute.newInstance(tour,driver,vehicle);
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).addService(first).addService(second).build();
|
||||
states.informInsertionStarts(Arrays.asList(route), null);
|
||||
|
||||
InsertionData iData = serviceInsertion.getInsertionData(route, third, newVehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE);
|
||||
|
|
@ -219,7 +219,7 @@ public class TestCalculatesServiceInsertionOnRouteLevel {
|
|||
tour.addActivity(ServiceActivity.newInstance(first));
|
||||
tour.addActivity(ServiceActivity.newInstance(third));
|
||||
|
||||
VehicleRoute route = VehicleRoute.newInstance(tour,driver,vehicle);
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).addService(first).addService(third).build();
|
||||
states.informInsertionStarts(Arrays.asList(route), null);
|
||||
|
||||
InsertionData iData = serviceInsertion.getInsertionData(route, second, vehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE);
|
||||
|
|
@ -233,7 +233,7 @@ public class TestCalculatesServiceInsertionOnRouteLevel {
|
|||
tour.addActivity(ServiceActivity.newInstance(first));
|
||||
tour.addActivity(ServiceActivity.newInstance(third));
|
||||
|
||||
VehicleRoute route = VehicleRoute.newInstance(tour,driver,vehicle);
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).addService(first).addService(third).build();
|
||||
states.informInsertionStarts(Arrays.asList(route), null);
|
||||
|
||||
InsertionData iData = serviceInsertion.getInsertionData(route, second, newVehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE);
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ public class TestDepartureTimeOpt {
|
|||
public void whenSettingOneCustWithTWAnd_NO_DepTimeChoice_totalCostsShouldBe50(){
|
||||
TimeWindow timeWindow = TimeWindow.newInstance(40, 45);
|
||||
Service service = Service.Builder.newInstance("s", 0).setLocationId("servLoc").setCoord(Coordinate.newInstance(0, 10)).setTimeWindow(timeWindow).build();
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setLocationId("vehLoc").setLocationCoord(Coordinate.newInstance(0, 0))
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("vehLoc").setStartLocationCoordinate(Coordinate.newInstance(0, 0))
|
||||
.setType(VehicleTypeImpl.Builder.newInstance("vType", 0).build()).build();
|
||||
|
||||
Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
|
|
@ -72,7 +72,7 @@ public class TestDepartureTimeOpt {
|
|||
public void whenSettingOneCustWithTWAnd_NO_DepTimeChoice_depTimeShouldBe0(){
|
||||
TimeWindow timeWindow = TimeWindow.newInstance(40, 45);
|
||||
Service service = Service.Builder.newInstance("s", 0).setLocationId("servLoc").setCoord(Coordinate.newInstance(0, 10)).setTimeWindow(timeWindow).build();
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setLocationId("vehLoc").setLocationCoord(Coordinate.newInstance(0, 0))
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("vehLoc").setStartLocationCoordinate(Coordinate.newInstance(0, 0))
|
||||
.setType(VehicleTypeImpl.Builder.newInstance("vType", 0).build()).build();
|
||||
|
||||
Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
|
|
@ -99,7 +99,7 @@ public class TestDepartureTimeOpt {
|
|||
public void whenSettingOneCustWithTWAndDepTimeChoice_totalCostsShouldBe50(){
|
||||
TimeWindow timeWindow = TimeWindow.newInstance(40, 45);
|
||||
Service service = Service.Builder.newInstance("s", 0).setLocationId("servLoc").setCoord(Coordinate.newInstance(0, 10)).setTimeWindow(timeWindow).build();
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setLocationId("vehLoc").setLocationCoord(Coordinate.newInstance(0, 0))
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("vehLoc").setStartLocationCoordinate(Coordinate.newInstance(0, 0))
|
||||
.setType(VehicleTypeImpl.Builder.newInstance("vType", 0).build()).build();
|
||||
|
||||
Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
|
|
@ -127,7 +127,7 @@ public class TestDepartureTimeOpt {
|
|||
public void whenSettingOneCustWithTWAndDepTimeChoice_depTimeShouldBe0(){
|
||||
TimeWindow timeWindow = TimeWindow.newInstance(40, 45);
|
||||
Service service = Service.Builder.newInstance("s", 0).setLocationId("servLoc").setCoord(Coordinate.newInstance(0, 10)).setTimeWindow(timeWindow).build();
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setLocationId("vehLoc").setLocationCoord(Coordinate.newInstance(0, 0))
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("vehLoc").setStartLocationCoordinate(Coordinate.newInstance(0, 0))
|
||||
.setType(VehicleTypeImpl.Builder.newInstance("vType", 0).build()).build();
|
||||
|
||||
Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
|
|
@ -159,7 +159,7 @@ public class TestDepartureTimeOpt {
|
|||
Service service2 = Service.Builder.newInstance("s2", 0).setLocationId("servLoc2").setCoord(Coordinate.newInstance(0, 20)).
|
||||
setTimeWindow(TimeWindow.newInstance(30, 40)).build();
|
||||
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setLocationId("vehLoc").setLocationCoord(Coordinate.newInstance(0, 0))
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("vehLoc").setStartLocationCoordinate(Coordinate.newInstance(0, 0))
|
||||
.setType(VehicleTypeImpl.Builder.newInstance("vType", 0).build()).build();
|
||||
|
||||
Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
|
|
@ -191,7 +191,7 @@ public class TestDepartureTimeOpt {
|
|||
Service service2 = Service.Builder.newInstance("s2", 0).setLocationId("servLoc2").setCoord(Coordinate.newInstance(0, 20)).
|
||||
setTimeWindow(TimeWindow.newInstance(30, 40)).build();
|
||||
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setLocationId("vehLoc").setLocationCoord(Coordinate.newInstance(0, 0))
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("vehLoc").setStartLocationCoordinate(Coordinate.newInstance(0, 0))
|
||||
.setType(VehicleTypeImpl.Builder.newInstance("vType", 0).build()).build();
|
||||
|
||||
Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
|
|
|
|||
|
|
@ -22,7 +22,8 @@ public class TestInserter {
|
|||
public void whenInsertingServiceAndRouteIsClosed_itInsertsCorrectly(){
|
||||
Service service = mock(Service.class);
|
||||
Vehicle vehicle = mock(Vehicle.class);
|
||||
when(vehicle.getLocationId()).thenReturn("vehLoc");
|
||||
when(vehicle.getStartLocationId()).thenReturn("vehLoc");
|
||||
when(vehicle.getEndLocationId()).thenReturn("vehLoc");
|
||||
when(vehicle.isReturnToDepot()).thenReturn(true);
|
||||
when(vehicle.getId()).thenReturn("vehId");
|
||||
|
||||
|
|
@ -40,14 +41,15 @@ public class TestInserter {
|
|||
|
||||
assertEquals(2,route.getTourActivities().getActivities().size());
|
||||
assertEquals(route.getTourActivities().getActivities().get(1).getLocationId(),serviceToInsert.getLocationId());
|
||||
assertEquals(route.getEnd().getLocationId(),vehicle.getLocationId());
|
||||
assertEquals(route.getEnd().getLocationId(),vehicle.getEndLocationId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenInsertingServiceAndRouteIsOpen_itInsertsCorrectlyAndSwitchesEndLocation(){
|
||||
Service service = mock(Service.class);
|
||||
Vehicle vehicle = mock(Vehicle.class);
|
||||
when(vehicle.getLocationId()).thenReturn("vehLoc");
|
||||
when(vehicle.getStartLocationId()).thenReturn("vehLoc");
|
||||
when(vehicle.getEndLocationId()).thenReturn("vehLoc");
|
||||
when(vehicle.isReturnToDepot()).thenReturn(false);
|
||||
when(vehicle.getId()).thenReturn("vehId");
|
||||
|
||||
|
|
@ -72,7 +74,8 @@ public class TestInserter {
|
|||
public void whenInsertingShipmentAndRouteIsClosed_itInsertsCorrectly(){
|
||||
Shipment shipment = mock(Shipment.class);
|
||||
Vehicle vehicle = mock(Vehicle.class);
|
||||
when(vehicle.getLocationId()).thenReturn("vehLoc");
|
||||
when(vehicle.getStartLocationId()).thenReturn("vehLoc");
|
||||
when(vehicle.getEndLocationId()).thenReturn("vehLoc");
|
||||
when(vehicle.isReturnToDepot()).thenReturn(true);
|
||||
when(vehicle.getId()).thenReturn("vehId");
|
||||
|
||||
|
|
@ -92,14 +95,13 @@ public class TestInserter {
|
|||
assertEquals(4,route.getTourActivities().getActivities().size());
|
||||
assertEquals(route.getTourActivities().getActivities().get(2).getLocationId(),shipmentToInsert.getPickupLocation());
|
||||
assertEquals(route.getTourActivities().getActivities().get(3).getLocationId(),shipmentToInsert.getDeliveryLocation());
|
||||
assertEquals(route.getEnd().getLocationId(),vehicle.getLocationId());
|
||||
assertEquals(route.getEnd().getLocationId(),vehicle.getEndLocationId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenInsertingShipmentAndRouteIsOpen_itInsertsCorrectlyAndSwitchesEndLocation(){
|
||||
Shipment shipment = mock(Shipment.class);
|
||||
Vehicle vehicle = mock(Vehicle.class);
|
||||
when(vehicle.getLocationId()).thenReturn("vehLoc");
|
||||
when(vehicle.isReturnToDepot()).thenReturn(false);
|
||||
when(vehicle.getId()).thenReturn("vehId");
|
||||
|
||||
|
|
@ -125,8 +127,8 @@ public class TestInserter {
|
|||
@Test
|
||||
public void whenSwitchingVehicleAndRouteIsClosed_newStartAndEndShouldBeTheLocationOfNewVehicle(){
|
||||
Shipment shipment = mock(Shipment.class);
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("vehId").setLocationId("vehLoc").setType(mock(VehicleType.class)).build();
|
||||
Vehicle newVehicle = VehicleImpl.Builder.newInstance("newVehId").setLocationId("newVehLoc").setType(mock(VehicleType.class)).build();
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("vehId").setStartLocationId("vehLoc").setType(mock(VehicleType.class)).build();
|
||||
Vehicle newVehicle = VehicleImpl.Builder.newInstance("newVehId").setStartLocationId("newVehLoc").setType(mock(VehicleType.class)).build();
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addPickup(shipment).addDelivery(shipment).build();
|
||||
//start - pick(shipment) - del(shipment) - end
|
||||
|
|
@ -142,14 +144,14 @@ public class TestInserter {
|
|||
Inserter inserter = new Inserter(mock(InsertionListeners.class));
|
||||
inserter.insertJob(shipmentToInsert, iData, route);
|
||||
|
||||
assertEquals(newVehicle.getLocationId(),route.getEnd().getLocationId());
|
||||
assertEquals(route.getEnd().getLocationId(),newVehicle.getEndLocationId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSwitchingVehicleAndRouteIsOpen_endLocationShouldBeTheLocationOfTheLastActivity(){
|
||||
Shipment shipment = mock(Shipment.class);
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("vehId").setReturnToDepot(false).setLocationId("vehLoc").setType(mock(VehicleType.class)).build();
|
||||
Vehicle newVehicle = VehicleImpl.Builder.newInstance("newVehId").setReturnToDepot(false).setLocationId("newVehLoc").setType(mock(VehicleType.class)).build();
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("vehId").setReturnToDepot(false).setStartLocationId("vehLoc").setType(mock(VehicleType.class)).build();
|
||||
Vehicle newVehicle = VehicleImpl.Builder.newInstance("newVehId").setReturnToDepot(false).setStartLocationId("newVehLoc").setType(mock(VehicleType.class)).build();
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addPickup(shipment).addDelivery(shipment).build();
|
||||
//start - pick(shipment) - del(shipment) - end
|
||||
|
|
@ -172,8 +174,8 @@ public class TestInserter {
|
|||
public void whenInsertingShipmentAtBeginningAndSwitchingVehicleAndRouteIsOpen_endLocationShouldBeTheLocationOfTheLastActivity(){
|
||||
Shipment shipment = mock(Shipment.class);
|
||||
when(shipment.getDeliveryLocation()).thenReturn("oldShipmentDelLoc");
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("vehId").setReturnToDepot(false).setLocationId("vehLoc").setType(mock(VehicleType.class)).build();
|
||||
Vehicle newVehicle = VehicleImpl.Builder.newInstance("newVehId").setReturnToDepot(false).setLocationId("newVehLoc").setType(mock(VehicleType.class)).build();
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("vehId").setReturnToDepot(false).setStartLocationId("vehLoc").setType(mock(VehicleType.class)).build();
|
||||
Vehicle newVehicle = VehicleImpl.Builder.newInstance("newVehId").setReturnToDepot(false).setStartLocationId("newVehLoc").setType(mock(VehicleType.class)).build();
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addPickup(shipment).addDelivery(shipment).build();
|
||||
//start - pick(shipment) - del(shipment) - end
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ public class TestMixedServiceAndShipmentsProblemOnRouteLevel {
|
|||
* get a vehicle-builder and build a vehicle located at (10,10) with type "vehicleType"
|
||||
*/
|
||||
Builder vehicleBuilder = VehicleImpl.Builder.newInstance("vehicle");
|
||||
vehicleBuilder.setLocationCoord(Coordinate.newInstance(10, 10));
|
||||
vehicleBuilder.setStartLocationCoordinate(Coordinate.newInstance(10, 10));
|
||||
vehicleBuilder.setType(vehicleType);
|
||||
Vehicle vehicle = vehicleBuilder.build();
|
||||
|
||||
|
|
@ -101,7 +101,7 @@ public class TestMixedServiceAndShipmentsProblemOnRouteLevel {
|
|||
* get a vehicle-builder and build a vehicle located at (10,10) with type "vehicleType"
|
||||
*/
|
||||
Builder vehicleBuilder = VehicleImpl.Builder.newInstance("vehicle");
|
||||
vehicleBuilder.setLocationCoord(Coordinate.newInstance(10, 10));
|
||||
vehicleBuilder.setStartLocationCoordinate(Coordinate.newInstance(10, 10));
|
||||
vehicleBuilder.setType(vehicleType);
|
||||
Vehicle vehicle = vehicleBuilder.build();
|
||||
|
||||
|
|
|
|||
|
|
@ -59,6 +59,10 @@ public class TestTourStateUpdaterWithService {
|
|||
|
||||
private VehicleRoute vehicleRoute;
|
||||
|
||||
private ServiceActivity act1;
|
||||
|
||||
private ServiceActivity act2;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
|
|
@ -103,7 +107,7 @@ public class TestTourStateUpdaterWithService {
|
|||
services.add(secondService);
|
||||
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("test", 10).build();
|
||||
vehicle = VehicleImpl.Builder.newInstance("testvehicle").setType(type).setLocationId("0,0")
|
||||
vehicle = VehicleImpl.Builder.newInstance("testvehicle").setType(type).setStartLocationId("0,0")
|
||||
.setEarliestStart(0.0).setLatestArrival(50.0).build();
|
||||
|
||||
|
||||
|
|
@ -115,11 +119,12 @@ public class TestTourStateUpdaterWithService {
|
|||
states.addStateUpdater(new UpdateVariableCosts(vrp.getActivityCosts(), vrp.getTransportCosts(), states));
|
||||
states.addStateUpdater(new UpdateActivityTimes(vrp.getTransportCosts()));
|
||||
|
||||
tour = new TourActivities();
|
||||
tour.addActivity(ServiceActivity.newInstance(firstService));
|
||||
tour.addActivity(ServiceActivity.newInstance(secondService));
|
||||
|
||||
vehicleRoute = VehicleRoute.newInstance(tour,DriverImpl.noDriver(),vehicle);
|
||||
act1 = ServiceActivity.newInstance(firstService);
|
||||
act2 = ServiceActivity.newInstance(secondService);
|
||||
|
||||
vehicleRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build();//.newInstance(tour,DriverImpl.noDriver(),vehicle);
|
||||
vehicleRoute.getTourActivities().addActivity(act1);
|
||||
vehicleRoute.getTourActivities().addActivity(act2);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -133,29 +138,26 @@ public class TestTourStateUpdaterWithService {
|
|||
public void testStatesOfAct0(){
|
||||
states.informInsertionStarts(Arrays.asList(vehicleRoute), null);
|
||||
assertEquals(0.0, vehicleRoute.getStart().getEndTime(),0.05);
|
||||
assertEquals(vehicleRoute.getVehicle().getLocationId(), vehicleRoute.getStart().getLocationId());
|
||||
assertEquals(vehicleRoute.getVehicle().getStartLocationId(), vehicleRoute.getStart().getLocationId());
|
||||
assertEquals(vehicleRoute.getVehicle().getEarliestDeparture(), vehicleRoute.getStart().getTheoreticalEarliestOperationStartTime(),0.05);
|
||||
assertEquals(vehicleRoute.getVehicle().getLatestArrival(), vehicleRoute.getStart().getTheoreticalLatestOperationStartTime(),0.05);
|
||||
assertEquals(Double.MAX_VALUE, vehicleRoute.getStart().getTheoreticalLatestOperationStartTime(),0.05);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStatesOfAct1(){
|
||||
states.informInsertionStarts(Arrays.asList(vehicleRoute), null);
|
||||
assertEquals(10.0, states.getActivityState(tour.getActivities().get(0), StateFactory.COSTS).toDouble(),0.05);
|
||||
assertEquals(5.0, states.getActivityState(tour.getActivities().get(0), StateFactory.LOAD).toDouble(),0.05);
|
||||
// assertEquals(10.0, states.getActivityState(tour.getActivities().get(0), StateTypes.EARLIEST_OPERATION_START_TIME).toDouble(),0.05);
|
||||
assertEquals(20.0, states.getActivityState(tour.getActivities().get(0), StateFactory.LATEST_OPERATION_START_TIME).toDouble(),0.05);
|
||||
assertEquals(10.0, states.getActivityState(act1, StateFactory.COSTS).toDouble(),0.05);
|
||||
assertEquals(5.0, states.getActivityState(act1, StateFactory.LOAD).toDouble(),0.05);
|
||||
assertEquals(20.0, states.getActivityState(act1, StateFactory.LATEST_OPERATION_START_TIME).toDouble(),0.05);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStatesOfAct2(){
|
||||
states.informInsertionStarts(Arrays.asList(vehicleRoute), null);
|
||||
|
||||
assertEquals(30.0, states.getActivityState(tour.getActivities().get(1), StateFactory.COSTS).toDouble(),0.05);
|
||||
assertEquals(10.0, states.getActivityState(tour.getActivities().get(1), StateFactory.LOAD).toDouble(),0.05);
|
||||
// assertEquals(10.0, states.getActivityState(tour.getActivities().get(0), StateTypes.EARLIEST_OPERATION_START_TIME).toDouble(),0.05);
|
||||
assertEquals(40.0, states.getActivityState(tour.getActivities().get(1), StateFactory.LATEST_OPERATION_START_TIME).toDouble(),0.05);
|
||||
assertEquals(30.0, states.getActivityState(act2, StateFactory.COSTS).toDouble(),0.05);
|
||||
assertEquals(10.0, states.getActivityState(act2, StateFactory.LOAD).toDouble(),0.05);
|
||||
assertEquals(40.0, states.getActivityState(act2, StateFactory.LATEST_OPERATION_START_TIME).toDouble(),0.05);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -66,10 +66,10 @@ public class VehicleRoutingProblemTest {
|
|||
public void whenBuildingWithFourVehicles_vrpShouldContainTheCorrectNuOfVehicles(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
|
||||
Vehicle v1 = mock(VehicleImpl.class);
|
||||
Vehicle v2 = mock(VehicleImpl.class);
|
||||
Vehicle v3 = mock(VehicleImpl.class);
|
||||
Vehicle v4 = mock(VehicleImpl.class);
|
||||
Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocationId("start").build();
|
||||
Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("start").build();
|
||||
Vehicle v3 = VehicleImpl.Builder.newInstance("v3").setStartLocationId("start").build();
|
||||
Vehicle v4 = VehicleImpl.Builder.newInstance("v4").setStartLocationId("start").build();
|
||||
|
||||
builder.addVehicle(v1).addVehicle(v2).addVehicle(v3).addVehicle(v4);
|
||||
|
||||
|
|
@ -82,10 +82,10 @@ public class VehicleRoutingProblemTest {
|
|||
public void whenAddingFourVehiclesAllAtOnce_vrpShouldContainTheCorrectNuOfVehicles(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
|
||||
Vehicle v1 = mock(VehicleImpl.class);
|
||||
Vehicle v2 = mock(VehicleImpl.class);
|
||||
Vehicle v3 = mock(VehicleImpl.class);
|
||||
Vehicle v4 = mock(VehicleImpl.class);
|
||||
Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocationId("start").build();
|
||||
Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("start").build();
|
||||
Vehicle v3 = VehicleImpl.Builder.newInstance("v3").setStartLocationId("start").build();
|
||||
Vehicle v4 = VehicleImpl.Builder.newInstance("v4").setStartLocationId("start").build();
|
||||
|
||||
builder.addAllVehicles(Arrays.asList(v1,v2,v3,v4));
|
||||
|
||||
|
|
@ -101,10 +101,10 @@ public class VehicleRoutingProblemTest {
|
|||
VehicleTypeImpl type1 = mock(VehicleTypeImpl.class);
|
||||
VehicleTypeImpl type2 = mock(VehicleTypeImpl.class);
|
||||
|
||||
Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setLocationId("yo").setType(type1).build();
|
||||
Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setLocationId("yo").setType(type1).build();
|
||||
Vehicle v3 = VehicleImpl.Builder.newInstance("v3").setLocationId("yo").setType(type2).build();
|
||||
Vehicle v4 = VehicleImpl.Builder.newInstance("v4").setLocationId("yo").setType(type2).build();
|
||||
Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocationId("yo").setType(type1).build();
|
||||
Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("yo").setType(type1).build();
|
||||
Vehicle v3 = VehicleImpl.Builder.newInstance("v3").setStartLocationId("yo").setType(type2).build();
|
||||
Vehicle v4 = VehicleImpl.Builder.newInstance("v4").setStartLocationId("yo").setType(type2).build();
|
||||
|
||||
builder.addVehicle(v1).addVehicle(v2).addVehicle(v3).addVehicle(v4);
|
||||
|
||||
|
|
@ -286,7 +286,7 @@ public class VehicleRoutingProblemTest {
|
|||
public void whenAddingAVehicle_getAddedVehicleTypesShouldReturnItsType(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("type", 0).build();
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setLocationId("loc").setType(type).build();
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("loc").setType(type).build();
|
||||
builder.addVehicle(vehicle);
|
||||
|
||||
assertEquals(1,builder.getAddedVehicleTypes().size());
|
||||
|
|
@ -298,8 +298,8 @@ public class VehicleRoutingProblemTest {
|
|||
public void whenAddingTwoVehicleWithSameType_getAddedVehicleTypesShouldReturnOnlyOneType(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("type", 0).build();
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setLocationId("loc").setType(type).build();
|
||||
Vehicle vehicle2 = VehicleImpl.Builder.newInstance("v").setLocationId("loc").setType(type).build();
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("loc").setType(type).build();
|
||||
Vehicle vehicle2 = VehicleImpl.Builder.newInstance("v").setStartLocationId("loc").setType(type).build();
|
||||
|
||||
builder.addVehicle(vehicle);
|
||||
builder.addVehicle(vehicle2);
|
||||
|
|
@ -314,8 +314,8 @@ public class VehicleRoutingProblemTest {
|
|||
VehicleType type = VehicleTypeImpl.Builder.newInstance("type", 0).build();
|
||||
VehicleType type2 = VehicleTypeImpl.Builder.newInstance("type2", 0).build();
|
||||
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setLocationId("loc").setType(type).build();
|
||||
Vehicle vehicle2 = VehicleImpl.Builder.newInstance("v").setLocationId("loc").setType(type2).build();
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("loc").setType(type).build();
|
||||
Vehicle vehicle2 = VehicleImpl.Builder.newInstance("v").setStartLocationId("loc").setType(type2).build();
|
||||
|
||||
builder.addVehicle(vehicle);
|
||||
builder.addVehicle(vehicle2);
|
||||
|
|
@ -328,7 +328,7 @@ public class VehicleRoutingProblemTest {
|
|||
public void whenSettingAddPenaltyVehicleOptions_itShouldAddPenaltyVehicle(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("type", 0).build();
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setLocationId("loc").setType(type).build();
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("loc").setType(type).build();
|
||||
|
||||
builder.addVehicle(vehicle);
|
||||
builder.setFleetSize(FleetSize.FINITE);
|
||||
|
|
@ -350,7 +350,7 @@ public class VehicleRoutingProblemTest {
|
|||
public void whenSettingAddPenaltyVehicleOptionsAndFleetSizeIsInfinite_noPenaltyVehicleIsAdded(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("type", 0).build();
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setLocationId("loc").setType(type).build();
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("loc").setType(type).build();
|
||||
|
||||
builder.addVehicle(vehicle);
|
||||
builder.addPenaltyVehicles(3.0);
|
||||
|
|
@ -371,8 +371,8 @@ public class VehicleRoutingProblemTest {
|
|||
public void whenSettingAddPenaltyVehicleOptionsAndTwoVehiclesWithSameLocationAndType_onlyOnePenaltyVehicleIsAdded(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("type", 0).build();
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setLocationId("loc").setType(type).build();
|
||||
Vehicle vehicle2 = VehicleImpl.Builder.newInstance("v2").setLocationId("loc").setType(type).build();
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("loc").setType(type).build();
|
||||
Vehicle vehicle2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("loc").setType(type).build();
|
||||
|
||||
builder.addVehicle(vehicle);
|
||||
builder.addVehicle(vehicle2);
|
||||
|
|
@ -395,8 +395,8 @@ public class VehicleRoutingProblemTest {
|
|||
public void whenSettingAddPenaltyVehicleOptionsWithAbsoluteFixedCostsAndTwoVehiclesWithSameLocationAndType_onePenaltyVehicleIsAddedWithTheCorrectPenaltyFixedCosts(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("type", 0).build();
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setLocationId("loc").setType(type).build();
|
||||
Vehicle vehicle2 = VehicleImpl.Builder.newInstance("v2").setLocationId("loc").setType(type).build();
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("loc").setType(type).build();
|
||||
Vehicle vehicle2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("loc").setType(type).build();
|
||||
|
||||
builder.addVehicle(vehicle);
|
||||
builder.addVehicle(vehicle2);
|
||||
|
|
@ -421,8 +421,8 @@ public class VehicleRoutingProblemTest {
|
|||
public void whenSettingAddPenaltyVehicleOptionsAndTwoVehiclesWithDiffLocationAndType_twoPenaltyVehicleIsAdded(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("type", 0).build();
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setLocationId("loc").setType(type).build();
|
||||
Vehicle vehicle2 = VehicleImpl.Builder.newInstance("v2").setLocationId("loc2").setType(type).build();
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("loc").setType(type).build();
|
||||
Vehicle vehicle2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("loc2").setType(type).build();
|
||||
|
||||
builder.addVehicle(vehicle);
|
||||
builder.addVehicle(vehicle2);
|
||||
|
|
@ -449,8 +449,8 @@ public class VehicleRoutingProblemTest {
|
|||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("type", 0).build();
|
||||
VehicleType type2 = VehicleTypeImpl.Builder.newInstance("type2", 0).build();
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setLocationId("loc").setType(type).build();
|
||||
Vehicle vehicle2 = VehicleImpl.Builder.newInstance("v2").setLocationId("loc").setType(type2).build();
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("loc").setType(type).build();
|
||||
Vehicle vehicle2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("loc").setType(type2).build();
|
||||
|
||||
builder.addVehicle(vehicle);
|
||||
builder.addVehicle(vehicle2);
|
||||
|
|
@ -471,4 +471,22 @@ public class VehicleRoutingProblemTest {
|
|||
assertTrue(anotherPenVehInCollection);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingVehicleWithDiffStartAndEnd_startLocationMustBeRegisteredInLocationMap(){
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("start").setEndLocationId("end").build();
|
||||
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
vrpBuilder.addVehicle(vehicle);
|
||||
assertTrue(vrpBuilder.getLocationMap().containsKey("start"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingVehicleWithDiffStartAndEnd_endLocationMustBeRegisteredInLocationMap(){
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("start").setEndLocationId("end").build();
|
||||
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
vrpBuilder.addVehicle(vehicle);
|
||||
assertTrue(vrpBuilder.getLocationMap().containsKey("end"));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
package jsprit.core.problem.io;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
|
|
@ -58,7 +59,7 @@ public class VrpReaderV2Test {
|
|||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrpXMLReader(builder, null).read(inFileName);
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
assertEquals(2,vrp.getVehicles().size());
|
||||
assertEquals(4,vrp.getVehicles().size());
|
||||
assertTrue(idsInCollection(Arrays.asList("v1","v2"),vrp.getVehicles()));
|
||||
}
|
||||
|
||||
|
|
@ -69,9 +70,9 @@ public class VrpReaderV2Test {
|
|||
VehicleRoutingProblem vrp = builder.build();
|
||||
Vehicle v1 = getVehicle("v1",vrp.getVehicles());
|
||||
assertEquals(20,v1.getCapacity());
|
||||
assertEquals(100.0,v1.getCoord().getX(),0.01);
|
||||
assertEquals(100.0,v1.getStartLocationCoordinate().getX(),0.01);
|
||||
assertEquals(0.0,v1.getEarliestDeparture(),0.01);
|
||||
assertEquals("depotLoc2",v1.getLocationId());
|
||||
assertEquals("depotLoc2",v1.getStartLocationId());
|
||||
assertNotNull(v1.getType());
|
||||
assertEquals("vehType", v1.getType().getTypeId());
|
||||
assertEquals(1000.0,v1.getLatestArrival(),0.01);
|
||||
|
|
@ -175,7 +176,128 @@ public class VrpReaderV2Test {
|
|||
assertEquals("service",s1.getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingFile_v2MustNotReturnToDepot(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrpXMLReader(builder, null).read(inFileName);
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
Vehicle v = getVehicle("v2",vrp.getVehicles());
|
||||
assertFalse(v.isReturnToDepot());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingFile_v3HasTheCorrectStartLocation(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrpXMLReader(builder, null).read(inFileName);
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
Vehicle v3 = getVehicle("v3",vrp.getVehicles());
|
||||
assertEquals("startLoc",v3.getStartLocationId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingFile_v3HasTheCorrectEndLocation(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrpXMLReader(builder, null).read(inFileName);
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
Vehicle v3 = getVehicle("v3",vrp.getVehicles());
|
||||
assertEquals("endLoc",v3.getEndLocationId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingFile_v3HasTheCorrectEndLocationCoordinate(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrpXMLReader(builder, null).read(inFileName);
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
Vehicle v3 = getVehicle("v3",vrp.getVehicles());
|
||||
assertEquals(1000.0,v3.getEndLocationCoordinate().getX(),0.01);
|
||||
assertEquals(2000.0,v3.getEndLocationCoordinate().getY(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingFile_v3HasTheCorrectStartLocationCoordinate(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrpXMLReader(builder, null).read(inFileName);
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
Vehicle v3 = getVehicle("v3",vrp.getVehicles());
|
||||
assertEquals(10.0,v3.getStartLocationCoordinate().getX(),0.01);
|
||||
assertEquals(100.0,v3.getStartLocationCoordinate().getY(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingFile_v3HasTheCorrectLocationCoordinate(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrpXMLReader(builder, null).read(inFileName);
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
Vehicle v3 = getVehicle("v3",vrp.getVehicles());
|
||||
assertEquals(10.0,v3.getStartLocationCoordinate().getX(),0.01);
|
||||
assertEquals(100.0,v3.getStartLocationCoordinate().getY(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingFile_v3HasTheCorrectLocationId(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrpXMLReader(builder, null).read(inFileName);
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
Vehicle v3 = getVehicle("v3",vrp.getVehicles());
|
||||
assertEquals("startLoc",v3.getStartLocationId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingFile_v4HasTheCorrectStartLocation(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrpXMLReader(builder, null).read(inFileName);
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
Vehicle v = getVehicle("v4",vrp.getVehicles());
|
||||
assertEquals("startLoc",v.getStartLocationId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingFile_v4HasTheCorrectEndLocation(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrpXMLReader(builder, null).read(inFileName);
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
Vehicle v = getVehicle("v4",vrp.getVehicles());
|
||||
assertEquals("endLoc",v.getEndLocationId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingFile_v4HasTheCorrectEndLocationCoordinate(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrpXMLReader(builder, null).read(inFileName);
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
Vehicle v = getVehicle("v4",vrp.getVehicles());
|
||||
assertEquals(1000.0,v.getEndLocationCoordinate().getX(),0.01);
|
||||
assertEquals(2000.0,v.getEndLocationCoordinate().getY(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingFile_v4HasTheCorrectStartLocationCoordinate(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrpXMLReader(builder, null).read(inFileName);
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
Vehicle v = getVehicle("v4",vrp.getVehicles());
|
||||
assertEquals(10.0,v.getStartLocationCoordinate().getX(),0.01);
|
||||
assertEquals(100.0,v.getStartLocationCoordinate().getY(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingFile_v4HasTheCorrectLocationCoordinate(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrpXMLReader(builder, null).read(inFileName);
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
Vehicle v = getVehicle("v4",vrp.getVehicles());
|
||||
assertEquals(10.0,v.getStartLocationCoordinate().getX(),0.01);
|
||||
assertEquals(100.0,v.getStartLocationCoordinate().getY(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingFile_v4HasTheCorrectLocationId(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrpXMLReader(builder, null).read(inFileName);
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
Vehicle v = getVehicle("v4",vrp.getVehicles());
|
||||
assertEquals("startLoc",v.getStartLocationId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingJobs_capOfShipment3IsReadCorrectly(){
|
||||
|
|
|
|||
|
|
@ -17,13 +17,20 @@
|
|||
package jsprit.core.problem.io;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.VehicleRoutingProblem.Builder;
|
||||
import jsprit.core.problem.VehicleRoutingProblem.FleetSize;
|
||||
import jsprit.core.problem.job.Service;
|
||||
import jsprit.core.problem.job.Shipment;
|
||||
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.VehicleTypeImpl;
|
||||
import jsprit.core.util.Coordinate;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
|
@ -43,13 +50,8 @@ public class VrpWriterV2Test {
|
|||
public void whenWritingInfiniteVrp_itWritesCorrectly(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
builder.setFleetSize(FleetSize.INFINITE);
|
||||
// Depot depot = new Depot("depotLoc",Coordinate.newInstance(0, 0));
|
||||
// Depot depot2 = new Depot("depotLoc2",Coordinate.newInstance(100, 100));
|
||||
// builder.addDepot(depot2);
|
||||
// builder.assignVehicleType(depot, VehicleType.Builder.newInstance("vehType", 20).build());
|
||||
// builder.assignVehicleType(depot, VehicleType.Builder.newInstance("vehType2", 200).build());
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("vehType", 20).build();
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("myVehicle").setLocationId("loc").setType(type).build();
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("myVehicle").setStartLocationId("loc").setType(type).build();
|
||||
builder.addVehicle(vehicle);
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
new VrpXMLWriter(vrp, null).write(infileName);
|
||||
|
|
@ -59,13 +61,10 @@ public class VrpWriterV2Test {
|
|||
public void whenWritingFiniteVrp_itWritesCorrectly(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
builder.setFleetSize(FleetSize.FINITE);
|
||||
// Depot depot = new Depot("depotLoc",Coordinate.newInstance(0, 0));
|
||||
// Depot depot2 = new Depot("depotLoc2",Coordinate.newInstance(100, 100));
|
||||
// builder.addDepot(depot2);
|
||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType", 20).build();
|
||||
VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2", 200).build();
|
||||
Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setLocationId("loc").setType(type1).build();
|
||||
Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setLocationId("loc").setType(type2).build();
|
||||
Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocationId("loc").setType(type1).build();
|
||||
Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("loc").setType(type2).build();
|
||||
builder.addVehicle(v1);
|
||||
builder.addVehicle(v2);
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
|
|
@ -76,13 +75,10 @@ public class VrpWriterV2Test {
|
|||
public void t(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
builder.setFleetSize(FleetSize.FINITE);
|
||||
// Depot depot = new Depot("depotLoc",Coordinate.newInstance(0, 0));
|
||||
// Depot depot2 = new Depot("depotLoc2",Coordinate.newInstance(100, 100));
|
||||
// builder.addDepot(depot2);
|
||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType", 20).build();
|
||||
VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2", 200).build();
|
||||
Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setLocationId("loc").setType(type1).build();
|
||||
Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setLocationId("loc").setType(type2).build();
|
||||
Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocationId("loc").setType(type1).build();
|
||||
Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("loc").setType(type2).build();
|
||||
builder.addVehicle(v1);
|
||||
builder.addVehicle(v2);
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
|
|
@ -98,8 +94,8 @@ public class VrpWriterV2Test {
|
|||
|
||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType", 20).build();
|
||||
VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2", 200).build();
|
||||
Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setLocationId("loc").setType(type1).build();
|
||||
Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setLocationId("loc").setType(type2).build();
|
||||
Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocationId("loc").setType(type1).build();
|
||||
Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("loc").setType(type2).build();
|
||||
|
||||
builder.addVehicle(v1);
|
||||
builder.addVehicle(v2);
|
||||
|
|
@ -122,6 +118,364 @@ public class VrpWriterV2Test {
|
|||
assertEquals(2.0,s1_read.getServiceDuration(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenWritingShipments_readingThemAgainMustReturnTheWrittenLocationIdsOfS1(){
|
||||
Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
|
||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType", 20).build();
|
||||
VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2", 200).build();
|
||||
Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocationId("loc").setType(type1).build();
|
||||
Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("loc").setType(type2).build();
|
||||
|
||||
builder.addVehicle(v1);
|
||||
builder.addVehicle(v2);
|
||||
|
||||
Shipment s1 = Shipment.Builder.newInstance("1", 10).setPickupLocation("pickLoc").setDeliveryLocation("delLoc").setPickupTimeWindow(TimeWindow.newInstance(1, 2))
|
||||
.setDeliveryTimeWindow(TimeWindow.newInstance(3, 4)).build();
|
||||
Shipment s2 = Shipment.Builder.newInstance("2", 20).setPickupLocation("pickLocation").setDeliveryLocation("delLocation").setPickupTimeWindow(TimeWindow.newInstance(5, 6))
|
||||
.setDeliveryTimeWindow(TimeWindow.newInstance(7, 8)).build();
|
||||
|
||||
|
||||
VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build();
|
||||
new VrpXMLWriter(vrp, null).write(infileName);
|
||||
|
||||
VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrpXMLReader(vrpToReadBuilder, null).read(infileName);
|
||||
VehicleRoutingProblem readVrp = vrpToReadBuilder.build();
|
||||
assertEquals(2,readVrp.getJobs().size());
|
||||
|
||||
assertEquals("pickLoc",((Shipment)readVrp.getJobs().get("1")).getPickupLocation());
|
||||
assertEquals("delLoc",((Shipment)readVrp.getJobs().get("1")).getDeliveryLocation());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenWritingShipments_readingThemAgainMustReturnTheWrittenPickupTimeWindowsOfS1(){
|
||||
Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
|
||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType", 20).build();
|
||||
VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2", 200).build();
|
||||
Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocationId("loc").setType(type1).build();
|
||||
Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("loc").setType(type2).build();
|
||||
|
||||
builder.addVehicle(v1);
|
||||
builder.addVehicle(v2);
|
||||
|
||||
Shipment s1 = Shipment.Builder.newInstance("1", 10).setPickupLocation("pickLoc").setDeliveryLocation("delLoc").setPickupTimeWindow(TimeWindow.newInstance(1, 2))
|
||||
.setDeliveryTimeWindow(TimeWindow.newInstance(3, 4)).build();
|
||||
Shipment s2 = Shipment.Builder.newInstance("2", 20).setPickupLocation("pickLocation").setDeliveryLocation("delLocation").setPickupTimeWindow(TimeWindow.newInstance(5, 6))
|
||||
.setDeliveryTimeWindow(TimeWindow.newInstance(7, 8)).build();
|
||||
|
||||
|
||||
VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build();
|
||||
new VrpXMLWriter(vrp, null).write(infileName);
|
||||
|
||||
VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrpXMLReader(vrpToReadBuilder, null).read(infileName);
|
||||
VehicleRoutingProblem readVrp = vrpToReadBuilder.build();
|
||||
assertEquals(2,readVrp.getJobs().size());
|
||||
|
||||
assertEquals(1.0,((Shipment)readVrp.getJobs().get("1")).getPickupTimeWindow().getStart(),0.01);
|
||||
assertEquals(2.0,((Shipment)readVrp.getJobs().get("1")).getPickupTimeWindow().getEnd(),0.01);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenWritingShipments_readingThemAgainMustReturnTheWrittenDeliveryTimeWindowsOfS1(){
|
||||
Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
|
||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType", 20).build();
|
||||
VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2", 200).build();
|
||||
Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocationId("loc").setType(type1).build();
|
||||
Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("loc").setType(type2).build();
|
||||
|
||||
builder.addVehicle(v1);
|
||||
builder.addVehicle(v2);
|
||||
|
||||
Shipment s1 = Shipment.Builder.newInstance("1", 10).setPickupLocation("pickLoc").setDeliveryLocation("delLoc").setPickupTimeWindow(TimeWindow.newInstance(1, 2))
|
||||
.setDeliveryTimeWindow(TimeWindow.newInstance(3, 4)).build();
|
||||
Shipment s2 = Shipment.Builder.newInstance("2", 20).setPickupLocation("pickLocation").setDeliveryLocation("delLocation").setPickupTimeWindow(TimeWindow.newInstance(5, 6))
|
||||
.setDeliveryTimeWindow(TimeWindow.newInstance(7, 8)).build();
|
||||
|
||||
|
||||
VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build();
|
||||
new VrpXMLWriter(vrp, null).write(infileName);
|
||||
|
||||
VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrpXMLReader(vrpToReadBuilder, null).read(infileName);
|
||||
VehicleRoutingProblem readVrp = vrpToReadBuilder.build();
|
||||
assertEquals(2,readVrp.getJobs().size());
|
||||
|
||||
assertEquals(3.0,((Shipment)readVrp.getJobs().get("1")).getDeliveryTimeWindow().getStart(),0.01);
|
||||
assertEquals(4.0,((Shipment)readVrp.getJobs().get("1")).getDeliveryTimeWindow().getEnd(),0.01);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenWritingShipments_readingThemAgainMustReturnTheWrittenDeliveryServiceTimeOfS1(){
|
||||
Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
|
||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType", 20).build();
|
||||
VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2", 200).build();
|
||||
Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocationId("loc").setType(type1).build();
|
||||
Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("loc").setType(type2).build();
|
||||
|
||||
builder.addVehicle(v1);
|
||||
builder.addVehicle(v2);
|
||||
|
||||
Shipment s1 = Shipment.Builder.newInstance("1", 10).setPickupLocation("pickLoc").setDeliveryLocation("delLoc").setPickupTimeWindow(TimeWindow.newInstance(1, 2))
|
||||
.setDeliveryTimeWindow(TimeWindow.newInstance(3, 4)).setPickupServiceTime(100).setDeliveryServiceTime(50).build();
|
||||
Shipment s2 = Shipment.Builder.newInstance("2", 20).setPickupLocation("pickLocation").setDeliveryLocation("delLocation").setPickupTimeWindow(TimeWindow.newInstance(5, 6))
|
||||
.setDeliveryTimeWindow(TimeWindow.newInstance(7, 8)).build();
|
||||
|
||||
|
||||
VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build();
|
||||
new VrpXMLWriter(vrp, null).write(infileName);
|
||||
|
||||
VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrpXMLReader(vrpToReadBuilder, null).read(infileName);
|
||||
VehicleRoutingProblem readVrp = vrpToReadBuilder.build();
|
||||
assertEquals(2,readVrp.getJobs().size());
|
||||
|
||||
assertEquals(100.0,((Shipment)readVrp.getJobs().get("1")).getPickupServiceTime(),0.01);
|
||||
assertEquals(50.0,((Shipment)readVrp.getJobs().get("1")).getDeliveryServiceTime(),0.01);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenWritingShipments_readingThemAgainMustReturnTheWrittenLocationIdOfS1(){
|
||||
Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
|
||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType", 20).build();
|
||||
VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2", 200).build();
|
||||
Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocationId("loc").setType(type1).build();
|
||||
Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("loc").setType(type2).build();
|
||||
|
||||
builder.addVehicle(v1);
|
||||
builder.addVehicle(v2);
|
||||
|
||||
Shipment s1 = Shipment.Builder.newInstance("1", 10).setPickupCoord(Coordinate.newInstance(1, 2)).setDeliveryLocation("delLoc").setPickupTimeWindow(TimeWindow.newInstance(1, 2))
|
||||
.setDeliveryTimeWindow(TimeWindow.newInstance(3, 4)).setPickupServiceTime(100).setDeliveryServiceTime(50).build();
|
||||
Shipment s2 = Shipment.Builder.newInstance("2", 20).setPickupLocation("pickLocation").setDeliveryLocation("delLocation").setPickupTimeWindow(TimeWindow.newInstance(5, 6))
|
||||
.setDeliveryTimeWindow(TimeWindow.newInstance(7, 8)).build();
|
||||
|
||||
|
||||
VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build();
|
||||
new VrpXMLWriter(vrp, null).write(infileName);
|
||||
|
||||
VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrpXMLReader(vrpToReadBuilder, null).read(infileName);
|
||||
VehicleRoutingProblem readVrp = vrpToReadBuilder.build();
|
||||
assertEquals(2,readVrp.getJobs().size());
|
||||
|
||||
assertEquals("[x=1.0][y=2.0]",((Shipment)readVrp.getJobs().get("1")).getPickupLocation());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenWritingShipments_readingThemAgainMustReturnTheWrittenLocationCoordOfS1(){
|
||||
Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
|
||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType", 20).build();
|
||||
VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2", 200).build();
|
||||
Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocationId("loc").setType(type1).build();
|
||||
Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("loc").setType(type2).build();
|
||||
|
||||
builder.addVehicle(v1);
|
||||
builder.addVehicle(v2);
|
||||
|
||||
Shipment s1 = Shipment.Builder.newInstance("1", 10).setPickupCoord(Coordinate.newInstance(1, 2)).setDeliveryCoord(Coordinate.newInstance(5, 6)).setDeliveryLocation("delLoc").setPickupTimeWindow(TimeWindow.newInstance(1, 2))
|
||||
.setDeliveryTimeWindow(TimeWindow.newInstance(3, 4)).setPickupServiceTime(100).setDeliveryServiceTime(50).build();
|
||||
Shipment s2 = Shipment.Builder.newInstance("2", 20).setPickupLocation("pickLocation").setDeliveryLocation("delLocation").setPickupTimeWindow(TimeWindow.newInstance(5, 6))
|
||||
.setDeliveryTimeWindow(TimeWindow.newInstance(7, 8)).build();
|
||||
|
||||
|
||||
VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build();
|
||||
new VrpXMLWriter(vrp, null).write(infileName);
|
||||
|
||||
VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrpXMLReader(vrpToReadBuilder, null).read(infileName);
|
||||
VehicleRoutingProblem readVrp = vrpToReadBuilder.build();
|
||||
assertEquals(2,readVrp.getJobs().size());
|
||||
|
||||
assertEquals(1.0,((Shipment)readVrp.getJobs().get("1")).getPickupCoord().getX(),0.01);
|
||||
assertEquals(2.0,((Shipment)readVrp.getJobs().get("1")).getPickupCoord().getY(),0.01);
|
||||
|
||||
assertEquals(5.0,((Shipment)readVrp.getJobs().get("1")).getDeliveryCoord().getX(),0.01);
|
||||
assertEquals(6.0,((Shipment)readVrp.getJobs().get("1")).getDeliveryCoord().getY(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenWritingVehicleV1_itsStartLocationMustBeWrittenCorrectly(){
|
||||
Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
|
||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType", 20).build();
|
||||
VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2", 200).build();
|
||||
Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocationId("loc").setType(type1).build();
|
||||
Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("loc").setType(type2).build();
|
||||
|
||||
builder.addVehicle(v1);
|
||||
builder.addVehicle(v2);
|
||||
|
||||
Service s1 = Service.Builder.newInstance("1", 1).setLocationId("loc").setServiceTime(2.0).build();
|
||||
Service s2 = Service.Builder.newInstance("2", 1).setLocationId("loc2").setServiceTime(4.0).build();
|
||||
|
||||
VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build();
|
||||
new VrpXMLWriter(vrp, null).write(infileName);
|
||||
|
||||
VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrpXMLReader(vrpToReadBuilder, null).read(infileName);
|
||||
VehicleRoutingProblem readVrp = vrpToReadBuilder.build();
|
||||
|
||||
Vehicle v = getVehicle("v1",readVrp.getVehicles());
|
||||
assertEquals("loc",v.getStartLocationId());
|
||||
assertEquals("loc",v.getEndLocationId());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenWritingVehicleV1_itDoesNotReturnToDepotMustBeWrittenCorrectly(){
|
||||
Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
|
||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType", 20).build();
|
||||
VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2", 200).build();
|
||||
Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setReturnToDepot(false).setStartLocationId("loc").setType(type1).build();
|
||||
Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("loc").setType(type2).build();
|
||||
|
||||
builder.addVehicle(v1);
|
||||
builder.addVehicle(v2);
|
||||
|
||||
Service s1 = Service.Builder.newInstance("1", 1).setLocationId("loc").setServiceTime(2.0).build();
|
||||
Service s2 = Service.Builder.newInstance("2", 1).setLocationId("loc2").setServiceTime(4.0).build();
|
||||
|
||||
VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build();
|
||||
new VrpXMLWriter(vrp, null).write(infileName);
|
||||
|
||||
VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrpXMLReader(vrpToReadBuilder, null).read(infileName);
|
||||
VehicleRoutingProblem readVrp = vrpToReadBuilder.build();
|
||||
|
||||
Vehicle v = getVehicle("v1",readVrp.getVehicles());
|
||||
assertFalse(v.isReturnToDepot());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenWritingVehicleV1_readingAgainAssignsCorrectType(){
|
||||
Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
|
||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType", 20).build();
|
||||
VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2", 200).build();
|
||||
Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setReturnToDepot(false).setStartLocationId("loc").setType(type1).build();
|
||||
Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("loc").setType(type2).build();
|
||||
|
||||
builder.addVehicle(v1);
|
||||
builder.addVehicle(v2);
|
||||
|
||||
Service s1 = Service.Builder.newInstance("1", 1).setLocationId("loc").setServiceTime(2.0).build();
|
||||
Service s2 = Service.Builder.newInstance("2", 1).setLocationId("loc2").setServiceTime(4.0).build();
|
||||
|
||||
VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build();
|
||||
new VrpXMLWriter(vrp, null).write(infileName);
|
||||
|
||||
VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrpXMLReader(vrpToReadBuilder, null).read(infileName);
|
||||
VehicleRoutingProblem readVrp = vrpToReadBuilder.build();
|
||||
|
||||
Vehicle v = getVehicle("v1",readVrp.getVehicles());
|
||||
assertEquals("vehType",v.getType().getTypeId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenWritingVehicleV2_readingAgainAssignsCorrectType(){
|
||||
Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
|
||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType", 20).build();
|
||||
VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2", 200).build();
|
||||
Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setReturnToDepot(false).setStartLocationId("loc").setType(type1).build();
|
||||
Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("loc").setType(type2).build();
|
||||
|
||||
builder.addVehicle(v1);
|
||||
builder.addVehicle(v2);
|
||||
|
||||
Service s1 = Service.Builder.newInstance("1", 1).setLocationId("loc").setServiceTime(2.0).build();
|
||||
Service s2 = Service.Builder.newInstance("2", 1).setLocationId("loc2").setServiceTime(4.0).build();
|
||||
|
||||
VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build();
|
||||
new VrpXMLWriter(vrp, null).write(infileName);
|
||||
|
||||
VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrpXMLReader(vrpToReadBuilder, null).read(infileName);
|
||||
VehicleRoutingProblem readVrp = vrpToReadBuilder.build();
|
||||
|
||||
Vehicle v = getVehicle("v2",readVrp.getVehicles());
|
||||
assertEquals("vehType2",v.getType().getTypeId());
|
||||
assertEquals(200,v.getType().getCapacity());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenWritingVehicleV2_readingItsLocationsAgainReturnsCorrectLocations(){
|
||||
Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
|
||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType", 20).build();
|
||||
VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2", 200).build();
|
||||
Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setReturnToDepot(false).setStartLocationId("loc").setType(type1).build();
|
||||
Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("startLoc").setStartLocationCoordinate(Coordinate.newInstance(1, 2))
|
||||
.setEndLocationId("endLoc").setEndLocationCoordinate(Coordinate.newInstance(4, 5)).setType(type2).build();
|
||||
|
||||
builder.addVehicle(v1);
|
||||
builder.addVehicle(v2);
|
||||
|
||||
Service s1 = Service.Builder.newInstance("1", 1).setLocationId("loc").setServiceTime(2.0).build();
|
||||
Service s2 = Service.Builder.newInstance("2", 1).setLocationId("loc2").setServiceTime(4.0).build();
|
||||
|
||||
VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build();
|
||||
new VrpXMLWriter(vrp, null).write(infileName);
|
||||
|
||||
VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrpXMLReader(vrpToReadBuilder, null).read(infileName);
|
||||
VehicleRoutingProblem readVrp = vrpToReadBuilder.build();
|
||||
|
||||
Vehicle v = getVehicle("v2",readVrp.getVehicles());
|
||||
assertEquals("startLoc",v.getStartLocationId());
|
||||
assertEquals("endLoc",v.getEndLocationId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenWritingVehicleV2_readingItsLocationsCoordsAgainReturnsCorrectLocationsCoords(){
|
||||
Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
|
||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType", 20).build();
|
||||
VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2", 200).build();
|
||||
Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setReturnToDepot(false).setStartLocationId("loc").setType(type1).build();
|
||||
Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("startLoc").setStartLocationCoordinate(Coordinate.newInstance(1, 2))
|
||||
.setEndLocationId("endLoc").setEndLocationCoordinate(Coordinate.newInstance(4, 5)).setType(type2).build();
|
||||
|
||||
builder.addVehicle(v1);
|
||||
builder.addVehicle(v2);
|
||||
|
||||
Service s1 = Service.Builder.newInstance("1", 1).setLocationId("loc").setServiceTime(2.0).build();
|
||||
Service s2 = Service.Builder.newInstance("2", 1).setLocationId("loc2").setServiceTime(4.0).build();
|
||||
|
||||
VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build();
|
||||
new VrpXMLWriter(vrp, null).write(infileName);
|
||||
|
||||
VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrpXMLReader(vrpToReadBuilder, null).read(infileName);
|
||||
VehicleRoutingProblem readVrp = vrpToReadBuilder.build();
|
||||
|
||||
Vehicle v = getVehicle("v2",readVrp.getVehicles());
|
||||
assertEquals(1.0,v.getStartLocationCoordinate().getX(),0.01);
|
||||
assertEquals(2.0,v.getStartLocationCoordinate().getY(),0.01);
|
||||
|
||||
assertEquals(4.0,v.getEndLocationCoordinate().getX(),0.01);
|
||||
assertEquals(5.0,v.getEndLocationCoordinate().getY(),0.01);
|
||||
}
|
||||
|
||||
private Vehicle getVehicle(String string, Collection<Vehicle> vehicles) {
|
||||
for(Vehicle v : vehicles) if(string.equals(v.getId())) return v;
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,10 +24,7 @@ import java.util.Iterator;
|
|||
import jsprit.core.problem.driver.DriverImpl;
|
||||
import jsprit.core.problem.driver.DriverImpl.NoDriver;
|
||||
import jsprit.core.problem.job.Service;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.ServiceActivity;
|
||||
import jsprit.core.problem.solution.route.activity.Start;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivities;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.problem.vehicle.VehicleImpl;
|
||||
|
|
@ -44,15 +41,13 @@ public class TestVehicleRoute {
|
|||
|
||||
@Before
|
||||
public void doBefore(){
|
||||
vehicle = VehicleImpl.Builder.newInstance("v").setLocationId("loc").setType(VehicleTypeImpl.Builder.newInstance("yo", 0).build()).build();
|
||||
vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("loc").setType(VehicleTypeImpl.Builder.newInstance("yo", 0).build()).build();
|
||||
driver = DriverImpl.noDriver();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void whenBuildingEmptyRouteCorrectly_go(){
|
||||
VehicleRoute route = VehicleRoute.newInstance(TourActivities.emptyTour(),DriverImpl.noDriver(),VehicleImpl.createNoVehicle());
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(VehicleImpl.createNoVehicle(),DriverImpl.noDriver()).build();
|
||||
assertTrue(route!=null);
|
||||
}
|
||||
|
||||
|
|
@ -74,56 +69,17 @@ public class TestVehicleRoute {
|
|||
assertEquals(0,count);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalStateException.class)
|
||||
public void whenBuildingEmptyRoute_(){
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void whenBuildingRouteWithNulls_itThrowsException(){
|
||||
@SuppressWarnings("unused")
|
||||
VehicleRoute route = VehicleRoute.newInstance(null,null,null);
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(null, null).build();
|
||||
}
|
||||
|
||||
@Test(expected=IllegalStateException.class)
|
||||
public void whenBuildingRouteWithNonEmptyTour_throwException(){
|
||||
TourActivities tour = new TourActivities();
|
||||
tour.addActivity(ServiceActivity.newInstance(Service.Builder.newInstance("jo", 10).build()));
|
||||
@SuppressWarnings("unused")
|
||||
VehicleRoute route = VehicleRoute.newInstance(tour,DriverImpl.noDriver(),VehicleImpl.createNoVehicle());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenBuildingEmptyTour_tourIterIteratesOverAnEmptyList(){
|
||||
TourActivities tour = new TourActivities();
|
||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setLocationId("loc").setType(VehicleTypeImpl.Builder.newInstance("yo", 0).build()).build();
|
||||
VehicleRoute route = VehicleRoute.newInstance(tour,DriverImpl.noDriver(),v);
|
||||
Iterator<TourActivity> iter = route.getTourActivities().iterator();
|
||||
int count = 0;
|
||||
while(iter.hasNext()){
|
||||
@SuppressWarnings("unused")
|
||||
TourActivity act = iter.next();
|
||||
count++;
|
||||
}
|
||||
assertEquals(0,count);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenBuildingANonEmptyTour_tourIterIteratesOverActivitiesCorrectly(){
|
||||
TourActivities tour = new TourActivities();
|
||||
tour.addActivity(Start.newInstance("", 0, 0));
|
||||
VehicleRoute route = VehicleRoute.newInstance(tour, driver, vehicle);
|
||||
Iterator<TourActivity> iter = route.getTourActivities().iterator();
|
||||
int count = 0;
|
||||
while(iter.hasNext()){
|
||||
@SuppressWarnings("unused")
|
||||
TourActivity act = iter.next();
|
||||
count++;
|
||||
}
|
||||
assertEquals(1,count);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void whenBuildingANonEmptyTour2Times_tourIterIteratesOverActivitiesCorrectly(){
|
||||
TourActivities tour = new TourActivities();
|
||||
tour.addActivity(ServiceActivity.newInstance(Service.Builder.newInstance("2", 30).setLocationId("1").build()));
|
||||
VehicleRoute route = VehicleRoute.newInstance(tour, driver, vehicle);
|
||||
VehicleRoute.Builder routeBuilder = VehicleRoute.Builder.newInstance(vehicle, driver);
|
||||
routeBuilder.addService(Service.Builder.newInstance("2", 30).setLocationId("1").build());
|
||||
VehicleRoute route = routeBuilder.build();
|
||||
|
||||
{
|
||||
Iterator<TourActivity> iter = route.getTourActivities().iterator();
|
||||
|
|
@ -136,7 +92,7 @@ public class TestVehicleRoute {
|
|||
assertEquals(1,count);
|
||||
}
|
||||
{
|
||||
tour.addActivity(ServiceActivity.newInstance(Service.Builder.newInstance("3", 30).setLocationId("1").build()));
|
||||
route.getTourActivities().addActivity(ServiceActivity.newInstance(Service.Builder.newInstance("3", 30).setLocationId("1").build()));
|
||||
Iterator<TourActivity> iter = route.getTourActivities().iterator();
|
||||
int count = 0;
|
||||
while(iter.hasNext()){
|
||||
|
|
@ -150,8 +106,7 @@ public class TestVehicleRoute {
|
|||
|
||||
@Test
|
||||
public void whenBuildingANonEmptyTour_tourReverseIterIteratesOverActivitiesCorrectly(){
|
||||
TourActivities tour = new TourActivities();
|
||||
VehicleRoute route = VehicleRoute.newInstance(tour, driver, vehicle);
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).build();
|
||||
Iterator<TourActivity> iter = route.getTourActivities().reverseActivityIterator();
|
||||
int count = 0;
|
||||
while(iter.hasNext()){
|
||||
|
|
@ -164,9 +119,9 @@ public class TestVehicleRoute {
|
|||
|
||||
@Test
|
||||
public void whenBuildingANonEmptyTourV2_tourReverseIterIteratesOverActivitiesCorrectly(){
|
||||
TourActivities tour = new TourActivities();
|
||||
tour.addActivity(ServiceActivity.newInstance(Service.Builder.newInstance("2", 30).setLocationId("1").build()));
|
||||
VehicleRoute route = VehicleRoute.newInstance(tour, driver, vehicle);
|
||||
VehicleRoute.Builder routeBuilder = VehicleRoute.Builder.newInstance(vehicle, driver);
|
||||
routeBuilder.addService(Service.Builder.newInstance("2", 30).setLocationId("1").build());
|
||||
VehicleRoute route = routeBuilder.build();
|
||||
Iterator<TourActivity> iter = route.getTourActivities().reverseActivityIterator();
|
||||
int count = 0;
|
||||
while(iter.hasNext()){
|
||||
|
|
@ -177,74 +132,162 @@ public class TestVehicleRoute {
|
|||
assertEquals(1,count);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenBuildingANonEmptyTourV3_tourReverseIterIteratesOverActivitiesCorrectly(){
|
||||
TourActivities tour = new TourActivities();
|
||||
tour.addActivity(ServiceActivity.newInstance(Service.Builder.newInstance("2", 30).setLocationId("1").build()));
|
||||
ServiceActivity del = ServiceActivity.newInstance(Service.Builder.newInstance("3", 30).setLocationId("1").build());
|
||||
tour.addActivity(del);
|
||||
VehicleRoute route = VehicleRoute.newInstance(tour, driver, vehicle);
|
||||
Iterator<TourActivity> iter = route.getTourActivities().reverseActivityIterator();
|
||||
int count = 0;
|
||||
TourActivity memAct = null;
|
||||
while(iter.hasNext()){
|
||||
TourActivity act = iter.next();
|
||||
if(count==0) memAct = act;
|
||||
count++;
|
||||
}
|
||||
assertEquals(memAct,del);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenBuildingANonEmptyTourV4_tourReverseIterIteratesOverActivitiesCorrectly(){
|
||||
TourActivities tour = new TourActivities();
|
||||
tour.addActivity(ServiceActivity.newInstance(Service.Builder.newInstance("2", 30).setLocationId("1").build()));
|
||||
ServiceActivity del = ServiceActivity.newInstance(Service.Builder.newInstance("3", 30).setLocationId("1").build());
|
||||
tour.addActivity(del);
|
||||
VehicleRoute route = VehicleRoute.newInstance(tour, driver, vehicle);
|
||||
Iterator<TourActivity> iter = route.getTourActivities().reverseActivityIterator();
|
||||
int count = 0;
|
||||
TourActivity memAct = null;
|
||||
while(iter.hasNext()){
|
||||
TourActivity act = iter.next();
|
||||
if(count==0) memAct = act;
|
||||
count++;
|
||||
}
|
||||
assertEquals(memAct,del);
|
||||
assertEquals(2,count);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenBuildingANonEmptyTour2Times_tourReverseIterIteratesOverActivitiesCorrectly(){
|
||||
TourActivities tour = new TourActivities();
|
||||
tour.addActivity(ServiceActivity.newInstance(Service.Builder.newInstance("2", 30).setLocationId("1").build()));
|
||||
ServiceActivity del = ServiceActivity.newInstance(Service.Builder.newInstance("3", 30).setLocationId("1").build());
|
||||
tour.addActivity(del);
|
||||
VehicleRoute route = VehicleRoute.newInstance(tour, driver, vehicle);
|
||||
VehicleRoute.Builder routeBuilder = VehicleRoute.Builder.newInstance(vehicle, driver);
|
||||
routeBuilder.addService(Service.Builder.newInstance("2", 30).setLocationId("1").build());
|
||||
routeBuilder.addService(Service.Builder.newInstance("3", 30).setLocationId("2").build());
|
||||
VehicleRoute route = routeBuilder.build();
|
||||
{
|
||||
Iterator<TourActivity> iter = route.getTourActivities().reverseActivityIterator();
|
||||
int count = 0;
|
||||
TourActivity memAct = null;
|
||||
while(iter.hasNext()){
|
||||
TourActivity act = iter.next();
|
||||
if(count==0) memAct = act;
|
||||
if(count==0) {
|
||||
assertEquals("2",act.getLocationId());
|
||||
}
|
||||
count++;
|
||||
}
|
||||
assertEquals(memAct,del);
|
||||
assertEquals(2,count);
|
||||
}
|
||||
{
|
||||
Iterator<TourActivity> secondIter = route.getTourActivities().reverseActivityIterator();
|
||||
int count = 0;
|
||||
TourActivity memAct = null;
|
||||
while(secondIter.hasNext()){
|
||||
TourActivity act = secondIter.next();
|
||||
if(count==0) memAct = act;
|
||||
if(count==0) {
|
||||
assertEquals("2",act.getLocationId());
|
||||
}
|
||||
count++;
|
||||
}
|
||||
assertEquals(memAct,del);
|
||||
assertEquals(2,count);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenBuildingRouteWithVehicleThatHasDifferentStartAndEndLocation_routeMustHaveCorrectStartLocation(){
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("start").setEndLocationId("end").build();
|
||||
VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build();
|
||||
assertTrue(vRoute.getStart().getLocationId().equals("start"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenBuildingRouteWithVehicleThatHasDifferentStartAndEndLocation_routeMustHaveCorrectEndLocation(){
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("start").setEndLocationId("end").build();
|
||||
VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build();
|
||||
assertTrue(vRoute.getEnd().getLocationId().equals("end"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenBuildingRouteWithVehicleThatHasSameStartAndEndLocation_routeMustHaveCorrectStartLocation(){
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("start").setEndLocationId("start").build();
|
||||
VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build();
|
||||
assertTrue(vRoute.getStart().getLocationId().equals("start"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenBuildingRouteWithVehicleThatHasSameStartAndEndLocation_routeMustHaveCorrectEndLocation(){
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("start").setEndLocationId("start").build();
|
||||
VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build();
|
||||
assertTrue(vRoute.getEnd().getLocationId().equals("start"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenBuildingRouteWithVehicleThatHasSameStartAndEndLocation_routeMustHaveCorrectStartLocationV2(){
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("start").setEndLocationId("start").build();
|
||||
VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build();
|
||||
assertTrue(vRoute.getStart().getLocationId().equals("start"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenBuildingRouteWithVehicleThatHasSameStartAndEndLocation_routeMustHaveCorrectEndLocationV2(){
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("start").setEndLocationId("start").build();
|
||||
VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build();
|
||||
assertTrue(vRoute.getEnd().getLocationId().equals("start"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenBuildingRouteWithVehicleThatHasDifferentStartAndEndLocation_routeMustHaveCorrectDepartureTime(){
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setEarliestStart(100).setStartLocationId("start").setEndLocationId("end").build();
|
||||
VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build();
|
||||
assertEquals(vRoute.getDepartureTime(),100.0,0.01);
|
||||
assertEquals(vRoute.getStart().getEndTime(),100.0,0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenBuildingRouteWithVehicleThatHasDifferentStartAndEndLocation_routeMustHaveCorrectEndTime(){
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setEarliestStart(100).setLatestArrival(200).setStartLocationId("start").setEndLocationId("end").build();
|
||||
VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build();
|
||||
assertEquals(200.0,vRoute.getEnd().getTheoreticalLatestOperationStartTime(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingDepartureTimeInBetweenEarliestStartAndLatestArr_routeMustHaveCorrectDepartureTime(){
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setEarliestStart(100).setLatestArrival(200).setStartLocationId("start").setEndLocationId("end").build();
|
||||
VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build();
|
||||
vRoute.setVehicleAndDepartureTime(vehicle, 150.0);
|
||||
assertEquals(vRoute.getStart().getEndTime(),150.0,0.01);
|
||||
assertEquals(vRoute.getDepartureTime(),150.0,0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingDepartureEarlierThanEarliestStart_routeMustHaveEarliestDepTimeAsDepTime(){
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setEarliestStart(100).setLatestArrival(200).setStartLocationId("start").setEndLocationId("end").build();
|
||||
VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build();
|
||||
vRoute.setVehicleAndDepartureTime(vehicle, 50.0);
|
||||
assertEquals(vRoute.getStart().getEndTime(),100.0,0.01);
|
||||
assertEquals(vRoute.getDepartureTime(),100.0,0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingDepartureTimeLaterThanLatestArrival_routeMustHaveThisDepTime(){
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setEarliestStart(100).setLatestArrival(200).setStartLocationId("start").setEndLocationId("end").build();
|
||||
VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build();
|
||||
vRoute.setVehicleAndDepartureTime(vehicle, 50.0);
|
||||
assertEquals(vRoute.getStart().getEndTime(),100.0,0.01);
|
||||
assertEquals(vRoute.getDepartureTime(),100.0,0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCreatingEmptyRoute_itMustReturnEmptyRoute(){
|
||||
@SuppressWarnings("unused")
|
||||
VehicleRoute route = VehicleRoute.emptyRoute();
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenIniRouteWithNewVehicle_startLocationMustBeCorrect(){
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setEarliestStart(100).setLatestArrival(200).setStartLocationId("start").setEndLocationId("end").build();
|
||||
Vehicle new_vehicle = VehicleImpl.Builder.newInstance("new_v").setEarliestStart(1000).setLatestArrival(2000).setStartLocationId("new_start").setEndLocationId("new_end").build();
|
||||
VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build();
|
||||
vRoute.setVehicleAndDepartureTime(new_vehicle, 50.0);
|
||||
assertEquals("new_start",vRoute.getStart().getLocationId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenIniRouteWithNewVehicle_endLocationMustBeCorrect(){
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setEarliestStart(100).setLatestArrival(200).setStartLocationId("start").setEndLocationId("end").build();
|
||||
Vehicle new_vehicle = VehicleImpl.Builder.newInstance("new_v").setEarliestStart(1000).setLatestArrival(2000).setStartLocationId("new_start").setEndLocationId("new_end").build();
|
||||
VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build();
|
||||
vRoute.setVehicleAndDepartureTime(new_vehicle, 50.0);
|
||||
assertEquals("new_end",vRoute.getEnd().getLocationId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenIniRouteWithNewVehicle_depTimeMustBeEarliestDepTimeOfNewVehicle(){
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setEarliestStart(100).setLatestArrival(200).setStartLocationId("start").setEndLocationId("end").build();
|
||||
Vehicle new_vehicle = VehicleImpl.Builder.newInstance("new_v").setEarliestStart(1000).setLatestArrival(2000).setStartLocationId("new_start").setEndLocationId("new_end").build();
|
||||
VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build();
|
||||
vRoute.setVehicleAndDepartureTime(new_vehicle, 50.0);
|
||||
assertEquals(1000.0,vRoute.getDepartureTime(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenIniRouteWithNewVehicle_depTimeMustBeSetDepTime(){
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setEarliestStart(100).setLatestArrival(200).setStartLocationId("start").setEndLocationId("end").build();
|
||||
Vehicle new_vehicle = VehicleImpl.Builder.newInstance("new_v").setEarliestStart(1000).setLatestArrival(2000).setStartLocationId("new_start").setEndLocationId("new_end").build();
|
||||
VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build();
|
||||
vRoute.setVehicleAndDepartureTime(new_vehicle, 1500.0);
|
||||
assertEquals(1500.0,vRoute.getDepartureTime(),0.01);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,14 +65,15 @@ public class VehicleRouteBuilderTest {
|
|||
Shipment s2 = mock(Shipment.class);
|
||||
Vehicle vehicle = mock(Vehicle.class);
|
||||
when(vehicle.isReturnToDepot()).thenReturn(true);
|
||||
when(vehicle.getLocationId()).thenReturn("vehLoc");
|
||||
when(vehicle.getStartLocationId()).thenReturn("vehLoc");
|
||||
when(vehicle.getEndLocationId()).thenReturn("vehLoc");
|
||||
VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class));
|
||||
builder.addPickup(s);
|
||||
builder.addPickup(s2);
|
||||
builder.addDelivery(s);
|
||||
builder.addDelivery(s2);
|
||||
VehicleRoute route = builder.build();
|
||||
assertEquals(route.getEnd().getLocationId(), vehicle.getLocationId());
|
||||
assertEquals("vehLoc",route.getEnd().getLocationId());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -82,7 +83,7 @@ public class VehicleRouteBuilderTest {
|
|||
when(s2.getDeliveryLocation()).thenReturn("delLoc");
|
||||
Vehicle vehicle = mock(Vehicle.class);
|
||||
when(vehicle.isReturnToDepot()).thenReturn(false);
|
||||
when(vehicle.getLocationId()).thenReturn("vehLoc");
|
||||
when(vehicle.getStartLocationId()).thenReturn("vehLoc");
|
||||
VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class));
|
||||
builder.addPickup(s);
|
||||
builder.addPickup(s2);
|
||||
|
|
@ -99,7 +100,7 @@ public class VehicleRouteBuilderTest {
|
|||
when(s2.getDeliveryLocation()).thenReturn("delLoc");
|
||||
Vehicle vehicle = mock(Vehicle.class);
|
||||
when(vehicle.isReturnToDepot()).thenReturn(false);
|
||||
when(vehicle.getLocationId()).thenReturn("vehLoc");
|
||||
when(vehicle.getStartLocationId()).thenReturn("vehLoc");
|
||||
VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class));
|
||||
builder.addPickup(s);
|
||||
builder.addPickup(s2);
|
||||
|
|
@ -119,7 +120,8 @@ public class VehicleRouteBuilderTest {
|
|||
when(s2.getDeliveryLocation()).thenReturn("delLoc");
|
||||
Vehicle vehicle = mock(Vehicle.class);
|
||||
when(vehicle.isReturnToDepot()).thenReturn(false);
|
||||
when(vehicle.getLocationId()).thenReturn("vehLoc");
|
||||
when(vehicle.getStartLocationId()).thenReturn("vehLoc");
|
||||
when(vehicle.getLatestArrival()).thenReturn(200.0);
|
||||
VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class));
|
||||
builder.addPickup(s);
|
||||
builder.addPickup(s2);
|
||||
|
|
|
|||
|
|
@ -39,8 +39,8 @@ public class TestVehicleFleetManagerImpl extends TestCase{
|
|||
public void setUp(){
|
||||
List<Vehicle> vehicles = new ArrayList<Vehicle>();
|
||||
|
||||
v1 = VehicleImpl.Builder.newInstance("standard").setLocationId("loc").setType(VehicleTypeImpl.Builder.newInstance("standard", 0).build()).build();
|
||||
v2 = VehicleImpl.Builder.newInstance("foo").setLocationId("fooLoc").setType(VehicleTypeImpl.Builder.newInstance("foo", 0).build()).build();
|
||||
v1 = VehicleImpl.Builder.newInstance("standard").setStartLocationId("loc").setType(VehicleTypeImpl.Builder.newInstance("standard", 0).build()).build();
|
||||
v2 = VehicleImpl.Builder.newInstance("foo").setStartLocationId("fooLoc").setType(VehicleTypeImpl.Builder.newInstance("foo", 0).build()).build();
|
||||
|
||||
// v1.
|
||||
vehicles.add(v1);
|
||||
|
|
@ -75,7 +75,7 @@ public class TestVehicleFleetManagerImpl extends TestCase{
|
|||
}
|
||||
|
||||
public void testGetVehiclesWithout(){
|
||||
Collection<Vehicle> vehicles = fleetManager.getAvailableVehicles(v1.getType().getTypeId(),v1.getLocationId());
|
||||
Collection<Vehicle> vehicles = fleetManager.getAvailableVehicles(v1);
|
||||
|
||||
assertEquals(v2, vehicles.iterator().next());
|
||||
assertEquals(1, vehicles.size());
|
||||
|
|
@ -91,7 +91,7 @@ public class TestVehicleFleetManagerImpl extends TestCase{
|
|||
}
|
||||
|
||||
public void testWithPenalty_whenHavingOneRegularVehicleAvailable_noPenaltyVehicleIsReturn(){
|
||||
Vehicle penalty4standard = VehicleImpl.Builder.newInstance("standard_penalty").setLocationId("loc").
|
||||
Vehicle penalty4standard = VehicleImpl.Builder.newInstance("standard_penalty").setStartLocationId("loc").
|
||||
setType(VehicleTypeImpl.Builder.newInstance("standard", 0).build()).build();
|
||||
|
||||
List<Vehicle> vehicles = new ArrayList<Vehicle>();
|
||||
|
|
@ -108,10 +108,10 @@ public class TestVehicleFleetManagerImpl extends TestCase{
|
|||
VehicleTypeImpl penaltyType = VehicleTypeImpl.Builder.newInstance("standard", 0).build();
|
||||
PenaltyVehicleType penaltyVehicleType = new PenaltyVehicleType(penaltyType);
|
||||
|
||||
Vehicle penalty4standard = VehicleImpl.Builder.newInstance("standard_penalty").setLocationId("loc").
|
||||
Vehicle penalty4standard = VehicleImpl.Builder.newInstance("standard_penalty").setStartLocationId("loc").
|
||||
setType(penaltyVehicleType).build();
|
||||
|
||||
Vehicle v3 = VehicleImpl.Builder.newInstance("standard_v3").setLocationId("loc").
|
||||
Vehicle v3 = VehicleImpl.Builder.newInstance("standard_v3").setStartLocationId("loc").
|
||||
setType(penaltyType).build();
|
||||
|
||||
List<Vehicle> vehicles = new ArrayList<Vehicle>();
|
||||
|
|
@ -130,7 +130,7 @@ public class TestVehicleFleetManagerImpl extends TestCase{
|
|||
public void testWithPenalty_whenHavingNoRegularVehicleAvailable_penaltyVehicleIsReturned(){
|
||||
VehicleTypeImpl penaltyType = VehicleTypeImpl.Builder.newInstance("standard", 0).build();
|
||||
|
||||
Vehicle penalty4standard = VehicleImpl.Builder.newInstance("standard_penalty").setLocationId("loc").
|
||||
Vehicle penalty4standard = VehicleImpl.Builder.newInstance("standard_penalty").setStartLocationId("loc").
|
||||
setType(penaltyType).build();
|
||||
|
||||
List<Vehicle> vehicles = new ArrayList<Vehicle>();
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import jsprit.core.util.Coordinate;
|
|||
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
@SuppressWarnings("deprecation") // still tests whether deprecated methods work correctly - if deprecated methods are removed entirely, shift to setStartLocationId(..) and setStartLocationCoordinate()
|
||||
public class VehicleImplTest {
|
||||
|
||||
@Test
|
||||
|
|
@ -98,5 +98,103 @@ public class VehicleImplTest {
|
|||
assertEquals("noVehicle",v.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenStartLocationIsSet_itIsDoneCorrectly(){
|
||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocationId("startLoc").build();
|
||||
assertEquals("startLoc", v.getLocationId());
|
||||
assertEquals("startLoc", v.getStartLocationId());
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void whenStartLocationIsNull_itThrowsException(){
|
||||
@SuppressWarnings("unused")
|
||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocationId(null).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenStartLocationCoordIsSet_itIsDoneCorrectly(){
|
||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocationCoordinate(Coordinate.newInstance(1, 2)).build();
|
||||
assertEquals(1.0, v.getStartLocationCoordinate().getX(),0.01);
|
||||
assertEquals(2.0, v.getStartLocationCoordinate().getY(),0.01);
|
||||
|
||||
assertEquals(1.0, v.getCoord().getX(),0.01);
|
||||
assertEquals(2.0, v.getCoord().getY(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenEndLocationIsSet_itIsDoneCorrectly(){
|
||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocationId("startLoc").setEndLocationId("endLoc").build();
|
||||
assertEquals("startLoc", v.getStartLocationId());
|
||||
assertEquals("endLoc", v.getEndLocationId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenEndLocationCoordIsSet_itIsDoneCorrectly(){
|
||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocationId("startLoc").setEndLocationCoordinate(Coordinate.newInstance(1, 2)).build();
|
||||
assertEquals(1.0, v.getEndLocationCoordinate().getX(),0.01);
|
||||
assertEquals(2.0, v.getEndLocationCoordinate().getY(),0.01);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void whenNeitherEndLocationIdNorEndLocationCoordAreSet_endLocationIdMustBeEqualToStartLocationId(){
|
||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocationId("startLoc").build();
|
||||
assertEquals("startLoc", v.getEndLocationId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenNeitherEndLocationIdNorEndLocationCoordAreSet_endLocationCoordMustBeEqualToStartLocationCoord(){
|
||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocationId("startLoc").build();
|
||||
assertEquals(v.getEndLocationCoordinate(), v.getStartLocationCoordinate());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenNeitherEndLocationIdNorEndLocationCoordAreSet_endLocationCoordMustBeEqualToStartLocationCoordV2(){
|
||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocationCoordinate(Coordinate.newInstance(1.0, 2.0)).build();
|
||||
assertEquals(v.getEndLocationCoordinate(), v.getStartLocationCoordinate());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenEndLocationCoordinateIsSetButNoId_idMustBeCoordToString(){
|
||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocationCoordinate(Coordinate.newInstance(1.0, 2.0)).setEndLocationCoordinate(Coordinate.newInstance(3.0, 4.0)).build();
|
||||
assertEquals(v.getEndLocationCoordinate().toString(), v.getEndLocationId());
|
||||
}
|
||||
|
||||
@Test(expected=IllegalStateException.class)
|
||||
public void whenEndLocationIdIsSpecifiedANDReturnToDepotIsFalse_itShouldThrowException(){
|
||||
@SuppressWarnings("unused")
|
||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocationCoordinate(Coordinate.newInstance(1.0, 2.0)).setEndLocationId("endLoc").setReturnToDepot(false).build();
|
||||
}
|
||||
|
||||
@Test(expected=IllegalStateException.class)
|
||||
public void whenEndLocationCoordIsSpecifiedANDReturnToDepotIsFalse_itShouldThrowException(){
|
||||
@SuppressWarnings("unused")
|
||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocationCoordinate(Coordinate.newInstance(1.0, 2.0)).setEndLocationCoordinate(Coordinate.newInstance(3, 4)).setReturnToDepot(false).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenEndLocationCoordIsNotSpecifiedANDReturnToDepotIsFalse_endLocationCoordMustBeStartLocationCoord(){
|
||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocationCoordinate(Coordinate.newInstance(1.0, 2.0)).setReturnToDepot(false).build();
|
||||
assertEquals(v.getStartLocationCoordinate(),v.getEndLocationCoordinate());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenEndLocationIdIsNotSpecifiedANDReturnToDepotIsFalse_endLocationIdMustBeStartLocationId(){
|
||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocationCoordinate(Coordinate.newInstance(1.0, 2.0)).setReturnToDepot(false).build();
|
||||
assertEquals(v.getStartLocationCoordinate().toString(),v.getEndLocationId());
|
||||
}
|
||||
|
||||
@Test(expected=IllegalStateException.class)
|
||||
public void whenStartAndEndAreUnequalANDReturnToDepotIsFalse_itShouldThrowException(){
|
||||
@SuppressWarnings("unused")
|
||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocationId("start").setEndLocationId("end").setReturnToDepot(false).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenStartAndEndAreEqualANDReturnToDepotIsFalse_itShouldThrowException(){
|
||||
@SuppressWarnings("unused")
|
||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocationId("start").setEndLocationId("start").setReturnToDepot(false).build();
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,6 +46,39 @@
|
|||
<id>depotLoc</id>
|
||||
<coord x="10.0" y="100.0"/>
|
||||
</location>
|
||||
<returnToDepot>false</returnToDepot>
|
||||
<typeId>vehType2</typeId>
|
||||
<timeSchedule>
|
||||
<start>0.0</start>
|
||||
<end>1000.0</end>
|
||||
</timeSchedule>
|
||||
</vehicle>
|
||||
<vehicle>
|
||||
<id>v3</id>
|
||||
<startLocation>
|
||||
<id>startLoc</id>
|
||||
<coord x="10.0" y="100.0"/>
|
||||
</startLocation>
|
||||
<endLocation>
|
||||
<id>endLoc</id>
|
||||
<coord x="1000.0" y="2000.0"/>
|
||||
</endLocation>
|
||||
<typeId>vehType2</typeId>
|
||||
<timeSchedule>
|
||||
<start>0.0</start>
|
||||
<end>1000.0</end>
|
||||
</timeSchedule>
|
||||
</vehicle>
|
||||
<vehicle>
|
||||
<id>v4</id>
|
||||
<location>
|
||||
<id>startLoc</id>
|
||||
<coord x="10.0" y="100.0"/>
|
||||
</location>
|
||||
<endLocation>
|
||||
<id>endLoc</id>
|
||||
<coord x="1000.0" y="2000.0"/>
|
||||
</endLocation>
|
||||
<typeId>vehType2</typeId>
|
||||
<timeSchedule>
|
||||
<start>0.0</start>
|
||||
|
|
|
|||
|
|
@ -9,21 +9,29 @@
|
|||
<vehicle>
|
||||
<id>v1</id>
|
||||
<typeId>vehType</typeId>
|
||||
<location>
|
||||
<startLocation>
|
||||
<id>loc</id>
|
||||
</location>
|
||||
</startLocation>
|
||||
<endLocation>
|
||||
<id>loc</id>
|
||||
</endLocation>
|
||||
<timeSchedule>
|
||||
<start>0.0</start>
|
||||
<end>1.7976931348623157E308</end>
|
||||
</timeSchedule>
|
||||
<returnToDepot>true</returnToDepot>
|
||||
<returnToDepot>false</returnToDepot>
|
||||
</vehicle>
|
||||
<vehicle>
|
||||
<id>v2</id>
|
||||
<typeId>vehType2</typeId>
|
||||
<location>
|
||||
<id>loc</id>
|
||||
</location>
|
||||
<startLocation>
|
||||
<id>startLoc</id>
|
||||
<coord x="1.0" y="2.0"/>
|
||||
</startLocation>
|
||||
<endLocation>
|
||||
<id>endLoc</id>
|
||||
<coord x="4.0" y="5.0"/>
|
||||
</endLocation>
|
||||
<timeSchedule>
|
||||
<start>0.0</start>
|
||||
<end>1.7976931348623157E308</end>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue