MATSim lab - exercises

MATSim exercises

During this session, you will use MATSim to simulate some basic scenarios. You should read chapters 1.1 and 1.2, and understand the basics of the utility function described in 1.3 of the MATSim book. During the third part of the session, you will have to write some Java code using the Eclipse IDE, so you have to be familiar with Java syntax, basic datatypes and control flow statements, basic data types and basic notions of object oriented programming.

In the first part of the session you will use MATSim through it's UI, and run simulations defined through editing configuration files. You will get a basic understanding of how to write configuration files and read MATSim output, and process this output with the Via data visualization tool.

In the second part, you will learn how to program MATSim through it's API and how to generate network files from Open Street Map data.

It the third part of the session you will learn how to use Strategies.

When answering the questions, indicate the source you used (configuration file, output file, Via UI)!

Don't forget to attach the configuration files to your submission!

Export and attach the final Eclipse project to your submission!

 

0. Virtual environment

Start up the MATsim -- Ubuntu disk image. After a lightweight Linux with VBox loads, start the matsim virtual machine. User name is matsim, password will be available on the whiteboard. Matsim user has superuser privileges. If the virtual machine doesn't span across the entire display, use the

xrandr -s 1920x1080

command. After that, set the screen resolution (DPI) under Settings > Appearance > Font.

The virtual machine comes with Sun Java 1.8, and Eclipse Mars..

Matsim and via are available in the folder /home/matsim/Work

Eclipse can be found in /home/matsim/eclipse folder.

1. MATSim user interface

MATSim is an opensource Java application. Source can be downloaded at: https://github.com/matsim-org/matsim . You can find examples and other materials aswell, including the Latex source of the MATSim book ( a compiled copy of the 2016.02.25. version is downloadable here).

Stable MATSim distributions can be downloaded from http://www.matsim.org/downloads. We will use these binaries during this session.

1.0. Preparations

Excercise

  1. Download attached configuration files!
  2. Run matsim.0.7.0.jar from the matsim directory!
  3. Register for a free Via licence, and add it to Via!

1.1. Hello World!

Excercise

  1. Load config_01_01.xml and run the simulation!
  2. Examine the configuration file and the structure of the output!
  3. Load results to Via! Play back last iteration!

Questions

  1. How many users does the configuration model?
  2. How many iterations are run?
  3. What were the users scores in the last iteration?
  4. How much time did the user spend more at his office than planned?
  5. What was the daily distance travelled?
  6. How much longer was the trip home than to the office in the morning why was that?
  7. What happens if you try to run the simulation one more time?
  8. Make the simulation re-runnable, and increment the iterations by one! What happens when you run the simulation again? Why?

1.2. Routing

Exercise

  1. Load and run config_01_02.xml!
  2. Examine the configuration file and the structure of the output, check the output with Via!
  3. Create an alternative network file named square_02_diagonal.xml. Add a bidirectional high speed (130km/h) diagonal link between the square's corner close to home and the one close to the office! Make the length of the link the euclidean distance! Create a configuration fileconfig_02_diagonal.xml, that uses the new network file!
  4. Run a simulation with this configuration!
  5. Create a new configurtion: square_02_diagonal_slow.xml! Find the speed at which it's no longer beneficial for the user to take the shortcut!

Questions

  1. What is the difference between this network file and the prevous one? How does it affect the outcome of the simulation? Why?
  2. How much does the high speed shortcut improves the user's score?

2. Using the MATSim API

Let's get down to business and write some code!

2.0. Preparations

Exercise

  1. Fire up Eclipse!
  2. Create a new Java project called matsim!
  3. Convert it to Maven project!
  4. Add a maven dependency to the pom.xml file, you can find an example at http://www.matsim.org/downloads (add it before the <build> tag).
  5. Run MATSim by creating a new launch configuration:
    ​Run > Run Configurations... > New launch configuration
    Project: matsim, Main class: org.matsim.run.gui.Gui
  6. Run one of the previous configurations!

 

2.1. Generate network file from OSM data

Excercise

  1. From http://www.openstreetmap.org/export download a map segment representing the surroundings of the university (just a couple of blocks).
  2. Download the class RunPNetworkGenerator and add it to your project.
  3. Add the correct file path to the input and output of the class.
  4. Run the new main method.
  5. Create a population file by hand with a single student who goes to the university in the morning and leaves in the evening.
  6. Run the scenario!

2.2. Generating populations from code

Now you'll have the chance to get rid of XML configuration files!

Excercise

  1. Examine the RunPCreateDrivingAgents example!
  2. Based on the file, create a class that generates 499 MSc students, who spend their day at the university, take a lunch break, and than go to a dorm to prepare for an exam.
  3. Set the output folder with Controler.setOutputDirectory() method.
  4. Use coordinates from the map created in the last exercise!
  5. Run the scenario on the previously prepared map!
  6. Examine the output!

3. Simulating several iterations

The main course: MATSim evolutionary model. Experience how MATSim optimizes user's strategies over iterations.

3.1. Simple evolution

Excercise

  1. Load and run config_03_01.xml!

Questions

  1. Which evolutionary step is used?
  2. How much did the utility of the user improve over the iterations?
  3. How many iterations did it take to reach the optimal strategy?

3.2. Utility function

Excercise

  1. Load and run config_03_02.xml!

Questions

  1. Which evolutionary step is used?
  2. Explain the used parameters in the utility function!
  3. Examine how close did the user's plan get to the optimal solution!
  4. Create the optimal plan for the given parameters, and run the simulation! What is the achieved utility?
  5. Estimate how many iterations would it take to reach the optimal solution!

3.3. The best day

Let's get back to the university.

Excercise

  1. Create a configuration file with different evolutionary steps!
  2. Create a utility function that represents a university student's preferences! It should support four activities: sleep (only at home: h) lectures (w1,w2,w3...) lunch (l) and homework (hw), keep in mind that writing homework needs at least 30 minutes of uninterruped concentration
  3. Create a population consisting of a single student. Add plans that represent real scenarios and choices.
  4. Run the simulation! What's the optimal plan?