MATSIM
RunEventsHandler.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.* *
3  * *
4  * *********************************************************************** *
5  * *
6  * copyright : (C) 2008 by the members listed in the COPYING, *
7  * LICENSE and WARRANTY file. *
8  * email : info at matsim dot org *
9  * *
10  * *********************************************************************** *
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * See also COPYING, LICENSE and WARRANTY file *
17  * *
18  * *********************************************************************** */
19 package tutorial.programming.example21tutorialTUBclass.class2016.events;
20 
21 import java.io.BufferedWriter;
22 import java.io.IOException;
23 
24 import org.matsim.api.core.v01.Scenario;
31 import org.matsim.core.utils.io.IOUtils;
32 
33 public class RunEventsHandler {
34 
35  public static void main(String[] args) {
36 
39 
40  new MatsimNetworkReader(scenario.getNetwork()).readFile("input/network.xml");
41 
42  CarTravelDistanceEvaluator carTravelDistanceEvaluator = new CarTravelDistanceEvaluator(scenario.getNetwork());
43  eventsManager.addHandler(carTravelDistanceEvaluator);
44  new MatsimEventsReader(eventsManager).readFile("output/davis-basecase1/davis01.output_events.xml.gz");
45 
46  writeDistancesToFile(carTravelDistanceEvaluator.getDistanceDistribution(), "output/davis-basecase1/cardistances.txt");
47 
48  }
49  static void writeDistancesToFile(int[] distanceDistribution, String fileName){
50  BufferedWriter bw = IOUtils.getBufferedWriter(fileName);
51  try {
52  bw.write("Distance\tRides");
53  for (int i = 0;i<distanceDistribution.length;i++){
54  bw.newLine();
55  bw.write(i+"\t"+distanceDistribution[i]);
56  }
57  bw.flush();
58  bw.close();
59 
60  } catch (IOException e) {
61  // TODO Auto-generated catch block
62  e.printStackTrace();
63  }
64 
65 
66  }
67 
68 }
void addHandler(final EventHandler handler)
static Config createConfig(final String filename)
static EventsManager createEventsManager()
static BufferedWriter getBufferedWriter(final String filename, final boolean useCompression)
Definition: IOUtils.java:167
static Scenario createScenario(final Config config)