Commit c8cd8c0b authored by Sebastian Hörl's avatar Sebastian Hörl
Browse files

Configure road types for long distance scenario

parent 7038997d
## Creating the scenarios
# How to create the partial scenarios
This repository only contains code to run the requested scenarios in the ASTRA 2018/002 project. For the sake of avoiding code duplication, the scenario cutting code is still located in the [baseline_scenario]( repository, specifically in the (synpop)[] branch.
The repository can be transformed into a "fat jar" by calling:
mvn -Pstandalone package
The basis for creating a partial scenario is the full Switzerland scenario in arbitrary sample size. How to create such a full Switzerland scenario is explained in the corresponding (Synthetic populaton of Switzerland)[] repository. This will create a scenario including `switzerland_population.xml.gz`, `switzerland_network.xml.gz` and so forth.
The `baseline_scenario` code can then be used to cut this population and network to a specific diameter. The relevant run script is `ch.ethz.matsim.baseline_scenario.CutScenario`. It has the following parameters:
- *input-config-path*: Path to `switzerland_config.xml`
- *shapefile-path*: Path to a shape file that contains the scenario boundary
- *shapefile-attribute*: Attribute of the shapes contained in the shape file that defines the scenario id
- *shapefile-value*: Defines which value the given attribute should have (see further below)
- *prefix*: Prefix in the filenames of the generated scenario, e.g. `prefix_population.xml.gz`
- *output-path*: Output path (directory) of the new scenario. The directoy must exist.
The concept is therefore as follows: One has to provide a shape file to the script. The shapes (polygons) in that file all have a specific attribute (e.g. `scenario_id`). Then the script will look up the one specific polygon in that file that has the given `shapefile-value` for that attribute, e.g. `zurich_30km` or similar. This way one shape file can contain multiple scenario diameters, which avoids having a shape file for each of the scenarios.
For ASTRA 2018/002, there is already a shape file in `gis/scenarios/scenarios.shp`. It is created from the initial `Gemeinden_fuer_Raumtypen.shp` using the script `gis/`. To create a "ländlich ungerichtet" (lu) scenario, one can call, for instance:
java -Xmx100G -cp baseline_scenario/baseline_scenario-0.0.1-synpop-SNAPSHOT.jar ch.ethz.matsim.baseline_scenario.CutScenario --input-config-path switzerland_config.xml --shapefile-path /path/to/gis/scenarios/scenarios.shp --shapefile-attribute scenario --shapefile-value lu --prefix lu_ --output-path lu_scenario
# How to create a long-distance scenario
To create the long-distance scenario, the script `ch.ethz.matsim.projects.astra_2018_002.long_distance.MakeLongDistanceScenario` is used. It receives a number of parameters:
- *network-path*: Path to the MATSim network file (e.g. `switzerland_network.xml.gz`)
- *population-path*: Path to the MATSim populaton file (e.g. `switzerland_population.xml.gz`)
- *output-path*: Output path of the long-distance population (e.g. `long_distance_population.xml.gz`)
- *osm-types*: `osm:highway` types that are considered as "long distance roads* (optional, default: "motorway,trunk")
- *threads*: Number of threads to use (optional, by default maximum is used)
- *batch-size*: Batch size in parallel processing (optional, default is 100)
The script will do the following:
1. Route every trip of every person using freespeed travel times
2. Find all persons that touch a link with the given `osm-types` at any point during their daily plan
3. Remove all remaining persons (those not interacting with "long distance roads")
4. Write out the reduced population
For a 0.1% sample that script removed around 1/3 of the agents. Remaining steps to verify the process are:
\ No newline at end of file
package ch.ethz.matsim.projects.astra_2018_002.long_distance;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Function;
import org.apache.log4j.Logger;
import org.matsim.api.core.v01.Id;
......@@ -37,7 +39,7 @@ public class MakeLongDistanceScenario {
static public void main(String[] args) throws ConfigurationException, InterruptedException {
CommandLine cmd = new CommandLine.Builder(args) //
.requireOptions("network-path", "population-path", "output-path") //
.allowOptions("threads", "batch-size") //
.allowOptions("threads", "batch-size", "osm-types") //
Config config = ConfigUtils.createConfig();
......@@ -66,9 +68,18 @@ public class MakeLongDistanceScenario {
LinkInteractionFinder interactionFinder = new LinkInteractionFinder(numberOfThreads, batchSize,
stageActivityTypes, populationFactory, routerFactory);
Set<String> osmTypes = new HashSet<>(Arrays.asList("motorway", "trunk"));
if (cmd.hasOption("osm-types")) {
osmTypes = new HashSet<>(Arrays.asList(cmd.getOptionStrict("osm-types").split(",")).stream()
final Set<String> finalOsmTypes = new HashSet<>(osmTypes);
Function<Link, Boolean> highwayFilter = (link) -> {
String attribute = (String) link.getAttributes().getAttribute("osm:way:highway");
return attribute != null && attribute.equals("primary");
return attribute != null && finalOsmTypes.contains(attribute);
Collection<Id<Person>> interactionIds = interactionFinder.findInteractingPersons(scenario.getPopulation(),
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment