Skip to content

Commit 7663c41

Browse files
committed
add minimal example for signals to start an own config file
1 parent f9ae03a commit 7663c41

File tree

4 files changed

+152
-5
lines changed

4 files changed

+152
-5
lines changed

contribs/signals/examples/tutorial/example90TrafficLights/useSignalInput/withLanes/config.xml

+57-1
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,36 @@
220220
<param name="waiting" value="-0.0" />
221221
<param name="waitingPt" value="-6.0" />
222222

223+
<parameterset type="activityParams" >
224+
<param name="activityType" value="h" />
225+
<param name="closingTime" value="undefined" />
226+
<param name="earliestEndTime" value="undefined" />
227+
<param name="latestStartTime" value="undefined" />
228+
<param name="minimalDuration" value="undefined" />
229+
<param name="openingTime" value="undefined" />
230+
<param name="priority" value="1.0" />
231+
<param name="scoringThisActivityAtAll" value="true" />
232+
<!-- typical duration of activity. needs to be defined and non-zero. in sec. -->
233+
<param name="typicalDuration" value="16:00:00" />
234+
<!-- method to compute score at typical duration. Options: | uniform | relative | Use uniform for backwards compatibility (all activities same score; higher proba to drop long acts). -->
235+
<param name="typicalDurationScoreComputation" value="uniform" />
236+
</parameterset>
237+
238+
<parameterset type="activityParams" >
239+
<param name="activityType" value="w" />
240+
<param name="closingTime" value="undefined" />
241+
<param name="earliestEndTime" value="undefined" />
242+
<param name="latestStartTime" value="undefined" />
243+
<param name="minimalDuration" value="undefined" />
244+
<param name="openingTime" value="undefined" />
245+
<param name="priority" value="1.0" />
246+
<param name="scoringThisActivityAtAll" value="true" />
247+
<!-- typical duration of activity. needs to be defined and non-zero. in sec. -->
248+
<param name="typicalDuration" value="08:00:00" />
249+
<!-- method to compute score at typical duration. Options: | uniform | relative | Use uniform for backwards compatibility (all activities same score; higher proba to drop long acts). -->
250+
<param name="typicalDurationScoreComputation" value="uniform" />
251+
</parameterset>
252+
223253
<parameterset type="activityParams" >
224254
<param name="activityType" value="car interaction" />
225255
<param name="closingTime" value="undefined" />
@@ -616,13 +646,39 @@
616646
<param name="ExternalExeTmpFileRootDir" value="null" />
617647

618648
<!-- fraction of iterations where innovative strategies are switched off. Something link 0.8 should be good. E.g. if you run from iteration 400 to iteration 500, innovation is switched off at iteration 480 -->
619-
<param name="fractionOfIterationsToDisableInnovation" value="Infinity" />
649+
<param name="fractionOfIterationsToDisableInnovation" value="0.8" />
620650

621651
<!-- maximum number of plans per agent. ``0'' means ``infinity''. Currently (2010), ``5'' is a good number -->
622652
<param name="maxAgentPlanMemorySize" value="5" />
623653

624654
<!-- strategyName of PlanSelector for plans removal. Possible defaults: WorstPlanSelector SelectRandom SelectExpBetaForRemoval ChangeExpBetaForRemoval PathSizeLogitSelectorForRemoval . The current default, WorstPlanSelector is not a good choice from a discrete choice theoretical perspective. Alternatives, however, have not been systematically tested. kai, feb'12 -->
625655
<param name="planSelectorForRemoval" value="WorstPlanSelector" />
656+
657+
<parameterset type="strategysettings" >
658+
<!-- iteration after which strategy will be disabled. most useful for ``innovative'' strategies (new routes, new times, ...). Normally, better use fractionOfIterationsToDisableInnovation -->
659+
<param name="disableAfterIteration" value="-1" />
660+
<!-- path to external executable (if applicable) -->
661+
<param name="executionPath" value="null" />
662+
<!-- strategyName of strategy. Possible default names: SelectRandomBestScoreKeepLastSelectedChangeExpBetaSelectExpBetaSelectPathSizeLogit (selectors), ReRoute TimeAllocationMutator ChangeLegMode TimeAllocationMutator_ReRoute ChangeSingleLegMode ChangeSingleTripMode SubtourModeChoice ChangeTripMode TripSubtourModeChoice (innovative strategies). -->
663+
<param name="strategyName" value="ChangeExpBeta" />
664+
<!-- subpopulation to which the strategy applies. "null" refers to the default population, that is, the set of persons for which no explicit subpopulation is defined (ie no subpopulation attribute) -->
665+
<param name="subpopulation" value="null" />
666+
<!-- weight of a strategy: for each agent, a strategy will be selected with a probability proportional to its weight -->
667+
<param name="weight" value="0.9" />
668+
</parameterset>
669+
670+
<parameterset type="strategysettings" >
671+
<!-- iteration after which strategy will be disabled. most useful for ``innovative'' strategies (new routes, new times, ...). Normally, better use fractionOfIterationsToDisableInnovation -->
672+
<param name="disableAfterIteration" value="-1" />
673+
<!-- path to external executable (if applicable) -->
674+
<param name="executionPath" value="null" />
675+
<!-- strategyName of strategy. Possible default names: SelectRandomBestScoreKeepLastSelectedChangeExpBetaSelectExpBetaSelectPathSizeLogit (selectors), ReRoute TimeAllocationMutator ChangeLegMode TimeAllocationMutator_ReRoute ChangeSingleLegMode ChangeSingleTripMode SubtourModeChoice ChangeTripMode TripSubtourModeChoice (innovative strategies). -->
676+
<param name="strategyName" value="ReRoute" />
677+
<!-- subpopulation to which the strategy applies. "null" refers to the default population, that is, the set of persons for which no explicit subpopulation is defined (ie no subpopulation attribute) -->
678+
<param name="subpopulation" value="null" />
679+
<!-- weight of a strategy: for each agent, a strategy will be selected with a probability proportional to its weight -->
680+
<param name="weight" value="0.1" />
681+
</parameterset>
626682
</module>
627683

