-
Notifications
You must be signed in to change notification settings - Fork 451
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add minimal example for signals to start an own config file
- Loading branch information
Showing
4 changed files
with
152 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
contribs/signals/src/main/java/org/matsim/contrib/signals/run/RunSignalSystemsExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* *********************************************************************** * | ||
* * project: org.matsim.* | ||
* * * | ||
* * *********************************************************************** * | ||
* * * | ||
* * copyright : (C) 2014 by the members listed in the COPYING, * | ||
* * LICENSE and WARRANTY file. * | ||
* * email : info at matsim dot org * | ||
* * * | ||
* * *********************************************************************** * | ||
* * * | ||
* * This program is free software; you can redistribute it and/or modify * | ||
* * it under the terms of the GNU General Public License as published by * | ||
* * the Free Software Foundation; either version 2 of the License, or * | ||
* * (at your option) any later version. * | ||
* * See also COPYING, LICENSE and WARRANTY file * | ||
* * * | ||
* * *********************************************************************** | ||
*/ | ||
package org.matsim.contrib.signals.run; | ||
|
||
import org.matsim.api.core.v01.Scenario; | ||
import org.matsim.contrib.signals.controler.SignalsModule; | ||
import org.matsim.contrib.signals.data.SignalsData; | ||
import org.matsim.contrib.signals.data.SignalsDataLoader; | ||
import org.matsim.core.config.Config; | ||
import org.matsim.core.config.ConfigUtils; | ||
import org.matsim.core.controler.Controler; | ||
import org.matsim.core.scenario.ScenarioUtils; | ||
|
||
/** | ||
* Minimal example how to start your matsim run with traffic signals | ||
* | ||
* @author tthunig | ||
*/ | ||
public class RunSignalSystemsExample { | ||
// do not change name of class; matsim book refers to it. theresa, apr'18 | ||
|
||
/** | ||
* @param args the path to your config file | ||
*/ | ||
public static void main(String[] args) { | ||
if (args.length==0 || args.length>1) { | ||
throw new RuntimeException("Please provide exactly one argument -- the path to your config.xml file.") ; | ||
} | ||
// --- create the config | ||
Config config = ConfigUtils.loadConfig(args[0]); | ||
|
||
run(config); // The run method is extracted so that a test can operate on it. | ||
} | ||
|
||
public static void run(Config config) { | ||
// --- create the scenario | ||
Scenario scenario = ScenarioUtils.loadScenario(config); | ||
// load the information about signals data (i.e. fill the SignalsData object) and add it to the scenario as scenario element | ||
scenario.addScenarioElement(SignalsData.ELEMENT_NAME, new SignalsDataLoader(config).loadSignalsData()); | ||
|
||
// --- create the controler | ||
Controler c = new Controler(scenario); | ||
// add the signals module to the simulation such that SignalsData is not only contained in the scenario but also used in the simulation | ||
c.addOverridingModule(new SignalsModule()); | ||
|
||
// --- run the simulation | ||
c.run(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters