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

Classes

class  LineData
 
class  RouteData
 
class  StopData
 
class  StopInformation
 
class  VehicleData
 

Public Member Functions

 TransitLoad ()
 
int getLoadAtDeparture (final TransitLine line, final TransitRoute route, final TransitStopFacility stopFacility, final Departure departure)
 
int getLoadAtDeparture (final TransitLine line, final TransitRoute route, final int transitRouteStopIndex, final Departure departure)
 
List< StopInformationgetDepartureStopInformation (final TransitLine line, final TransitRoute route, final TransitStopFacility stopFacility, final Departure departure)
 
void handleEvent (TransitDriverStartsEvent event)
 
void handleEvent (final VehicleArrivesAtFacilityEvent event)
 
void handleEvent (final VehicleDepartsAtFacilityEvent event)
 
void handleEvent (final PersonEntersVehicleEvent event)
 
void handleEvent (final PersonLeavesVehicleEvent event)
 
void reset (final int iteration)
 

Private Member Functions

List< StopInformationgetStopInformation (final Id< TransitLine > lineId, final Id< TransitRoute > routeId, final Id< TransitStopFacility > stopFacilityId, final Id< Departure > departureId, final boolean createIfMissing)
 

Private Attributes

final Map< Id< TransitLine >, LineData > lineData = new HashMap<>()
 
final Map< Id< Vehicle >, Id< TransitStopFacility > > vehicleFacilityMap = new HashMap<>()
 
final Map< Id< Vehicle >, VehicleDatavehicleData = new HashMap<>()
 

Detailed Description

Calculates the number of passenger that are in a transit vehicle when the vehicle departs a stop location.

Author
mrieser

Definition at line 52 of file TransitLoad.java.

Constructor & Destructor Documentation

◆ TransitLoad()

org.matsim.pt.analysis.TransitLoad.TransitLoad ( )

Definition at line 59 of file TransitLoad.java.

59  {
60  }

Member Function Documentation

◆ getLoadAtDeparture() [1/2]

int org.matsim.pt.analysis.TransitLoad.getLoadAtDeparture ( final TransitLine  line,
final TransitRoute  route,
final TransitStopFacility  stopFacility,
final Departure  departure 
)

Always returns first occurence of the TransitStopFacility in the route.

Parameters
line
route
stopFacility
departure
Returns

Definition at line 72 of file TransitLoad.java.

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

72  {
73  for (int i = 0; i < route.getStops().size(); i++) {
74  if (route.getStops().get(i).getStopFacility().getId().equals(stopFacility.getId())) {
75  return getLoadAtDeparture(line, route, i, departure);
76  }
77  }
78  return -1;
79  }
int getLoadAtDeparture(final TransitLine line, final TransitRoute route, final TransitStopFacility stopFacility, final Departure departure)
Here is the call graph for this function:

◆ getLoadAtDeparture() [2/2]

int org.matsim.pt.analysis.TransitLoad.getLoadAtDeparture ( final TransitLine  line,
final TransitRoute  route,
final int  transitRouteStopIndex,
final Departure  departure 
)

Definition at line 81 of file TransitLoad.java.

References org.matsim.api.core.v01.Identifiable< T >.getId(), org.matsim.pt.transitSchedule.api.TransitRouteStop.getStopFacility(), org.matsim.pt.analysis.TransitLoad.getStopInformation(), org.matsim.pt.transitSchedule.api.TransitRoute.getStops(), org.matsim.pt.analysis.TransitLoad.StopInformation.nOfEntering, and org.matsim.pt.analysis.TransitLoad.StopInformation.nOfLeaving.

