diff --git a/jsprit-core/src/main/java/algorithms/RuinRadial.java b/jsprit-core/src/main/java/algorithms/RuinRadial.java index 7b9c5edf..330f6a1a 100644 --- a/jsprit-core/src/main/java/algorithms/RuinRadial.java +++ b/jsprit-core/src/main/java/algorithms/RuinRadial.java @@ -38,7 +38,7 @@ import basics.route.VehicleRoute; /** * - * RuinStrategy that ruins the neighborhood of a randomly selected service. The size and the structure of the neighborhood is defined by + * RuinStrategy that ruins the neighborhood of a randomly selected job. The size and the structure of the neighborhood is defined by * the share of jobs to be removed and the distance between jobs (where distance not necessarily mean Euclidean distance but an arbitrary * measure). * diff --git a/jsprit-core/src/main/java/basics/Shipment.java b/jsprit-core/src/main/java/basics/Shipment.java index 2e89396f..fe45070e 100644 --- a/jsprit-core/src/main/java/basics/Shipment.java +++ b/jsprit-core/src/main/java/basics/Shipment.java @@ -133,7 +133,7 @@ public class Shipment implements Job{ return demand; } - public int getDemand() { + public int getSize() { return demand; } diff --git a/jsprit-core/src/main/java/basics/VehicleRoutingProblem.java b/jsprit-core/src/main/java/basics/VehicleRoutingProblem.java index 78035117..dad31f6a 100644 --- a/jsprit-core/src/main/java/basics/VehicleRoutingProblem.java +++ b/jsprit-core/src/main/java/basics/VehicleRoutingProblem.java @@ -236,7 +236,10 @@ public class VehicleRoutingProblem { if(job instanceof Service) { addService((Service) job); } - else throw new IllegalStateException("job can only be a shipment or a service, but is instance of " + job.getClass()); + else{ + if(jobs.containsKey(job.getId())){ logger.warn("job " + job + " already in job list. overrides existing job."); } + jobs.put(job.getId(),job); + } return this; } @@ -357,6 +360,10 @@ public class VehicleRoutingProblem { public Collection getAddedServices(){ return Collections.unmodifiableCollection(services); } + + public Collection getAddedJobs(){ + return Collections.unmodifiableCollection(jobs.values()); + } } /** diff --git a/jsprit-core/src/test/java/basics/ShipmentTest.java b/jsprit-core/src/test/java/basics/ShipmentTest.java index d33cab30..6313d8a5 100644 --- a/jsprit-core/src/test/java/basics/ShipmentTest.java +++ b/jsprit-core/src/test/java/basics/ShipmentTest.java @@ -1,5 +1,56 @@ package basics; -public class ShipmentTest { +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import org.junit.Test; + +import util.Coordinate; +import basics.route.TimeWindow; + +public class ShipmentTest { + + @Test + public void whenTwoShipmentsHaveTheSameId_theyReferencesShouldBeUnEqual(){ + Shipment one = Shipment.Builder.newInstance("s", 10).setPickupLocation("foo"). + setDeliveryLocation("foofoo").setPickupServiceTime(10).setDeliveryServiceTime(20).build(); + Shipment two = Shipment.Builder.newInstance("s", 10).setPickupLocation("foo"). + setDeliveryLocation("foofoo").setPickupServiceTime(10).setDeliveryServiceTime(20).build(); + + assertTrue(one != two); + } + + @Test + public void whenTwoShipmentsHaveTheSameId_theyShouldBeEqual(){ + Shipment one = Shipment.Builder.newInstance("s", 10).setPickupLocation("foo"). + setDeliveryLocation("foofoo").setPickupServiceTime(10).setDeliveryServiceTime(20).build(); + Shipment two = Shipment.Builder.newInstance("s", 10).setPickupLocation("foo"). + setDeliveryLocation("foofoo").setPickupServiceTime(10).setDeliveryServiceTime(20).build(); + + assertTrue(one.equals(two)); + } + + @Test + public void whenShipmentIsInstantiatedWithASizeOf10_theSizeShouldBe10(){ + Shipment one = Shipment.Builder.newInstance("s", 10).setPickupLocation("foo"). + setDeliveryLocation("foofoo").setPickupServiceTime(10).setDeliveryServiceTime(20).build(); + assertEquals(10,one.getSize()); + } + + @Test + public void whenShipmentIsDefined_itsFieldsShouldBeDefinedCorrectly(){ + Shipment one = Shipment.Builder.newInstance("s", 10).setPickupLocation("foo").setPickupCoord(Coordinate.newInstance(0, 0)).setPickupServiceTime(1.0) + .setPickupTimeWindow(TimeWindow.newInstance(0.0, 1.0)) + .setDeliveryLocation("foofoo").setDeliveryServiceTime(20).setDeliveryCoord(Coordinate.newInstance(1, 1)). + setDeliveryTimeWindow(TimeWindow.newInstance(1.0, 2.0)).build(); + assertEquals("s",one.getId()); + assertEquals(10,one.getSize()); + assertEquals("foo",one.getPickupLocation()); + assertEquals(0,one.getPickupCoord().getX(),0.01); + assertEquals(1.0,one.getPickupServiceTime(),0.01); + assertEquals("foofoo",one.getDeliveryLocation()); + assertEquals(20.0,one.getDeliveryServiceTime(),0.01); + assertEquals(1.0,one.getDeliveryCoord().getX(),0.01); + assertEquals(1.0,one.getDeliveryTimeWindow().getStart(),0.01); + } } diff --git a/jsprit-core/src/test/java/basics/VehicleRoutingProblemBuilderTest.java b/jsprit-core/src/test/java/basics/VehicleRoutingProblemBuilderTest.java index b392f94b..dc712f1e 100644 --- a/jsprit-core/src/test/java/basics/VehicleRoutingProblemBuilderTest.java +++ b/jsprit-core/src/test/java/basics/VehicleRoutingProblemBuilderTest.java @@ -64,5 +64,20 @@ public class VehicleRoutingProblemBuilderTest { } + @Test + public void whenShipmentsAreAdded_theyShouldBePartOfTheProblem(){ + Shipment s = Shipment.Builder.newInstance("s", 10).setPickupLocation("foofoo").setDeliveryLocation("foo").build(); + Shipment s2 = Shipment.Builder.newInstance("s2", 100).setPickupLocation("foofoo").setDeliveryLocation("foo").build(); + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + vrpBuilder.addJob(s); + vrpBuilder.addJob(s2); + VehicleRoutingProblem vrp = vrpBuilder.build(); + assertEquals(2,vrp.getJobs().size()); + + Job j = vrp.getJobs().get("s"); + assertEquals(s,j); + assertEquals(s2,vrp.getJobs().get("s2")); + } + }