21 package org.matsim.pt.counts;
23 import org.apache.logging.log4j.Level;
24 import org.apache.logging.log4j.LogManager;
25 import org.apache.logging.log4j.Logger;
42 import java.util.HashMap;
43 import java.util.HashSet;
46 import java.util.TreeSet;
60 private Map<Id<TransitStopFacility>,
int[]>
boards, alights, occupancies;
66 private final Map<Id<Vehicle>, Integer>
vehPassengers =
new HashMap<>();
67 private StringBuffer
occupancyRecord =
new StringBuffer(
"time\tvehId\tStopId\tno.ofPassengersInVeh\n");
74 this.maxSlotIndex = ((int) this.maxTime) / this.timeBinSize + 1;
85 this.alights = alights;
89 this.occupancies = occupancies;
93 if (time > this.maxTime) {
94 return this.maxSlotIndex;
96 return ((
int) time / this.timeBinSize);
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();
119 if (this.transitDrivers.contains(event.
getPersonId()) || !this.transitVehicles.contains(event.
getVehicleId())) {
125 double time =
event.getTime();
127 int[] getOn = this.boards.get(stopId);
129 getOn =
new int[this.maxSlotIndex + 1];
130 this.boards.put(stopId, getOn);
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");
141 if (this.transitDrivers.contains(event.
getPersonId()) || !this.transitVehicles.contains(event.
getVehicleId())) {
147 double time =
event.getTime();
149 int[] getDown = this.alights.get(stopId);
150 if (getDown == null) {
151 getDown =
new int[this.maxSlotIndex + 1];
152 this.alights.put(stopId, getDown);
156 Integer nPassengers = this.vehPassengers.get(vehId);
157 if (nPassengers == null) {
158 log.error(
"tests for `null' but exception says 'negative'??? kai, oct'10 ") ;
161 this.vehPassengers.put(vehId, nPassengers - 1);
162 if (this.vehPassengers.get(vehId).intValue() == 0) {
163 this.vehPassengers.remove(vehId);
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");
180 this.vehStops.remove(vehId);
182 int[] occupancyAtStop = this.occupancies.
get(stopId);
184 if (occupancyAtStop == null) {
186 occupancyAtStop =
new int[this.maxSlotIndex + 1];
187 this.occupancies.put(stopId, occupancyAtStop);
190 Integer noPassengersInVeh = this.vehPassengers.get(vehId);
192 if (noPassengersInVeh != null) {
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");
213 int[] values = this.boards.get(stopId);
214 if (values == null) {
215 return new int[this.maxSlotIndex + 1];
227 int[] values = this.alights.get(stopId);
228 if (values == null) {
229 return new int[this.maxSlotIndex + 1];
241 int[] values = this.occupancies.get(stopId);
242 if (values == null) {
243 return new int[this.maxSlotIndex + 1];
253 return this.boards.keySet();
261 return this.alights.keySet();
265 return this.occupancies.keySet();
273 Set<Id<TransitStopFacility>> allStopIds =
new TreeSet<>();
280 public void write(String filename) {
283 writer.
write(
"stopId\t");
284 for (
int i = 0; i < 24; i++) {
285 writer.
write(
"bo" + i +
"-" + (i + 1) +
"\t");
287 for (
int i = 0; i < 24; i++) {
288 writer.
write(
"al" + i +
"-" + (i + 1) +
"\t");
290 for (
int i = 0; i < 24; i++) {
291 writer.
write(
"oc" + i +
"-" + (i + 1) +
"\t");
296 writer.
write(stopId +
"\t");
298 int[] board = this.boards.get(stopId);
300 log.debug(
"stopId:\t" + stopId +
"\thas null boards!");
302 for (
int i = 0; i < 24; i++) {
303 writer.
write((board != null ? board[i] : 0) +
"\t");
306 int[] alight = this.alights.get(stopId);
307 if (alight == null) {
308 log.debug(
"stopId:\t" + stopId +
"\thas null alights!");
310 for (
int i = 0; i < 24; i++) {
311 writer.
write((alight != null ? alight[i] : 0) +
"\t");
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!");
318 for (
int i = 0; i < 24; i++) {
319 writer.
write((ocuppancy != null ? ocuppancy[i] : 0) +
"\t");
323 writer.
write(this.occupancyRecord.toString());
Id< Vehicle > getVehicleId()
static< T > Id< T > get(int index, final Class< T > type)
void setAlights(Map< Id< TransitStopFacility >, int[]> alights)
Id< Person > getDriverId()
final Map< Id< Vehicle >, Integer > vehPassengers
Map< Id< TransitStopFacility >, int[]> boards
Id< Vehicle > getVehicleId()
void handleEvent(PersonEntersVehicleEvent event)
final Set< Id< Person > > transitDrivers
Set< Id< TransitStopFacility > > getAllStopIds()
StringBuffer occupancyRecord
void handleEvent(VehicleArrivesAtFacilityEvent event)
Id< Person > getPersonId()
void setOccupancies(Map< Id< TransitStopFacility >, int[]> occupancies)
int [] getOccupancyVolumesForStop(final Id< TransitStopFacility > stopId)
OccupancyAnalyzer(final int timeBinSize, final double maxTime)
int [] getAlightVolumesForStop(final Id< TransitStopFacility > stopId)
Id< Vehicle > getVehicleId()
Set< Id< TransitStopFacility > > getAlightStopIds()
void write(String filename)
Set< Id< TransitStopFacility > > getBoardStopIds()
void reset(int iteration)
void setBoards(Map< Id< TransitStopFacility >, int[]> boards)
final Set< Id< Vehicle > > transitVehicles
Id< Vehicle > getVehicleId()
final Map< Id< Vehicle >, Id< TransitStopFacility > > vehStops
Set< Id< TransitStopFacility > > getOccupancyStopIds()
int getTimeSlotIndex(final double time)
void handleEvent(VehicleDepartsAtFacilityEvent event)
void handleEvent(TransitDriverStartsEvent event)
int [] getBoardVolumesForStop(final Id< TransitStopFacility > stopId)
void handleEvent(PersonLeavesVehicleEvent event)
Id< Person > getPersonId()