public class StateManager extends Object implements RouteAndActivityStateGetter, IterationStartsListener, RuinListener, InsertionStartsListener, JobInsertedListener, InsertionEndsListener
Some condition, rules or constraints are stateful. This StateManager manages these states, i.e. it offers methods to add, store and retrieve states based on the problem, vehicle-routes and tour-activities.
| Constructor and Description |
|---|
StateManager(VehicleRoutingProblem vehicleRoutingProblem)
Constructs the stateManager with the specified VehicleRoutingProblem.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addAllStateUpdater(Collection<StateUpdater> updaters) |
void |
addStateUpdater(StateUpdater updater)
Adds state updater.
|
void |
clear()
Clears all states, i.e.
|
StateId |
createStateId(String name)
Create and returns a stateId with the specified state-name.
|
<T> T |
getActivityState(TourActivity act,
StateId stateId,
Class<T> type)
Returns associated state for the specified activity and stateId, or it returns null if no value is associated.
|
<T> T |
getActivityState(TourActivity act,
Vehicle vehicle,
StateId stateId,
Class<T> type)
Returns the associated state value to the specified activity, vehicle and stateId, or null if no state value is
associated.
|
<T> T |
getProblemState(StateId stateId,
Class<T> type)
Returns mapped state value that is associated to the specified stateId, or null if no value is associated to
the specified stateId.
|
<T> T |
getRouteState(VehicleRoute route,
StateId stateId,
Class<T> type)
Returns the route state that is associated to the route and stateId, or null if no state is associated.
|
<T> T |
getRouteState(VehicleRoute route,
Vehicle vehicle,
StateId stateId,
Class<T> type)
Returns the route state that is assigned to the specified route, vehicle and stateId.
|
boolean |
hasActivityState(TourActivity act,
Vehicle vehicle,
StateId stateId)
Returns true if a state value is associated to the specified activity, vehicle and stateId.
|
boolean |
hasRouteState(VehicleRoute route,
Vehicle vehicle,
StateId stateId)
Returns true if a state is assigned to the specified route, vehicle and stateId.
|
void |
informInsertionEnds(Collection<VehicleRoute> vehicleRoutes) |
void |
informInsertionStarts(Collection<VehicleRoute> vehicleRoutes,
Collection<Job> unassignedJobs) |
void |
informIterationStarts(int i,
VehicleRoutingProblem problem,
Collection<VehicleRoutingProblemSolution> solutions) |
void |
informJobInserted(Job job2insert,
VehicleRoute inRoute,
double additionalCosts,
double additionalTime) |
<T> void |
putActivityState(TourActivity act,
StateId stateId,
T state)
Associates the specified activity and stateId to the state value.
|
<T> void |
putActivityState(TourActivity act,
Vehicle vehicle,
StateId stateId,
T state)
Associates the specified activity, vehicle and stateId to the state value.
|
<T> void |
putProblemState(StateId stateId,
Class<T> type,
T state)
Associates the specified state to the stateId.
|
<T> void |
putRouteState(VehicleRoute route,
StateId stateId,
T state)
Associates the specified route, vehicle and stateId to the state value.
|
<T> void |
putRouteState(VehicleRoute route,
Vehicle vehicle,
StateId stateId,
T state)
Associates the specified route, vehicle and stateId to the state value.
|
void |
reCalculateStates(VehicleRoute route) |
void |
removed(Job job,
VehicleRoute fromRoute)
informs if a
Job has been removed from a VehicleRoute. |
void |
ruinEnds(Collection<VehicleRoute> routes,
Collection<Job> unassignedJobs)
informs about ruin-end.
|
void |
ruinStarts(Collection<VehicleRoute> routes)
informs about ruin-start.
|
boolean |
timeWindowUpdateIsActivated() |
void |
updateLoadStates()
Updates load states.
|
void |
updateSkillStates()
Updates skill states.
|
void |
updateTimeWindowStates()
Updates time-window states.
|
public StateManager(VehicleRoutingProblem vehicleRoutingProblem)
vehicleRoutingProblem - the corresponding VehicleRoutingProblempublic StateId createStateId(String name)
If a stateId with the specified name has already been created, it returns the created stateId.
If the specified is equal to a name that is already used internally, it throws an IllegalStateException
name - the specified name of the stateIllegalStateException - if name of state is already used internallypublic <T> void putProblemState(StateId stateId, Class<T> type, T state)
T - the type of the state valuestateId - the stateId which is the associated key to the problem statetype - the type of the problem statestate - the actual state valuepublic <T> T getProblemState(StateId stateId, Class<T> type)
T - the typestateId - the stateId which is the associated key to the problem statetype - the type class of the state valuepublic void clear()
public <T> T getActivityState(TourActivity act, StateId stateId, Class<T> type)
If type class is not equal to the associated type class of the requested state value, it throws a ClassCastException.
getActivityState in interface RouteAndActivityStateGetterT - the typeact - the activity for which a state value is associated tostateId - the stateId for which a state value is associated totype - the type of class of the associated state valueClassCastException - if type class is not equal to the associated type class of the requested state valueIllegalStateException - if act.getIndex()==0 since this suggests that act has no index at allpublic boolean hasActivityState(TourActivity act, Vehicle vehicle, StateId stateId)
act - the activity for which a state value is associated tovehicle - the vehicle for which a state value is associated tostateId - the stateId which is the associated key to the problem stateIllegalStateException - if act.getIndex()==0 since this suggests that act has no index at allpublic <T> T getActivityState(TourActivity act, Vehicle vehicle, StateId stateId, Class<T> type)
If type class is not equal to the associated type class of the requested state value, it throws a ClassCastException.
getActivityState in interface RouteAndActivityStateGetterT - the type of the classact - the activity for which a state value is associated tovehicle - the vehicle for which a state value is associated tostateId - the stateId which is the associated key to the problem statetype - the class of the associated state valueClassCastException - if type class is not equal to the associated type class of the requested state valueIllegalStateException - if act.getIndex()==0 since this suggests that act has no index at allpublic <T> T getRouteState(VehicleRoute route, StateId stateId, Class<T> type)
If type class is not equal to the associated type class of the requested state value, it throws a ClassCastException.
getRouteState in interface RouteAndActivityStateGetterT - the type of the classroute - the route which the associated route key to the route statestateId - the stateId which is the associated key to the route statetype - the class of the associated state valueClassCastException - if type class is not equal to the associated type class of the requested state valueIllegalStateException - if !route.isEmpty() and act(0).getIndex()==0 since this suggests that act has no index at allpublic boolean hasRouteState(VehicleRoute route, Vehicle vehicle, StateId stateId)
route - the route for which the state is requestedvehicle - the vehicle for which the state is requestedstateId - the stateId(entifier) for the state that is requestedpublic <T> T getRouteState(VehicleRoute route, Vehicle vehicle, StateId stateId, Class<T> type)
Returns null if no state can be found
getRouteState in interface RouteAndActivityStateGetterT - the type of the classroute - the route for which the state is requestedvehicle - the vehicle for which the state is requestedstateId - the stateId(entifier) for the state that is requestedtype - the type class of the requested stateClassCastException - if specified type is not equal to the memorized typeIllegalStateException - if !route.isEmpty() and act(0).getIndex()==0 since this suggests that act has no index at allpublic <T> void putActivityState(TourActivity act, StateId stateId, T state)
T - the type of the stateact - the activity for which a state value is associated tostateId - the stateId which is the associated key to the activity statestate - the state that is associated to the activity and stateIdIllegalStateException - if act.getIndex() == 0
|| stateId.getIndex < noInternalStatespublic <T> void putActivityState(TourActivity act, Vehicle vehicle, StateId stateId, T state)
T - the type of the stateact - the activity for which a state value is associated tovehicle - the vehicle for which a state value is associated tostateId - the stateId which is the associated key to the activity statestate - the state that is associated to the activity and stateIdIllegalStateException - if act.getIndex() == 0
|| stateId.getIndex < noInternalStatespublic <T> void putRouteState(VehicleRoute route, StateId stateId, T state)
T - the type of the stateroute - the route for which a state value is associated tostateId - the stateId which is the associated key to the activity statestate - the state that is associated to the activity and stateIdIllegalStateException - if stateId is equal to a stateId that is already used internally.public <T> void putRouteState(VehicleRoute route, Vehicle vehicle, StateId stateId, T state)
T - the type of the stateroute - the route for which a state value is associated tovehicle - the vehicle for which a state value is associated tostateId - the stateId which is the associated key to the activity statestate - the state that is associated to the activity and stateIdIllegalStateException - if vehicle.getIndex() == 0 || stateId.getIndex() < noInternalStatespublic void addStateUpdater(StateUpdater updater)
Note that a state update occurs if route and/or activity states have changed, i.e. if jobs are removed or inserted into a route. Thus here, it is assumed that a state updater is either of type InsertionListener, RuinListener, ActivityVisitor, ReverseActivityVisitor, RouteVisitor, ReverseRouteVisitor.
The following rule pertain for activity/route visitors:These visitors visits all activities/route in a route subsequently in two cases. First, if insertionStart (after ruinStrategies have removed activities from routes) and, second, if a job has been inserted and thus if a route has changed.
updater - the update to be addedpublic void addAllStateUpdater(Collection<StateUpdater> updaters)
public void informJobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime)
informJobInserted in interface JobInsertedListenerpublic void informInsertionStarts(Collection<VehicleRoute> vehicleRoutes, Collection<Job> unassignedJobs)
informInsertionStarts in interface InsertionStartsListenerpublic void reCalculateStates(VehicleRoute route)
public void informIterationStarts(int i,
VehicleRoutingProblem problem,
Collection<VehicleRoutingProblemSolution> solutions)
informIterationStarts in interface IterationStartsListenerpublic void ruinStarts(Collection<VehicleRoute> routes)
RuinListenerruinStarts in interface RuinListenerpublic void ruinEnds(Collection<VehicleRoute> routes, Collection<Job> unassignedJobs)
RuinListenerruinEnds in interface RuinListenerpublic void removed(Job job, VehicleRoute fromRoute)
RuinListenerJob has been removed from a VehicleRoute.removed in interface RuinListenerpublic void informInsertionEnds(Collection<VehicleRoute> vehicleRoutes)
informInsertionEnds in interface InsertionEndsListenerpublic void updateLoadStates()
public void updateTimeWindowStates()
public boolean timeWindowUpdateIsActivated()
public void updateSkillStates()
Copyright © 2013–2016. All rights reserved.