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

Public Member Functions

 VolumesAnalyzer (final int timeBinSize, final int maxTime, final Network network)
 
 VolumesAnalyzer (final int timeBinSize, final int maxTime, final Network network, boolean observeModes)
 
void handleEvent (VehicleEntersTrafficEvent event)
 
void handleEvent (final LinkLeaveEvent event)
 
int [] getVolumesForLink (final Id< Link > linkId)
 
int [] getVolumesForLink (final Id< Link > linkId, String mode)
 
int getVolumesArraySize ()
 
double [] getVolumesPerHourForLink (final Id< Link > linkId)
 
double [] getVolumesPerHourForLink (final Id< Link > linkId, String mode)
 
Set< String > getModes ()
 
Set< Id< Link > > getLinkIds ()
 
void reset (final int iteration)
 

Private Member Functions

int getTimeSlotIndex (final double time)
 

Private Attributes

final int timeBinSize
 
final int maxTime
 
final int maxSlotIndex
 
final IdMap< Link, int[]> links
 
final boolean observeModes
 
final IdMap< Vehicle, String > enRouteModes
 
final IdMap< Link, Map< String, int[]> > linksPerMode
 

Static Private Attributes

static final Logger log = LogManager.getLogger(VolumesAnalyzer.class)
 

Detailed Description

Counts the number of vehicles leaving a link, aggregated into time bins of a specified size.

Author
mrieser

Definition at line 47 of file VolumesAnalyzer.java.

Constructor & Destructor Documentation

◆ VolumesAnalyzer() [1/2]

org.matsim.analysis.VolumesAnalyzer.VolumesAnalyzer ( final int  timeBinSize,
final int  maxTime,
final Network  network 
)

◆ VolumesAnalyzer() [2/2]

org.matsim.analysis.VolumesAnalyzer.VolumesAnalyzer ( final int  timeBinSize,
final int  maxTime,
final Network  network,
boolean  observeModes 
)

Definition at line 70 of file VolumesAnalyzer.java.

References org.matsim.analysis.VolumesAnalyzer.maxTime, org.matsim.analysis.VolumesAnalyzer.observeModes, and org.matsim.analysis.VolumesAnalyzer.timeBinSize.

70  {
71  this.timeBinSize = timeBinSize;
72  this.maxTime = maxTime;
73  this.maxSlotIndex = (this.maxTime / this.timeBinSize) + 1;
74  this.links = new IdMap<>(Link.class);
75 
77  if (this.observeModes) {
78  this.enRouteModes = new IdMap<>(Vehicle.class);
79  this.linksPerMode = new IdMap<>(Link.class);
80  } else {
81  this.enRouteModes = null;
82  this.linksPerMode = null;
83  }
84  }
final IdMap< Link, Map< String, int[]> > linksPerMode
final IdMap< Vehicle, String > enRouteModes
final IdMap< Link, int[]> links

Member Function Documentation

◆ handleEvent() [1/2]

void org.matsim.analysis.VolumesAnalyzer.handleEvent ( VehicleEntersTrafficEvent  event)

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

Definition at line 87 of file VolumesAnalyzer.java.

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

87  {
88  if (this.observeModes) {
89  this.enRouteModes.put(event.getVehicleId(), event.getNetworkMode());
90  }
91  }
final IdMap< Vehicle, String > enRouteModes
Here is the call graph for this function:

◆ handleEvent() [2/2]

void org.matsim.analysis.VolumesAnalyzer.handleEvent ( final LinkLeaveEvent  event)

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

Definition at line 94 of file VolumesAnalyzer.java.

References org.matsim.api.core.v01.IdMap< T, V >.get(), org.matsim.api.core.v01.events.LinkLeaveEvent.getLinkId(), org.matsim.api.core.v01.events.Event.getTime(), org.matsim.analysis.VolumesAnalyzer.getTimeSlotIndex(), org.matsim.api.core.v01.events.LinkLeaveEvent.getVehicleId(), and org.matsim.api.core.v01.IdMap< T, V >.put().