81  {
82  int nOfPassengers = 0;
83 
84  /*
85  * count how often a stop was visited while following the route in
86  * route.getStops() to differentiate multiple servings of the same
87  * TransitStopFacility. Count from 0, so count equals index in list
88  */
89  Map<Id<TransitStopFacility>, Integer> stop2nrVisited = new HashMap<>();
90  for (int i = 0; i < route.getStops().size(); i++) {
91  TransitRouteStop stop = route.getStops().get(i);
92  Integer nrVisited = stop2nrVisited.get(stop.getStopFacility().getId());
93  if (nrVisited == null) {
94  nrVisited = 0;
95  } else {
96  nrVisited++;
97  }
98  stop2nrVisited.put(stop.getStopFacility().getId(), nrVisited);
99 
100  List<StopInformation> siList = getStopInformation(line.getId(), route.getId(), stop.getStopFacility().getId(), departure.getId(), false);
101  if (siList != null) {
102  StopInformation si = siList.get(nrVisited);
103  if (si != null) {
104  nOfPassengers -= si.nOfLeaving;
105  nOfPassengers += si.nOfEntering;
106  }
107  }
108  if (i == transitRouteStopIndex) {
109  return nOfPassengers;
110  }
111  }
112  return -1;
113  }
List< StopInformation > getStopInformation(final Id< TransitLine > lineId, final Id< TransitRoute > routeId, final Id< TransitStopFacility > stopFacilityId, final Id< Departure > departureId, final boolean createIfMissing)
Here is the call graph for this function:

◆ getDepartureStopInformation()

List<StopInformation> org.matsim.pt.analysis.TransitLoad.getDepartureStopInformation ( final TransitLine  line,
final TransitRoute  route,
final TransitStopFacility  stopFacility,
final Departure  departure 
)

Definition at line 115 of file TransitLoad.java.

References org.matsim.api.core.v01.Identifiable< T >.getId(), and org.matsim.pt.analysis.TransitLoad.getStopInformation().

115  {
116  return getStopInformation(line.getId(), route.getId(), stopFacility.getId(), departure.getId(), false);
117  }
List< StopInformation > getStopInformation(final Id< TransitLine > lineId, final Id< TransitRoute > routeId, final Id< TransitStopFacility > stopFacilityId, final Id< Departure > departureId, final boolean createIfMissing)
Here is the call graph for this function:

◆ handleEvent() [1/5]

void org.matsim.pt.analysis.TransitLoad.handleEvent ( TransitDriverStartsEvent  event)

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

Definition at line 120 of file TransitLoad.java.

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

120  {
121  this.vehicleData.put(event.getVehicleId(), new VehicleData(event.getVehicleId(), event.getTransitLineId(), event.getTransitRouteId(), event.getDepartureId(), event.getDriverId()));
122  }
final Map< Id< Vehicle >, VehicleData > vehicleData
Here is the call graph for this function:

◆ handleEvent() [2/5]

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

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

Definition at line 125 of file TransitLoad.java.

References org.matsim.pt.analysis.TransitLoad.StopInformation.arrivalTime, org.matsim.pt.analysis.TransitLoad.VehicleData.departureId, org.matsim.pt.analysis.TransitLoad.getStopInformation(), org.matsim.core.api.experimental.events.VehicleArrivesAtFacilityEvent.getVehicleId(), org.matsim.pt.analysis.TransitLoad.VehicleData.lineId, and org.matsim.pt.analysis.TransitLoad.VehicleData.routeId.

125  {
126  this.vehicleFacilityMap.put(event.getVehicleId(), event.getFacilityId());
127  VehicleData vData = this.vehicleData.get(event.getVehicleId());
128  if (vData != null) {
129  List<StopInformation> siList = getStopInformation(vData.lineId, vData.routeId, this.vehicleFacilityMap.get(event.getVehicleId()), vData.departureId, true);
130  // Vehicle arrives at facility -> begin of serving the stop (once more) -> create new StopInformation
131  StopInformation si = new StopInformation();
132  si.arrivalTime = event.getTime();
133  siList.add(si);
134  }
135  }
final Map< Id< Vehicle >, Id< TransitStopFacility > > vehicleFacilityMap
final Map< Id< Vehicle >, VehicleData > vehicleData
List< StopInformation > getStopInformation(final Id< TransitLine > lineId, final Id< TransitRoute > routeId, final Id< TransitStopFacility > stopFacilityId, final Id< Departure > departureId, final boolean createIfMissing)
Here is the call graph for this function:

