|
MATSIM
|
Packages | |
| package | annealing |
| package | choosers |
| package | conflicts |
| package | inheritance |
| package | modules |
| package | selectors |
| package | strategies |
Classes | |
| interface | GenericPlanStrategy |
| class | GenericPlanStrategyImpl |
| interface | GenericStrategyManager |
| class | GenericStrategyManagerImpl |
| interface | PlanStrategy |
| class | PlanStrategyImpl |
| interface | ReplanningContext |
| class | ReplanningContextImpl |
| class | ReplanningUtils |
| class | StrategyManager |
| class | StrategyManagerModule |
The StrategyManager controls the replanning of all agents in a population.
Various strategies can be created and added to the org.matsim.core.replanning.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 org.matsim.core.replanning.PlanStrategyImpl always consists of exactly one PlanSelector and zero or more StrategyModules. 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.
The strategy manager contains the following 5 strategies:
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);
1.8.13