628684
<!-- ====================================================================== -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* *********************************************************************** *
3+
* * project: org.matsim.*
4+
* * *
5+
* * *********************************************************************** *
6+
* * *
7+
* * copyright : (C) 2014 by the members listed in the COPYING, *
8+
* * LICENSE and WARRANTY file. *
9+
* * email : info at matsim dot org *
10+
* * *
11+
* * *********************************************************************** *
12+
* * *
13+
* * This program is free software; you can redistribute it and/or modify *
14+
* * it under the terms of the GNU General Public License as published by *
15+
* * the Free Software Foundation; either version 2 of the License, or *
16+
* * (at your option) any later version. *
17+
* * See also COPYING, LICENSE and WARRANTY file *
18+
* * *
19+
* * ***********************************************************************
20+
*/
21+
package org.matsim.contrib.signals.run;
22+
23+
import org.matsim.api.core.v01.Scenario;
24+
import org.matsim.contrib.signals.controler.SignalsModule;
25+
import org.matsim.contrib.signals.data.SignalsData;
26+
import org.matsim.contrib.signals.data.SignalsDataLoader;
27+
import org.matsim.core.config.Config;
28+
import org.matsim.core.config.ConfigUtils;
29+
import org.matsim.core.controler.Controler;
30+
import org.matsim.core.scenario.ScenarioUtils;
31+
32+
/**
33+
* Minimal example how to start your matsim run with traffic signals
34+
*
35+
* @author tthunig
36+
*/
37+
public class RunSignalSystemsExample {
38+
// do not change name of class; matsim book refers to it. theresa, apr'18
39+
40+
/**
41+
* @param args the path to your config file
42+
*/
43+
public static void main(String[] args) {
44+
if (args.length==0 || args.length>1) {
45+
throw new RuntimeException("Please provide exactly one argument -- the path to your config.xml file.") ;
46+
}
47+
// --- create the config
48+
Config config = ConfigUtils.loadConfig(args[0]);
49+
50+
run(config); // The run method is extracted so that a test can operate on it.
51+
}
52+
53+
public static void run(Config config) {
54+
// --- create the scenario
55+
Scenario scenario = ScenarioUtils.loadScenario(config);
56+
// load the information about signals data (i.e. fill the SignalsData object) and add it to the scenario as scenario element
57+
scenario.addScenarioElement(SignalsData.ELEMENT_NAME, new SignalsDataLoader(config).loadSignalsData());
58+
59+
// --- create the controler
60+
Controler c = new Controler(scenario);
61+
// add the signals module to the simulation such that SignalsData is not only contained in the scenario but also used in the simulation
62+
c.addOverridingModule(new SignalsModule());
63+
64+
// --- run the simulation
65+
c.run();
66+
}
67+
68+
}

contribs/signals/src/main/java/tutorial/fixedTimeSignals/RunSignalSystemsExample.java contribs/signals/src/main/java/tutorial/fixedTimeSignals/RunSignalSystemsExampleWithHoles.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
*
4545
* @author dgrether, tthunig
4646
*/
47-
public class RunSignalSystemsExample {
47+
public class RunSignalSystemsExampleWithHoles {
4848

4949
public static void main(String[] args) {
5050
run(true);

contribs/signals/src/test/java/tutorial/fixedTimeSignals/RunSignalSystemsExampleTest.java

+26-3
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,45 @@
1919
package tutorial.fixedTimeSignals;
2020

2121
import org.junit.Assert;
22+
import org.junit.Rule;
2223
import org.junit.Test;
24+
import org.matsim.contrib.signals.run.RunSignalSystemsExample;
25+
import org.matsim.core.config.Config;
26+
import org.matsim.core.config.ConfigUtils;
27+
import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting;
28+
import org.matsim.testcases.MatsimTestUtils;
2329

2430
/**
2531
* @author nagel
2632
*
2733
*/
2834
public class RunSignalSystemsExampleTest {
2935

36+
@Rule public MatsimTestUtils testUtils = new MatsimTestUtils();
37+
3038
@Test
31-
public final void test() {
39+
public final void testExampleWithHoles() {
3240
boolean usingOTFVis = false ;
3341
try {
34-
RunSignalSystemsExample.run(usingOTFVis);
42+
RunSignalSystemsExampleWithHoles.run(usingOTFVis);
43+
} catch (Exception ee ) {
44+
ee.printStackTrace();
45+
Assert.fail("something went wrong: " + ee.getMessage()) ;
46+
}
47+
}
48+
49+
@Test
50+
public final void testMinimalExample() {
51+
try {
52+
Config config = ConfigUtils.loadConfig("./examples/tutorial/example90TrafficLights/useSignalInput/withLanes/config.xml");
53+
config.controler().setOverwriteFileSetting(OverwriteFileSetting.deleteDirectoryIfExists);
54+
config.controler().setLastIteration(0);
55+
config.controler().setOutputDirectory(testUtils.getOutputDirectory());
56+
57+
RunSignalSystemsExample.run(config);
3558
} catch (Exception ee ) {
3659
ee.printStackTrace();
37-
Assert.fail("something went wrong") ;
60+
Assert.fail("something went wrong: " + ee.getMessage()) ;
3861
}
3962
}
4063

0 commit comments

Comments
 (0)