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

Public Member Functions

 CalcLegTimes ()
 
void handleEvent (ActivityEndEvent event)
 
void handleEvent (final PersonDepartureEvent event)
 
void handleEvent (final PersonArrivalEvent event)
 
void handleEvent (ActivityStartEvent event)
 
void reset (final int iteration)
 
Map< String, int[]> getLegStats ()
 
double getAverageLegDuration ()
 
void writeStats (final String filename)
 
void writeStats (final java.io.Writer out) throws UncheckedIOException
 

Static Public Member Functions

static int getTimeslotIndex (final double time_s)
 

Private Attributes

final IdMap< Person, Double > agentDepartures = new IdMap<>(Person.class)
 
final IdMap< Person, Double > agentArrivals = new IdMap<>(Person.class)
 
final Map< String, int[]> legStats = new TreeMap<>()
 
final IdMap< Person, String > previousActivityTypes = new IdMap<>(Person.class)
 
double sumLegDurations = 0
 
int sumLegs = 0
 

Static Private Attributes

static final Logger log = LogManager.getLogger(CalcLegTimes.class)
 
static final int SLOT_SIZE = 300
 
static final int MAXINDEX = 12
 

Detailed Description

Author
mrieser

Calculates the distribution of legs-durations, e.g. how many legs took at most 5 minutes, how many between 5 and 10 minutes, and so on. Also calculates the average leg duration. Legs ended because of vehicles being stuck are not counted.

Definition at line 54 of file CalcLegTimes.java.

Constructor & Destructor Documentation

◆ CalcLegTimes()

org.matsim.analysis.CalcLegTimes.CalcLegTimes ( )

Definition at line 74 of file CalcLegTimes.java.

74  {
75 
76  }

Member Function Documentation

◆ handleEvent() [1/4]

void org.matsim.analysis.CalcLegTimes.handleEvent ( ActivityEndEvent  event)

Implements org.matsim.api.core.v01.events.handler.ActivityEndEventHandler.

Definition at line 79 of file CalcLegTimes.java.

References org.matsim.api.core.v01.events.ActivityEndEvent.getPersonId(), and org.matsim.api.core.v01.IdMap< T, V >.put().

79  {
80  this.previousActivityTypes.put(event.getPersonId(), event.getActType());
81  }
final IdMap< Person, String > previousActivityTypes
Here is the call graph for this function:

◆ handleEvent() [2/4]

void org.matsim.analysis.CalcLegTimes.handleEvent ( final PersonDepartureEvent  event)

Implements org.matsim.api.core.v01.events.handler.PersonDepartureEventHandler.

Definition at line 84 of file CalcLegTimes.java.

References org.matsim.api.core.v01.events.PersonDepartureEvent.getPersonId(), and org.matsim.api.core.v01.IdMap< T, V >.put().

84  {
85  this.agentDepartures.put(event.getPersonId(), event.getTime());
86  }
final IdMap< Person, Double > agentDepartures
Here is the call graph for this function:

◆ handleEvent() [3/4]

void org.matsim.analysis.CalcLegTimes.handleEvent ( final PersonArrivalEvent  event)

Implements org.matsim.api.core.v01.events.handler.PersonArrivalEventHandler.

Definition at line 89 of file CalcLegTimes.java.

References org.matsim.api.core.v01.events.PersonArrivalEvent.getPersonId(), and org.matsim.api.core.v01.IdMap< T, V >.put().

89  {
90  this.agentArrivals.put(event.getPersonId(), event.getTime());
91  }
final IdMap< Person, Double > agentArrivals
Here is the call graph for this function:

◆ handleEvent() [4/4]

void org.matsim.analysis.CalcLegTimes.handleEvent ( ActivityStartEvent  event)

Implements org.matsim.api.core.v01.events.handler.ActivityStartEventHandler.

Definition at line 95 of file CalcLegTimes.java.

References org.matsim.api.core.v01.events.ActivityStartEvent.getPersonId(), org.matsim.analysis.CalcLegTimes.getTimeslotIndex(), org.matsim.analysis.CalcLegTimes.MAXINDEX, and org.matsim.api.core.v01.IdMap< T, V >.remove().

95  {
96  Double depTime = this.agentDepartures.remove(event.getPersonId());
97  Double arrTime = this.agentArrivals.remove(event.getPersonId());
98  if (depTime != null) {
99  double travTime = arrTime - depTime;
100  String fromActType = previousActivityTypes.remove(event.getPersonId());
101  String toActType = event.getActType();
102  String legType = fromActType + "---" + toActType;
103  int[] stats = this.legStats.get(legType);
104  if (stats == null) {
105  stats = new int[MAXINDEX + 1];
106  for (int i = 0; i <= MAXINDEX; i++) {
107  stats[i] = 0;
108  }
109  this.legStats.put(legType, stats);
110  }
111  stats[getTimeslotIndex(travTime)]++;
112 
113  this.sumLegDurations += travTime;
114  this.sumLegs++;
115  }
116  }
final IdMap< Person, Double > agentDepartures
static int getTimeslotIndex(final double time_s)
final IdMap< Person, String > previousActivityTypes
final IdMap< Person, Double > agentArrivals
final Map< String, int[]> legStats
Here is the call graph for this function:

◆ reset()

void org.matsim.analysis.CalcLegTimes.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 120 of file CalcLegTimes.java.

