MATSIM
RunCustomTravelTimeExample.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.example20customTravelTime;
24 
37 
47 
48  public static void main(String[] args) {
49  String configFilename = "examples/equil/config.xml";
50  Controler controler = new Controler(configFilename);
51  controler.setModules(new AbstractModule() {
52  @Override
53  public void install() {
54  // Include some things from ControlerDefaultsModule.java,
55  // but leave out TravelTimeCalculator.
56  // You can just comment out these lines if you don't want them,
57  // these modules are optional.
58  // For an alternative approach (which uses the defaults and just overrides), see below.
59  install(new DefaultMobsimModule());
61  install(new TripRouterModule());
62  install(new StrategyManagerModule());
63  install(new LinkStatsModule());
64  install(new VolumesAnalyzerModule());
65  install(new LegHistogramModule());
66  install(new TravelDisutilityModule());
67 
68  // Because TravelTimeCalculatorModule is left out,
69  // we have to provide a TravelTime.
70  // This line says: Use this thing here as the TravelTime implementation.
71  // Try removing this line: You will get an error because there is no
72  // TravelTime and someone needs it.
73  bind(TravelTime.class).toInstance(new FreeSpeedTravelTime());
74  }
75  });
76  controler.run();
77  }
78 
79  // alternative variant:
80  public static void main2() {
81  String configFilename = "examples/equil/config.xml";
82  Controler controler = new Controler(configFilename);
83 
84  // this uses "addOVERRIDINGModule". It thus uses the Controler defaults, and overrides them or adds to them.
85  controler.addOverridingModule( new AbstractModule(){
86  @Override public void install() {
87  this.bind( TravelTime.class ).toInstance( new FreeSpeedTravelTime() );
88  }
89  });
90  }
91 }
final void addOverridingModule(AbstractModule abstractModule)
Definition: Controler.java:410
final void setModules(AbstractModule...modules)
Definition: Controler.java:417