94  {
95  int[] volumes = this.links.get(event.getLinkId());
96  if (volumes == null) {
97  volumes = new int[this.maxSlotIndex + 1]; // initialized to 0 by default, according to JVM specs
98  this.links.put(event.getLinkId(), volumes);
99  }
100  int timeslot = getTimeSlotIndex(event.getTime());
101  volumes[timeslot]++;
102 
103  if (this.observeModes) {
104  Map<String, int[]> modeVolumes = this.linksPerMode.get(event.getLinkId());
105  if (modeVolumes == null) {
106  modeVolumes = new HashMap<>();
107  this.linksPerMode.put(event.getLinkId(), modeVolumes);
108  }
109  String mode = this.enRouteModes.get(event.getVehicleId());
110  volumes = modeVolumes.get(mode);
111  if (volumes == null) {
112  volumes = new int[this.maxSlotIndex + 1]; // initialized to 0 by default, according to JVM specs
113  modeVolumes.put(mode, volumes);
114  }
115  volumes[timeslot]++;
116  }
117  }
final IdMap< Link, Map< String, int[]> > linksPerMode
final IdMap< Vehicle, String > enRouteModes
int getTimeSlotIndex(final double time)
final IdMap< Link, int[]> links
Here is the call graph for this function:

◆ getTimeSlotIndex()

int org.matsim.analysis.VolumesAnalyzer.getTimeSlotIndex ( final double  time)
private

◆ getVolumesForLink() [1/2]

int [] org.matsim.analysis.VolumesAnalyzer.getVolumesForLink ( final Id< Link linkId)
Parameters
linkId
Returns
Array containing the number of vehicles leaving the link linkId per time bin, starting with time bin 0 from 0 seconds to (timeBinSize-1)seconds.

Definition at line 131 of file VolumesAnalyzer.java.

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

Referenced by org.matsim.analysis.VolumesAnalyzer.getVolumesPerHourForLink().

131  {
132  return this.links.get(linkId);
133  }
final IdMap< Link, int[]> links
Here is the call graph for this function:

◆ getVolumesForLink() [2/2]

int [] org.matsim.analysis.VolumesAnalyzer.getVolumesForLink ( final Id< Link linkId,
String  mode 
)
Parameters
linkId
mode
Returns
Array containing the number of vehicles using the specified mode leaving the link linkId per time bin, starting with time bin 0 from 0 seconds to (timeBinSize-1)seconds.

Definition at line 141 of file VolumesAnalyzer.java.

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

141  {
142  if (observeModes) {
143  Map<String, int[]> modeVolumes = this.linksPerMode.get(linkId);
144  if (modeVolumes != null) return modeVolumes.get(mode);
145  }
146  return null;
147  }
final IdMap< Link, Map< String, int[]> > linksPerMode
Here is the call graph for this function:

◆ getVolumesArraySize()

int org.matsim.analysis.VolumesAnalyzer.getVolumesArraySize ( )
Returns
The size of the arrays returned by calls to the getVolumesForLink(Id) and the getVolumesForLink(Id, String) methods.

Definition at line 153 of file VolumesAnalyzer.java.

153  {
154  return this.maxSlotIndex + 1;
155  }

◆ getVolumesPerHourForLink() [1/2]

double [] org.matsim.analysis.VolumesAnalyzer.getVolumesPerHourForLink ( final Id< Link linkId)

Definition at line 177 of file VolumesAnalyzer.java.

References org.matsim.analysis.VolumesAnalyzer.getTimeSlotIndex(), org.matsim.analysis.VolumesAnalyzer.getVolumesForLink(), and org.matsim.analysis.VolumesAnalyzer.timeBinSize.

Referenced by org.matsim.analysis.CalcLinkStats.addData(), and org.matsim.counts.algorithms.CountsComparisonAlgorithm.CountsComparisonAlgorithm().

177  {
178  if (3600.0 % this.timeBinSize != 0) log.error("Volumes per hour and per link probably not correct!");
179 
180  double[] volumes = new double[24];
181 
182  int[] volumesForLink = this.getVolumesForLink(linkId);
183  if (volumesForLink == null) return volumes;
184 
185  int slotsPerHour = (int) (3600.0 / this.timeBinSize);
186  for (int hour = 0; hour < 24; hour++) {
187  double time = hour * 3600.0;
188  for (int i = 0; i < slotsPerHour; i++) {
189  volumes[hour] += volumesForLink[this.getTimeSlotIndex(time)];
190  time += this.timeBinSize;
191  }
192  }
193  return volumes;
194  }
int [] getVolumesForLink(final Id< Link > linkId)
int getTimeSlotIndex(final double time)
Here is the call graph for this function:

