Skip to content

Commit

Permalink
REFACTOR: #181 - Remove not complete doInitialTransferRealaxation fro…
Browse files Browse the repository at this point in the history
…m raptor router.
  • Loading branch information
clukas1 committed Feb 13, 2025
1 parent 651b653 commit 1615e6e
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 81 deletions.
2 changes: 0 additions & 2 deletions src/main/java/ch/naviqore/raptor/QueryConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ public class QueryConfig {
@Setter
private EnumSet<TravelMode> allowedTravelModes = EnumSet.allOf(TravelMode.class);

@Setter
private boolean doInitialTransferRelaxation = true;
@Setter
private boolean allowSourceTransfer = true;
@Setter
Expand Down
16 changes: 2 additions & 14 deletions src/main/java/ch/naviqore/raptor/router/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,8 @@ List<QueryState.Label[]> run() {
// initially relax all source stops and add the newly improved stops by relaxation to the marked stops
initialize();

if (config.isDoInitialTransferRelaxation()) {
footpathRelaxer.relaxInitial();
removeSuboptimalLabelsForRound(0);
}
footpathRelaxer.relaxInitial();
removeSuboptimalLabelsForRound(0);

// if range is 0 or smaller there is no range, and we don't need to rerun rounds with different start offsets
if (raptorRange <= 0) {
Expand Down Expand Up @@ -174,16 +172,6 @@ private void doRounds() {
// scan all routs and mark stops that have improved
routeScanner.scan(queryState.getRound());

// this is a special case where no initial transfer relaxation was done, to ensure that transfers from
// source stops are still accounted for these are manually marked in round 1 (after route scanning for
// performance reasons)
if( !config.isDoInitialTransferRelaxation() && queryState.getRound() == 1 ){
// mark all source stops for transfer relaxation after round 1
for (int sourceStopIndex : sourceStopIndices) {
queryState.mark(sourceStopIndex);
}
}

// relax footpaths for all newly marked stops
footpathRelaxer.relax(queryState.getRound());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,14 @@ List<ch.naviqore.raptor.Connection> routeConnections(Map<String, LocalDateTime>
Map<String, ch.naviqore.raptor.Connection> createIsolines(Map<String, LocalDateTime> sourceStops, TimeType timeType,
ConnectionQueryConfig queryConfig,
boolean allowSourceTransfer) {
// TODO: discuss whether allowTargetTransfers should be modifiable
// allow target transfers does not work for isolines since no targets are defined
return raptor.routeIsolines(sourceStops, TypeMapper.map(timeType),
prepareQueryConfig(queryConfig, allowSourceTransfer, true));
}

private static QueryConfig prepareQueryConfig(ConnectionQueryConfig queryConfig, boolean allowSourceTransfer,
boolean allowTargetTransfer) {
QueryConfig config = TypeMapper.map(queryConfig);
// TODO: discuss whether this should be modifiable
// we don't want two one leg results if connection can be achieved with initial transfer (Round 0) and a one leg
// connection (that is faster) --> Round 1
config.setDoInitialTransferRelaxation(false);
config.setAllowSourceTransfer(allowSourceTransfer);
config.setAllowTargetTransfer(allowTargetTransfer);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,66 +22,6 @@ public class RaptorTransferBehaviorTest {
private static final int DAY_START_HOUR = 8;
private static final int DAY_END_HOUR = 9;

@Nested
class InitialTransferRelaxation {
@Test
void connectBetweenStops_withInitialFootpathRelaxation(RaptorRouterTestBuilder builder) {
RaptorAlgorithm router = TransferBehaviorHelpers.prepareRouter(builder, 5, 30);
QueryConfig config = new QueryConfig();
config.setDoInitialTransferRelaxation(true);

List<Connection> connections = TransferBehaviorHelpers.routeBetweenStops(router, "A", "B", config);

// Because initial transfer relaxation is one, this will return two solutions.
// Round 0 best time with transfer between A-B with one transfer leg
// Round 1 best time (faster) with route 1 from A to B with one route leg (no transfers)
assertEquals(2, connections.size());
Connection walkConnection = connections.getFirst();
assertEquals(0, walkConnection.getRouteLegs().size());
assertEquals(1, walkConnection.getWalkTransfers().size());

Connection routeConnection = connections.getLast();
assertEquals(1, routeConnection.getRouteLegs().size());
assertEquals(0, routeConnection.getWalkTransfers().size());
}

@Test
void connectBetweenStops_withoutInitialFootpathRelaxation(RaptorRouterTestBuilder builder) {
RaptorAlgorithm router = TransferBehaviorHelpers.prepareRouter(builder, 5, 30);
QueryConfig config = new QueryConfig();
config.setDoInitialTransferRelaxation(false);

List<Connection> connections = TransferBehaviorHelpers.routeBetweenStops(router, "A", "B", config);

// Because nothing should happen in round 0 (no initial transfer relaxation) only one "one leg" connection
// should be returned and since the route leg will be faster, this should be the only solution
assertEquals(1, connections.size());
Connection connection = connections.getFirst();
assertEquals(1, connection.getRouteLegs().size());
assertEquals(0, connection.getWalkTransfers().size());
}

@Test
void connectBetweenStops_withoutInitialFootpathRelaxationOnlyByTransfer(RaptorRouterTestBuilder builder) {
RaptorAlgorithm router = TransferBehaviorHelpers.prepareRouter(builder, 5, 30);
QueryConfig config = new QueryConfig();
config.setDoInitialTransferRelaxation(false);

// ensure that no routes are active anymore
LocalDateTime startTime = LocalDateTime.of(2000, 1, 1, DAY_END_HOUR + 1, 0);

List<Connection> connections = TransferBehaviorHelpers.routeBetweenStops(router, "A", "B", startTime,
config);

// even though initial transfer relaxation is turned off, in round 1 transfer relaxation should be performed
// from source stops (after no faster route trips were found!).
assertEquals(1, connections.size());
Connection connection = connections.getFirst();
assertEquals(0, connection.getRouteLegs().size());
assertEquals(1, connection.getWalkTransfers().size());
}
}

@Nested
class SourceTransferRelaxation {

Expand Down

0 comments on commit 1615e6e

Please sign in to comment.