MATSIM
RunSimpleAdaptiveSignalExample.java
Go to the documentation of this file.
1 /*
2  * *********************************************************************** *
3  * * project: org.matsim.*
4  * * Main.java
5  * * *
6  * * *********************************************************************** *
7  * * *
8  * * copyright : (C) 2014 by the members listed in the COPYING, *
9  * * LICENSE and WARRANTY file. *
10  * * email : info at matsim dot org *
11  * * *
12  * * *********************************************************************** *
13  * * *
14  * * This program is free software; you can redistribute it and/or modify *
15  * * it under the terms of the GNU General Public License as published by *
16  * * the Free Software Foundation; either version 2 of the License, or *
17  * * (at your option) any later version. *
18  * * See also COPYING, LICENSE and WARRANTY file *
19  * * *
20  * * ***********************************************************************
21  */
22 
23 package tutorial.programming.simpleAdaptiveSignalEngine;
24 
25 import org.matsim.core.config.Config;
30 
39 
40  private static String outputDir = "output/simpleAdaptiveSignalEngineExample/";
41 
45  public static void main(String[] args) {
46  if (args != null){
47  // use the given output if args is not null
48  outputDir = args[0];
49  }
50  // load the daganzo example
51  final Config config = ConfigUtils.loadConfig("examples/daganzo/config.xml");
52  config.controler().setOutputDirectory(outputDir);
53  config.controler().setWriteEventsInterval(config.controler().getLastIteration());
54  config.vspExperimental().setWritingOutputEvents(true);
55  // remove unmaterialized module from the config
56  config.removeModule("otfvis");
57  final Controler controler = new Controler(config);
58 
59  controler.getConfig().controler().setOverwriteFileSetting( OverwriteFileSetting.deleteDirectoryIfExists ) ;
60  controler.addOverridingModule(new AbstractModule() {
61  @Override
62  public void install() {
63  /* bind the adaptive signal as mobsim listener (to be able to create the signals before simulation)
64  * and as events handler (to get information about agent behavior)
65  * but both times as the same instance (asEagerSingleton) */
66  bind(SimpleAdaptiveSignal.class).asEagerSingleton();
67  addMobsimListenerBinding().to(SimpleAdaptiveSignal.class);
68  addEventHandlerBinding().to(SimpleAdaptiveSignal.class);
69  }
70  });
71 
72  controler.run();
73  }
74 
75 }
final void addOverridingModule(AbstractModule abstractModule)
Definition: Controler.java:410
final void removeModule(final String name)
Definition: Config.java:309
VspExperimentalConfigGroup vspExperimental()
Definition: Config.java:480
ControlerConfigGroup controler
Definition: Config.java:87
static Config loadConfig(final String filename, ConfigGroup...customModules)