MATSIM
Public Member Functions | Private Attributes | List of all members
org.matsim.pt.analysis.RouteTimeDiagram Class Reference
Inheritance diagram for org.matsim.pt.analysis.RouteTimeDiagram:
Inheritance graph
[legend]

Public Member Functions

void handleEvent (final VehicleArrivesAtFacilityEvent event)
 
void handleEvent (final VehicleDepartsAtFacilityEvent event)
 
void reset (final int iteration)
 
void writeData ()
 
void createGraph (final String filename, final TransitRoute route)
 

Private Attributes

final Map< Id, List< Tuple< Id, Double > > > positions = new HashMap<Id, List<Tuple<Id, Double>>>()
 

Detailed Description

Collects data to create Route-Time-Diagrams based on the actual simulation. A Route-Time-Diagram shows the position along one transit route of one or more vehicles over the lapse of time.

Author
mrieser

Definition at line 57 of file RouteTimeDiagram.java.

Member Function Documentation

◆ handleEvent() [1/2]

void org.matsim.pt.analysis.RouteTimeDiagram.handleEvent ( final VehicleArrivesAtFacilityEvent  event)

Implements org.matsim.core.api.experimental.events.handler.VehicleArrivesAtFacilityEventHandler.

Definition at line 64 of file RouteTimeDiagram.java.

References org.matsim.core.api.experimental.events.VehicleArrivesAtFacilityEvent.getFacilityId(), org.matsim.api.core.v01.events.Event.getTime(), and org.matsim.core.api.experimental.events.VehicleArrivesAtFacilityEvent.getVehicleId().

64  {
65  List<Tuple<Id, Double>> list = this.positions.get(event.getVehicleId());
66  if (list == null) {
67  list = new ArrayList<Tuple<Id, Double>>();
68  this.positions.put(event.getVehicleId(), list);
69  }
70  list.add(new Tuple<Id, Double>(event.getFacilityId(), Double.valueOf(event.getTime())));
71  }
final Map< Id, List< Tuple< Id, Double > > > positions
Here is the call graph for this function:

◆ handleEvent() [2/2]

void org.matsim.pt.analysis.RouteTimeDiagram.handleEvent ( final VehicleDepartsAtFacilityEvent  event)

Implements org.matsim.core.api.experimental.events.handler.VehicleDepartsAtFacilityEventHandler.

Definition at line 73 of file RouteTimeDiagram.java.

References org.matsim.core.api.experimental.events.VehicleDepartsAtFacilityEvent.getFacilityId(), org.matsim.api.core.v01.events.Event.getTime(), and org.matsim.core.api.experimental.events.VehicleDepartsAtFacilityEvent.getVehicleId().

73  {
74  List<Tuple<Id, Double>> list = this.positions.get(event.getVehicleId());
75  if (list == null) {
76  list = new ArrayList<Tuple<Id, Double>>();
77  this.positions.put(event.getVehicleId(), list);
78  }
79  list.add(new Tuple<Id, Double>(event.getFacilityId(), Double.valueOf(event.getTime())));
80  }
final Map< Id, List< Tuple< Id, Double > > > positions
Here is the call graph for this function:

◆ reset()

void org.matsim.pt.analysis.RouteTimeDiagram.reset ( final int  iteration)

Gives the event handler the possibility to clean up its internal state. Within a Controler-Simulation, this is called before the mobsim starts.

Parameters
iterationthe up-coming iteration from which up-coming events will be from.

Implements org.matsim.core.events.handler.EventHandler.

Definition at line 82 of file RouteTimeDiagram.java.

82  {
83  this.positions.clear();
84  }
final Map< Id, List< Tuple< Id, Double > > > positions

◆ writeData()

void org.matsim.pt.analysis.RouteTimeDiagram.writeData ( )

Definition at line 86 of file RouteTimeDiagram.java.

86  {
87  for (List<Tuple<Id, Double>> list : this.positions.values()) {
88  for (Tuple<Id, Double> info : list) {
89  System.out.println(info.getFirst().toString() + "\t" + info.getSecond().toString());
90  }
91  System.out.println();
92  }
93  }
final Map< Id, List< Tuple< Id, Double > > > positions

◆ createGraph()

void org.matsim.pt.analysis.RouteTimeDiagram.createGraph ( final String  filename,
final TransitRoute  route 
)

Definition at line 95 of file RouteTimeDiagram.java.

References org.matsim.pt.transitSchedule.api.TransitRoute.getDepartures(), org.matsim.api.core.v01.Identifiable< T >.getId(), and org.matsim.pt.transitSchedule.api.TransitRoute.getStops().

95  {
96 
97  HashMap<Id, Integer> stopIndex = new HashMap<Id, Integer>();
98  int idx = 0;
99  for (TransitRouteStop stop : route.getStops()) {
100  stopIndex.put(stop.getStopFacility().getId(), idx);
101  idx++;
102  }
103 
104  HashSet<Id> vehicles = new HashSet<Id>();
105  for (Departure dep : route.getDepartures().values()) {
106  vehicles.add(dep.getVehicleId());
107  }
108 
109  XYSeriesCollection dataset = new XYSeriesCollection();
110  int numSeries = 0;
111  double earliestTime = Double.POSITIVE_INFINITY;
112  double latestTime = Double.NEGATIVE_INFINITY;
113 
114  for (Map.Entry<Id, List<Tuple<Id, Double>>> entry : this.positions.entrySet()) {
115  if (vehicles.contains(entry.getKey())) {
116  XYSeries series = new XYSeries("t", false, true);
117  for (Tuple<Id, Double> pos : entry.getValue()) {
118  Integer stopIdx = stopIndex.get(pos.getFirst());
119  if (stopIdx != null) {
120  double time = pos.getSecond().doubleValue();
121  series.add(stopIdx.intValue(), time);
122  if (time < earliestTime) {
123  earliestTime = time;
124  }
125  if (time > latestTime) {
126  latestTime = time;
127  }
128  }
129  }
130  dataset.addSeries(series);
131  numSeries++;
132 
133  }
134  }
135 
136  JFreeChart c = ChartFactory.createXYLineChart("Route-Time Diagram, Route = " + route.getId(), "stops", "time",
137  dataset, PlotOrientation.VERTICAL,
138  false, // legend?
139  false, // tooltips?
140  false // URLs?
141  );
142  c.setBackgroundPaint(new Color(1.0f, 1.0f, 1.0f, 1.0f));
143 
144  XYPlot p = (XYPlot) c.getPlot();
145 
146  p.getRangeAxis().setInverted(true);
147  p.getRangeAxis().setRange(earliestTime, latestTime);
148  XYItemRenderer renderer = p.getRenderer();
149  for (int i = 0; i < numSeries; i++) {
150  renderer.setSeriesPaint(i, Color.black);
151  }
152 
153  try {
154  ChartUtils.saveChartAsPNG(new File(filename), c, 1024, 768, null, true, 9);
155  } catch (IOException e) {
156  e.printStackTrace();
157  }
158  }
Here is the call graph for this function:

Member Data Documentation

◆ positions

final Map<Id, List<Tuple<Id, Double> > > org.matsim.pt.analysis.RouteTimeDiagram.positions = new HashMap<Id, List<Tuple<Id, Double>>>()
private

Map containing for each vehicle a list of positions, stored as StopFacility Ids and the time.

Definition at line 62 of file RouteTimeDiagram.java.


The documentation for this class was generated from the following file: