From c9f75a826e1713a381fd1777e01d8c0775c5ac34 Mon Sep 17 00:00:00 2001 From: oblonski <4sschroeder@gmail.com> Date: Mon, 4 Aug 2014 13:41:31 +0200 Subject: [PATCH] try to reproduce potential bug #116 --- .../core/algorithm/InitialRoutesTest.java | 53 +++++++++++- .../resources/simpleProblem_iniRoutes_2.xml | 86 +++++++++++++++++++ 2 files changed, 137 insertions(+), 2 deletions(-) create mode 100644 jsprit-core/src/test/resources/simpleProblem_iniRoutes_2.xml diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/InitialRoutesTest.java b/jsprit-core/src/test/java/jsprit/core/algorithm/InitialRoutesTest.java index 28ff79a7..d213d397 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/InitialRoutesTest.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/InitialRoutesTest.java @@ -1,6 +1,7 @@ package jsprit.core.algorithm; +import jsprit.core.algorithm.box.GreedySchrimpfFactory; import jsprit.core.algorithm.box.SchrimpfFactory; import jsprit.core.problem.AbstractActivity; import jsprit.core.problem.VehicleRoutingProblem; @@ -10,16 +11,20 @@ import jsprit.core.problem.job.Service; import jsprit.core.problem.job.Shipment; import jsprit.core.problem.solution.VehicleRoutingProblemSolution; import jsprit.core.problem.solution.route.VehicleRoute; +import jsprit.core.problem.solution.route.activity.PickupShipment; import jsprit.core.problem.solution.route.activity.TourActivity; +import jsprit.core.problem.vehicle.VehicleImpl; +import jsprit.core.problem.vehicle.VehicleType; +import jsprit.core.problem.vehicle.VehicleTypeImpl; import jsprit.core.reporting.SolutionPrinter; +import jsprit.core.util.Coordinate; import jsprit.core.util.Solutions; import org.junit.Test; import java.util.Collection; import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; public class InitialRoutesTest { @@ -241,4 +246,48 @@ public class InitialRoutesTest { assertTrue(hasActivityIn(solution.getRoutes().iterator().next(), "2")); } + + @Test + public void maxCapacityShouldNotBeExceeded(){ + VehicleType type = VehicleTypeImpl.Builder.newInstance("type").addCapacityDimension(0, 100).build(); + VehicleImpl vehicle = VehicleImpl.Builder.newInstance("veh").setStartLocationCoordinate(Coordinate.newInstance(0, 0)).setType(type).setStartLocationId("start").build(); + + Shipment shipment = Shipment.Builder.newInstance("s").setPickupLocation("pick").setDeliveryLocation("del").setPickupCoord(Coordinate.newInstance(10, 0)) + .setDeliveryCoord(Coordinate.newInstance(0, 10)).addSizeDimension(0, 100).build(); + + Shipment another_shipment = Shipment.Builder.newInstance("another_s").setPickupLocation("pick").setDeliveryLocation("del").setPickupCoord(Coordinate.newInstance(10, 0)) + .setDeliveryCoord(Coordinate.newInstance(0, 10)).addSizeDimension(0, 50).build(); + + VehicleRoute iniRoute = VehicleRoute.Builder.newInstance(vehicle).addPickup(shipment).addDelivery(shipment).build(); + + VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(shipment).addVehicle(vehicle).addJob(another_shipment) + .setFleetSize(VehicleRoutingProblem.FleetSize.FINITE).addInitialVehicleRoute(iniRoute).build(); + + VehicleRoutingAlgorithm vra = new GreedySchrimpfFactory().createAlgorithm(vrp); + vra.setNuOfIterations(10); + + Collection solutions = vra.searchSolutions(); + + assertFalse(secondActIsPickup(solutions)); + + } + + @Test + public void whenReadingProblemFromFile_maxCapacityShouldNotBeExceeded(){ + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_iniRoutes_2.xml"); + VehicleRoutingAlgorithm vra = new GreedySchrimpfFactory().createAlgorithm(vrpBuilder.build()); + vra.setNuOfIterations(10); + + Collection solutions = vra.searchSolutions(); + + assertFalse(secondActIsPickup(solutions)); + + } + + private boolean secondActIsPickup(Collection solutions) { + VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions); + TourActivity secondAct = solution.getRoutes().iterator().next().getActivities().get(1); + return secondAct instanceof PickupShipment; + } } diff --git a/jsprit-core/src/test/resources/simpleProblem_iniRoutes_2.xml b/jsprit-core/src/test/resources/simpleProblem_iniRoutes_2.xml new file mode 100644 index 00000000..c370023c --- /dev/null +++ b/jsprit-core/src/test/resources/simpleProblem_iniRoutes_2.xml @@ -0,0 +1,86 @@ + + + + FINITE + HOMOGENEOUS + + + + veh1 + type1 + + [x=0.0][y=0.0] + + + + [x=0.0][y=0.0] + + + + 0.0 + 46800.0 + + true + + + + + type1 + + 100 + + + 0.0 + 1.0 + + + + + + + + + loc_pickup_shipment_3 + + + + loc_deliver_shipment_3 + + + + 100 + + + + + + loc_pickup_shipment_4 + + + + loc_deliver_shipment_4 + + + + 50 + + + + + + + + noDriver + veh1 + 0. + + 3 + + + 3 + + + + +