Package org.matsim.core.replanning
The StrategyManager controls the replanning of all agents in a population.
Various strategies can be created and added to the
StrategyManager
. The
StrategyManager
selects for each agent randomly one of the
strategies. When adding strategies to the strategy manager, a weight must be
provided which influences the probability the strategy gets chosen for a person.
The probability for a strategy to be chosen is defined as the strategy's weight
divided by the sum of all strategies' weights.
A PlanStrategyImpl
always consists
of exactly one PlanSelector
and zero or more StrategyModule
s.
A PlanSelector
selects one of the agents' existing plans, while
a StrategyModule
modifies a plan. A StrategyModule
can
change the route information, time information, change the sequence of
activities, change locations of activities and so on.
After a plan is selected, the strategy makes a copy of the plan before it is modified by a strategy module. If a strategy contains no strategy module, the plan will not be duplicated. If a strategy contains multiple strategy modules, the plan will be modified by one strategy module after the other, in the order the strategy modules were added to the strategy.
Example
The strategy manager contains the following 5 strategies:
- the time information of the currently selected plan is modified
- the route information of a randomly selected plan is modified
- first, the time information of a randomly selected plan is modified, and afterwards new routes are assigned according to the new times
- the plan with the best score is selected for the agent, but not modified
- a random plan is selected from the agent, but plans with higher score have a higher probability to be selected
This could be visualized as follows, including the probabilities each strategy is chosen:
StrategyManager | +--- 5% -- KeepSelected | |_ TimeAllocationMutator | +--- 7% -- RandomPlanSelector | |_ ReRoute | +--- 8% -- RandomPlanSelector | |_ TimeAllocationMutator | |_ ReRoute | +-- 75% -- BestScoreSelector | +--- 5% -- ExpBetaSelector
And here is the corresponding code to setup such a StrategyManager:
StrategyManager manager = new StrategyManager(); // strategy1 PlanStrategy strategy1 = new PlanStrategy(new KeepSelected()); strategy1.addStrategyModule(new TimeAllocationMutator()); // strategy2 PlanStrategy strategy2 = new PlanStrategy(new RandomPlanSelector()); strategy2.addStrategyModule(new ReRoute()); // strategy3 PlanStrategy strategy3 = new PlanStrategy(new RandomPlanSelector()); strategy3.addStrategyModule(new TimeAllocationMutator()); strategy3.addStrategyModule(new ReRoute()); // strategy4 PlanStrategy strategy4 = new PlanStrategy(new BestScoreSelector()); // strategy5 PlanStrategy strategy5 = new PlanStrategy(new ExpBetaSelector()); // add the strategies to the manager manager.addStrategy(strategy1, 0.05); manager.addStrategy(strategy2, 0.07); manager.addStrategy(strategy3, 0.08); manager.addStrategy(strategy4, 0.75); manager.addStrategy(strategy5, 0.05); // run it // Plans plans = new Plans(); manager.run(plans);
-
Interface Summary Interface Description GenericPlanStrategy<T extends BasicPlan,I> Notes: If an implementation of this interface is "innovative", i.e.PlanStrategy Examples of how this class can be used can be found aretutorial.programming.example10PluggablePlanStrategyFromFile.RunPluggablePlanStrategyFromFileExample
andtutorial.programming.example11PluggablePlanStrategyInCode.RunPluggablePlanStrategyInCodeExample
.ReplanningContext A partial, inside view of the Controler which is available during replanning. -
Class Summary Class Description GenericPlanStrategyImpl<T extends BasicPlan,I> GenericStrategyManager<PL extends BasicPlan,AG extends HasPlansAndId<? extends BasicPlan,AG>> Notes: This version is now a bit more restrictive than the original strategy manager in terms of public methods and in terms of final methods.PlanStrategyImpl A strategy defines how an agent can be modified during re-planning.PlanStrategyImpl.Builder ReplanningUtils StrategyManager Manages and applies strategies to agents for re-planning.StrategyManagerModule