Skip to content

Commit

Permalink
fix departures that are the same at the end of a route
Browse files Browse the repository at this point in the history
  • Loading branch information
rakow committed Oct 22, 2024
1 parent 13a8868 commit 81667a3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.matsim.core.utils.geometry.CoordUtils;
import org.matsim.core.utils.misc.OptionalTime;
import org.matsim.pt.transitSchedule.api.*;

Expand Down Expand Up @@ -61,10 +62,41 @@ private List<TransitRouteStop> adjustDepartures(TransitScheduleFactory f, Transi
List<TransitRouteStop> stops = new ArrayList<>(route.getStops());

boolean adjusted = false;

// Check if the times at the end of the schedule are the same
// These need to be calculated and can not be interpolated
// The arrival at the last stop is shifted by small travel time
if (stops.size() > 1) {
TransitRouteStop last = stops.getLast();
TransitRouteStop secondLast = stops.get(stops.size() - 2);

OptionalTime lastDep = last.getDepartureOffset().or(last.getArrivalOffset());
OptionalTime secondLastDep = secondLast.getDepartureOffset().or(secondLast.getArrivalOffset());

if (lastDep.isDefined() && secondLastDep.isDefined() && lastDep.equals(secondLastDep)) {
// Calculate the time between the last two stops
double dist = Math.max(20, CoordUtils.calcEuclideanDistance(last.getStopFacility().getCoord(), secondLast.getStopFacility().getCoord()));
double time = dist / 10; // 10 m/s

// Calculate the time for the last stop
TransitRouteStop newStop = f.createTransitRouteStop(
last.getStopFacility(),
add(last.getArrivalOffset(), time),
add(last.getDepartureOffset(), time)
);

newStop.setAwaitDepartureTime(last.isAwaitDepartureTime());
newStop.setAllowAlighting(last.isAllowAlighting());
newStop.setAllowBoarding(last.isAllowBoarding());

stops.set(stops.size() - 1, newStop);
adjusted = true;
}
}

for (int i = 0; i < stops.size() - 1; ) {

TransitRouteStop stop = stops.get(i);

OptionalTime dep = stop.getDepartureOffset().or(stop.getArrivalOffset());

if (!dep.isDefined()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ public static ValidationResult validateStopCoordinates(final TransitSchedule sch
}

// Some hard coded rules to detect suspicious stops, these are speed m/s, so quite high values
if (((toStop > 3 * mean && both > 30) || toStop > 120) && (((fromStop > 3 * mean && both > 30) || fromStop > 120))) {
if (((toStop > 3 * mean && both > 50) || toStop > 120) && (((fromStop > 3 * mean && both > 50) || fromStop > 120))) {
DoubleList suspiciousSpeeds = suspiciousStops.computeIfAbsent(stop.getStopFacility(), (k) -> new DoubleArrayList());
suspiciousSpeeds.add(toStop);
suspiciousSpeeds.add(fromStop);
Expand Down

0 comments on commit 81667a3

Please sign in to comment.