From 3080be59ed57cbe6491f6d66d5e3d4bd3497839c Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Mon, 31 Oct 2022 21:58:18 +0100 Subject: [PATCH] Take stop signs into account during routing --- features/car/give_way_sign_penalties.feature | 10 +++++----- features/car/stop_sign_penalties.feature | 9 +++++---- src/extractor/extractor_callbacks.cpp | 6 ++++-- unit_tests/extractor/graph_compressor.cpp | 20 +++++++++++++++++++ .../extractor/intersection_analysis_tests.cpp | 13 ++++++++++++ 5 files changed, 47 insertions(+), 11 deletions(-) diff --git a/features/car/give_way_sign_penalties.feature b/features/car/give_way_sign_penalties.feature index ed84ab922..4f9b45deb 100644 --- a/features/car/give_way_sign_penalties.feature +++ b/features/car/give_way_sign_penalties.feature @@ -31,12 +31,13 @@ Feature: Car - Handle give way signs | e | give_way | | l | give_way | + # TODO: give way signs with no direction has no any impact on routing at the moment When I route I should get | from | to | time | # | | 1 | 2 | 11.1s | no turn with no give way | - | 3 | 4 | 13.1s | no turn with give way | + | 3 | 4 | 11.1s | no turn with give way | | g | j | 18.7s | turn with no give way | - | k | n | 20.7s | turn with give way | + | k | n | 18.7s | turn with give way | Scenario: Car - Give way direction @@ -64,13 +65,12 @@ Feature: Car - Handle give way signs | e | give_way | | | h | give_way | forward | | k | give_way | backward | - When I route I should get | from | to | time | weight | # | | 1 | 2 | 11.1s | 11.1 | no turn with no give way | | 2 | 1 | 11.1s | 11.1 | no turn with no give way | - | 3 | 4 | 13.1s | 13.1 | no turn with give way | - | 4 | 3 | 13.1s | 13.1 | no turn with give way | + | 3 | 4 | 11.1s | 11.1 | no turn with give way | + | 4 | 3 | 11.1s | 11.1 | no turn with give way | | 5 | 6 | 13.1s | 13.1 | no turn with give way | | 6 | 5 | 11.1s | 11.1 | no turn with no give way | | 7 | 8 | 11.1s | 11.1 | no turn with no give way | diff --git a/features/car/stop_sign_penalties.feature b/features/car/stop_sign_penalties.feature index 8ae42263a..35c15540a 100644 --- a/features/car/stop_sign_penalties.feature +++ b/features/car/stop_sign_penalties.feature @@ -31,12 +31,13 @@ Feature: Car - Handle stop signs | e | stop | | l | stop | + # TODO: stop signs with no direction has no any impact on routing at the moment When I route I should get | from | to | time | # | | 1 | 2 | 11.1s | no turn with no stop sign | - | 3 | 4 | 13.1s | no turn with stop sign | + | 3 | 4 | 11.1s | no turn with stop sign | | g | j | 18.7s | turn with no stop sign | - | k | n | 20.7s | turn with stop sign | + | k | n | 18.7s | turn with stop sign | Scenario: Car - Stop sign direction Given the node map @@ -68,8 +69,8 @@ Feature: Car - Handle stop signs | from | to | time | weight | # | | 1 | 2 | 11.1s | 11.1 | no turn with no stop sign | | 2 | 1 | 11.1s | 11.1 | no turn with no stop sign | - | 3 | 4 | 13.1s | 13.1 | no turn with stop sign | - | 4 | 3 | 13.1s | 13.1 | no turn with stop sign | + | 3 | 4 | 11.1s | 11.1 | no turn with stop sign | + | 4 | 3 | 11.1s | 11.1 | no turn with stop sign | | 5 | 6 | 13.1s | 13.1 | no turn with stop sign | | 6 | 5 | 11.1s | 11.1 | no turn with no stop sign | | 7 | 8 | 11.1s | 11.1 | no turn with no stop sign | diff --git a/src/extractor/extractor_callbacks.cpp b/src/extractor/extractor_callbacks.cpp index f40507a88..76369f2cf 100644 --- a/src/extractor/extractor_callbacks.cpp +++ b/src/extractor/extractor_callbacks.cpp @@ -82,11 +82,13 @@ void ExtractorCallbacks::ProcessNode(const osmium::Node &input_node, { external_memory.external_traffic_signals.push_back({id, result_node.traffic_lights}); } - if (result_node.give_way != TrafficFlowControlNodeDirection::NONE) + // TODO: we ignore `ALL` for both stop signs and give way signs, because we cannot understand direction of the way they should be applied yet + // see: https://wiki.openstreetmap.org/wiki/Tag:highway%3Dstop#Direction + if (result_node.give_way != TrafficFlowControlNodeDirection::NONE && result_node.give_way != TrafficFlowControlNodeDirection::ALL) { external_memory.external_give_ways.push_back({id, result_node.give_way}); } - if (result_node.stop_sign != TrafficFlowControlNodeDirection::NONE) + if (result_node.stop_sign != TrafficFlowControlNodeDirection::NONE && result_node.stop_sign != TrafficFlowControlNodeDirection::ALL) { external_memory.external_stop_signs.push_back({id, result_node.stop_sign}); } diff --git a/unit_tests/extractor/graph_compressor.cpp b/unit_tests/extractor/graph_compressor.cpp index 128ed8e52..f20a1fb14 100644 --- a/unit_tests/extractor/graph_compressor.cpp +++ b/unit_tests/extractor/graph_compressor.cpp @@ -66,6 +66,8 @@ BOOST_AUTO_TEST_CASE(long_road_test) std::unordered_set barrier_nodes; TrafficFlowControlNodes traffic_lights; + TrafficFlowControlNodes stop_signs; + TrafficFlowControlNodes give_way_signs; std::vector restrictions; std::vector annotations(1); CompressedEdgeContainer container; @@ -88,6 +90,8 @@ BOOST_AUTO_TEST_CASE(long_road_test) compressor.Compress(barrier_nodes, traffic_lights, + stop_signs, + give_way_signs, scripting_environment, restrictions, maneuver_overrides, @@ -112,6 +116,8 @@ BOOST_AUTO_TEST_CASE(loop_test) std::unordered_set barrier_nodes; TrafficFlowControlNodes traffic_lights; + TrafficFlowControlNodes stop_signs; + TrafficFlowControlNodes give_way_signs; std::vector restrictions; CompressedEdgeContainer container; std::vector annotations(1); @@ -148,6 +154,8 @@ BOOST_AUTO_TEST_CASE(loop_test) compressor.Compress(barrier_nodes, traffic_lights, + stop_signs, + give_way_signs, scripting_environment, restrictions, maneuver_overrides, @@ -175,6 +183,8 @@ BOOST_AUTO_TEST_CASE(t_intersection) std::unordered_set barrier_nodes; TrafficFlowControlNodes traffic_lights; + TrafficFlowControlNodes stop_signs; + TrafficFlowControlNodes give_way_signs; std::vector annotations(1); std::vector restrictions; CompressedEdgeContainer container; @@ -197,6 +207,8 @@ BOOST_AUTO_TEST_CASE(t_intersection) compressor.Compress(barrier_nodes, traffic_lights, + stop_signs, + give_way_signs, scripting_environment, restrictions, maneuver_overrides, @@ -218,6 +230,8 @@ BOOST_AUTO_TEST_CASE(street_name_changes) std::unordered_set barrier_nodes; TrafficFlowControlNodes traffic_lights; + TrafficFlowControlNodes stop_signs; + TrafficFlowControlNodes give_way_signs; std::vector annotations(2); std::vector restrictions; CompressedEdgeContainer container; @@ -236,6 +250,8 @@ BOOST_AUTO_TEST_CASE(street_name_changes) compressor.Compress(barrier_nodes, traffic_lights, + stop_signs, + give_way_signs, scripting_environment, restrictions, maneuver_overrides, @@ -256,6 +272,8 @@ BOOST_AUTO_TEST_CASE(direction_changes) std::unordered_set barrier_nodes; TrafficFlowControlNodes traffic_lights; + TrafficFlowControlNodes stop_signs; + TrafficFlowControlNodes give_way_signs; std::vector annotations(1); std::vector restrictions; CompressedEdgeContainer container; @@ -270,6 +288,8 @@ BOOST_AUTO_TEST_CASE(direction_changes) Graph graph(5, edges); compressor.Compress(barrier_nodes, traffic_lights, + stop_signs, + give_way_signs, scripting_environment, restrictions, maneuver_overrides, diff --git a/unit_tests/extractor/intersection_analysis_tests.cpp b/unit_tests/extractor/intersection_analysis_tests.cpp index eb35730e1..6bf39570c 100644 --- a/unit_tests/extractor/intersection_analysis_tests.cpp +++ b/unit_tests/extractor/intersection_analysis_tests.cpp @@ -20,6 +20,9 @@ BOOST_AUTO_TEST_CASE(simple_intersection_connectivity) { std::unordered_set barrier_nodes{6}; TrafficFlowControlNodes traffic_lights; + TrafficFlowControlNodes stop_signs; + TrafficFlowControlNodes give_way_signs; + std::vector annotations{ {EMPTY_NAMEID, 0, INAVLID_CLASS_DATA, TRAVEL_MODE_DRIVING, false}, {EMPTY_NAMEID, 1, INAVLID_CLASS_DATA, TRAVEL_MODE_DRIVING, false}}; @@ -87,6 +90,8 @@ BOOST_AUTO_TEST_CASE(simple_intersection_connectivity) GraphCompressor().Compress(barrier_nodes, traffic_lights, + stop_signs, + give_way_signs, scripting_environment, restrictions, maneuver_overrides, @@ -153,6 +158,8 @@ BOOST_AUTO_TEST_CASE(roundabout_intersection_connectivity) { std::unordered_set barrier_nodes; TrafficFlowControlNodes traffic_lights; + TrafficFlowControlNodes stop_signs; + TrafficFlowControlNodes give_way_signs; std::vector annotations; std::vector restrictions; CompressedEdgeContainer container; @@ -210,6 +217,8 @@ BOOST_AUTO_TEST_CASE(roundabout_intersection_connectivity) GraphCompressor().Compress(barrier_nodes, traffic_lights, + stop_signs, + give_way_signs, scripting_environment, restrictions, maneuver_overrides, @@ -260,6 +269,8 @@ BOOST_AUTO_TEST_CASE(skip_degree_two_nodes) { std::unordered_set barrier_nodes{1}; TrafficFlowControlNodes traffic_lights = {{2}, {}}; + TrafficFlowControlNodes stop_signs = {}; + TrafficFlowControlNodes give_way_signs = {}; std::vector annotations(1); std::vector restrictions; CompressedEdgeContainer container; @@ -309,6 +320,8 @@ BOOST_AUTO_TEST_CASE(skip_degree_two_nodes) GraphCompressor().Compress(barrier_nodes, traffic_lights, + stop_signs, + give_way_signs, scripting_environment, restrictions, maneuver_overrides,