20 package org.matsim.analysis.pt.stop2stop;
22 import org.apache.commons.csv.CSVFormat;
23 import org.apache.commons.csv.CSVPrinter;
24 import org.apache.logging.log4j.LogManager;
25 import org.apache.logging.log4j.Logger;
44 import java.io.IOException;
46 import java.nio.file.Path;
48 import java.util.stream.Collectors;
86 stop2StopEntriesForEachDeparture =
new ArrayList<>(transitVehicles.
getVehicles().size() * 30);
95 event.getTransitRouteId(),
event.getDepartureId(),
event.getDriverId(),
105 if (ptVehicleData == null) {
106 log.error(
"Encountered a VehicleArrivesAtFacilityEvent without a previous TransitDriverStartsEvent for vehicle {} at facility {} at time {}. This should not happen, this analysis might fail subsequently.", event.
getVehicleId(),
event.getFacilityId(),
event.getTime());
118 if (ptVehicleData == null) {
119 log.error(
"Encountered a VehicleDepartsAtFacilityEvent without a previous TransitDriverStartsEvent for vehicle {} at facility {} at time {}. This should not happen, this analysis might fail subsequently.", event.
getVehicleId(),
event.getFacilityId(),
event.getTime());
122 stop2StopEntriesForEachDeparture.add(
new Stop2StopEntry(ptVehicleData.
transitLineId,
139 ptVehicleData.
lastStopId =
event.getFacilityId();
165 if (ptVehicleData != null) {
169 transitVehicle2temporaryVehicleData.remove(event.
getVehicleId());
179 if(!transitVehicle2temporaryVehicleData.isEmpty()) {
180 log.warn(
"{} transit vehicles did not finish service in the last iteration.", transitVehicle2temporaryVehicleData.size());
182 transitVehicle2temporaryVehicleData.clear();
183 stop2StopEntriesForEachDeparture.clear();
193 if (ptVehicleData != null) {
205 if (ptVehicleData != null) {
244 double departureTimeScheduled,
double departureDelay,
double passengersAtArrival,
double totalVehicleCapacity,
245 double passengersAlighting,
double passengersBoarding, List<
Id<Link>> linkIdsSincePreviousStop) {}
247 static final String[] HEADER = {
"transitLine",
"transitRoute",
"departure",
"stop",
"stopSequence",
248 "stopPrevious",
"arrivalTimeScheduled",
"arrivalDelay",
"departureTimeScheduled",
"departureDelay",
249 "passengersAtArrival",
"totalVehicleCapacity",
"passengersAlighting",
"passengersBoarding",
250 "linkIdsSincePreviousStop"};
252 static Comparator<Stop2StopEntry> stop2StopEntryByTransitLineComparator =
253 Comparator.nullsLast(Comparator.comparing(Stop2StopEntry::transitLineId));
254 static Comparator<Stop2StopEntry> stop2StopEntryByTransitRouteComparator =
255 Comparator.nullsLast(Comparator.comparing(Stop2StopEntry::transitRouteId));
256 static Comparator<Stop2StopEntry> stop2StopEntryByDepartureComparator =
257 Comparator.nullsLast(Comparator.comparing(Stop2StopEntry::departureId));
258 static Comparator<Stop2StopEntry> stop2StopEntryByStopSequenceComparator =
259 Comparator.nullsLast(Comparator.comparing(Stop2StopEntry::stopSequence));
270 stop2StopEntriesForEachDeparture.sort(stop2StopEntryByTransitLineComparator.
271 thenComparing(stop2StopEntryByTransitRouteComparator).
272 thenComparing(stop2StopEntryByDepartureComparator).
273 thenComparing(stop2StopEntryByStopSequenceComparator));
275 CSVFormat.Builder.create()
276 .setDelimiter(columnSeparator)
280 for (Stop2StopEntry entry : stop2StopEntriesForEachDeparture) {
281 printer.print(entry.transitLineId);
282 printer.print(entry.transitRouteId);
283 printer.print(entry.departureId);
284 printer.print(entry.stopId);
285 printer.print(entry.stopSequence);
286 printer.print(entry.stopPreviousId);
287 printer.print(entry.arrivalTimeScheduled);
288 printer.print(entry.arrivalDelay);
289 printer.print(entry.departureTimeScheduled);
290 printer.print(entry.departureDelay);
291 printer.print(entry.passengersAtArrival);
292 printer.print(entry.totalVehicleCapacity);
293 printer.print(entry.passengersAlighting);
294 printer.print(entry.passengersBoarding);
295 printer.print(entry.linkIdsSincePreviousStop.stream().map(Object::toString).collect(Collectors.joining(listSeparatorInsideColumn)));
298 }
catch (IOException e) {
303 List<Stop2StopEntry> getStop2StopEntriesByDeparture () {
304 return List.copyOf(stop2StopEntriesForEachDeparture);
Id< Vehicle > getVehicleId()
final Id< Departure > departureId
PtVehicleData(Id< TransitLine > transitLineId, Id< TransitRoute > transitRouteId, Id< Departure > departureId, Id< Person > driverId, VehicleType vehicleType)
VehicleArrivesAtFacilityEvent lastVehicleArrivesAtFacilityEvent
final Id< TransitLine > transitLineId
final Id< TransitRoute > transitRouteId
void handleEvent(VehicleDepartsAtFacilityEvent event)
Id< Vehicle > getVehicleId()
final List< Stop2StopEntry > stop2StopEntriesForEachDeparture
static URL getFileUrl(String filename)
void handleEvent(LinkEnterEvent event)
Id< TransitStopFacility > getFacilityId()
void writeStop2StopEntriesByDepartureCsv(Path path, String columnSeparator, String listSeparatorInsideColumn)
Integer getStandingRoom()
static BufferedWriter getBufferedWriter(URL url, Charset charset, boolean append)
Id< Person > getPersonId()
Id< Vehicle > getVehicleId()
PtStop2StopAnalysis(Vehicles transitVehicles, double sampleUpscaleFactor)
final double sampleUpscaleFactor
final VehicleCapacity getCapacity()
final Id< Person > driverId
final double totalVehicleCapacity
Id< Vehicle > getVehicleId()
void handleEvent(TransitDriverStartsEvent event)
void reset(int iteration)
Id< TransitStopFacility > lastStopId
final Vehicles transitVehicles
void handleEvent(VehicleArrivesAtFacilityEvent event)
void writeStop2StopEntriesByDepartureCsv(String fileName, String columnSeparator, String listSeparatorInsideColumn)
final List< Id< Link > > linksTravelledOnSincePreviousStop
Id< TransitLine > getTransitLineId()
void handleEvent(PersonLeavesVehicleEvent event)
void handleEvent(VehicleEntersTrafficEvent event)
Map< Id< Vehicle >, Vehicle > getVehicles()
Id< Vehicle > getVehicleId()
Id< Vehicle > getVehicleId()
void writeStop2StopEntriesByDepartureCsv(URL url, String columnSeparator, String listSeparatorInsideColumn)
void handleEvent(PersonEntersVehicleEvent event)
Id< Person > getPersonId()
Id< Vehicle > getVehicleId()
final Map< Id< Vehicle >, PtVehicleData > transitVehicle2temporaryVehicleData