MATSIM
RunPluggablePlanStrategyInCodeExample.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * *
4  * *********************************************************************** *
5  * *
6  * copyright : (C) 2010 by the members listed in the COPYING, *
7  * LICENSE and WARRANTY file. *
8  * email : info at matsim dot org *
9  * *
10  * *********************************************************************** *
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * See also COPYING, LICENSE and WARRANTY file *
17  * *
18  * *********************************************************************** */
19 
20 package tutorial.programming.example11PluggablePlanStrategyInCode;
21 
22 import org.matsim.core.config.Config;
29 
31  private static final String STRATEGY_NAME = "doSomethingSpecial";
32 
33  public static void main(final String[] args) {
35 
36 
37  Config config;
38  if ( args.length==0 ) {
39  config = ConfigUtils.loadConfig("examples/equil/config.xml") ;
40  } else {
41  config = ConfigUtils.loadConfig(args[0]);
42  }
43 
44  //add a strategy to the config
45  StrategySettings stratSets = new StrategySettings();
46  stratSets.setStrategyName(STRATEGY_NAME);
47  stratSets.setWeight(0.1);
48  config.strategy().addStrategySettings(stratSets);
49 
50  //let the output directory be overwritten
51  config.controler().setOverwriteFileSetting(OverwriteFileSetting.deleteDirectoryIfExists);
52 
53  //only run one iteration
54  config.controler().setFirstIteration(0);
55  config.controler().setLastIteration(1);
56 
57  final Controler controler = new Controler(config);
58 
59  //add the binding strategy
60  controler.addOverridingModule(new AbstractModule() {
61  @Override
62  public void install() {
63  addPlanStrategyBinding(STRATEGY_NAME).toProvider(MyPlanStrategyFactory.class);
64  }
65  });
66  controler.run();
67 
68  }
69 
70 }
final void addOverridingModule(AbstractModule abstractModule)
Definition: Controler.java:410
StrategyConfigGroup strategy
Definition: Config.java:98
void addStrategySettings(final StrategySettings stratSets)
ControlerConfigGroup controler
Definition: Config.java:87
static Config loadConfig(final String filename, ConfigGroup...customModules)