You will hear in more detail about the input components in Lesson 4. Thus, only a brief overview is given here. Often these files are handled in MATSim in the compressed format gzip with the extension ".gz".
Network (network.xml)
The network file gives information about the transport infrastructure. A MATSim network contains links and nodes each with its specific attributes such as the node coordinates or the link capacity.
Plans / Population (plans.xml)
Plans represent the population and the demand of a scenario. Usually, you will not create plans by writing into the actual plans files but will generate your demand by either using the API or your own code. You will hear more on population demand generation in Lesson 4.
Configuration file (config.xml)
The controler needs one argument and that is the configuration file. As long as you do not write code, the configuration file is your way to adapt the behavior of MATSim.
Additional input:
During this tutorial you will use facilities (facilities.xml.gz) and count data (counts.xml). Facilities are an optional part of MATSim. They can roughly be interpreted as buildings. Count data is one of the most important sources for validation as obviously they are associated to a small measurement error, in contrary to e.g., survey data.
Now it is time to run the simulation. There are some example scenarios which can be started without modifiying anything in MATSim. You might want to look at them later. But we are continuing with setting up our own java project already here.
Create your own java project:
File -> New -> Java ProjectmyProjectNextJava Settings click the tab LibrariesAdd JARs ...matsim-0.5.x foldermatsim-0.5.x.jarOK twiceFinishCreate your own controler:
New -> FolderFolder name and enter inputoutput foldersrc folder in myProject and click New -> PackagetutorialFinishNew -> ClassMyFirstControlerWhich method stubs would you like to create? select public static void main(String[] args)Finishpublic static void main(String[] args) {Config config = ConfigUtils.loadConfig("input/config.xml");
Controler controler = new Controler(config);
// controler.setOverwriteFiles(true);
controler.run();
Controler. There is an option to instruct Eclipse to organize the imports automatically. If you see red lines this option is deactivated in your configuration. For the moment just move the mouse over the word Controler. A dialog appears which suggests some quickfixes. Double-click on the (first) entry Import 'Controler' (org.matsim.core.controler)Copy the input files to your project:
plans.xml.gz), the network file (network.xml), the facilities file (facilities.xml.gz) and the config file (config.xml) and copy them to the input folder. You may have to refresh the Eclipse view afterwards (right-click your project and click Refresh).save as. Do not open the xml files in the browser for copying them into a text editor! Browsers usually add some characters for better visualization, which produce erros during xml parsing in MATSim.Run the simulation:
Run and click Run Configurations...Java Application in the left box and press the New buttonmyProject if it is not yet autofilledSearch... button to choose the Main classMyFirstControler and click OKArguments tab and type under Program arguments the path to the config file, i.e., input/config.xmlApply -mx700m in VM arguments.RunS H U T D O W N --- regular shutdown completed appears everything went fine.If you want to rerun the scenario again, you have to clean the output folder. For safety reasons MATSim does not overwrite files in the output folder and exits if files are in there. For small sceanrios this looks incomfortable but imagine that you accidentally overwrite a run that took a few days. You will be grateful to MATSim that it refuses to overwrite this work. If it gets on your nerves at the moment just open the MyFirstControler and remove the comment in front of controler.setOverwriteFiles(true); If you don't know how comments work in Java please check the Section 2.2.3.
Your simulation finished after 1 iteration. As you have learned earlier, MATSim is based on the principle of evolution. Clearly, no evolutionary process is able to find an optimum in only one iteration, not even a local one. Hence, try to increase the number of iterations to 10. Open the configuration file and try it!
Has it worked out? Yes? Great! But where are the counts? Download the counts file (counts.xml) and copy it to the input folder. Now, open the configuration file again and try to add the traffic counts. You need the set the path to the counts input file. Additionally, you need to set the counts scale factor correctly. Please note, that we are using a 1% sample in this example. So the scale factor is 100. Illogical? Yes at first sight. But we are actually scaling the simulated values and not the counted values although that factor is given in the counts section of the configuration file.
Now it is time to have a look at the visualizer. When the simulation ran, many files were created in its output directory. One of the files is a so-called events file, typically generated for every 10th iteration. The events file for the first iteration is located in output/ITERS/it.0/run0.0.events.xml.gz. This contains a lot of information that can be visualized. Now, when you start the visualizer, you should see a large, black area. This is where the traffic will be visualized. On the right side of this area, you see a smaller area with 5 icons on the top ("Controls"). Click the first icon ("Data Sources"). Now you can either drag and drop files into this section (e.g. a network.xml, or events.xml.gz), or click the green "+" at the bottom to select a file to be added. Use either option to add first network.xml to the list of available data and then events.xml.gz. Now the visualizer knows about our data, and we can tell it how to visualize it.
Next, click on the second icon ("Layers") in the "Controls" section. Initially, you will see only the background layer listed. Click on the green '+' to select the data you want to have displayed. It should already suggest to visualize the network with the loaded network.xml, so just click "Add". After a short moment, the network should be shown in the visualization area. Click the green '+' again, but this time choose "Vehicles" as layer type. The events.xml.gz file will be already pre-selected. Click on "Add". As any layer depending on the events, a "Load Data" button will appear at the bottom of the layer tag. Click it to extract the vehicles' positions from the events.
Zoom in to the Zurich area, and change the time with the slider below the visualization area to see how the vehicles move around.
| Attachment | Size |
|---|---|
| 1.07 MB | |
| 579.36 KB |