mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
extended stateManager to memorize vehicle dependent states
This commit is contained in:
parent
952570952a
commit
dbdb3372c7
11 changed files with 167 additions and 76 deletions
|
|
@ -157,7 +157,7 @@ public class VehicleRoutingAlgorithmBuilder {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public VehicleRoutingAlgorithm build() {
|
public VehicleRoutingAlgorithm build() {
|
||||||
if(stateManager == null) stateManager = new StateManager(vrp.getTransportCosts());
|
if(stateManager == null) stateManager = new StateManager(vrp);
|
||||||
if(constraintManager == null) constraintManager = new ConstraintManager(vrp,stateManager,vrp.getConstraints());
|
if(constraintManager == null) constraintManager = new ConstraintManager(vrp,stateManager,vrp.getConstraints());
|
||||||
//add core updater
|
//add core updater
|
||||||
stateManager.addStateUpdater(new UpdateEndLocationIfRouteIsOpen());
|
stateManager.addStateUpdater(new UpdateEndLocationIfRouteIsOpen());
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ import jsprit.core.algorithm.ruin.listener.RuinListeners;
|
||||||
import jsprit.core.problem.Capacity;
|
import jsprit.core.problem.Capacity;
|
||||||
import jsprit.core.problem.VehicleRoutingProblem;
|
import jsprit.core.problem.VehicleRoutingProblem;
|
||||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||||
|
import jsprit.core.problem.driver.Driver;
|
||||||
import jsprit.core.problem.job.Job;
|
import jsprit.core.problem.job.Job;
|
||||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||||
import jsprit.core.problem.solution.route.ReverseRouteActivityVisitor;
|
import jsprit.core.problem.solution.route.ReverseRouteActivityVisitor;
|
||||||
|
|
@ -35,6 +36,7 @@ import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||||
import jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter;
|
import jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter;
|
||||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||||
import jsprit.core.problem.solution.route.state.StateFactory.StateId;
|
import jsprit.core.problem.solution.route.state.StateFactory.StateId;
|
||||||
|
import jsprit.core.problem.vehicle.Vehicle;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
|
@ -109,10 +111,16 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
|
||||||
|
|
||||||
private int nuActivities;
|
private int nuActivities;
|
||||||
|
|
||||||
|
private int nuVehicleTypeKeys;
|
||||||
|
|
||||||
private Object[][] activity_states;
|
private Object[][] activity_states;
|
||||||
|
|
||||||
|
private Object[][][] vehicle_dependent_activity_states;
|
||||||
|
|
||||||
private Object[][] route_states;
|
private Object[][] route_states;
|
||||||
|
|
||||||
|
private Object[][][] vehicle_dependent_route_states;
|
||||||
|
|
||||||
private VehicleRoutingProblem vrp;
|
private VehicleRoutingProblem vrp;
|
||||||
|
|
||||||
public StateId createStateId(String name){
|
public StateId createStateId(String name){
|
||||||
|
|
@ -120,6 +128,8 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
|
||||||
if(stateIndexCounter>=activity_states[0].length){
|
if(stateIndexCounter>=activity_states[0].length){
|
||||||
activity_states = new Object[vrp.getNuActivities()+1][stateIndexCounter+1];
|
activity_states = new Object[vrp.getNuActivities()+1][stateIndexCounter+1];
|
||||||
route_states = new Object[vrp.getNuActivities()+1][stateIndexCounter+1];
|
route_states = new Object[vrp.getNuActivities()+1][stateIndexCounter+1];
|
||||||
|
vehicle_dependent_activity_states = new Object[nuActivities][nuVehicleTypeKeys][stateIndexCounter+1];
|
||||||
|
vehicle_dependent_route_states = new Object[nuActivities][nuVehicleTypeKeys][stateIndexCounter+1];
|
||||||
}
|
}
|
||||||
StateId id = StateFactory.createId(name,stateIndexCounter);
|
StateId id = StateFactory.createId(name,stateIndexCounter);
|
||||||
incStateIndexCounter();
|
incStateIndexCounter();
|
||||||
|
|
@ -164,13 +174,24 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
|
||||||
public StateManager(VehicleRoutingProblem vehicleRoutingProblem){
|
public StateManager(VehicleRoutingProblem vehicleRoutingProblem){
|
||||||
this.routingCosts = vehicleRoutingProblem.getTransportCosts();
|
this.routingCosts = vehicleRoutingProblem.getTransportCosts();
|
||||||
this.vrp = vehicleRoutingProblem;
|
this.vrp = vehicleRoutingProblem;
|
||||||
nuActivities = vrp.getNuActivities() + 1;
|
nuActivities = Math.max(10,vrp.getNuActivities() + 1);
|
||||||
|
nuVehicleTypeKeys = Math.max(3,getNuVehicleTypes(vrp) + 1);
|
||||||
activity_states = new Object[nuActivities][initialNuStates];
|
activity_states = new Object[nuActivities][initialNuStates];
|
||||||
route_states = new Object[nuActivities][initialNuStates];
|
route_states = new Object[nuActivities][initialNuStates];
|
||||||
|
vehicle_dependent_activity_states = new Object[nuActivities][nuVehicleTypeKeys][initialNuStates];
|
||||||
|
vehicle_dependent_route_states = new Object[nuActivities][nuVehicleTypeKeys][initialNuStates];
|
||||||
addDefaultStates();
|
addDefaultStates();
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> void addDefaultProblemState(StateId stateId, Class<T> type, T defaultState){
|
private int getNuVehicleTypes(VehicleRoutingProblem vrp) {
|
||||||
|
int maxIndex = 0;
|
||||||
|
for(Vehicle v : vrp.getVehicles()){
|
||||||
|
maxIndex = Math.max(maxIndex,v.getVehicleTypeIdentifier().getIndex());
|
||||||
|
}
|
||||||
|
return maxIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> void addDefaultProblemState(StateId stateId, Class<T> type, T defaultState){
|
||||||
defaultProblemStates_.putState(stateId, type, defaultState);
|
defaultProblemStates_.putState(stateId, type, defaultState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -225,6 +246,8 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
|
||||||
public void clear(){
|
public void clear(){
|
||||||
activity_states = new Object[nuActivities][stateIndexCounter];
|
activity_states = new Object[nuActivities][stateIndexCounter];
|
||||||
route_states = new Object[nuActivities][stateIndexCounter];
|
route_states = new Object[nuActivities][stateIndexCounter];
|
||||||
|
vehicle_dependent_activity_states = new Object[nuActivities][nuVehicleTypeKeys][initialNuStates];
|
||||||
|
vehicle_dependent_route_states = new Object[nuActivities][nuVehicleTypeKeys][initialNuStates];
|
||||||
problemStates_.clear();
|
problemStates_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -240,6 +263,17 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns activity state of type 'type'.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public <T> T getActivityState(TourActivity act, Vehicle vehicle, Driver driver, StateId stateId, Class<T> type) {
|
||||||
|
if(act.getIndex()<0) return getDefaultTypedActivityState(act, stateId, type);
|
||||||
|
T state = type.cast(vehicle_dependent_activity_states[act.getIndex()][vehicle.getVehicleTypeIdentifier().getIndex()][stateId.getIndex()]);
|
||||||
|
if(state == null) return getDefaultTypedActivityState(act, stateId, type);
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param act activity for which the state is requested
|
* @param act activity for which the state is requested
|
||||||
|
|
@ -269,15 +303,18 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
|
||||||
@Override
|
@Override
|
||||||
public <T> T getRouteState(VehicleRoute route, StateId stateId, Class<T> type) {
|
public <T> T getRouteState(VehicleRoute route, StateId stateId, Class<T> type) {
|
||||||
if(route.isEmpty()) return getDefaultTypedRouteState(stateId,type);
|
if(route.isEmpty()) return getDefaultTypedRouteState(stateId,type);
|
||||||
// if(route.getActivities().get(0).getIndex()>=route_states.length){
|
|
||||||
// nuActivities=route.getActivities().get(0).getIndex()+1;
|
|
||||||
// this.route_states = resizeArr(route_states,nuActivities);
|
|
||||||
// }
|
|
||||||
T state = type.cast(route_states[route.getActivities().get(0).getIndex()][stateId.getIndex()]);
|
T state = type.cast(route_states[route.getActivities().get(0).getIndex()][stateId.getIndex()]);
|
||||||
if(state==null) return getDefaultTypedRouteState(stateId,type);
|
if(state==null) return getDefaultTypedRouteState(stateId,type);
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public <T> T getRouteState(VehicleRoute route, Vehicle vehicle, Driver driver, StateId stateId, Class<T> type) {
|
||||||
|
if(route.isEmpty()) return getDefaultTypedRouteState(stateId,type);
|
||||||
|
T state = type.cast(vehicle_dependent_route_states[route.getActivities().get(0).getIndex()][vehicle.getVehicleTypeIdentifier().getIndex()][stateId.getIndex()]);
|
||||||
|
if(state==null) return getDefaultTypedRouteState(stateId,type);
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
private <T> T getDefaultTypedRouteState(StateId stateId, Class<T> type) {
|
private <T> T getDefaultTypedRouteState(StateId stateId, Class<T> type) {
|
||||||
if(defaultRouteStates_.containsKey(stateId)){
|
if(defaultRouteStates_.containsKey(stateId)){
|
||||||
return type.cast(defaultRouteStates_.get(stateId));
|
return type.cast(defaultRouteStates_.get(stateId));
|
||||||
|
|
@ -303,20 +340,16 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public <T> void putTypedActivityState(TourActivity act, StateId stateId, Class<T> type, T state){
|
public <T> void putTypedActivityState(TourActivity act, StateId stateId, Class<T> type, T state){
|
||||||
// if(act.getIndex()>=activity_states.length){
|
|
||||||
// nuActivities=act.getIndex()+1;
|
|
||||||
// this.activity_states = resizeArr(activity_states,nuActivities);
|
|
||||||
// }
|
|
||||||
if(stateId.getIndex()<10) throw new IllegalStateException("either you use a reserved stateId that is applied\n" +
|
if(stateId.getIndex()<10) throw new IllegalStateException("either you use a reserved stateId that is applied\n" +
|
||||||
"internally or your stateId has been created without index, e.g. StateFactory.createId(stateName)\n" +
|
"internally or your stateId has been created without index, e.g. StateFactory.createId(stateName)\n" +
|
||||||
" does not assign indeces thus do not use it anymore, but use\n " +
|
" does not assign indeces thus do not use it anymore, but use\n " +
|
||||||
"stateManager.createStateId(name)\n" +
|
"stateManager.createStateId(name)\n" +
|
||||||
" instead.\n");
|
" instead.\n");
|
||||||
putInternalTypedActivityState(act, stateId, type, state);
|
putInternalTypedActivityState(act, stateId, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generic method to memorize state 'state' of type 'type' of act and stateId.
|
* Method to memorize state 'state' of type 'type' of act and stateId.
|
||||||
*
|
*
|
||||||
* <p><b>For example: </b><br>
|
* <p><b>For example: </b><br>
|
||||||
* <code>Capacity loadAtMyActivity = Capacity.Builder.newInstance().addCapacityDimension(0,10).build();<br>
|
* <code>Capacity loadAtMyActivity = Capacity.Builder.newInstance().addCapacityDimension(0,10).build();<br>
|
||||||
|
|
@ -329,17 +362,32 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
|
||||||
* @param type class of state-value
|
* @param type class of state-value
|
||||||
* @param state state-value
|
* @param state state-value
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public <T> void putActivityState(TourActivity act, StateId stateId, Class<T> type, T state){
|
public <T> void putActivityState(TourActivity act, StateId stateId, Class<T> type, T state){
|
||||||
// if(act.getIndex()>=activity_states.length){
|
|
||||||
// nuActivities=act.getIndex()+1;
|
|
||||||
// this.activity_states = resizeArr(activity_states,nuActivities);
|
|
||||||
// }
|
|
||||||
if(stateId.getIndex()<10) throw new IllegalStateException("either you use a reserved stateId that is applied\n" +
|
if(stateId.getIndex()<10) throw new IllegalStateException("either you use a reserved stateId that is applied\n" +
|
||||||
"internally or your stateId has been created without index, e.g. StateFactory.createId(stateName)\n" +
|
"internally or your stateId has been created without index, e.g. StateFactory.createId(stateName)\n" +
|
||||||
" does not assign indeces thus do not use it anymore, but use\n " +
|
" does not assign indeces thus do not use it anymore, but use\n " +
|
||||||
"stateManager.createStateId(name)\n" +
|
"stateManager.createStateId(name)\n" +
|
||||||
" instead.\n");
|
" instead.\n");
|
||||||
putInternalTypedActivityState(act, stateId, type, state);
|
putInternalTypedActivityState(act, stateId, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> void putActivityState(TourActivity act, StateId stateId, T state){
|
||||||
|
if(stateId.getIndex()<10) throw new IllegalStateException("either you use a reserved stateId that is applied\n" +
|
||||||
|
"internally or your stateId has been created without index, e.g. StateFactory.createId(stateName)\n" +
|
||||||
|
" does not assign indeces thus do not use it anymore, but use\n " +
|
||||||
|
"stateManager.createStateId(name)\n" +
|
||||||
|
" instead.\n");
|
||||||
|
putInternalTypedActivityState(act, stateId, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> void putActivityState(TourActivity act, Vehicle vehicle, Driver driver, StateId stateId, T state){
|
||||||
|
if(stateId.getIndex()<10) throw new IllegalStateException("either you use a reserved stateId that is applied\n" +
|
||||||
|
"internally or your stateId has been created without index, e.g. StateFactory.createId(stateName)\n" +
|
||||||
|
" does not assign indeces thus do not use it anymore, but use\n " +
|
||||||
|
"stateManager.createStateId(name)\n" +
|
||||||
|
" instead.\n");
|
||||||
|
putInternalTypedActivityState(act, vehicle, driver, stateId, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object[][] resizeArr(Object[][] states, int newLength) {
|
private Object[][] resizeArr(Object[][] states, int newLength) {
|
||||||
|
|
@ -349,10 +397,14 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
|
||||||
return new_states;
|
return new_states;
|
||||||
}
|
}
|
||||||
|
|
||||||
<T> void putInternalTypedActivityState(TourActivity act, StateId stateId, Class<T> type, T state){
|
<T> void putInternalTypedActivityState(TourActivity act, StateId stateId, T state){
|
||||||
activity_states[act.getIndex()][stateId.getIndex()]=state;
|
activity_states[act.getIndex()][stateId.getIndex()]=state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<T> void putInternalTypedActivityState(TourActivity act, Vehicle vehicle, Driver driver, StateId stateId, T state){
|
||||||
|
vehicle_dependent_activity_states[act.getIndex()][vehicle.getVehicleTypeIdentifier().getIndex()][stateId.getIndex()]=state;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generic method to memorize state 'state' of type 'type' of route and stateId.
|
* Generic method to memorize state 'state' of type 'type' of route and stateId.
|
||||||
*
|
*
|
||||||
|
|
@ -391,11 +443,21 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
|
||||||
putTypedInternalRouteState(route, stateId, state);
|
putTypedInternalRouteState(route, stateId, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public <T> void putRouteState(VehicleRoute route, Vehicle vehicle, Driver driver, StateId stateId, T state){
|
||||||
|
if(stateId.getIndex()<10) StateFactory.throwReservedIdException(stateId.toString());
|
||||||
|
putTypedInternalRouteState(route, vehicle, driver, stateId, state);
|
||||||
|
}
|
||||||
|
|
||||||
<T> void putTypedInternalRouteState(VehicleRoute route, StateId stateId, T state){
|
<T> void putTypedInternalRouteState(VehicleRoute route, StateId stateId, T state){
|
||||||
if(route.isEmpty()) return;
|
if(route.isEmpty()) return;
|
||||||
route_states[route.getActivities().get(0).getIndex()][stateId.getIndex()] = state;
|
route_states[route.getActivities().get(0).getIndex()][stateId.getIndex()] = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<T> void putTypedInternalRouteState(VehicleRoute route, Vehicle vehicle, Driver driver, StateId stateId, T state){
|
||||||
|
if(route.isEmpty()) return;
|
||||||
|
vehicle_dependent_route_states[route.getActivities().get(0).getIndex()][vehicle.getVehicleTypeIdentifier().getIndex()][stateId.getIndex()] = state;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds state updater.
|
* Adds state updater.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ class UpdateLoads implements ActivityVisitor, StateUpdater, InsertionStartsListe
|
||||||
@Override
|
@Override
|
||||||
public void visit(TourActivity act) {
|
public void visit(TourActivity act) {
|
||||||
currentLoad = Capacity.addup(currentLoad, act.getSize());
|
currentLoad = Capacity.addup(currentLoad, act.getSize());
|
||||||
stateManager.putInternalTypedActivityState(act, StateFactory.LOAD, Capacity.class, currentLoad);
|
stateManager.putInternalTypedActivityState(act, StateFactory.LOAD, 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";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ class UpdateMaxCapacityUtilisationAtActivitiesByLookingBackwardInRoute implement
|
||||||
@Override
|
@Override
|
||||||
public void visit(TourActivity act) {
|
public void visit(TourActivity act) {
|
||||||
maxLoad = Capacity.max(maxLoad, stateManager.getActivityState(act, StateFactory.LOAD, Capacity.class));
|
maxLoad = Capacity.max(maxLoad, stateManager.getActivityState(act, StateFactory.LOAD, Capacity.class));
|
||||||
stateManager.putInternalTypedActivityState(act, StateFactory.PAST_MAXLOAD, Capacity.class, maxLoad);
|
stateManager.putInternalTypedActivityState(act, StateFactory.PAST_MAXLOAD, maxLoad);
|
||||||
assert maxLoad.isGreaterOrEqual(Capacity.Builder.newInstance().build()) : "maxLoad can never be smaller than 0";
|
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";
|
assert maxLoad.isLessOrEqual(route.getVehicle().getType().getCapacityDimensions()) : "maxLoad can never be bigger than vehicleCap";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ class UpdateMaxCapacityUtilisationAtActivitiesByLookingForwardInRoute implements
|
||||||
@Override
|
@Override
|
||||||
public void visit(TourActivity act) {
|
public void visit(TourActivity act) {
|
||||||
maxLoad = Capacity.max(maxLoad, stateManager.getActivityState(act, StateFactory.LOAD, Capacity.class));
|
maxLoad = Capacity.max(maxLoad, stateManager.getActivityState(act, StateFactory.LOAD, Capacity.class));
|
||||||
stateManager.putInternalTypedActivityState(act, StateFactory.FUTURE_MAXLOAD, Capacity.class, maxLoad);
|
stateManager.putInternalTypedActivityState(act, StateFactory.FUTURE_MAXLOAD, maxLoad);
|
||||||
assert maxLoad.isLessOrEqual(route.getVehicle().getType().getCapacityDimensions()) : "maxLoad can in every capacity dimension never be bigger than vehicleCap";
|
assert maxLoad.isLessOrEqual(route.getVehicle().getType().getCapacityDimensions()) : "maxLoad can in every capacity dimension never be bigger than vehicleCap";
|
||||||
assert maxLoad.isGreaterOrEqual(Capacity.Builder.newInstance().build()) : "maxLoad can never be smaller than 0";
|
assert maxLoad.isGreaterOrEqual(Capacity.Builder.newInstance().build()) : "maxLoad can never be smaller than 0";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ class UpdatePracticalTimeWindows implements ReverseActivityVisitor, StateUpdater
|
||||||
double potentialLatestArrivalTimeAtCurrAct = latestArrTimeAtPrevAct - transportCosts.getBackwardTransportTime(activity.getLocationId(), prevAct.getLocationId(), latestArrTimeAtPrevAct, route.getDriver(),route.getVehicle()) - activity.getOperationTime();
|
double potentialLatestArrivalTimeAtCurrAct = latestArrTimeAtPrevAct - transportCosts.getBackwardTransportTime(activity.getLocationId(), prevAct.getLocationId(), latestArrTimeAtPrevAct, route.getDriver(),route.getVehicle()) - activity.getOperationTime();
|
||||||
double latestArrivalTime = Math.min(activity.getTheoreticalLatestOperationStartTime(), potentialLatestArrivalTimeAtCurrAct);
|
double latestArrivalTime = Math.min(activity.getTheoreticalLatestOperationStartTime(), potentialLatestArrivalTimeAtCurrAct);
|
||||||
|
|
||||||
states.putInternalTypedActivityState(activity, StateFactory.LATEST_OPERATION_START_TIME, Double.class, latestArrivalTime);
|
states.putInternalTypedActivityState(activity, StateFactory.LATEST_OPERATION_START_TIME, latestArrivalTime);
|
||||||
|
|
||||||
latestArrTimeAtPrevAct = latestArrivalTime;
|
latestArrTimeAtPrevAct = latestArrivalTime;
|
||||||
prevAct = activity;
|
prevAct = activity;
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,7 @@ public class UpdateVariableCosts implements ActivityVisitor,StateUpdater{
|
||||||
totalOperationCost += transportCost;
|
totalOperationCost += transportCost;
|
||||||
totalOperationCost += actCost;
|
totalOperationCost += actCost;
|
||||||
|
|
||||||
states.putInternalTypedActivityState(act, StateFactory.COSTS, Double.class, totalOperationCost);
|
states.putInternalTypedActivityState(act, StateFactory.COSTS, totalOperationCost);
|
||||||
|
|
||||||
prevAct = act;
|
prevAct = act;
|
||||||
startTimeAtPrevAct = timeTracker.getActEndTime();
|
startTimeAtPrevAct = timeTracker.getActEndTime();
|
||||||
|
|
|
||||||
|
|
@ -18,13 +18,10 @@
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package jsprit.core.algorithm.state;
|
package jsprit.core.algorithm.state;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
import jsprit.core.problem.Capacity;
|
import jsprit.core.problem.Capacity;
|
||||||
|
import jsprit.core.problem.VehicleRoutingProblem;
|
||||||
import jsprit.core.problem.constraint.HardActivityStateLevelConstraint.ConstraintsStatus;
|
import jsprit.core.problem.constraint.HardActivityStateLevelConstraint.ConstraintsStatus;
|
||||||
import jsprit.core.problem.constraint.PickupAndDeliverShipmentLoadActivityLevelConstraint;
|
import jsprit.core.problem.constraint.PickupAndDeliverShipmentLoadActivityLevelConstraint;
|
||||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
|
||||||
import jsprit.core.problem.job.Service;
|
import jsprit.core.problem.job.Service;
|
||||||
import jsprit.core.problem.job.Shipment;
|
import jsprit.core.problem.job.Shipment;
|
||||||
import jsprit.core.problem.misc.JobInsertionContext;
|
import jsprit.core.problem.misc.JobInsertionContext;
|
||||||
|
|
@ -34,10 +31,13 @@ import jsprit.core.problem.solution.route.activity.PickupShipment;
|
||||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||||
import jsprit.core.problem.vehicle.Vehicle;
|
import jsprit.core.problem.vehicle.Vehicle;
|
||||||
import jsprit.core.problem.vehicle.VehicleType;
|
import jsprit.core.problem.vehicle.VehicleType;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
|
||||||
public class HardPickupAndDeliveryShipmentActivityConstraintTest {
|
public class HardPickupAndDeliveryShipmentActivityConstraintTest {
|
||||||
|
|
||||||
|
|
@ -59,7 +59,7 @@ public class HardPickupAndDeliveryShipmentActivityConstraintTest {
|
||||||
when(type.getCapacityDimensions()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 2).build());
|
when(type.getCapacityDimensions()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 2).build());
|
||||||
when(vehicle.getType()).thenReturn(type);
|
when(vehicle.getType()).thenReturn(type);
|
||||||
// when(vehicle.getType().getCapacityDimensions()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 2).build());
|
// when(vehicle.getType().getCapacityDimensions()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 2).build());
|
||||||
stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
stateManager = new StateManager(mock(VehicleRoutingProblem.class));
|
||||||
shipment = mock(Shipment.class);
|
shipment = mock(Shipment.class);
|
||||||
when(shipment.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1).build());
|
when(shipment.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1).build());
|
||||||
// when(shipment.getCapacityDemand()).thenReturn(1);
|
// when(shipment.getCapacityDemand()).thenReturn(1);
|
||||||
|
|
@ -83,7 +83,7 @@ public class HardPickupAndDeliveryShipmentActivityConstraintTest {
|
||||||
PickupService anotherService = new PickupService(mock(Service.class));
|
PickupService anotherService = new PickupService(mock(Service.class));
|
||||||
PickupShipment pickupShipment = new PickupShipment(shipment);
|
PickupShipment pickupShipment = new PickupShipment(shipment);
|
||||||
|
|
||||||
stateManager.putInternalTypedActivityState(pickupService, StateFactory.LOAD, Capacity.class, Capacity.Builder.newInstance().addDimension(0, 2).build());
|
stateManager.putInternalTypedActivityState(pickupService, StateFactory.LOAD, Capacity.Builder.newInstance().addDimension(0, 2).build());
|
||||||
// when(stateManager.getActivityState(pickupService, StateFactory.LOAD)).thenReturn(StateFactory.createState(2.0));
|
// when(stateManager.getActivityState(pickupService, StateFactory.LOAD)).thenReturn(StateFactory.createState(2.0));
|
||||||
assertEquals(ConstraintsStatus.NOT_FULFILLED,constraint.fulfilled(iFacts, pickupService, pickupShipment, anotherService, 0.0));
|
assertEquals(ConstraintsStatus.NOT_FULFILLED,constraint.fulfilled(iFacts, pickupService, pickupShipment, anotherService, 0.0));
|
||||||
}
|
}
|
||||||
|
|
@ -94,7 +94,7 @@ public class HardPickupAndDeliveryShipmentActivityConstraintTest {
|
||||||
PickupService anotherService = new PickupService(mock(Service.class));
|
PickupService anotherService = new PickupService(mock(Service.class));
|
||||||
DeliverShipment pickupShipment = new DeliverShipment(shipment);
|
DeliverShipment pickupShipment = new DeliverShipment(shipment);
|
||||||
|
|
||||||
stateManager.putInternalTypedActivityState(pickupService, StateFactory.LOAD, Capacity.class, Capacity.Builder.newInstance().addDimension(0, 2).build());
|
stateManager.putInternalTypedActivityState(pickupService, StateFactory.LOAD, Capacity.Builder.newInstance().addDimension(0, 2).build());
|
||||||
assertEquals(ConstraintsStatus.NOT_FULFILLED_BREAK,constraint.fulfilled(iFacts, pickupService, pickupShipment, anotherService, 0.0));
|
assertEquals(ConstraintsStatus.NOT_FULFILLED_BREAK,constraint.fulfilled(iFacts, pickupService, pickupShipment, anotherService, 0.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -104,7 +104,7 @@ public class HardPickupAndDeliveryShipmentActivityConstraintTest {
|
||||||
PickupService anotherService = new PickupService(mock(Service.class));
|
PickupService anotherService = new PickupService(mock(Service.class));
|
||||||
DeliverShipment pickupShipment = new DeliverShipment(shipment);
|
DeliverShipment pickupShipment = new DeliverShipment(shipment);
|
||||||
|
|
||||||
stateManager.putInternalTypedActivityState(pickupService, StateFactory.LOAD, Capacity.class, Capacity.Builder.newInstance().addDimension(0, 1).build());
|
stateManager.putInternalTypedActivityState(pickupService, StateFactory.LOAD, Capacity.Builder.newInstance().addDimension(0, 1).build());
|
||||||
// stateManager.putInternalActivityState(pickupService, StateFactory.LOAD, StateFactory.createState(1));
|
// stateManager.putInternalActivityState(pickupService, StateFactory.LOAD, StateFactory.createState(1));
|
||||||
assertEquals(ConstraintsStatus.FULFILLED,constraint.fulfilled(iFacts, pickupService, pickupShipment, anotherService, 0.0));
|
assertEquals(ConstraintsStatus.FULFILLED,constraint.fulfilled(iFacts, pickupService, pickupShipment, anotherService, 0.0));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import jsprit.core.problem.AbstractActivity;
|
||||||
import jsprit.core.problem.Capacity;
|
import jsprit.core.problem.Capacity;
|
||||||
import jsprit.core.problem.JobActivityFactory;
|
import jsprit.core.problem.JobActivityFactory;
|
||||||
import jsprit.core.problem.VehicleRoutingProblem;
|
import jsprit.core.problem.VehicleRoutingProblem;
|
||||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
|
||||||
import jsprit.core.problem.job.*;
|
import jsprit.core.problem.job.*;
|
||||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||||
|
|
@ -88,7 +87,7 @@ public class LoadStateTest {
|
||||||
});
|
});
|
||||||
shipment_route = shipmentRouteBuilder.addPickup(shipment1).addPickup(shipment2).addDelivery(shipment2).addDelivery(shipment1).build();
|
shipment_route = shipmentRouteBuilder.addPickup(shipment1).addPickup(shipment2).addDelivery(shipment2).addDelivery(shipment1).build();
|
||||||
|
|
||||||
stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
stateManager = new StateManager(mock(VehicleRoutingProblem.class));
|
||||||
stateManager.updateLoadStates();
|
stateManager.updateLoadStates();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,12 +19,15 @@
|
||||||
package jsprit.core.algorithm.state;
|
package jsprit.core.algorithm.state;
|
||||||
|
|
||||||
import jsprit.core.problem.Capacity;
|
import jsprit.core.problem.Capacity;
|
||||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
import jsprit.core.problem.VehicleRoutingProblem;
|
||||||
|
import jsprit.core.problem.job.Service;
|
||||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||||
import jsprit.core.problem.solution.route.state.StateFactory.State;
|
import jsprit.core.problem.solution.route.state.StateFactory.State;
|
||||||
import jsprit.core.problem.solution.route.state.StateFactory.StateId;
|
import jsprit.core.problem.solution.route.state.StateFactory.StateId;
|
||||||
|
import jsprit.core.problem.vehicle.Vehicle;
|
||||||
|
import jsprit.core.problem.vehicle.VehicleImpl;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
@ -35,42 +38,46 @@ public class StateManagerTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenRouteStateIsSetWithGenericMethod_itMustBeSetCorrectly(){
|
public void whenRouteStateIsSetWithGenericMethod_itMustBeSetCorrectly(){
|
||||||
VehicleRoute route = mock(VehicleRoute.class);
|
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().build();
|
||||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
VehicleRoute route = getRoute(mock(Vehicle.class));
|
||||||
StateId id = StateFactory.createId("myState");
|
StateManager stateManager = new StateManager(vrp);
|
||||||
|
StateId id = stateManager.createStateId("myState");
|
||||||
State state = StateFactory.createState(1.);
|
State state = StateFactory.createState(1.);
|
||||||
stateManager.putTypedRouteState(route, id, State.class, state);
|
stateManager.putRouteState(route, id, state);
|
||||||
assertEquals(1.,stateManager.getRouteState(route, id, State.class).toDouble(),0.01);
|
assertEquals(1.,stateManager.getRouteState(route, id, State.class).toDouble(),0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
private VehicleRoute getRoute(Vehicle vehicle) {
|
||||||
|
return VehicleRoute.Builder.newInstance(vehicle).addService(Service.Builder.newInstance("s").setLocationId("loc").build()).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void whenRouteStateIsSetWithGenericMethodAndBoolean_itMustBeSetCorrectly(){
|
public void whenRouteStateIsSetWithGenericMethodAndBoolean_itMustBeSetCorrectly(){
|
||||||
VehicleRoute route = mock(VehicleRoute.class);
|
VehicleRoute route = getRoute(mock(Vehicle.class));
|
||||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
StateManager stateManager = new StateManager(mock(VehicleRoutingProblem.class));
|
||||||
StateId id = StateFactory.createId("myState");
|
StateId id = stateManager.createStateId("myState");
|
||||||
boolean routeIsRed = true;
|
stateManager.putRouteState(route, id, true);
|
||||||
stateManager.putTypedRouteState(route, id, Boolean.class, routeIsRed);
|
|
||||||
assertTrue(stateManager.getRouteState(route, id, Boolean.class));
|
assertTrue(stateManager.getRouteState(route, id, Boolean.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenRouteStateIsSetWithGenericMethodAndInteger_itMustBeSetCorrectly(){
|
public void whenRouteStateIsSetWithGenericMethodAndInteger_itMustBeSetCorrectly(){
|
||||||
VehicleRoute route = mock(VehicleRoute.class);
|
VehicleRoute route = getRoute(mock(Vehicle.class));
|
||||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
StateManager stateManager = new StateManager(mock(VehicleRoutingProblem.class));
|
||||||
StateId id = StateFactory.createId("myState");
|
StateId id = stateManager.createStateId("myState");
|
||||||
int load = 3;
|
int load = 3;
|
||||||
stateManager.putTypedRouteState(route, id, Integer.class, load);
|
stateManager.putRouteState(route, id, load);
|
||||||
int getLoad = stateManager.getRouteState(route, id, Integer.class);
|
int getLoad = stateManager.getRouteState(route, id, Integer.class);
|
||||||
assertEquals(3, getLoad);
|
assertEquals(3, getLoad);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenRouteStateIsSetWithGenericMethodAndCapacity_itMustBeSetCorrectly(){
|
public void whenRouteStateIsSetWithGenericMethodAndCapacity_itMustBeSetCorrectly(){
|
||||||
VehicleRoute route = mock(VehicleRoute.class);
|
VehicleRoute route = getRoute(mock(Vehicle.class));
|
||||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
StateManager stateManager = new StateManager(mock(VehicleRoutingProblem.class));
|
||||||
StateId id = StateFactory.createId("myState");
|
StateId id = stateManager.createStateId("myState");
|
||||||
Capacity capacity = Capacity.Builder.newInstance().addDimension(0, 500).build();
|
Capacity capacity = Capacity.Builder.newInstance().addDimension(0, 500).build();
|
||||||
stateManager.putTypedRouteState(route, id, Capacity.class, capacity);
|
stateManager.putRouteState(route, id, capacity);
|
||||||
Capacity getCap = stateManager.getRouteState(route, id, Capacity.class);
|
Capacity getCap = stateManager.getRouteState(route, id, Capacity.class);
|
||||||
assertEquals(500, getCap.get(0));
|
assertEquals(500, getCap.get(0));
|
||||||
}
|
}
|
||||||
|
|
@ -79,30 +86,29 @@ public class StateManagerTest {
|
||||||
public void whenActivityStateIsSetWithGenericMethod_itMustBeSetCorrectly(){
|
public void whenActivityStateIsSetWithGenericMethod_itMustBeSetCorrectly(){
|
||||||
TourActivity activity = mock(TourActivity.class);
|
TourActivity activity = mock(TourActivity.class);
|
||||||
when(activity.getIndex()).thenReturn(0);
|
when(activity.getIndex()).thenReturn(0);
|
||||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
StateManager stateManager = new StateManager(mock(VehicleRoutingProblem.class));
|
||||||
StateId id = stateManager.createStateId("myState");
|
StateId id = stateManager.createStateId("myState");
|
||||||
State state = StateFactory.createState(1.);
|
State state = StateFactory.createState(1.);
|
||||||
stateManager.putTypedActivityState(activity, id, State.class, state);
|
stateManager.putActivityState(activity, id, state);
|
||||||
assertEquals(1.,stateManager.getActivityState(activity, id, State.class).toDouble(),0.01);
|
assertEquals(1.,stateManager.getActivityState(activity, id, State.class).toDouble(),0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenActivityStateIsSetWithGenericMethodAndBoolean_itMustBeSetCorrectly(){
|
public void whenActivityStateIsSetWithGenericMethodAndBoolean_itMustBeSetCorrectly(){
|
||||||
TourActivity activity = mock(TourActivity.class);
|
TourActivity activity = mock(TourActivity.class);
|
||||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
StateManager stateManager = new StateManager(mock(VehicleRoutingProblem.class));
|
||||||
StateId id = stateManager.createStateId("myState");
|
StateId id = stateManager.createStateId("myState");
|
||||||
boolean routeIsRed = true;
|
stateManager.putActivityState(activity, id, true);
|
||||||
stateManager.putTypedActivityState(activity, id, Boolean.class, routeIsRed);
|
|
||||||
assertTrue(stateManager.getActivityState(activity, id, Boolean.class));
|
assertTrue(stateManager.getActivityState(activity, id, Boolean.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenActivityStateIsSetWithGenericMethodAndInteger_itMustBeSetCorrectly(){
|
public void whenActivityStateIsSetWithGenericMethodAndInteger_itMustBeSetCorrectly(){
|
||||||
TourActivity activity = mock(TourActivity.class);
|
TourActivity activity = mock(TourActivity.class);
|
||||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
StateManager stateManager = new StateManager(mock(VehicleRoutingProblem.class));
|
||||||
StateId id = stateManager.createStateId("myState");
|
StateId id = stateManager.createStateId("myState");
|
||||||
int load = 3;
|
int load = 3;
|
||||||
stateManager.putTypedActivityState(activity, id, Integer.class, load);
|
stateManager.putActivityState(activity, id, load);
|
||||||
int getLoad = stateManager.getActivityState(activity, id, Integer.class);
|
int getLoad = stateManager.getActivityState(activity, id, Integer.class);
|
||||||
assertEquals(3, getLoad);
|
assertEquals(3, getLoad);
|
||||||
}
|
}
|
||||||
|
|
@ -110,17 +116,17 @@ public class StateManagerTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenActivityStateIsSetWithGenericMethodAndCapacity_itMustBeSetCorrectly(){
|
public void whenActivityStateIsSetWithGenericMethodAndCapacity_itMustBeSetCorrectly(){
|
||||||
TourActivity activity = mock(TourActivity.class);
|
TourActivity activity = mock(TourActivity.class);
|
||||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
StateManager stateManager = new StateManager(mock(VehicleRoutingProblem.class));
|
||||||
StateId id = stateManager.createStateId("myState");
|
StateId id = stateManager.createStateId("myState");
|
||||||
Capacity capacity = Capacity.Builder.newInstance().addDimension(0, 500).build();
|
Capacity capacity = Capacity.Builder.newInstance().addDimension(0, 500).build();
|
||||||
stateManager.putTypedActivityState(activity, id, Capacity.class, capacity);
|
stateManager.putActivityState(activity, id, capacity);
|
||||||
Capacity getCap = stateManager.getActivityState(activity, id, Capacity.class);
|
Capacity getCap = stateManager.getActivityState(activity, id, Capacity.class);
|
||||||
assertEquals(500, getCap.get(0));
|
assertEquals(500, getCap.get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenProblemStateIsSet_itMustBeSetCorrectly(){
|
public void whenProblemStateIsSet_itMustBeSetCorrectly(){
|
||||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
StateManager stateManager = new StateManager(mock(VehicleRoutingProblem.class));
|
||||||
StateId id = stateManager.createStateId("problemState");
|
StateId id = stateManager.createStateId("problemState");
|
||||||
stateManager.putProblemState(id, Boolean.class, true);
|
stateManager.putProblemState(id, Boolean.class, true);
|
||||||
boolean problemState = stateManager.getProblemState(id, Boolean.class);
|
boolean problemState = stateManager.getProblemState(id, Boolean.class);
|
||||||
|
|
@ -129,8 +135,8 @@ public class StateManagerTest {
|
||||||
|
|
||||||
@Test(expected=NullPointerException.class)
|
@Test(expected=NullPointerException.class)
|
||||||
public void whenProblemStateIsSetAndStateManagerClearedAfterwards_itThrowsException(){
|
public void whenProblemStateIsSetAndStateManagerClearedAfterwards_itThrowsException(){
|
||||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
StateManager stateManager = new StateManager(mock(VehicleRoutingProblem.class));
|
||||||
StateId id = StateFactory.createId("problemState");
|
StateId id = stateManager.createStateId("problemState");
|
||||||
stateManager.putProblemState(id, Boolean.class, true);
|
stateManager.putProblemState(id, Boolean.class, true);
|
||||||
stateManager.clear();
|
stateManager.clear();
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
|
|
@ -139,7 +145,7 @@ public class StateManagerTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenProblemStateIsSetAndStateManagerClearedAfterwards_itReturnsDefault(){
|
public void whenProblemStateIsSetAndStateManagerClearedAfterwards_itReturnsDefault(){
|
||||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
StateManager stateManager = new StateManager(mock(VehicleRoutingProblem.class));
|
||||||
StateId id = StateFactory.createId("problemState");
|
StateId id = StateFactory.createId("problemState");
|
||||||
stateManager.addDefaultProblemState(id, Boolean.class, false);
|
stateManager.addDefaultProblemState(id, Boolean.class, false);
|
||||||
stateManager.putProblemState(id, Boolean.class, true);
|
stateManager.putProblemState(id, Boolean.class, true);
|
||||||
|
|
@ -150,14 +156,14 @@ public class StateManagerTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenCreatingNewState_itShouldHaveAnIndex(){
|
public void whenCreatingNewState_itShouldHaveAnIndex(){
|
||||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
StateManager stateManager = new StateManager(mock(VehicleRoutingProblem.class));
|
||||||
StateId stateId = stateManager.createStateId("foo-state");
|
StateId stateId = stateManager.createStateId("foo-state");
|
||||||
assertEquals(10,stateId.getIndex());
|
assertEquals(10,stateId.getIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenCreatingNewStates_theyShouldHaveAnIndex(){
|
public void whenCreatingNewStates_theyShouldHaveAnIndex(){
|
||||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
StateManager stateManager = new StateManager(mock(VehicleRoutingProblem.class));
|
||||||
StateId fooState = stateManager.createStateId("foo-state");
|
StateId fooState = stateManager.createStateId("foo-state");
|
||||||
StateId foofooState = stateManager.createStateId("foo-foo-state");
|
StateId foofooState = stateManager.createStateId("foo-foo-state");
|
||||||
assertEquals(10,fooState.getIndex());
|
assertEquals(10,fooState.getIndex());
|
||||||
|
|
@ -166,10 +172,34 @@ public class StateManagerTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenCreatingTwoStatesWithTheSameName_theyShouldHaveTheSameIndex(){
|
public void whenCreatingTwoStatesWithTheSameName_theyShouldHaveTheSameIndex(){
|
||||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
StateManager stateManager = new StateManager(mock(VehicleRoutingProblem.class));
|
||||||
StateId fooState = stateManager.createStateId("foo-state");
|
StateId fooState = stateManager.createStateId("foo-state");
|
||||||
StateId foofooState = stateManager.createStateId("foo-state");
|
StateId foofooState = stateManager.createStateId("foo-state");
|
||||||
assertEquals(10,fooState.getIndex());
|
assertEquals(10, fooState.getIndex());
|
||||||
assertEquals(10,foofooState.getIndex());
|
assertEquals(10, foofooState.getIndex());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCreatingAVehicleDependentRouteState_itShouldBeMemorized(){
|
||||||
|
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("loc").build();
|
||||||
|
VehicleRoute route = getRoute(vehicle);
|
||||||
|
StateManager stateManager = new StateManager(mock(VehicleRoutingProblem.class));
|
||||||
|
StateId id = stateManager.createStateId("myState");
|
||||||
|
Capacity capacity = Capacity.Builder.newInstance().addDimension(0, 500).build();
|
||||||
|
stateManager.putRouteState(route, vehicle, null, id, capacity);
|
||||||
|
Capacity getCap = stateManager.getRouteState(route, vehicle, null, id, Capacity.class);
|
||||||
|
assertEquals(500, getCap.get(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCreatingAVehicleDependentActivityState_itShouldBeMemorized(){
|
||||||
|
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("loc").build();
|
||||||
|
StateManager stateManager = new StateManager(mock(VehicleRoutingProblem.class));
|
||||||
|
StateId id = stateManager.createStateId("myState");
|
||||||
|
Capacity capacity = Capacity.Builder.newInstance().addDimension(0, 500).build();
|
||||||
|
TourActivity act = mock(TourActivity.class);
|
||||||
|
stateManager.putActivityState(act, vehicle, null, id, capacity);
|
||||||
|
Capacity getCap = stateManager.getActivityState(act, vehicle, null, id, Capacity.class);
|
||||||
|
assertEquals(500, getCap.get(0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ public class UpdatePracticalTimeWindowTest {
|
||||||
|
|
||||||
routingCosts = CostFactory.createManhattanCosts();
|
routingCosts = CostFactory.createManhattanCosts();
|
||||||
|
|
||||||
stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
stateManager = new StateManager(mock(VehicleRoutingProblem.class));
|
||||||
|
|
||||||
reverseActivityVisitor = new ReverseRouteActivityVisitor();
|
reverseActivityVisitor = new ReverseRouteActivityVisitor();
|
||||||
reverseActivityVisitor.addActivityVisitor(new UpdatePracticalTimeWindows(stateManager, routingCosts));
|
reverseActivityVisitor.addActivityVisitor(new UpdatePracticalTimeWindows(stateManager, routingCosts));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue