1
0
Fork 0
mirror of https://github.com/graphhopper/jsprit.git synced 2020-01-24 07:45:05 +01:00

modeling the problem

This commit is contained in:
oblonski 2013-10-16 21:22:46 +02:00
parent 6b8e4c8a79
commit c55d67e3c2
5 changed files with 77 additions and 4 deletions

View file

@ -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 * the share of jobs to be removed and the distance between jobs (where distance not necessarily mean Euclidean distance but an arbitrary
* measure). * measure).
* *

View file

@ -133,7 +133,7 @@ public class Shipment implements Job{
return demand; return demand;
} }
public int getDemand() { public int getSize() {
return demand; return demand;
} }

View file

@ -236,7 +236,10 @@ public class VehicleRoutingProblem {
if(job instanceof Service) { if(job instanceof Service) {
addService((Service) job); 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; return this;
} }
@ -357,6 +360,10 @@ public class VehicleRoutingProblem {
public Collection<Service> getAddedServices(){ public Collection<Service> getAddedServices(){
return Collections.unmodifiableCollection(services); return Collections.unmodifiableCollection(services);
} }
public Collection<Job> getAddedJobs(){
return Collections.unmodifiableCollection(jobs.values());
}
} }
/** /**

View file

@ -1,5 +1,56 @@
package basics; package basics;
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 { 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);
}
} }

View file

@ -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"));
}
} }