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

Public Member Functions

 OccupancyAnalyzer (final int timeBinSize, final double maxTime)
 
void setBoards (Map< Id< TransitStopFacility >, int[]> boards)
 
void setAlights (Map< Id< TransitStopFacility >, int[]> alights)
 
void setOccupancies (Map< Id< TransitStopFacility >, int[]> occupancies)
 
int getTimeSlotIndex (final double time)
 
void reset (int iteration)
 
void handleEvent (TransitDriverStartsEvent event)
 
void handleEvent (PersonEntersVehicleEvent event)
 
void handleEvent (PersonLeavesVehicleEvent event)
 
void handleEvent (VehicleArrivesAtFacilityEvent event)
 
void handleEvent (VehicleDepartsAtFacilityEvent event)
 
int [] getBoardVolumesForStop (final Id< TransitStopFacility > stopId)
 
int [] getAlightVolumesForStop (final Id< TransitStopFacility > stopId)
 
int [] getOccupancyVolumesForStop (final Id< TransitStopFacility > stopId)
 
Set< Id< TransitStopFacility > > getBoardStopIds ()
 
Set< Id< TransitStopFacility > > getAlightStopIds ()
 
Set< Id< TransitStopFacility > > getOccupancyStopIds ()
 
Set< Id< TransitStopFacility > > getAllStopIds ()
 
void write (String filename)
 

Private Attributes

final int timeBinSize
 
final double maxTime
 
Map< Id< TransitStopFacility >, int[]> boards
 
final Map< Id< Vehicle >, Id< TransitStopFacility > > vehStops = new HashMap<>()
 
final Map< Id< Vehicle >, Integer > vehPassengers = new HashMap<>()
 
StringBuffer occupancyRecord = new StringBuffer("time\tvehId\tStopId\tno.ofPassengersInVeh\n")
 
final Set< Id< Person > > transitDrivers = new HashSet<>()
 
final Set< Id< Vehicle > > transitVehicles = new HashSet<>()
 

Static Private Attributes

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

Detailed Description

Author
yChen
mrieser / senozon

Definition at line 52 of file OccupancyAnalyzer.java.

Constructor & Destructor Documentation

◆ OccupancyAnalyzer()

org.matsim.pt.counts.OccupancyAnalyzer.OccupancyAnalyzer ( final int  timeBinSize,
final double  maxTime 
)

Definition at line 71 of file OccupancyAnalyzer.java.

References org.matsim.pt.counts.OccupancyAnalyzer.maxTime, and org.matsim.pt.counts.OccupancyAnalyzer.timeBinSize.

71  {
72  this.timeBinSize = timeBinSize;
73  this.maxTime = maxTime;
74  this.maxSlotIndex = ((int) this.maxTime) / this.timeBinSize + 1;
75  this.boards = new IdMap<>(TransitStopFacility.class);
76  this.alights = new IdMap<>(TransitStopFacility.class);
77  this.occupancies = new IdMap<>(TransitStopFacility.class);
78  }
Map< Id< TransitStopFacility >, int[]> boards

Member Function Documentation

◆ setBoards()

void org.matsim.pt.counts.OccupancyAnalyzer.setBoards ( Map< Id< TransitStopFacility >, int[]>  boards)

Definition at line 80 of file OccupancyAnalyzer.java.

References org.matsim.pt.counts.OccupancyAnalyzer.boards.

80  {
81  this.boards = boards;
82  }
Map< Id< TransitStopFacility >, int[]> boards

◆ setAlights()

void org.matsim.pt.counts.OccupancyAnalyzer.setAlights ( Map< Id< TransitStopFacility >, int[]>  alights)

Definition at line 84 of file OccupancyAnalyzer.java.

84  {
85  this.alights = alights;
86  }

◆ setOccupancies()

void org.matsim.pt.counts.OccupancyAnalyzer.setOccupancies ( Map< Id< TransitStopFacility >, int[]>  occupancies)

Definition at line 88 of file OccupancyAnalyzer.java.

88  {
89  this.occupancies = occupancies;
90  }

◆ getTimeSlotIndex()

int org.matsim.pt.counts.OccupancyAnalyzer.getTimeSlotIndex ( final double  time)

Definition at line 92 of file OccupancyAnalyzer.java.

Referenced by org.matsim.pt.counts.OccupancyAnalyzer.handleEvent().

92  {
93  if (time > this.maxTime) {
94  return this.maxSlotIndex;
95  }
96  return ((int) time / this.timeBinSize);
97  }

