MATSIM
MyPlanStrategyProvider.java
Go to the documentation of this file.
1 package tutorial.programming.example10PluggablePlanStrategyFromFile;
2 
3 
9 
10 import javax.inject.Inject;
11 import javax.inject.Provider;
12 
13 class MyPlanStrategyProvider implements Provider<PlanStrategy> {
14 
15  @Inject
16  Network network;
17 
18  @Inject
19  Population population;
20 
21  @Inject
22  EventsManager eventsManager;
23 
24  @Override
25  public PlanStrategy get() {
26  // A PlanStrategy is something that can be applied to a Person (not a Plan).
27  // Define how to select between existing plans:
28  PlanStrategyImpl.Builder builder = new PlanStrategyImpl.Builder(new MyPlanSelector());
29 
30  // if you just want to select plans, you can stop here (except for the builder.build() below).
31 
32 
33  // Otherwise, to do something with that plan, one needs to add modules into the strategy. If there is at least
34  // one module added here, then the plan is copied and then modified.
35  MyPlanStrategyModule mod = new MyPlanStrategyModule(network, population);
36  builder.addStrategyModule(mod);
37 
38  // these modules may, at the same time, be events listeners (so that they can collect information):
39  eventsManager.addHandler(mod);
40 
41  return builder.build();
42  }
43 
44 }
Builder(final PlanSelector< Plan, Person > planSelector)