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