6 - Programming Event Analysis

As pointed out in the „Getting Started“ - Tutorial, Events are a key concept of MATSim. This tutorial will introduce you into the possibilities of data analysing using events.

MATSim Events

In order to use this tutorial, we strongly recommend using the latest SVN checkout. Using Eclipse will ease your work. Furthermore you will need to have run a simulation in order to use the examples given here. If you don't have your own, simply run MyMainClass.java in src/tutorial/example7ControlerListener (this will run a simulation from the forthcoming Controler tutorial ). After running, you should have an output-Folder in your MATSim-directory with a total of 12 iterations. Each iteration contains an events.txt.gz file listing the events.

 

1) Controler generated Analysis

Before getting into the deep analyis, a look at the controler generated output is worthwile. You will find:

  • score statistics

  • leg histograms (each iteration)

  • Snapshots and plans (every 10th iteration)

These statistics are useful for a basic analysis.

 

3) Creating Charts

MATSim uses the JFreeChart library to generate charts (see http://www.jfree.org/jfreechart/ for additional information). The library is somewhat complex to understand, but we have included the most useful tools in:

org.matsim.core.utils.charts

A simple chart may be created like this:

public class MyChartCreator {
    public static void main(String[] args) {
    XYLineChart chart = new XYLineChart("Title","x-axis","y-axis");
    chart.addSeries("SeriesTitle", new double[]{1.0,2.0,2.4}, new double[]{1.0,2.0,4.0});

    //adds a Series to the chart
    charta.saveAsPng("a-chart.png", 800, 600); //File Export
    }
}

 

Now, try to use a chart in your EventHandler:
Try to collect the number of vehicles on link 6 per hour and write them to a chart.
You will find the solution in MyEventHandler3.