From 561be765445aefc35c0a337aadbf3a8c75704a77 Mon Sep 17 00:00:00 2001 From: Zsombor Welker Date: Mon, 21 Nov 2022 08:22:15 +0100 Subject: [PATCH] Allow bike walking through bicycle no thru traffic areas --- .../street/model/edge/StreetEdge.java | 15 ++++ .../street/integration/BikeWalkingTest.java | 69 +++++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/application/src/main/java/org/opentripplanner/street/model/edge/StreetEdge.java b/application/src/main/java/org/opentripplanner/street/model/edge/StreetEdge.java index 92244fe2af2..505d2a95a3a 100644 --- a/application/src/main/java/org/opentripplanner/street/model/edge/StreetEdge.java +++ b/application/src/main/java/org/opentripplanner/street/model/edge/StreetEdge.java @@ -381,6 +381,21 @@ else if (s0.currentMode() == TraverseMode.BICYCLE) { State state = editor != null ? editor.makeState() : null; + // Add an explicit bike-walking state for no-thru-traffic edges, so that dismounting and walking + // is an option to avoid the restriction + if ( + s0.getBackMode() == TraverseMode.BICYCLE && + canTraverse(TraverseMode.BICYCLE) && + isBicycleNoThruTraffic() && + !s0.hasEnteredNoThruTrafficArea() + ) { + var bikeWalk = doTraverse(s0, TraverseMode.WALK, true); + if (bikeWalk != null) { + State forkState = bikeWalk.makeState(); + return State.ofNullable(forkState, state); + } + } + // we are transitioning into a no-drop-off zone therefore we add a second state for dropping // off the vehicle and walking if (state != null && !fromv.rentalDropOffBanned(s0) && tov.rentalDropOffBanned(s0)) { diff --git a/application/src/test/java/org/opentripplanner/street/integration/BikeWalkingTest.java b/application/src/test/java/org/opentripplanner/street/integration/BikeWalkingTest.java index 41ec677b3bb..1d4ec2f3f79 100644 --- a/application/src/test/java/org/opentripplanner/street/integration/BikeWalkingTest.java +++ b/application/src/test/java/org/opentripplanner/street/integration/BikeWalkingTest.java @@ -295,6 +295,75 @@ public void testElevatorBiking() { ); } + @Test + public void testBicycleBicycleNoThruTrafficStart() { + CD.setBicycleNoThruTraffic(true); + + assertPath( + C, + F, + StreetMode.BIKE, + List.of( + "null - 0 / 0.0 - null", + "BICYCLE - 5 / 10.0 - CD street", + "BICYCLE - 5 / 10.0 - DE street", + "BICYCLE - 5 / 10.0 - EF street" + ), + List.of( + "null - 0 / 0.0 - null", + "BICYCLE - 5 / 10.0 - CD street", + "BICYCLE - 5 / 10.0 - DE street", + "BICYCLE - 5 / 10.0 - EF street" + ) + ); + } + + @Test + public void testBicycleBicycleNoThruTrafficMiddle() { + DE.setBicycleNoThruTraffic(true); + + assertPath( + C, + F, + StreetMode.BIKE, + List.of( + "null - 0 / 0.0 - null", + "BICYCLE - 5 / 10.0 - CD street", + "🚲WALK - 120 / 1100.0 - DE street", + "BICYCLE - 105 / 1010.0 - EF street" + ), + List.of( + "null - 0 / 0.0 - null", + "BICYCLE - 105 / 1010.0 - CD street", + "🚲WALK - 120 / 1100.0 - DE street", + "BICYCLE - 5 / 10.0 - EF street" + ) + ); + } + + @Test + public void testBicycleBicycleNoThruTrafficEnd() { + EF.setBicycleNoThruTraffic(true); + + assertPath( + C, + F, + StreetMode.BIKE, + List.of( + "null - 0 / 0.0 - null", + "BICYCLE - 5 / 10.0 - CD street", + "BICYCLE - 5 / 10.0 - DE street", + "BICYCLE - 5 / 10.0 - EF street" + ), + List.of( + "null - 0 / 0.0 - null", + "BICYCLE - 5 / 10.0 - CD street", + "BICYCLE - 5 / 10.0 - DE street", + "BICYCLE - 5 / 10.0 - EF street" + ) + ); + } + @BeforeEach protected void setUp() throws Exception { // Generate a very simple graph