From 1615e6e2cb960de35438f2f80202dae5a82bafbb Mon Sep 17 00:00:00 2001 From: Lukas Connolly Date: Fri, 14 Feb 2025 00:15:04 +0100 Subject: [PATCH] REFACTOR: #181 - Remove not complete doInitialTransferRealaxation from raptor router. --- .../java/ch/naviqore/raptor/QueryConfig.java | 2 - .../java/ch/naviqore/raptor/router/Query.java | 16 +---- .../raptor/routing/RoutingQueryUtils.java | 6 +- .../router/RaptorTransferBehaviorTest.java | 60 ------------------- 4 files changed, 3 insertions(+), 81 deletions(-) diff --git a/src/main/java/ch/naviqore/raptor/QueryConfig.java b/src/main/java/ch/naviqore/raptor/QueryConfig.java index 0d05641b..d4f4be9b 100644 --- a/src/main/java/ch/naviqore/raptor/QueryConfig.java +++ b/src/main/java/ch/naviqore/raptor/QueryConfig.java @@ -28,8 +28,6 @@ public class QueryConfig { @Setter private EnumSet allowedTravelModes = EnumSet.allOf(TravelMode.class); - @Setter - private boolean doInitialTransferRelaxation = true; @Setter private boolean allowSourceTransfer = true; @Setter diff --git a/src/main/java/ch/naviqore/raptor/router/Query.java b/src/main/java/ch/naviqore/raptor/router/Query.java index c7f59aa6..55d51421 100644 --- a/src/main/java/ch/naviqore/raptor/router/Query.java +++ b/src/main/java/ch/naviqore/raptor/router/Query.java @@ -102,10 +102,8 @@ List 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) { @@ -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()); diff --git a/src/main/java/ch/naviqore/service/gtfs/raptor/routing/RoutingQueryUtils.java b/src/main/java/ch/naviqore/service/gtfs/raptor/routing/RoutingQueryUtils.java index a0838e2f..82e7aaa2 100644 --- a/src/main/java/ch/naviqore/service/gtfs/raptor/routing/RoutingQueryUtils.java +++ b/src/main/java/ch/naviqore/service/gtfs/raptor/routing/RoutingQueryUtils.java @@ -54,7 +54,7 @@ List routeConnections(Map Map createIsolines(Map 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)); } @@ -62,10 +62,6 @@ Map createIsolines(Map Round 1 - config.setDoInitialTransferRelaxation(false); config.setAllowSourceTransfer(allowSourceTransfer); config.setAllowTargetTransfer(allowTargetTransfer); diff --git a/src/test/java/ch/naviqore/raptor/router/RaptorTransferBehaviorTest.java b/src/test/java/ch/naviqore/raptor/router/RaptorTransferBehaviorTest.java index 20bbe2ef..ac0d03eb 100644 --- a/src/test/java/ch/naviqore/raptor/router/RaptorTransferBehaviorTest.java +++ b/src/test/java/ch/naviqore/raptor/router/RaptorTransferBehaviorTest.java @@ -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 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 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 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 {