◆ handleEvent() [3/5]

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

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

Definition at line 138 of file TransitLoad.java.

References org.matsim.pt.analysis.TransitLoad.VehicleData.departureId, org.matsim.pt.analysis.TransitLoad.StopInformation.departureTime, org.matsim.pt.analysis.TransitLoad.getStopInformation(), org.matsim.core.api.experimental.events.VehicleDepartsAtFacilityEvent.getVehicleId(), org.matsim.pt.analysis.TransitLoad.VehicleData.lineId, and org.matsim.pt.analysis.TransitLoad.VehicleData.routeId.

138  {
139  Id<TransitStopFacility> stopId = this.vehicleFacilityMap.remove(event.getVehicleId());
140  VehicleData vData = this.vehicleData.get(event.getVehicleId());
141  if (vData != null) {
142  List<StopInformation> siList = getStopInformation(vData.lineId, vData.routeId, stopId, vData.departureId, true);
143  // Vehicle is already at facility -> add information to last StopInformation
144  StopInformation si = siList.get(siList.size() - 1);
145  si.departureTime = event.getTime();
146  }
147  }
final Map< Id< Vehicle >, Id< TransitStopFacility > > vehicleFacilityMap
final Map< Id< Vehicle >, VehicleData > vehicleData
List< StopInformation > getStopInformation(final Id< TransitLine > lineId, final Id< TransitRoute > routeId, final Id< TransitStopFacility > stopFacilityId, final Id< Departure > departureId, final boolean createIfMissing)
Here is the call graph for this function:

◆ handleEvent() [4/5]

void org.matsim.pt.analysis.TransitLoad.handleEvent ( final PersonEntersVehicleEvent  event)

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

Definition at line 150 of file TransitLoad.java.

References org.matsim.pt.analysis.TransitLoad.VehicleData.departureId, org.matsim.pt.analysis.TransitLoad.VehicleData.driverId, org.matsim.api.core.v01.events.PersonEntersVehicleEvent.getPersonId(), org.matsim.pt.analysis.TransitLoad.getStopInformation(), org.matsim.api.core.v01.events.PersonEntersVehicleEvent.getVehicleId(), org.matsim.pt.analysis.TransitLoad.VehicleData.lineId, org.matsim.pt.analysis.TransitLoad.StopInformation.nOfEntering, and org.matsim.pt.analysis.TransitLoad.VehicleData.routeId.

150  {
151  VehicleData vData = this.vehicleData.get(event.getVehicleId());
152  if (vData != null) {
153  if (!vData.driverId.equals(event.getPersonId())) {
154  List<StopInformation> siList = getStopInformation(vData.lineId, vData.routeId,
155  this.vehicleFacilityMap.get(event.getVehicleId()), vData.departureId, true);
156  // Vehicle is already at facility -> add information to last StopInformation
157  StopInformation si = siList.get(siList.size() - 1);
158  si.nOfEntering++;
159  }
160  }
161  }
final Map< Id< Vehicle >, VehicleData > vehicleData
List< StopInformation > getStopInformation(final Id< TransitLine > lineId, final Id< TransitRoute > routeId, final Id< TransitStopFacility > stopFacilityId, final Id< Departure > departureId, final boolean createIfMissing)
Here is the call graph for this function:

◆ handleEvent() [5/5]

void org.matsim.pt.analysis.TransitLoad.handleEvent ( final PersonLeavesVehicleEvent  event)

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

Definition at line 164 of file TransitLoad.java.

References org.matsim.pt.analysis.TransitLoad.VehicleData.departureId, org.matsim.pt.analysis.TransitLoad.VehicleData.driverId, org.matsim.api.core.v01.events.PersonLeavesVehicleEvent.getPersonId(), org.matsim.pt.analysis.TransitLoad.getStopInformation(), org.matsim.api.core.v01.events.PersonLeavesVehicleEvent.getVehicleId(), org.matsim.pt.analysis.TransitLoad.VehicleData.lineId, org.matsim.pt.analysis.TransitLoad.StopInformation.nOfLeaving, and org.matsim.pt.analysis.TransitLoad.VehicleData.routeId.

