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

modified Pickup and Delivery to deal with multiple cap-dims

This commit is contained in:
oblonski 2014-02-17 22:34:23 +01:00
parent 8946e130c8
commit fe4b4ae4ca
6 changed files with 117 additions and 2 deletions

View file

@ -16,6 +16,8 @@
******************************************************************************/
package jsprit.core.problem.job;
import jsprit.core.problem.job.Pickup.Builder;
/**
* Delivery extends Service and is intended to model a Service where smth is UNLOADED (i.e. delivered) from a transport unit.
*
@ -33,9 +35,24 @@ public class Delivery extends Service{
* @param size
* @return builder
* @throws IllegalArgumentException if size < 0 or id is null
* @deprecated use <code>.newInstance(String id)</code> instead, and add a capacity dimension
* with dimensionIndex='your index' and and dimsionValue=size to the returned builder
*/
@Deprecated
public static Builder newInstance(String id, int size){
return new Builder(id,size);
Builder builder = new Builder(id,size);
builder.addCapacityDimension(0, size);
return builder;
}
/**
* Returns a new instance of builder that builds a delivery.
*
* @param id
* @return the builder
*/
public static Builder newInstance(String id){
return new Builder(id);
}
/**
@ -48,6 +65,11 @@ public class Delivery extends Service{
Builder(String id, int size) {
super(id, size);
}
Builder(String id) {
super(id);
}
/**
* Builds Delivery.
*

View file

@ -16,6 +16,7 @@
******************************************************************************/
package jsprit.core.problem.job;
/**
* Pickup extends Service and is intended to model a Service where smth is LOADED (i.e. picked up) to a transport unit.
*
@ -33,9 +34,24 @@ public class Pickup extends Service {
* @param size
* @return builder
* @throws IllegalArgumentException if size < 0 or id is null
* @deprecated use <code>.newInstance(String id)</code> instead, and add a capacity dimension
* with dimensionIndex='your index' and and dimsionValue=size to the returned builder
*/
@Deprecated
public static Builder newInstance(String id, int size){
return new Builder(id,size);
Builder builder = new Builder(id,size);
builder.addCapacityDimension(0, size);
return builder;
}
/**
* Returns a new instance of builder that builds a pickup.
*
* @param id
* @return the builder
*/
public static Builder newInstance(String id){
return new Builder(id);
}
/**
@ -49,6 +65,10 @@ public class Pickup extends Service {
super(id, size);
}
Builder(String id) {
super(id);
}
/**
* Builds Pickup.
*

View file

@ -60,6 +60,12 @@ public class Service implements Job {
return builder;
}
/**
* Returns a new instance of builder that builds a service.
*
* @param id
* @return the builder
*/
public static Builder newInstance(String id){
return new Builder(id);
}

View file

@ -20,6 +20,7 @@ import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
import jsprit.core.problem.driver.Driver;
import jsprit.core.problem.driver.DriverImpl;
import jsprit.core.problem.job.Pickup;
import jsprit.core.problem.job.Service;
import jsprit.core.problem.job.Shipment;
import jsprit.core.problem.misc.JobInsertionContext;
import jsprit.core.problem.solution.route.VehicleRoute;
@ -240,8 +241,10 @@ public class ShipmentInsertionCalculatorTest {
ServiceInsertionCalculator serviceInsertionCalc = new ServiceInsertionCalculator(routingCosts, activityInsertionCostsCalculator, constraintManager);
ShipmentInsertionCalculator insertionCalculator = new ShipmentInsertionCalculator(routingCosts, activityInsertionCostsCalculator, constraintManager);
switcher.put(Pickup.class, serviceInsertionCalc);
switcher.put(Service.class, serviceInsertionCalc);
switcher.put(Shipment.class, insertionCalculator);
// Service service = Service.Builder.newInstance("pick", 1).setLocationId("5,5").build();
Pickup service = (Pickup)Pickup.Builder.newInstance("pick", 1).setLocationId("5,5").build();
InsertionData iData = switcher.getInsertionData(route, service, vehicle, 0, DriverImpl.noDriver(), Double.MAX_VALUE);
// routeActVisitor.visit(route);

View file

@ -1,5 +1,7 @@
package jsprit.core.problem.job;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class DeliveryTest {
@ -9,4 +11,34 @@ public class DeliveryTest {
Delivery.Builder.newInstance("p", 0).build();
}
@Test
public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo(){
Delivery one = (Delivery)Delivery.Builder.newInstance("s").setLocationId("foofoo")
.addCapacityDimension(0,2)
.addCapacityDimension(1,4)
.build();
assertEquals(2,one.getCapacity().getNuOfDimensions());
assertEquals(2,one.getCapacity().get(0));
assertEquals(4,one.getCapacity().get(1));
}
@Test
public void whenPickupIsBuiltWithoutSpecifyingCapacity_itShouldHvCapWithOneDimAndDimValOfZero(){
Delivery one = (Delivery)Delivery.Builder.newInstance("s").setLocationId("foofoo")
.build();
assertEquals(1,one.getCapacity().getNuOfDimensions());
assertEquals(0,one.getCapacity().get(0));
}
@Test
public void whenPickupIsBuiltWithConstructorWhereSizeIsSpecified_capacityShouldBeSetCorrectly(){
Delivery one = (Delivery)Delivery.Builder.newInstance("s",1).setLocationId("foofoo")
.build();
assertEquals(1,one.getCapacityDemand());
assertEquals(1,one.getCapacity().getNuOfDimensions());
assertEquals(1,one.getCapacity().get(0));
}
}

View file

@ -1,5 +1,7 @@
package jsprit.core.problem.job;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class PickupTest {
@ -9,4 +11,34 @@ public class PickupTest {
Pickup.Builder.newInstance("p", 0).build();
}
@Test
public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo(){
Pickup one = (Pickup)Pickup.Builder.newInstance("s").setLocationId("foofoo")
.addCapacityDimension(0,2)
.addCapacityDimension(1,4)
.build();
assertEquals(2,one.getCapacity().getNuOfDimensions());
assertEquals(2,one.getCapacity().get(0));
assertEquals(4,one.getCapacity().get(1));
}
@Test
public void whenPickupIsBuiltWithoutSpecifyingCapacity_itShouldHvCapWithOneDimAndDimValOfZero(){
Pickup one = (Pickup)Pickup.Builder.newInstance("s").setLocationId("foofoo")
.build();
assertEquals(1,one.getCapacity().getNuOfDimensions());
assertEquals(0,one.getCapacity().get(0));
}
@Test
public void whenPickupIsBuiltWithConstructorWhereSizeIsSpecified_capacityShouldBeSetCorrectly(){
Pickup one = (Pickup)Pickup.Builder.newInstance("s",1).setLocationId("foofoo")
.build();
assertEquals(1,one.getCapacityDemand());
assertEquals(1,one.getCapacity().getNuOfDimensions());
assertEquals(1,one.getCapacity().get(0));
}
}