◆ reset()

void org.matsim.pt.counts.OccupancyAnalyzer.reset ( 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 100 of file OccupancyAnalyzer.java.

Referenced by org.matsim.pt.counts.PtCountControlerListener.notifyBeforeMobsim().

100  {
101  this.boards.clear();
102  this.alights.clear();
103  this.occupancies.clear();
104  this.vehStops.clear();
105  this.vehPassengers.clear();
106  this.occupancyRecord = new StringBuffer("time\tvehId\tStopId\tno.ofPassengersInVeh\n");
107  this.transitDrivers.clear();
108  this.transitVehicles.clear();
109  }
final Map< Id< Vehicle >, Integer > vehPassengers
Map< Id< TransitStopFacility >, int[]> boards
final Set< Id< Person > > transitDrivers
final Set< Id< Vehicle > > transitVehicles
final Map< Id< Vehicle >, Id< TransitStopFacility > > vehStops

◆ handleEvent() [1/5]

void org.matsim.pt.counts.OccupancyAnalyzer.handleEvent ( TransitDriverStartsEvent  event)

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

Definition at line 112 of file OccupancyAnalyzer.java.

References org.matsim.api.core.v01.events.TransitDriverStartsEvent.getDriverId(), and org.matsim.api.core.v01.events.TransitDriverStartsEvent.getVehicleId().

112  {
113  this.transitDrivers.add(event.getDriverId());
114  this.transitVehicles.add(event.getVehicleId());
115  }
final Set< Id< Person > > transitDrivers
final Set< Id< Vehicle > > transitVehicles
Here is the call graph for this function:

◆ handleEvent() [2/5]

void org.matsim.pt.counts.OccupancyAnalyzer.handleEvent ( PersonEntersVehicleEvent  event)

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

Definition at line 118 of file OccupancyAnalyzer.java.

References org.matsim.api.core.v01.Id< T >.get(), org.matsim.api.core.v01.events.PersonEntersVehicleEvent.getPersonId(), org.matsim.pt.counts.OccupancyAnalyzer.getTimeSlotIndex(), and org.matsim.api.core.v01.events.PersonEntersVehicleEvent.getVehicleId().

118  {
119  if (this.transitDrivers.contains(event.getPersonId()) || !this.transitVehicles.contains(event.getVehicleId())) {
120  return; // ignore transit drivers or persons entering non-transit vehicles
121  }
122 
123  Id<Vehicle> vehId = event.getVehicleId();
124  Id<TransitStopFacility> stopId = this.vehStops.get(vehId);
125  double time = event.getTime();
126  // --------------------------getOns---------------------------
127  int[] getOn = this.boards.get(stopId);
128  if (getOn == null) {
129  getOn = new int[this.maxSlotIndex + 1];
130  this.boards.put(stopId, getOn);
131  }
132  getOn[getTimeSlotIndex(time)]++;
133  // ------------------------veh_passenger---------------------------
134  Integer nPassengers = this.vehPassengers.get(vehId);
135  this.vehPassengers.put(vehId, (nPassengers != null) ? (nPassengers + 1) : 1);
136  this.occupancyRecord.append("time :\t").append(time).append(" veh :\t").append(vehId).append(" has Passenger\t").append(this.vehPassengers.get(vehId)).append(" \tat stop :\t").append(stopId).append(" ENTERING PERSON :\t").append(event.getPersonId()).append("\n");
137  }
final Map< Id< Vehicle >, Integer > vehPassengers
Map< Id< TransitStopFacility >, int[]> boards
final Set< Id< Person > > transitDrivers
final Set< Id< Vehicle > > transitVehicles
final Map< Id< Vehicle >, Id< TransitStopFacility > > vehStops
Here is the call graph for this function:

◆ handleEvent() [3/5]

void org.matsim.pt.counts.OccupancyAnalyzer.handleEvent ( PersonLeavesVehicleEvent  event)

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

Definition at line 140 of file OccupancyAnalyzer.java.

References org.matsim.api.core.v01.Id< T >.get(), org.matsim.api.core.v01.events.PersonLeavesVehicleEvent.getPersonId(), org.matsim.pt.counts.OccupancyAnalyzer.getTimeSlotIndex(), and org.matsim.api.core.v01.events.PersonLeavesVehicleEvent.getVehicleId().

140  {
141  if (this.transitDrivers.contains(event.getPersonId()) || !this.transitVehicles.contains(event.getVehicleId())) {
142  return; // ignore transit drivers or persons entering non-transit vehicles
143  }
144 
145  Id<Vehicle> vehId = event.getVehicleId();
146  Id<TransitStopFacility> stopId = this.vehStops.get(vehId);
147  double time = event.getTime();
148  // --------------------------getDowns---------------------------
149  int[] getDown = this.alights.get(stopId);
150  if (getDown == null) {
151  getDown = new int[this.maxSlotIndex + 1];
152  this.alights.put(stopId, getDown);
153  }
154  getDown[getTimeSlotIndex(time)]++;
155  // ------------------------veh_passenger---------------------------
156  Integer nPassengers = this.vehPassengers.get(vehId);
157  if (nPassengers == null) {
158  log.error( "tests for `null' but exception says 'negative'??? kai, oct'10 ") ;
159  throw new RuntimeException("negative passenger-No. in vehicle?");
160  }
161  this.vehPassengers.put(vehId, nPassengers - 1);
162  if (this.vehPassengers.get(vehId).intValue() == 0) {
163  this.vehPassengers.remove(vehId);
164  }
165 
166  Integer passengers = this.vehPassengers.get(vehId);
167  this.occupancyRecord.append("time :\t").append(time).append(" veh :\t").append(vehId).append(" has Passenger\t").append((passengers != null) ? passengers : 0).append("\n");
168  }
final Map< Id< Vehicle >, Integer > vehPassengers
final Set< Id< Person > > transitDrivers
final Set< Id< Vehicle > > transitVehicles
final Map< Id< Vehicle >, Id< TransitStopFacility > > vehStops
Here is the call graph for this function:

◆ handleEvent() [4/5]

void org.matsim.pt.counts.OccupancyAnalyzer.handleEvent ( VehicleArrivesAtFacilityEvent  event)

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

Definition at line 171 of file OccupancyAnalyzer.java.

References org.matsim.core.api.experimental.events.VehicleArrivesAtFacilityEvent.getVehicleId().

171  {
172  Id<TransitStopFacility> stopId = event.getFacilityId();
173  this.vehStops.put(event.getVehicleId(), stopId);
174  }
final Map< Id< Vehicle >, Id< TransitStopFacility > > vehStops
Here is the call graph for this function:

◆ handleEvent() [5/5]

void org.matsim.pt.counts.OccupancyAnalyzer.handleEvent ( VehicleDepartsAtFacilityEvent  event)

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

Definition at line 177 of file OccupancyAnalyzer.java.

References org.matsim.api.core.v01.Id< T >.get(), org.matsim.api.core.v01.events.Event.getTime(), and org.matsim.pt.counts.OccupancyAnalyzer.getTimeSlotIndex().

177  {
178  Id<TransitStopFacility> stopId = event.getFacilityId();
179  Id<Vehicle> vehId = event.getVehicleId();
180  this.vehStops.remove(vehId);
181  // -----------------------occupancy--------------------------------
182  int[] occupancyAtStop = this.occupancies.get(stopId);
183 
184  if (occupancyAtStop == null) {
185  // no previous departure from this stop, therefore no occupancy record yet. Create this:
186  occupancyAtStop = new int[this.maxSlotIndex + 1];
187  this.occupancies.put(stopId, occupancyAtStop);
188  }
189 
190  Integer noPassengersInVeh = this.vehPassengers.get(vehId);
191 
192  if (noPassengersInVeh != null) {
193  occupancyAtStop[this.getTimeSlotIndex(event.getTime())] += noPassengersInVeh;
194 
195  this.occupancyRecord.append(event.getTime());
196  this.occupancyRecord.append("\t");
197  this.occupancyRecord.append(vehId);
198  this.occupancyRecord.append("\t");
199  this.occupancyRecord.append(stopId);
200  this.occupancyRecord.append("\t");
201  this.occupancyRecord.append(noPassengersInVeh);
202  this.occupancyRecord.append("\n");
203  }
204  }
final Map< Id< Vehicle >, Integer > vehPassengers
final Map< Id< Vehicle >, Id< TransitStopFacility > > vehStops
Here is the call graph for this function:

◆ getBoardVolumesForStop()

int [] org.matsim.pt.counts.OccupancyAnalyzer.getBoardVolumesForStop ( final Id< TransitStopFacility stopId)
Parameters
stopId
Returns
Array containing the number of agents boarding at the stop stopId per time bin, starting with time bin 0 from 0 seconds to (timeBinSize-1)seconds.

Definition at line 212 of file OccupancyAnalyzer.java.

Referenced by org.matsim.pt.counts.PtCountControlerListener.notifyIterationEnds().

212  {
213  int[] values = this.boards.get(stopId);
214  if (values == null) {
215  return new int[this.maxSlotIndex + 1];
216  }
217  return values;
218  }
Map< Id< TransitStopFacility >, int[]> boards

◆ getAlightVolumesForStop()

int [] org.matsim.pt.counts.OccupancyAnalyzer.getAlightVolumesForStop ( final Id< TransitStopFacility stopId)
Parameters
stopId
Returns
Array containing the number of agents alighting at the stop
stopId
per time bin, starting with time bin 0 from 0 seconds to (timeBinSize-1)seconds.

Definition at line 226 of file OccupancyAnalyzer.java.

Referenced by org.matsim.pt.counts.PtCountControlerListener.notifyIterationEnds().

226  {
227  int[] values = this.alights.get(stopId);
228  if (values == null) {
229  return new int[this.maxSlotIndex + 1];
230  }
231  return values;
232  }

◆ getOccupancyVolumesForStop()

int [] org.matsim.pt.counts.OccupancyAnalyzer.getOccupancyVolumesForStop ( final Id< TransitStopFacility stopId)
Parameters
stopId
Returns
Array containing the number of passengers in bus after the transfer at the stop
stopId
per time bin, starting with time bin 0 from 0 seconds to (timeBinSize-1)seconds.

Definition at line 240 of file OccupancyAnalyzer.java.

Referenced by org.matsim.pt.counts.PtCountControlerListener.notifyIterationEnds().

240  {
241  int[] values = this.occupancies.get(stopId);
242  if (values == null) {
243  return new int[this.maxSlotIndex + 1];
244  }
245  return values;
246  }

◆ getBoardStopIds()

Set<Id<TransitStopFacility> > org.matsim.pt.counts.OccupancyAnalyzer.getBoardStopIds ( )
Returns
Set of
Id
s containing all stop ids, where the agents boarded, for which counting-values are available.

Definition at line 252 of file OccupancyAnalyzer.java.

Referenced by org.matsim.pt.counts.OccupancyAnalyzer.getAllStopIds().

252  {
253  return this.boards.keySet();
254  }
Map< Id< TransitStopFacility >, int[]> boards

◆ getAlightStopIds()

Set<Id<TransitStopFacility> > org.matsim.pt.counts.OccupancyAnalyzer.getAlightStopIds ( )
Returns
Set of
Id
s containing all stop ids, where the agents alit, for which counting-values are available.

Definition at line 260 of file OccupancyAnalyzer.java.

Referenced by org.matsim.pt.counts.OccupancyAnalyzer.getAllStopIds().

260  {
261  return this.alights.keySet();
262  }

◆ getOccupancyStopIds()

Set<Id<TransitStopFacility> > org.matsim.pt.counts.OccupancyAnalyzer.getOccupancyStopIds ( )

Definition at line 264 of file OccupancyAnalyzer.java.

Referenced by org.matsim.pt.counts.OccupancyAnalyzer.getAllStopIds().

264  {
265  return this.occupancies.keySet();
266  }

◆ getAllStopIds()

Set<Id<TransitStopFacility> > org.matsim.pt.counts.OccupancyAnalyzer.getAllStopIds ( )
Returns
Set of
Id
s containing all stop ids, where the agents alit or/and boarded, for which counting-values are available.

Definition at line 272 of file OccupancyAnalyzer.java.

References org.matsim.pt.counts.OccupancyAnalyzer.getAlightStopIds(), org.matsim.pt.counts.OccupancyAnalyzer.getBoardStopIds(), and org.matsim.pt.counts.OccupancyAnalyzer.getOccupancyStopIds().

Referenced by org.matsim.pt.counts.OccupancyAnalyzer.write().

272  {
273  Set<Id<TransitStopFacility>> allStopIds = new TreeSet<>();
274  allStopIds.addAll(getBoardStopIds());
275  allStopIds.addAll(getAlightStopIds());
276  allStopIds.addAll(getOccupancyStopIds());
277  return allStopIds;
278  }
Set< Id< TransitStopFacility > > getAlightStopIds()
Set< Id< TransitStopFacility > > getBoardStopIds()
Set< Id< TransitStopFacility > > getOccupancyStopIds()
Here is the call graph for this function:

◆ write()

void org.matsim.pt.counts.OccupancyAnalyzer.write ( String  filename)

Definition at line 280 of file OccupancyAnalyzer.java.

References org.matsim.pt.counts.SimpleWriter.close(), org.matsim.pt.counts.OccupancyAnalyzer.getAllStopIds(), org.matsim.pt.counts.SimpleWriter.write(), and org.matsim.pt.counts.SimpleWriter.writeln().

Referenced by org.matsim.pt.counts.PtCountControlerListener.notifyAfterMobsim().

280  {
281  SimpleWriter writer = new SimpleWriter(filename);
282  // write filehead
283  writer.write("stopId\t");
284  for (int i = 0; i < 24; i++) {
285  writer.write("bo" + i + "-" + (i + 1) + "\t");
286  }
287  for (int i = 0; i < 24; i++) {
288  writer.write("al" + i + "-" + (i + 1) + "\t");
289  }
290  for (int i = 0; i < 24; i++) {
291  writer.write("oc" + i + "-" + (i + 1) + "\t");
292  }
293  writer.writeln();
294  // write content
295  for (Id<TransitStopFacility> stopId : getAllStopIds()) {
296  writer.write(stopId + "\t");
297 
298  int[] board = this.boards.get(stopId);
299  if (board == null){
300  log.debug("stopId:\t" + stopId + "\thas null boards!");
301  }
302  for (int i = 0; i < 24; i++) {
303  writer.write((board != null ? board[i] : 0) + "\t");
304  }
305 
306  int[] alight = this.alights.get(stopId);
307  if (alight == null) {
308  log.debug("stopId:\t" + stopId + "\thas null alights!");
309  }
310  for (int i = 0; i < 24; i++) {
311  writer.write((alight != null ? alight[i] : 0) + "\t");
312  }
313 
314  int[] ocuppancy = this.occupancies.get(stopId);
315  if (ocuppancy == null) {
316  log.debug("stopId:\t" + stopId + "\tthere aren't passengers in Bus after the transfer!");
317  }
318  for (int i = 0; i < 24; i++) {
319  writer.write((ocuppancy != null ? ocuppancy[i] : 0) + "\t");
320  }
321  writer.writeln();
322  }
323  writer.write(this.occupancyRecord.toString());
324  writer.close();
325  }
Map< Id< TransitStopFacility >, int[]> boards
Set< Id< TransitStopFacility > > getAllStopIds()
Here is the call graph for this function:

Member Data Documentation

◆ log

final Logger org.matsim.pt.counts.OccupancyAnalyzer.log = LogManager.getLogger(OccupancyAnalyzer.class)
staticprivate

Definition at line 55 of file OccupancyAnalyzer.java.

◆ timeBinSize

final int org.matsim.pt.counts.OccupancyAnalyzer.timeBinSize
private

◆ maxTime

final double org.matsim.pt.counts.OccupancyAnalyzer.maxTime
private

◆ boards

Map<Id<TransitStopFacility>, int[]> org.matsim.pt.counts.OccupancyAnalyzer.boards
private

Map< stopFacilityId,value[]>

Definition at line 60 of file OccupancyAnalyzer.java.

Referenced by org.matsim.pt.counts.OccupancyAnalyzer.setBoards().

◆ vehStops

final Map<Id<Vehicle>, Id<TransitStopFacility> > org.matsim.pt.counts.OccupancyAnalyzer.vehStops = new HashMap<>()
private

Map< vehId,stopFacilityId>

Definition at line 64 of file OccupancyAnalyzer.java.

◆ vehPassengers

final Map<Id<Vehicle>, Integer> org.matsim.pt.counts.OccupancyAnalyzer.vehPassengers = new HashMap<>()
private

Map<vehId,passengersNo. in Veh>

Definition at line 66 of file OccupancyAnalyzer.java.

◆ occupancyRecord

StringBuffer org.matsim.pt.counts.OccupancyAnalyzer.occupancyRecord = new StringBuffer("time\tvehId\tStopId\tno.ofPassengersInVeh\n")
private

Definition at line 67 of file OccupancyAnalyzer.java.

◆ transitDrivers

final Set<Id<Person> > org.matsim.pt.counts.OccupancyAnalyzer.transitDrivers = new HashSet<>()
private

Definition at line 68 of file OccupancyAnalyzer.java.

◆ transitVehicles

final Set<Id<Vehicle> > org.matsim.pt.counts.OccupancyAnalyzer.transitVehicles = new HashSet<>()
private

Definition at line 69 of file OccupancyAnalyzer.java.


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