164  {
165  VehicleData vData = this.vehicleData.get(event.getVehicleId());
166  if (vData != null) {
167  if (!vData.driverId.equals(event.getPersonId())) {
168  List<StopInformation> siList = getStopInformation(vData.lineId, vData.routeId,
169  this.vehicleFacilityMap.get(event.getVehicleId()), vData.departureId, true);
170  // Vehicle is already at facility -> add information to last StopInformation
171  StopInformation si = siList.get(siList.size() - 1);
172  si.nOfLeaving++;
173  }
174  }
175  }
final Map< Id< Vehicle >, VehicleData > vehicleData
List< StopInformation > getStopInformation(final Id< TransitLine > lineId, final Id< TransitRoute > routeId, final Id< TransitStopFacility > stopFacilityId, final Id< Departure > departureId, final boolean createIfMissing)
Here is the call graph for this function:

◆ reset()

void org.matsim.pt.analysis.TransitLoad.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 178 of file TransitLoad.java.

178  {
179  this.vehicleFacilityMap.clear();
180  this.vehicleData.clear();
181  }
final Map< Id< Vehicle >, Id< TransitStopFacility > > vehicleFacilityMap
final Map< Id< Vehicle >, VehicleData > vehicleData

◆ getStopInformation()

List<StopInformation> org.matsim.pt.analysis.TransitLoad.getStopInformation ( final Id< TransitLine lineId,
final Id< TransitRoute routeId,
final Id< TransitStopFacility stopFacilityId,
final Id< Departure departureId,
final boolean  createIfMissing 
)
private

Definition at line 183 of file TransitLoad.java.

Referenced by org.matsim.pt.analysis.TransitLoad.getDepartureStopInformation(), org.matsim.pt.analysis.TransitLoad.getLoadAtDeparture(), and org.matsim.pt.analysis.TransitLoad.handleEvent().

183  {
184  LineData ld = this.lineData.get(lineId);
185  if (ld == null) {
186  if (createIfMissing) {
187  ld = new LineData();
188  this.lineData.put(lineId, ld);
189  } else {
190  return null;
191  }
192  }
193 
194  RouteData rd = ld.routeData.get(routeId);
195  if (rd == null) {
196  if (createIfMissing) {
197  rd = new RouteData();
198  ld.routeData.put(routeId, rd);
199  } else {
200  return null;
201  }
202  }
203 
204  StopData sd = rd.stopData.get(stopFacilityId);
205  if (sd == null) {
206  if (createIfMissing) {
207  sd = new StopData();
208  rd.stopData.put(stopFacilityId, sd);
209  } else {
210  return null;
211  }
212  }
213 
214  List<StopInformation> siList = sd.departureData.get(departureId);
215  if (siList == null) {
216  if (createIfMissing) {
217  siList = new ArrayList<>();
218  sd.departureData.put(departureId, siList);
219  } else {
220  return null;
221  }
222  }
223  return siList;
224  }
final Map< Id< TransitLine >, LineData > lineData

Member Data Documentation

◆ lineData

final Map<Id<TransitLine>, LineData> org.matsim.pt.analysis.TransitLoad.lineData = new HashMap<>()
private

Definition at line 54 of file TransitLoad.java.

◆ vehicleFacilityMap

final Map<Id<Vehicle>, Id<TransitStopFacility> > org.matsim.pt.analysis.TransitLoad.vehicleFacilityMap = new HashMap<>()
private

Definition at line 56 of file TransitLoad.java.

◆ vehicleData

final Map<Id<Vehicle>, VehicleData> org.matsim.pt.analysis.TransitLoad.vehicleData = new HashMap<>()
private

Definition at line 57 of file TransitLoad.java.


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