MATSIM
RunEventsHandlingWithControlerExample.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.* *
3  * *
4  * *********************************************************************** *
5  * *
6  * copyright : (C) 2008 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 package tutorial.programming.example06EventsHandling;
20 
21 import org.matsim.api.core.v01.Scenario;
22 import org.matsim.core.config.Config;
28 
34 
35  public static final String outputDirectory = "output/example7" ;
36 
40  public static void main(String[] args) {
42 
43 
44  Config config ;
45  if ( args==null || args.length==0 ) {
46  config = ConfigUtils.loadConfig( "examples/tutorial/programming/example7-config.xml" ) ;
47  } else {
48  config = ConfigUtils.loadConfig( args[0] ) ;
49  }
50 
51  config.controler().setOutputDirectory(outputDirectory);
52 
53  final Scenario scenario = ScenarioUtils.loadScenario(config) ;
54 
55  //Create an instance of the controler
56  Controler controler = new Controler(config);
57 
58  // add the events handlers
59  controler.addOverridingModule(new AbstractModule(){
60  @Override public void install() {
61  this.addEventHandlerBinding().toInstance( new MyEventHandler1() );
62  this.addEventHandlerBinding().toInstance( new MyEventHandler2( ) );
63  this.addEventHandlerBinding().toInstance( new MyEventHandler3() );
64  this.addEventHandlerBinding().toInstance( new CongestionDetectionEventHandler( scenario.getNetwork() ) );
65  }
66  });
67 
68  //call run() to start the simulation
69  controler.run();
70  }
71 
72 }
final void addOverridingModule(AbstractModule abstractModule)
Definition: Controler.java:410
ControlerConfigGroup controler
Definition: Config.java:87
static Config loadConfig(final String filename, ConfigGroup...customModules)
static Scenario loadScenario(final Config config)