◆ getVolumesPerHourForLink() [2/2]

double [] org.matsim.analysis.VolumesAnalyzer.getVolumesPerHourForLink ( final Id< Link linkId,
String  mode 
)

Definition at line 196 of file VolumesAnalyzer.java.

References org.matsim.analysis.VolumesAnalyzer.getTimeSlotIndex(), org.matsim.analysis.VolumesAnalyzer.getVolumesForLink(), and org.matsim.analysis.VolumesAnalyzer.timeBinSize.

196  {
197  if (observeModes) {
198  if (3600.0 % this.timeBinSize != 0) log.error("Volumes per hour and per link probably not correct!");
199 
200  double[] volumes = new double[24];
201  for (int hour = 0; hour < 24; hour++) {
202  volumes[hour] = 0.0;
203  }
204 
205  int[] volumesForLink = this.getVolumesForLink(linkId, mode);
206  if (volumesForLink == null) return volumes;
207 
208  int slotsPerHour = (int) (3600.0 / this.timeBinSize);
209  for (int hour = 0; hour < 24; hour++) {
210  double time = hour * 3600.0;
211  for (int i = 0; i < slotsPerHour; i++) {
212  volumes[hour] += volumesForLink[this.getTimeSlotIndex(time)];
213  time += this.timeBinSize;
214  }
215  }
216  return volumes;
217  }
218  return null;
219  }
int [] getVolumesForLink(final Id< Link > linkId)
int getTimeSlotIndex(final double time)
Here is the call graph for this function:

◆ getModes()

Set<String> org.matsim.analysis.VolumesAnalyzer.getModes ( )
Returns
Set of Strings containing all modes for which counting-values are available.

Definition at line 224 of file VolumesAnalyzer.java.

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

224  {
225  Set<String> modes = new TreeSet<>();
226 
227  for (Map<String, int[]> map : this.linksPerMode.values()) {
228  try {
229  modes.addAll(map.keySet());
230  } catch (NullPointerException ex) {
231  // Fails on initialized entries, which can happen during tests
232  // will just be ignored here
233  }
234  }
235 
236  return modes;
237  }
final IdMap< Link, Map< String, int[]> > linksPerMode
Here is the call graph for this function:

◆ getLinkIds()

Set<Id<Link> > org.matsim.analysis.VolumesAnalyzer.getLinkIds ( )
Returns
Set of Strings containing all link ids for which counting-values are available.

Definition at line 242 of file VolumesAnalyzer.java.

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

242  {
243  return this.links.keySet();
244  }
final IdMap< Link, int[]> links
Here is the call graph for this function:

◆ reset()

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

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

247  {
248  this.links.clear();
249  if (observeModes) {
250  this.linksPerMode.clear();
251  this.enRouteModes.clear();
252  }
253  }
final IdMap< Link, Map< String, int[]> > linksPerMode
final IdMap< Vehicle, String > enRouteModes
final IdMap< Link, int[]> links
Here is the call graph for this function:

Member Data Documentation

◆ log

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

Definition at line 49 of file VolumesAnalyzer.java.

◆ timeBinSize

final int org.matsim.analysis.VolumesAnalyzer.timeBinSize
private

◆ maxTime

final int org.matsim.analysis.VolumesAnalyzer.maxTime
private

◆ maxSlotIndex

final int org.matsim.analysis.VolumesAnalyzer.maxSlotIndex
private

◆ links

final IdMap<Link, int[]> org.matsim.analysis.VolumesAnalyzer.links
private

Definition at line 53 of file VolumesAnalyzer.java.

◆ observeModes

final boolean org.matsim.analysis.VolumesAnalyzer.observeModes
private

◆ enRouteModes

final IdMap<Vehicle, String> org.matsim.analysis.VolumesAnalyzer.enRouteModes
private

Definition at line 57 of file VolumesAnalyzer.java.

◆ linksPerMode

final IdMap<Link, Map<String, int[]> > org.matsim.analysis.VolumesAnalyzer.linksPerMode
private

Definition at line 58 of file VolumesAnalyzer.java.


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