Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: 158 - Ensure GTFS and RAPTOR router have the same stop set #159

Merged
merged 18 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
189d7e5
FIX: 158 - Ensure GTFS and RAPTOR router have the same stop set
munterfi Dec 9, 2024
07c362c
TEST: 158 - Adjust and refactor GtfsToRaptorConverterIT
munterfi Jan 4, 2025
027e908
TEST: 158 - Improve test case comment
munterfi Jan 4, 2025
e293533
STYLE: 158 - Format javadoc
munterfi Jan 4, 2025
8dbf6aa
ENH: 158 - Reuse existing logic for GTFS to RAPTOR conversion
munterfi Jan 10, 2025
5d0d015
TEST: 158 - Adjust converter test
munterfi Jan 10, 2025
281c420
TEST: 158 - Only add stops with departures to raptor, catch exception…
munterfi Jan 10, 2025
26f29a6
REFACTOR: 158 - Simplify transfer generation in gtfs raptor converter.
clukas1 Jan 12, 2025
036b5de
TEST: 158 - Add test case for multiple transfer generators.
clukas1 Jan 12, 2025
45c3650
FIX: 158 - Fix reversing list order of transfer generators for proper…
clukas1 Jan 12, 2025
87b1bd7
ENH: 158 - Add custom exceptions for raptor router algorithm.
clukas1 Jan 12, 2025
68f3c9d
ENH: 158 - Catch specifically InvalidStopExceptions in service.
clukas1 Jan 12, 2025
7755d73
STYLE: 158 - Rename mapper to converter to be more precise.
clukas1 Jan 12, 2025
015c1e7
STYLE: 158 - Refactor project
munterfi Jan 13, 2025
f3c2a41
STYLE: 158 - Remove unused constructors
munterfi Jan 13, 2025
0a54895
STYLE: 158 - Analyze complete project and solve code issues
munterfi Jan 13, 2025
20eec36
STYLE: 158 - Remove snake_case in test cases
munterfi Jan 13, 2025
23a4e2d
STYLE: 158 - Reorder methods in public transit service, and change to…
munterfi Jan 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ public List<StopConnection> getIsolines(@RequestParam(required = false) String s
// determine routing case and get isolines
try {
if (sourceStop != null) {
return map(service.getIsoLines(sourceStop, dateTime, map(timeType), config), timeType,
return map(service.getIsolines(sourceStop, dateTime, map(timeType), config), timeType,
returnConnections);
} else {
return map(service.getIsoLines(sourceCoordinate, dateTime, map(timeType), config), timeType,
return map(service.getIsolines(sourceCoordinate, dateTime, map(timeType), config), timeType,
returnConnections);
}
} catch (ConnectionRoutingException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ public List<Connection> getConnections(GeoCoordinate source, Stop target, LocalD
}

@Override
public Map<Stop, Connection> getIsoLines(GeoCoordinate source, LocalDateTime time, TimeType timeType,
public Map<Stop, Connection> getIsolines(GeoCoordinate source, LocalDateTime time, TimeType timeType,
ConnectionQueryConfig config) throws ConnectionRoutingException {
return delegate.getIsoLines(source, time, timeType, config);
return delegate.getIsolines(source, time, timeType, config);
}

@Override
public Map<Stop, Connection> getIsoLines(Stop source, LocalDateTime time, TimeType timeType,
public Map<Stop, Connection> getIsolines(Stop source, LocalDateTime time, TimeType timeType,
ConnectionQueryConfig config) throws ConnectionRoutingException {
return delegate.getIsoLines(source, time, timeType, config);
return delegate.getIsolines(source, time, timeType, config);
}

@Override
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/ch/naviqore/raptor/RaptorAlgorithm.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public interface RaptorAlgorithm {
* @param config Query configuration
* @return a list of pareto-optimal earliest arrival connections sorted in ascending order by the number of route
* legs (rounds)
* @throws InvalidStopException if departure or arrival stops are invalid
* @throws InvalidTimeException if departure or arrival times are invalid
* @throws IllegalArgumentException for other argument related errors
*/
List<Connection> routeEarliestArrival(Map<String, LocalDateTime> departureStops, Map<String, Integer> arrivalStops,
QueryConfig config);
Expand All @@ -26,6 +29,9 @@ List<Connection> routeEarliestArrival(Map<String, LocalDateTime> departureStops,
* @param config Query configuration
* @return a list of pareto-optimal latest departure connections sorted in ascending order by the number of route
* legs (rounds)
* @throws InvalidStopException if departure or arrival stops are invalid
* @throws InvalidTimeException if departure or arrival times are invalid
* @throws IllegalArgumentException for other argument related errors
*/
List<Connection> routeLatestDeparture(Map<String, Integer> departureStops, Map<String, LocalDateTime> arrivalStops,
QueryConfig config);
Expand All @@ -38,8 +44,23 @@ List<Connection> routeLatestDeparture(Map<String, Integer> departureStops, Map<S
* @param timeType is the type of time to route for (arrival or departure)
* @param config is the query configuration
* @return the earliest arrival (timeType=departure) or latest departure (timeType=arrival) connection for each stop
* @throws InvalidStopException if source stop is invalid
* @throws InvalidTimeException if source time is invalid
* @throws IllegalArgumentException for other argument related errors
*/
Map<String, Connection> routeIsolines(Map<String, LocalDateTime> sourceStops, TimeType timeType,
QueryConfig config);

class InvalidStopException extends IllegalArgumentException {
public InvalidStopException(String message) {
super(message);
}
}

class InvalidTimeException extends IllegalArgumentException {
public InvalidTimeException(String message) {
super(message);
}
}

}
16 changes: 8 additions & 8 deletions src/main/java/ch/naviqore/raptor/router/RaptorRouter.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,24 +149,24 @@ private static class InputValidator {

private static void checkNonNullOrEmptyStops(Map<String, ?> stops, String labelSource) {
if (stops == null) {
throw new IllegalArgumentException(String.format("%s stops must not be null.", labelSource));
throw new InvalidStopException(String.format("%s stops must not be null.", labelSource));
}
if (stops.isEmpty()) {
throw new IllegalArgumentException(String.format("%s stops must not be empty.", labelSource));
throw new InvalidStopException(String.format("%s stops must not be empty.", labelSource));
}
}

private static void validateSourceStopTimes(Map<String, LocalDateTime> sourceStops) {
// check that no null values are present
if (sourceStops.values().stream().anyMatch(Objects::isNull)) {
throw new IllegalArgumentException("Source stop times must not be null.");
throw new InvalidTimeException("Source stop times must not be null.");
}

// get min and max values
LocalDateTime min = sourceStops.values().stream().min(LocalDateTime::compareTo).orElseThrow();
LocalDateTime max = sourceStops.values().stream().max(LocalDateTime::compareTo).orElseThrow();
if (Duration.between(min, max).getSeconds() > MAX_DIFFERENCE_IN_SOURCE_STOP_TIMES) {
throw new IllegalArgumentException("Difference between source stop times must be less than 24 hours.");
throw new InvalidTimeException("Difference between source stop times must be less than 24 hours.");
}
}

Expand All @@ -176,7 +176,7 @@ private static void validateStopPermutations(Map<String, Integer> sourceStops,

// ensure departure and arrival stops are not the same
if (!Collections.disjoint(sourceStops.keySet(), targetStops.keySet())) {
throw new IllegalArgumentException("Source and target stop IDs must not be the same.");
throw new InvalidStopException("Source and target stop IDs must not be the same.");
}
}

Expand All @@ -191,14 +191,14 @@ private static void validateWalkingTimeToTarget(int walkingDurationToTarget) {
* Validate the stops provided in the query. This method will check that the map of stop ids and their
* corresponding departure / walk to target times are valid. This is done by checking if the map is not empty
* and then checking each entry if the stop id is present in the lookup. If not it is removed from the query. If
* no valid stops are found an IllegalArgumentException is thrown.
* no valid stops are found an InvalidStopException is thrown.
*
* @param stops the stops to validate.
* @return a map of valid stop IDs and their corresponding departure / walk to target times.
*/
private Map<Integer, Integer> validateStopsAndGetIndices(Map<String, Integer> stops) {
if (stops.isEmpty()) {
throw new IllegalArgumentException("At least one stop ID must be provided.");
throw new InvalidStopException("At least one stop ID must be provided.");
}

// loop over all stop pairs and check if stop exists in raptor, then validate departure time
Expand All @@ -215,7 +215,7 @@ private Map<Integer, Integer> validateStopsAndGetIndices(Map<String, Integer> st
}

if (validStopIds.isEmpty()) {
throw new IllegalArgumentException("No valid stops provided.");
throw new InvalidStopException("No valid stops provided.");
}

return validStopIds;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ List<Connection> getConnections(Stop source, GeoCoordinate target, LocalDateTime
* @param config additional configuration for the query
* @return a map of stops to the shortest possible connection to each stop from the departure location
*/
Map<Stop, Connection> getIsoLines(GeoCoordinate source, LocalDateTime time, TimeType timeType,
Map<Stop, Connection> getIsolines(GeoCoordinate source, LocalDateTime time, TimeType timeType,
ConnectionQueryConfig config) throws ConnectionRoutingException;

/**
Expand All @@ -92,6 +92,6 @@ Map<Stop, Connection> getIsoLines(GeoCoordinate source, LocalDateTime time, Time
* @param config additional configuration for the query
* @return a map of stops to the shortest possible connection to each stop from the departure location
*/
Map<Stop, Connection> getIsoLines(Stop source, LocalDateTime time, TimeType timeType,
Map<Stop, Connection> getIsolines(Stop source, LocalDateTime time, TimeType timeType,
ConnectionQueryConfig config) throws ConnectionRoutingException;
}
Loading
Loading