Skip to content

Commit

Permalink
add minimal example for signals to start an own config file
Browse files Browse the repository at this point in the history
  • Loading branch information
tthunig committed Apr 12, 2018
1 parent f9ae03a commit 7663c41
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 5 deletions.
Expand Up @@ -220,6 +220,36 @@
<param name="waiting" value="-0.0" />
<param name="waitingPt" value="-6.0" />

<parameterset type="activityParams" >
<param name="activityType" value="h" />
<param name="closingTime" value="undefined" />
<param name="earliestEndTime" value="undefined" />
<param name="latestStartTime" value="undefined" />
<param name="minimalDuration" value="undefined" />
<param name="openingTime" value="undefined" />
<param name="priority" value="1.0" />
<param name="scoringThisActivityAtAll" value="true" />
<!-- typical duration of activity. needs to be defined and non-zero. in sec. -->
<param name="typicalDuration" value="16:00:00" />
<!-- 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). -->
<param name="typicalDurationScoreComputation" value="uniform" />
</parameterset>

<parameterset type="activityParams" >
<param name="activityType" value="w" />
<param name="closingTime" value="undefined" />
<param name="earliestEndTime" value="undefined" />
<param name="latestStartTime" value="undefined" />
<param name="minimalDuration" value="undefined" />
<param name="openingTime" value="undefined" />
<param name="priority" value="1.0" />
<param name="scoringThisActivityAtAll" value="true" />
<!-- typical duration of activity. needs to be defined and non-zero. in sec. -->
<param name="typicalDuration" value="08:00:00" />
<!-- 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). -->
<param name="typicalDurationScoreComputation" value="uniform" />
</parameterset>

<parameterset type="activityParams" >
<param name="activityType" value="car interaction" />
<param name="closingTime" value="undefined" />
Expand Down Expand Up @@ -616,13 +646,39 @@
<param name="ExternalExeTmpFileRootDir" value="null" />

<!-- 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 -->
<param name="fractionOfIterationsToDisableInnovation" value="Infinity" />
<param name="fractionOfIterationsToDisableInnovation" value="0.8" />

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

<!-- 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 -->
<param name="planSelectorForRemoval" value="WorstPlanSelector" />

<parameterset type="strategysettings" >
<!-- iteration after which strategy will be disabled. most useful for ``innovative'' strategies (new routes, new times, ...). Normally, better use fractionOfIterationsToDisableInnovation -->
<param name="disableAfterIteration" value="-1" />
<!-- path to external executable (if applicable) -->
<param name="executionPath" value="null" />
<!-- strategyName of strategy. Possible default names: SelectRandomBestScoreKeepLastSelectedChangeExpBetaSelectExpBetaSelectPathSizeLogit (selectors), ReRoute TimeAllocationMutator ChangeLegMode TimeAllocationMutator_ReRoute ChangeSingleLegMode ChangeSingleTripMode SubtourModeChoice ChangeTripMode TripSubtourModeChoice (innovative strategies). -->
<param name="strategyName" value="ChangeExpBeta" />
<!-- 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) -->
<param name="subpopulation" value="null" />
<!-- weight of a strategy: for each agent, a strategy will be selected with a probability proportional to its weight -->
<param name="weight" value="0.9" />
</parameterset>

<parameterset type="strategysettings" >
<!-- iteration after which strategy will be disabled. most useful for ``innovative'' strategies (new routes, new times, ...). Normally, better use fractionOfIterationsToDisableInnovation -->
<param name="disableAfterIteration" value="-1" />
<!-- path to external executable (if applicable) -->
<param name="executionPath" value="null" />
<!-- strategyName of strategy. Possible default names: SelectRandomBestScoreKeepLastSelectedChangeExpBetaSelectExpBetaSelectPathSizeLogit (selectors), ReRoute TimeAllocationMutator ChangeLegMode TimeAllocationMutator_ReRoute ChangeSingleLegMode ChangeSingleTripMode SubtourModeChoice ChangeTripMode TripSubtourModeChoice (innovative strategies). -->
<param name="strategyName" value="ReRoute" />
<!-- 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) -->
<param name="subpopulation" value="null" />
<!-- weight of a strategy: for each agent, a strategy will be selected with a probability proportional to its weight -->
<param name="weight" value="0.1" />
</parameterset>
</module>

<!-- ====================================================================== -->
Expand Down
@@ -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();
}

}
Expand Up @@ -44,7 +44,7 @@
*
* @author dgrether, tthunig
*/
public class RunSignalSystemsExample {
public class RunSignalSystemsExampleWithHoles {

public static void main(String[] args) {
run(true);
Expand Down
Expand Up @@ -19,22 +19,45 @@
package tutorial.fixedTimeSignals;

import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.matsim.contrib.signals.run.RunSignalSystemsExample;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting;
import org.matsim.testcases.MatsimTestUtils;

/**
* @author nagel
*
*/
public class RunSignalSystemsExampleTest {

@Rule public MatsimTestUtils testUtils = new MatsimTestUtils();

@Test
public final void test() {
public final void testExampleWithHoles() {
boolean usingOTFVis = false ;
try {
RunSignalSystemsExample.run(usingOTFVis);
RunSignalSystemsExampleWithHoles.run(usingOTFVis);
} catch (Exception ee ) {
ee.printStackTrace();
Assert.fail("something went wrong: " + ee.getMessage()) ;
}
}

@Test
public final void testMinimalExample() {
try {
Config config = ConfigUtils.loadConfig("./examples/tutorial/example90TrafficLights/useSignalInput/withLanes/config.xml");
config.controler().setOverwriteFileSetting(OverwriteFileSetting.deleteDirectoryIfExists);
config.controler().setLastIteration(0);
config.controler().setOutputDirectory(testUtils.getOutputDirectory());

RunSignalSystemsExample.run(config);
} catch (Exception ee ) {
ee.printStackTrace();
Assert.fail("something went wrong") ;
Assert.fail("something went wrong: " + ee.getMessage()) ;
}
}

Expand Down

0 comments on commit 7663c41

Please sign in to comment.