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.
- Download attached configuration files!
- Run matsim.0.7.0.jar from the matsim directory!
- Register for a free Via licence, and add it to Via!
1.1. Hello World!
- Load config_01_01.xml and run the simulation!
- Examine the configuration file and the structure of the output!
- Load results to Via! Play back last iteration!
- How many users does the configuration model?
- How many iterations are run?
- What were the users scores in the last iteration?
- How much time did the user spend more at his office than planned?
- What was the daily distance travelled?
- How much longer was the trip home than to the office in the morning why was that?
- What happens if you try to run the simulation one more time?
- Make the simulation re-runnable, and increment the iterations by one! What happens when you run the simulation again? Why?
- Load and run config_01_02.xml!
- Examine the configuration file and the structure of the output, check the output with Via!
- 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!
- Run a simulation with this configuration!
- 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!
- What is the difference between this network file and the prevous one? How does it affect the outcome of the simulation? Why?
- 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!
- Fire up Eclipse!
- Create a new Java project called matsim!
- Convert it to Maven project!
- 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).
- Run MATSim by creating a new launch configuration:
Run > Run Configurations... > New launch configuration
Project: matsim, Main class: org.matsim.run.gui.Gui
- Run one of the previous configurations!
2.1. Generate network file from OSM data
- From http://www.openstreetmap.org/export download a map segment representing the surroundings of the university (just a couple of blocks).
- Download the class RunPNetworkGenerator and add it to your project.
- Add the correct file path to the input and output of the class.
- Run the new main method.
- Create a population file by hand with a single student who goes to the university in the morning and leaves in the evening.
- Run the scenario!
2.2. Generating populations from code
Now you'll have the chance to get rid of XML configuration files!
- Examine the RunPCreateDrivingAgents example!
- 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.
- Set the output folder with Controler.setOutputDirectory() method.
- Use coordinates from the map created in the last exercise!
- Run the scenario on the previously prepared map!
- 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
Load and run config_03_01.xml!
- Which evolutionary step is used?
- How much did the utility of the user improve over the iterations?
- How many iterations did it take to reach the optimal strategy?
3.2. Utility function
Load and run config_03_02.xml!
- Which evolutionary step is used?
- Explain the used parameters in the utility function!
- Examine how close did the user's plan get to the optimal solution!
- Create the optimal plan for the given parameters, and run the simulation! What is the achieved utility?
- Estimate how many iterations would it take to reach the optimal solution!
3.3. The best day
Let's get back to the university.
- Create a configuration file with different evolutionary steps!
- 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
- Create a population consisting of a single student. Add plans that represent real scenarios and choices.
- Run the simulation! What's the optimal plan?