References org.matsim.api.core.v01.IdMap< T, V >.clear().

120  {
121  this.previousActivityTypes.clear();
122  this.agentDepartures.clear();
123  this.legStats.clear();
124  this.sumLegDurations = 0;
125  this.sumLegs = 0;
126  }
final IdMap< Person, Double > agentDepartures
final IdMap< Person, String > previousActivityTypes
final Map< String, int[]> legStats
Here is the call graph for this function:

◆ getLegStats()

Map<String, int[]> org.matsim.analysis.CalcLegTimes.getLegStats ( )

Definition at line 128 of file CalcLegTimes.java.

References org.matsim.analysis.CalcLegTimes.legStats.

128  {
129  return this.legStats;
130  }
final Map< String, int[]> legStats

◆ getTimeslotIndex()

static int org.matsim.analysis.CalcLegTimes.getTimeslotIndex ( final double  time_s)
static

Definition at line 132 of file CalcLegTimes.java.

References org.matsim.analysis.CalcLegTimes.MAXINDEX.

Referenced by org.matsim.analysis.CalcLegTimes.handleEvent().

132  {
133  int idx = (int) (time_s / SLOT_SIZE);
134  if (idx > MAXINDEX) idx = MAXINDEX;
135  return idx;
136  }

◆ getAverageLegDuration()

double org.matsim.analysis.CalcLegTimes.getAverageLegDuration ( )

Definition at line 138 of file CalcLegTimes.java.

138  {
139  return (this.sumLegDurations / this.sumLegs);
140  }

◆ writeStats() [1/2]

void org.matsim.analysis.CalcLegTimes.writeStats ( final String  filename)

Definition at line 142 of file CalcLegTimes.java.

References org.matsim.core.utils.io.IOUtils.getBufferedWriter().

142  {
143  try (BufferedWriter legStatsFile = IOUtils.getBufferedWriter(filename)) {
144  writeStats(legStatsFile);
145  } catch (IOException e) {
146  log.error(e);
147  }
148  }
void writeStats(final String filename)
Here is the call graph for this function:

◆ writeStats() [2/2]

void org.matsim.analysis.CalcLegTimes.writeStats ( final java.io.Writer  out) throws UncheckedIOException

Definition at line 150 of file CalcLegTimes.java.

References org.matsim.core.utils.misc.Time.writeTime().

150  {
151  try {
152  boolean first = true;
153  for (Map.Entry<String, int[]> entry : this.legStats.entrySet()) {
154  String key = entry.getKey();
155  int[] counts = entry.getValue();
156  if (first) {
157  first = false;
158  out.write("pattern");
159  for (int i = 0; i < counts.length; i++) {
160  out.write("\t" + (i * SLOT_SIZE / 60) + "+");
161  }
162  out.write("\n");
163  }
164  out.write(key);
165  for (int count : counts) {
166  out.write("\t" + count);
167  }
168  out.write("\n");
169  }
170  out.write("\n");
171  if (this.sumLegs == 0) {
172  out.write("average legs duration: no legs!");
173  } else {
174  out.write("average leg duration: "
175  + (this.sumLegDurations / this.sumLegs)
176  + " seconds = "
177  + Time.writeTime(((int) (this.sumLegDurations / this.sumLegs))));
178  }
179  out.write("\n");
180  } catch (IOException e) {
181  throw new UncheckedIOException(e);
182  } finally {
183  try {
184  out.flush();
185  } catch (IOException e) {
186  log.error(e);
187  }
188  }
189  }
Here is the call graph for this function:

Member Data Documentation

◆ log

final Logger org.matsim.analysis.CalcLegTimes.log = LogManager.getLogger(CalcLegTimes.class)
staticprivate

Definition at line 57 of file CalcLegTimes.java.

◆ SLOT_SIZE

final int org.matsim.analysis.CalcLegTimes.SLOT_SIZE = 300
staticprivate

Definition at line 59 of file CalcLegTimes.java.

◆ MAXINDEX

final int org.matsim.analysis.CalcLegTimes.MAXINDEX = 12
staticprivate

◆ agentDepartures

final IdMap<Person, Double> org.matsim.analysis.CalcLegTimes.agentDepartures = new IdMap<>(Person.class)
private

Definition at line 62 of file CalcLegTimes.java.

◆ agentArrivals

final IdMap<Person, Double> org.matsim.analysis.CalcLegTimes.agentArrivals = new IdMap<>(Person.class)
private

Definition at line 63 of file CalcLegTimes.java.

◆ legStats

final Map<String, int[]> org.matsim.analysis.CalcLegTimes.legStats = new TreeMap<>()
private

Definition at line 64 of file CalcLegTimes.java.

Referenced by org.matsim.analysis.CalcLegTimes.getLegStats().

◆ previousActivityTypes

final IdMap<Person, String> org.matsim.analysis.CalcLegTimes.previousActivityTypes = new IdMap<>(Person.class)
private

Definition at line 65 of file CalcLegTimes.java.

◆ sumLegDurations

double org.matsim.analysis.CalcLegTimes.sumLegDurations = 0
private

Definition at line 66 of file CalcLegTimes.java.

◆ sumLegs

int org.matsim.analysis.CalcLegTimes.sumLegs = 0
private

Definition at line 67 of file CalcLegTimes.java.


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