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

adjusted load updater to cope with multiple capacity dimensions

This commit is contained in:
oblonski 2014-03-01 17:59:18 +01:00
parent f6bf46ca9a
commit 217c824506
24 changed files with 380 additions and 198 deletions

View file

@ -428,9 +428,9 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
UpdateLoads updateLoads = new UpdateLoads(this); UpdateLoads updateLoads = new UpdateLoads(this);
addActivityVisitor(updateLoads); addActivityVisitor(updateLoads);
addListener(updateLoads); addListener(updateLoads);
addActivityVisitor(new UpdatePrevMaxLoad(this)); addActivityVisitor(new UpdateMaxCapacityUtilisationAtActivitiesByLookingBackwardInRoute(this));
addActivityVisitor(new UpdateMaxLoadForwardLooking(this)); addActivityVisitor(new UpdateMaxCapacityUtilisationAtActivitiesByLookingForwardInRoute(this));
addActivityVisitor(new UpdateMaxLoad_(this)); addActivityVisitor(new UpdateMaxCapacityUtilisationAtRoute(this));
} }
} }

View file

@ -50,7 +50,7 @@ class UpdateLoads implements ActivityVisitor, StateUpdater, InsertionStartsListe
@Override @Override
public void visit(TourActivity act) { public void visit(TourActivity act) {
currentLoad = Capacity.addup(currentLoad, act.getCapacity()); currentLoad = Capacity.addup(currentLoad, act.getSize());
stateManager.putInternalActivityState_(act, StateFactory.LOAD, Capacity.class, currentLoad); stateManager.putInternalActivityState_(act, StateFactory.LOAD, Capacity.class, currentLoad);
assert currentLoad.isLessOrEqual(route.getVehicle().getType().getCapacityDimensions()) : "currentLoad at activity must not be > vehicleCapacity"; assert currentLoad.isLessOrEqual(route.getVehicle().getType().getCapacityDimensions()) : "currentLoad at activity must not be > vehicleCapacity";
assert currentLoad.isGreaterOrEqual(Capacity.Builder.newInstance().build()) : "currentLoad at act must not be < 0 in one of the applied dimensions"; assert currentLoad.isGreaterOrEqual(Capacity.Builder.newInstance().build()) : "currentLoad at act must not be < 0 in one of the applied dimensions";

View file

@ -0,0 +1,44 @@
package jsprit.core.algorithm.state;
import jsprit.core.problem.Capacity;
import jsprit.core.problem.solution.route.VehicleRoute;
import jsprit.core.problem.solution.route.activity.ActivityVisitor;
import jsprit.core.problem.solution.route.activity.TourActivity;
import jsprit.core.problem.solution.route.state.StateFactory;
/**
* Determines and memorizes the maximum capacity utilization at each activity by looking backward in route,
* i.e. the maximum capacity utilization at previous activities.
*
* @author schroeder
*
*/
class UpdateMaxCapacityUtilisationAtActivitiesByLookingBackwardInRoute implements ActivityVisitor, StateUpdater {
private StateManager stateManager;
private VehicleRoute route;
private Capacity maxLoad;
public UpdateMaxCapacityUtilisationAtActivitiesByLookingBackwardInRoute(StateManager stateManager) {
this.stateManager = stateManager;
}
@Override
public void begin(VehicleRoute route) {
this.route = route;
maxLoad = stateManager.getRouteState(route, StateFactory.LOAD_AT_BEGINNING, Capacity.class);
}
@Override
public void visit(TourActivity act) {
maxLoad = Capacity.max(maxLoad, stateManager.getActivityState(act, StateFactory.LOAD, Capacity.class));
stateManager.putInternalActivityState_(act, StateFactory.PAST_MAXLOAD, Capacity.class, maxLoad);
assert maxLoad.isGreaterOrEqual(Capacity.Builder.newInstance().build()) : "maxLoad can never be smaller than 0";
assert maxLoad.isLessOrEqual(route.getVehicle().getType().getCapacityDimensions()) : "maxLoad can never be bigger than vehicleCap";
}
@Override
public void finish() {}
}

View file

@ -0,0 +1,63 @@
package jsprit.core.algorithm.state;
import jsprit.core.problem.Capacity;
import jsprit.core.problem.solution.route.VehicleRoute;
import jsprit.core.problem.solution.route.activity.ReverseActivityVisitor;
import jsprit.core.problem.solution.route.activity.TourActivity;
import jsprit.core.problem.solution.route.state.StateFactory;
/**
* A {@link ReverseActivityVisitor} that looks forward in the vehicle route and determines
* the maximum capacity utilization (in terms of loads) at subsequent activities.
*
* <p>Assume a vehicle route with the following activity sequence {start,pickup(1,4),delivery(2,3),pickup(3,2),end} where
* pickup(1,2) = pickup(id,cap-demand).<br>
* Future maxLoad for each activity are calculated as follows:<br>
* loadAt(end)=6 (since two pickups need to be delivered to depot)<br>
* pickup(3)=max(loadAt(pickup(3)), futureMaxLoad(end))=max(6,6)=6
* delivery(2)=max(loadAt(delivery(2),futureMaxLoad(pickup(3))=max(4,6)=6
* pickup(1)=max(7,6)=7
* start=max(7,7)=7
* activity (apart from start and end), the maximum capacity is determined when forward looking into the route.
* That is at each activity we know how much capacity is available whithout breaking future capacity constraints.
*
*
* @author schroeder
*
*/
class UpdateMaxCapacityUtilisationAtActivitiesByLookingForwardInRoute implements ReverseActivityVisitor, StateUpdater {
private StateManager stateManager;
private VehicleRoute route;
private Capacity maxLoad = Capacity.Builder.newInstance().build();
// private double maxLoad;
public UpdateMaxCapacityUtilisationAtActivitiesByLookingForwardInRoute(StateManager stateManager) {
super();
this.stateManager = stateManager;
}
@Override
public void begin(VehicleRoute route) {
this.route = route;
maxLoad = stateManager.getRouteState(route, StateFactory.LOAD_AT_END, Capacity.class);
// maxLoad = stateManager.getRouteState(route, StateFactory.LOAD_AT_END).toDouble();
}
@Override
public void visit(TourActivity act) {
maxLoad = Capacity.max(maxLoad, stateManager.getActivityState(act, StateFactory.LOAD, Capacity.class));
// maxLoad = Math.max(maxLoad, stateManager.getActivityState(act, StateFactory.LOAD).toDouble());
stateManager.putInternalActivityState_(act, StateFactory.FUTURE_MAXLOAD, Capacity.class, maxLoad);
// stateManager.putInternalActivityState(act, StateFactory.FUTURE_MAXLOAD, StateFactory.createState(maxLoad));
assert maxLoad.isLessOrEqual(route.getVehicle().getType().getCapacityDimensions()) : "maxLoad can in every capacity dimension never be bigger than vehicleCap";
// assert maxLoad <= route.getVehicle().getCapacity() : "maxLoad can never be bigger than vehicleCap";
assert maxLoad.isGreaterOrEqual(Capacity.Builder.newInstance().build()) : "maxLoad can never be smaller than 0";
// assert maxLoad >= 0 : "maxLoad can never be smaller than 0";
}
@Override
public void finish() {}
}

View file

@ -0,0 +1,52 @@
package jsprit.core.algorithm.state;
import jsprit.core.problem.Capacity;
import jsprit.core.problem.solution.route.VehicleRoute;
import jsprit.core.problem.solution.route.activity.ActivityVisitor;
import jsprit.core.problem.solution.route.activity.TourActivity;
import jsprit.core.problem.solution.route.state.StateFactory;
/**
* Updates load at activity level.
*
* <p>Note that this assumes that StateTypes.LOAD_AT_DEPOT is already updated, i.e. it starts by setting loadAtDepot to StateTypes.LOAD_AT_DEPOT.
* If StateTypes.LOAD_AT_DEPOT is not set, it starts with 0 load at depot.
*
* <p>Thus it DEPENDS on StateTypes.LOAD_AT_DEPOT
*
* @author stefan
*
*/
class UpdateMaxCapacityUtilisationAtRoute implements ActivityVisitor, StateUpdater {
private StateManager stateManager;
private Capacity currentLoad = Capacity.Builder.newInstance().build();
private VehicleRoute route;
private Capacity maxLoad = Capacity.Builder.newInstance().build();
public UpdateMaxCapacityUtilisationAtRoute(StateManager stateManager) {
super();
this.stateManager = stateManager;
}
@Override
public void begin(VehicleRoute route) {
currentLoad = stateManager.getRouteState(route, StateFactory.LOAD_AT_BEGINNING, Capacity.class);
maxLoad = currentLoad;
this.route = route;
}
@Override
public void visit(TourActivity act) {
currentLoad = Capacity.addup(currentLoad, act.getSize());
maxLoad = Capacity.max(maxLoad, currentLoad);
}
@Override
public void finish() {
stateManager.putInternalRouteState_(route, StateFactory.MAXLOAD, Capacity.class, maxLoad);
}
}

View file

@ -1,46 +0,0 @@
package jsprit.core.algorithm.state;
import jsprit.core.problem.solution.route.VehicleRoute;
import jsprit.core.problem.solution.route.activity.ReverseActivityVisitor;
import jsprit.core.problem.solution.route.activity.TourActivity;
import jsprit.core.problem.solution.route.state.StateFactory;
/**
* A {@link ReverseActivityVisitor} that looks forward in the vehicle route and determines
* the maximum load for subsequent activities.
*
* <p>
*
* @author schroeder
*
*/
class UpdateMaxLoadForwardLooking implements ReverseActivityVisitor, StateUpdater {
private StateManager stateManager;
private VehicleRoute route;
private double maxLoad;
public UpdateMaxLoadForwardLooking(StateManager stateManager) {
super();
this.stateManager = stateManager;
}
@Override
public void begin(VehicleRoute route) {
this.route = route;
maxLoad = stateManager.getRouteState(route, StateFactory.LOAD_AT_END).toDouble();
}
@Override
public void visit(TourActivity act) {
maxLoad = Math.max(maxLoad, stateManager.getActivityState(act, StateFactory.LOAD).toDouble());
stateManager.putInternalActivityState(act, StateFactory.FUTURE_MAXLOAD, StateFactory.createState(maxLoad));
assert maxLoad <= route.getVehicle().getCapacity() : "maxLoad can never be bigger than vehicleCap";
assert maxLoad >= 0 : "maxLoad can never be smaller than 0";
}
@Override
public void finish() {}
}

View file

@ -1,68 +0,0 @@
package jsprit.core.algorithm.state;
import jsprit.core.problem.solution.route.VehicleRoute;
import jsprit.core.problem.solution.route.activity.ActivityVisitor;
import jsprit.core.problem.solution.route.activity.TourActivity;
import jsprit.core.problem.solution.route.state.StateFactory;
/**
* Updates load at activity level.
*
* <p>Note that this assumes that StateTypes.LOAD_AT_DEPOT is already updated, i.e. it starts by setting loadAtDepot to StateTypes.LOAD_AT_DEPOT.
* If StateTypes.LOAD_AT_DEPOT is not set, it starts with 0 load at depot.
*
* <p>Thus it DEPENDS on StateTypes.LOAD_AT_DEPOT
*
* @author stefan
*
*/
class UpdateMaxLoad_ implements ActivityVisitor, StateUpdater {
private StateManager stateManager;
private int currentLoad = 0;
private VehicleRoute route;
private int maxLoad = 0;
/**
* Updates load at activity level.
*
* <p>Note that this assumes that StateTypes.LOAD_AT_DEPOT is already updated, i.e. it starts by setting loadAtDepot to StateTypes.LOAD_AT_DEPOT.
* If StateTypes.LOAD_AT_DEPOT is not set, it starts with 0 load at depot.
*
* <p>Thus it DEPENDS on StateTypes.LOAD_AT_DEPOT
*
*
*
* <p>The loads can be retrieved by <br>
* <code>stateManager.getActivityState(activity,StateTypes.LOAD);</code>
*
*
* @author stefan
*
*/
public UpdateMaxLoad_(StateManager stateManager) {
super();
this.stateManager = stateManager;
}
@Override
public void begin(VehicleRoute route) {
currentLoad = (int) stateManager.getRouteState(route, StateFactory.LOAD_AT_BEGINNING).toDouble();
maxLoad = currentLoad;
this.route = route;
}
@Override
public void visit(TourActivity act) {
currentLoad += act.getCapacityDemand();
maxLoad = Math.max(maxLoad, currentLoad);
assert currentLoad <= route.getVehicle().getCapacity() : "currentLoad at activity must not be > vehicleCapacity";
assert currentLoad >= 0 : "currentLoad at act must not be < 0";
}
@Override
public void finish() {
stateManager.putInternalRouteState(route, StateFactory.MAXLOAD, StateFactory.createState(maxLoad));
currentLoad = 0;
maxLoad = 0;
}
}

View file

@ -1,37 +0,0 @@
package jsprit.core.algorithm.state;
import jsprit.core.problem.solution.route.VehicleRoute;
import jsprit.core.problem.solution.route.activity.ActivityVisitor;
import jsprit.core.problem.solution.route.activity.TourActivity;
import jsprit.core.problem.solution.route.state.StateFactory;
class UpdatePrevMaxLoad implements ActivityVisitor, StateUpdater {
private StateManager stateManager;
private VehicleRoute route;
private double currLoad;
private double prevMaxLoad;
public UpdatePrevMaxLoad(StateManager stateManager) {
super();
this.stateManager = stateManager;
}
@Override
public void begin(VehicleRoute route) {
this.route = route;
currLoad = stateManager.getRouteState(route, StateFactory.LOAD_AT_BEGINNING).toDouble();
prevMaxLoad = currLoad;
}
@Override
public void visit(TourActivity act) {
prevMaxLoad = Math.max(prevMaxLoad, stateManager.getActivityState(act, StateFactory.LOAD).toDouble());
stateManager.putInternalActivityState(act, StateFactory.PAST_MAXLOAD, StateFactory.createState(prevMaxLoad));
assert prevMaxLoad >= 0 : "maxLoad can never be smaller than 0";
assert prevMaxLoad <= route.getVehicle().getCapacity() : "maxLoad can never be bigger than vehicleCap";
}
@Override
public void finish() {}
}

View file

@ -23,7 +23,7 @@ public final class DeliverService implements DeliveryActivity{
this.delivery=deliveryActivity.getJob(); this.delivery=deliveryActivity.getJob();
this.arrTime=deliveryActivity.getArrTime(); this.arrTime=deliveryActivity.getArrTime();
this.endTime=deliveryActivity.getEndTime(); this.endTime=deliveryActivity.getEndTime();
capacity = deliveryActivity.getCapacity(); capacity = deliveryActivity.getSize();
} }
/** /**
@ -96,7 +96,7 @@ public final class DeliverService implements DeliveryActivity{
} }
@Override @Override
public Capacity getCapacity() { public Capacity getSize() {
return capacity; return capacity;
} }
} }

View file

@ -24,7 +24,7 @@ public final class DeliverShipment implements DeliveryActivity{
this.shipment = (Shipment) deliveryShipmentActivity.getJob(); this.shipment = (Shipment) deliveryShipmentActivity.getJob();
this.arrTime = deliveryShipmentActivity.getArrTime(); this.arrTime = deliveryShipmentActivity.getArrTime();
this.endTime = deliveryShipmentActivity.getEndTime(); this.endTime = deliveryShipmentActivity.getEndTime();
this.capacity = deliveryShipmentActivity.getCapacity(); this.capacity = deliveryShipmentActivity.getSize();
} }
@Override @Override
@ -97,7 +97,7 @@ public final class DeliverShipment implements DeliveryActivity{
} }
@Override @Override
public Capacity getCapacity() { public Capacity getSize() {
return capacity; return capacity;
} }
} }

View file

@ -151,7 +151,7 @@ public final class End implements TourActivity {
} }
@Override @Override
public Capacity getCapacity() { public Capacity getSize() {
return capacity; return capacity;
} }

View file

@ -98,7 +98,7 @@ public final class PickupService implements PickupActivity{
} }
@Override @Override
public Capacity getCapacity() { public Capacity getSize() {
return pickup.getSize(); return pickup.getSize();
} }

View file

@ -93,7 +93,7 @@ public final class PickupShipment implements PickupActivity{
} }
@Override @Override
public Capacity getCapacity() { public Capacity getSize() {
return shipment.getSize(); return shipment.getSize();
} }

View file

@ -159,7 +159,7 @@ public class ServiceActivity implements JobActivity{
} }
@Override @Override
public Capacity getCapacity() { public Capacity getSize() {
return service.getSize(); return service.getSize();
} }

View file

@ -155,7 +155,7 @@ public final class Start implements TourActivity {
} }
@Override @Override
public Capacity getCapacity() { public Capacity getSize() {
return capacity; return capacity;
} }

View file

@ -133,7 +133,7 @@ public interface TourActivity {
* *
* @return capacity * @return capacity
*/ */
public abstract Capacity getCapacity(); public abstract Capacity getSize();
/** /**
* Makes a deep copy of this activity. * Makes a deep copy of this activity.

View file

@ -0,0 +1,174 @@
package jsprit.core.algorithm.state;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.Arrays;
import java.util.Collections;
import jsprit.core.problem.Capacity;
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
import jsprit.core.problem.driver.Driver;
import jsprit.core.problem.job.Delivery;
import jsprit.core.problem.job.Job;
import jsprit.core.problem.job.Pickup;
import jsprit.core.problem.solution.route.ReverseRouteActivityVisitor;
import jsprit.core.problem.solution.route.RouteActivityVisitor;
import jsprit.core.problem.solution.route.VehicleRoute;
import jsprit.core.problem.solution.route.state.StateFactory;
import jsprit.core.problem.vehicle.Vehicle;
import org.junit.Test;
public class UpdateCapacityUtilizationForwardLookingTest {
@Test
public void whenVehicleRouteHasPickupAndDelivery_futureMaxLoadAtEachActivityShouldBeCalculatedCorrectly(){
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
UpdateLoads updateLoad = new UpdateLoads(stateManager);
UpdateMaxCapacityUtilisationAtActivitiesByLookingForwardInRoute updateMaxLoad = new UpdateMaxCapacityUtilisationAtActivitiesByLookingForwardInRoute(stateManager);
RouteActivityVisitor routeActivityVisitor = new RouteActivityVisitor();
routeActivityVisitor.addActivityVisitor(updateLoad);
ReverseRouteActivityVisitor revRouteActivityVisitor = new ReverseRouteActivityVisitor();
revRouteActivityVisitor.addActivityVisitor(updateMaxLoad);
Pickup pickup = mock(Pickup.class);
when(pickup.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1).build());
Delivery delivery = mock(Delivery.class);
when(delivery.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 10).build());
VehicleRoute route = VehicleRoute.Builder.newInstance(mock(Vehicle.class), mock(Driver.class))
.addService(pickup).addService(delivery).build();
updateLoad.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
routeActivityVisitor.visit(route);
revRouteActivityVisitor.visit(route);
assertEquals(11,stateManager.getActivityState(route.getActivities().get(0), StateFactory.FUTURE_MAXLOAD, Capacity.class).get(0),0.1);
assertEquals(1,stateManager.getActivityState(route.getActivities().get(1), StateFactory.FUTURE_MAXLOAD, Capacity.class).get(0),0.1);
}
@Test
public void whenVehicleRouteHasPickupAndDeliveryWithMultipleCapDims_futureMaxLoadAtEachActivityShouldBeCalculatedCorrectly(){
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
UpdateLoads updateLoad = new UpdateLoads(stateManager);
UpdateMaxCapacityUtilisationAtActivitiesByLookingForwardInRoute updateMaxLoad = new UpdateMaxCapacityUtilisationAtActivitiesByLookingForwardInRoute(stateManager);
RouteActivityVisitor routeActivityVisitor = new RouteActivityVisitor();
routeActivityVisitor.addActivityVisitor(updateLoad);
ReverseRouteActivityVisitor revRouteActivityVisitor = new ReverseRouteActivityVisitor();
revRouteActivityVisitor.addActivityVisitor(updateMaxLoad);
Pickup pickup = mock(Pickup.class);
when(pickup.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1)
.addDimension(1, 5).build());
Delivery delivery = mock(Delivery.class);
when(delivery.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 10)
.addDimension(1, 3).build());
VehicleRoute route = VehicleRoute.Builder.newInstance(mock(Vehicle.class), mock(Driver.class))
.addService(pickup).addService(delivery).build();
updateLoad.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
routeActivityVisitor.visit(route);
revRouteActivityVisitor.visit(route);
assertEquals(11,stateManager.getActivityState(route.getActivities().get(0), StateFactory.FUTURE_MAXLOAD, Capacity.class).get(0),0.1);
assertEquals(8,stateManager.getActivityState(route.getActivities().get(0), StateFactory.FUTURE_MAXLOAD, Capacity.class).get(1),0.1);
assertEquals(1,stateManager.getActivityState(route.getActivities().get(1), StateFactory.FUTURE_MAXLOAD, Capacity.class).get(0),0.1);
assertEquals(5,stateManager.getActivityState(route.getActivities().get(1), StateFactory.FUTURE_MAXLOAD, Capacity.class).get(1),0.1);
}
@Test
public void whenVehicleRouteHasPickupAndDeliveryAndPickupWithMultipleCapDims_futureMaxLoadAtEachActivityShouldBeCalculatedCorrectly(){
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
UpdateLoads updateLoad = new UpdateLoads(stateManager);
UpdateMaxCapacityUtilisationAtActivitiesByLookingForwardInRoute updateMaxLoad = new UpdateMaxCapacityUtilisationAtActivitiesByLookingForwardInRoute(stateManager);
RouteActivityVisitor routeActivityVisitor = new RouteActivityVisitor();
routeActivityVisitor.addActivityVisitor(updateLoad);
ReverseRouteActivityVisitor revRouteActivityVisitor = new ReverseRouteActivityVisitor();
revRouteActivityVisitor.addActivityVisitor(updateMaxLoad);
Pickup pickup = mock(Pickup.class);
when(pickup.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1)
.addDimension(1, 5).build());
Delivery delivery = mock(Delivery.class);
when(delivery.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 10)
.addDimension(1, 3).build());
Pickup pickup2 = mock(Pickup.class);
when(pickup2.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 3)
.addDimension(1, 8).build());
VehicleRoute route = VehicleRoute.Builder.newInstance(mock(Vehicle.class), mock(Driver.class))
.addService(pickup).addService(delivery).addService(pickup2).build();
updateLoad.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
routeActivityVisitor.visit(route);
revRouteActivityVisitor.visit(route);
assertEquals(11,stateManager.getActivityState(route.getActivities().get(0), StateFactory.FUTURE_MAXLOAD, Capacity.class).get(0));
assertEquals(13,stateManager.getActivityState(route.getActivities().get(0), StateFactory.FUTURE_MAXLOAD, Capacity.class).get(1));
assertEquals(4,stateManager.getActivityState(route.getActivities().get(1), StateFactory.FUTURE_MAXLOAD, Capacity.class).get(0));
assertEquals(13,stateManager.getActivityState(route.getActivities().get(1), StateFactory.FUTURE_MAXLOAD, Capacity.class).get(1));
assertEquals(4,stateManager.getActivityState(route.getActivities().get(2), StateFactory.FUTURE_MAXLOAD, Capacity.class).get(0));
assertEquals(13,stateManager.getActivityState(route.getActivities().get(2), StateFactory.FUTURE_MAXLOAD, Capacity.class).get(1));
}
@Test
public void whenVehicleRouteHasPickupAndDeliveryAndPickupWithMultipleCapDims_futureMaxLoadAtEachActivityShouldBeCalculatedCorrectly_v2(){
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
UpdateLoads updateLoad = new UpdateLoads(stateManager);
UpdateMaxCapacityUtilisationAtActivitiesByLookingForwardInRoute updateMaxLoad = new UpdateMaxCapacityUtilisationAtActivitiesByLookingForwardInRoute(stateManager);
RouteActivityVisitor routeActivityVisitor = new RouteActivityVisitor();
routeActivityVisitor.addActivityVisitor(updateLoad);
ReverseRouteActivityVisitor revRouteActivityVisitor = new ReverseRouteActivityVisitor();
revRouteActivityVisitor.addActivityVisitor(updateMaxLoad);
Pickup pickup = mock(Pickup.class);
when(pickup.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1)
.addDimension(1, 5).build());
Delivery delivery = mock(Delivery.class);
when(delivery.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 10)
.addDimension(1, 3).build());
Pickup pickup2 = mock(Pickup.class);
when(pickup2.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 3)
.addDimension(1, 8).addDimension(4, 29).build());
VehicleRoute route = VehicleRoute.Builder.newInstance(mock(Vehicle.class), mock(Driver.class))
.addService(pickup).addService(delivery).addService(pickup2).build();
updateLoad.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
routeActivityVisitor.visit(route);
revRouteActivityVisitor.visit(route);
assertEquals(11,stateManager.getActivityState(route.getActivities().get(0), StateFactory.FUTURE_MAXLOAD, Capacity.class).get(0));
assertEquals(13,stateManager.getActivityState(route.getActivities().get(0), StateFactory.FUTURE_MAXLOAD, Capacity.class).get(1));
assertEquals(29,stateManager.getActivityState(route.getActivities().get(0), StateFactory.FUTURE_MAXLOAD, Capacity.class).get(4));
assertEquals(4,stateManager.getActivityState(route.getActivities().get(1), StateFactory.FUTURE_MAXLOAD, Capacity.class).get(0));
assertEquals(13,stateManager.getActivityState(route.getActivities().get(1), StateFactory.FUTURE_MAXLOAD, Capacity.class).get(1));
assertEquals(29,stateManager.getActivityState(route.getActivities().get(1), StateFactory.FUTURE_MAXLOAD, Capacity.class).get(4));
assertEquals(4,stateManager.getActivityState(route.getActivities().get(2), StateFactory.FUTURE_MAXLOAD, Capacity.class).get(0));
assertEquals(13,stateManager.getActivityState(route.getActivities().get(2), StateFactory.FUTURE_MAXLOAD, Capacity.class).get(1));
}
}

View file

@ -23,9 +23,9 @@ public class DeliverServiceTest {
@Test @Test
public void whenCallingCapacity_itShouldReturnCorrectCapacity(){ public void whenCallingCapacity_itShouldReturnCorrectCapacity(){
assertEquals(-10,deliver.getCapacity().get(0)); assertEquals(-10,deliver.getSize().get(0));
assertEquals(-100,deliver.getCapacity().get(1)); assertEquals(-100,deliver.getSize().get(1));
assertEquals(-1000,deliver.getCapacity().get(2)); assertEquals(-1000,deliver.getSize().get(2));
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@ -67,9 +67,9 @@ public class DeliverServiceTest {
assertEquals(1.,copy.getTheoreticalEarliestOperationStartTime(),0.01); assertEquals(1.,copy.getTheoreticalEarliestOperationStartTime(),0.01);
assertEquals(2.,copy.getTheoreticalLatestOperationStartTime(),0.01); assertEquals(2.,copy.getTheoreticalLatestOperationStartTime(),0.01);
assertEquals("loc",copy.getLocationId()); assertEquals("loc",copy.getLocationId());
assertEquals(-10,copy.getCapacity().get(0)); assertEquals(-10,copy.getSize().get(0));
assertEquals(-100,copy.getCapacity().get(1)); assertEquals(-100,copy.getSize().get(1));
assertEquals(-1000,copy.getCapacity().get(2)); assertEquals(-1000,copy.getSize().get(2));
assertTrue(copy!=deliver); assertTrue(copy!=deliver);
} }

View file

@ -25,9 +25,9 @@ public class DeliverShipmentTest {
@Test @Test
public void whenCallingCapacity_itShouldReturnCorrectCapacity(){ public void whenCallingCapacity_itShouldReturnCorrectCapacity(){
assertEquals(-10,deliver.getCapacity().get(0)); assertEquals(-10,deliver.getSize().get(0));
assertEquals(-100,deliver.getCapacity().get(1)); assertEquals(-100,deliver.getSize().get(1));
assertEquals(-1000,deliver.getCapacity().get(2)); assertEquals(-1000,deliver.getSize().get(2));
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@ -69,9 +69,9 @@ public class DeliverShipmentTest {
assertEquals(3.,copy.getTheoreticalEarliestOperationStartTime(),0.01); assertEquals(3.,copy.getTheoreticalEarliestOperationStartTime(),0.01);
assertEquals(4.,copy.getTheoreticalLatestOperationStartTime(),0.01); assertEquals(4.,copy.getTheoreticalLatestOperationStartTime(),0.01);
assertEquals("deliveryLoc",copy.getLocationId()); assertEquals("deliveryLoc",copy.getLocationId());
assertEquals(-10,copy.getCapacity().get(0)); assertEquals(-10,copy.getSize().get(0));
assertEquals(-100,copy.getCapacity().get(1)); assertEquals(-100,copy.getSize().get(1));
assertEquals(-1000,copy.getCapacity().get(2)); assertEquals(-1000,copy.getSize().get(2));
assertTrue(copy!=deliver); assertTrue(copy!=deliver);
} }
@ -81,8 +81,8 @@ public class DeliverShipmentTest {
Shipment shipment = Shipment.Builder.newInstance("s").setPickupLocation("pickLoc").setDeliveryLocation("delLoc") Shipment shipment = Shipment.Builder.newInstance("s").setPickupLocation("pickLoc").setDeliveryLocation("delLoc")
.addSizeDimension(0, 10).addSizeDimension(1, 100).build(); .addSizeDimension(0, 10).addSizeDimension(1, 100).build();
PickupShipment pick = new PickupShipment(shipment); PickupShipment pick = new PickupShipment(shipment);
assertEquals(10,pick.getCapacity().get(0)); assertEquals(10,pick.getSize().get(0));
assertEquals(100,pick.getCapacity().get(1)); assertEquals(100,pick.getSize().get(1));
} }
} }

View file

@ -10,7 +10,7 @@ public class EndTest {
@Test @Test
public void whenCallingCapacity_itShouldReturnEmptyCapacity(){ public void whenCallingCapacity_itShouldReturnEmptyCapacity(){
End end = End.newInstance("loc", 0., 0.); End end = End.newInstance("loc", 0., 0.);
assertEquals(0,end.getCapacity().get(0)); assertEquals(0,end.getSize().get(0));
} }
@Test @Test

View file

@ -23,9 +23,9 @@ public class PickupServiceTest {
@Test @Test
public void whenCallingCapacity_itShouldReturnCorrectCapacity(){ public void whenCallingCapacity_itShouldReturnCorrectCapacity(){
assertEquals(10,pickup.getCapacity().get(0)); assertEquals(10,pickup.getSize().get(0));
assertEquals(100,pickup.getCapacity().get(1)); assertEquals(100,pickup.getSize().get(1));
assertEquals(1000,pickup.getCapacity().get(2)); assertEquals(1000,pickup.getSize().get(2));
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@ -67,9 +67,9 @@ public class PickupServiceTest {
assertEquals(1.,copy.getTheoreticalEarliestOperationStartTime(),0.01); assertEquals(1.,copy.getTheoreticalEarliestOperationStartTime(),0.01);
assertEquals(2.,copy.getTheoreticalLatestOperationStartTime(),0.01); assertEquals(2.,copy.getTheoreticalLatestOperationStartTime(),0.01);
assertEquals("loc",copy.getLocationId()); assertEquals("loc",copy.getLocationId());
assertEquals(10,copy.getCapacity().get(0)); assertEquals(10,copy.getSize().get(0));
assertEquals(100,copy.getCapacity().get(1)); assertEquals(100,copy.getSize().get(1));
assertEquals(1000,copy.getCapacity().get(2)); assertEquals(1000,copy.getSize().get(2));
assertTrue(copy!=pickup); assertTrue(copy!=pickup);
} }

View file

@ -25,9 +25,9 @@ public class PickupShipmentTest {
@Test @Test
public void whenCallingCapacity_itShouldReturnCorrectCapacity(){ public void whenCallingCapacity_itShouldReturnCorrectCapacity(){
assertEquals(10,pickup.getCapacity().get(0)); assertEquals(10,pickup.getSize().get(0));
assertEquals(100,pickup.getCapacity().get(1)); assertEquals(100,pickup.getSize().get(1));
assertEquals(1000,pickup.getCapacity().get(2)); assertEquals(1000,pickup.getSize().get(2));
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@ -69,9 +69,9 @@ public class PickupShipmentTest {
assertEquals(1.,copy.getTheoreticalEarliestOperationStartTime(),0.01); assertEquals(1.,copy.getTheoreticalEarliestOperationStartTime(),0.01);
assertEquals(2.,copy.getTheoreticalLatestOperationStartTime(),0.01); assertEquals(2.,copy.getTheoreticalLatestOperationStartTime(),0.01);
assertEquals("pickupLoc",copy.getLocationId()); assertEquals("pickupLoc",copy.getLocationId());
assertEquals(10,copy.getCapacity().get(0)); assertEquals(10,copy.getSize().get(0));
assertEquals(100,copy.getCapacity().get(1)); assertEquals(100,copy.getSize().get(1));
assertEquals(1000,copy.getCapacity().get(2)); assertEquals(1000,copy.getSize().get(2));
assertTrue(copy!=pickup); assertTrue(copy!=pickup);
} }
@ -81,8 +81,8 @@ public class PickupShipmentTest {
Shipment shipment = Shipment.Builder.newInstance("s").setPickupLocation("pickLoc").setDeliveryLocation("delLoc") Shipment shipment = Shipment.Builder.newInstance("s").setPickupLocation("pickLoc").setDeliveryLocation("delLoc")
.addSizeDimension(0, 10).addSizeDimension(1, 100).build(); .addSizeDimension(0, 10).addSizeDimension(1, 100).build();
PickupShipment pick = new PickupShipment(shipment); PickupShipment pick = new PickupShipment(shipment);
assertEquals(10,pick.getCapacity().get(0)); assertEquals(10,pick.getSize().get(0));
assertEquals(100,pick.getCapacity().get(1)); assertEquals(100,pick.getSize().get(1));
} }
} }

View file

@ -42,9 +42,9 @@ public class ServiceActivityTest {
@Test @Test
public void whenCallingCapacity_itShouldReturnCorrectCapacity(){ public void whenCallingCapacity_itShouldReturnCorrectCapacity(){
assertEquals(10,serviceActivity.getCapacity().get(0)); assertEquals(10,serviceActivity.getSize().get(0));
assertEquals(100,serviceActivity.getCapacity().get(1)); assertEquals(100,serviceActivity.getSize().get(1));
assertEquals(1000,serviceActivity.getCapacity().get(2)); assertEquals(1000,serviceActivity.getSize().get(2));
} }

View file

@ -9,7 +9,7 @@ public class StartTest {
@Test @Test
public void whenCallingCapacity_itShouldReturnEmptyCapacity(){ public void whenCallingCapacity_itShouldReturnEmptyCapacity(){
Start start = Start.newInstance("loc", 0., 0.); Start start = Start.newInstance("loc", 0., 0.);
assertEquals(0,start.getCapacity().get(0)); assertEquals(0,start.getSize().get(0));
} }
@Test @Test