From bbcf343e40e93a66f9a2f49fb63ed6a528de405c Mon Sep 17 00:00:00 2001 From: Moritz Kobitzsch Date: Thu, 20 Jul 2017 14:03:39 +0200 Subject: [PATCH] compress traffic signals - handle penalties within edges (not phantom nodes) - changes model from providing penalties on turns to using additional segments --- features/car/restrictions.feature | 10 ++-- features/guidance/turn-angles.feature | 20 ++++---- features/testbot/penalty.feature | 27 +++++++++++ include/engine/guidance/assemble_geometry.hpp | 10 ++-- .../routing_algorithms/routing_base.hpp | 20 +------- .../extractor/compressed_edge_container.hpp | 8 +++- include/extractor/extraction_containers.hpp | 2 +- include/extractor/extraction_turn.hpp | 8 ++++ include/extractor/graph_compressor.hpp | 2 + src/extractor/compressed_edge_container.cpp | 31 ++++++++---- src/extractor/edge_based_graph_factory.cpp | 5 ++ src/extractor/extraction_containers.cpp | 8 ++-- src/extractor/extractor.cpp | 9 ++-- src/extractor/extractor_callbacks.cpp | 2 +- src/extractor/graph_compressor.cpp | 47 ++++++++++++++++--- unit_tests/extractor/graph_compressor.cpp | 22 +++++++-- .../mocks/mock_scripting_environment.hpp | 47 +++++++++++++++++++ 17 files changed, 209 insertions(+), 69 deletions(-) create mode 100644 unit_tests/mocks/mock_scripting_environment.hpp diff --git a/features/car/restrictions.feature b/features/car/restrictions.feature index fed40ee2a..ee325da23 100644 --- a/features/car/restrictions.feature +++ b/features/car/restrictions.feature @@ -954,11 +954,11 @@ Feature: Car - Turn restrictions # this case is currently not handling the via-way restrictions and we need support for looking across traffic signals. # It is mainly included to show limitations and to prove that we don't crash hard here When I route I should get - | from | to | route | - | a | d | ab,bge,de,de | - | a | f | ab,bge,ef,ef | - | c | d | bc,bge,de,de | - | c | f | bc,bge,ef,ef | + | from | to | route | + | a | d | ab,bge,ef,ef,de,de | + | a | f | ab,bge,ef,ef | + | c | d | bc,bge,de,de | + | c | f | bc,bge,de,de,ef,ef | # don't crash hard on invalid restrictions @restriction @invalid diff --git a/features/guidance/turn-angles.feature b/features/guidance/turn-angles.feature index c15b58f34..b700b4ce6 100644 --- a/features/guidance/turn-angles.feature +++ b/features/guidance/turn-angles.feature @@ -809,14 +809,14 @@ Feature: Simple Turns When I route I should get | waypoints | route | turns | intersections | - | a,g | Perle,Heide,Heide | depart,turn right,arrive | true:90;true:90 true:180 false:270 true:345;true:18 | - | a,k | Perle,Friede,Friede | depart,turn left,arrive | true:90;true:90 true:180 false:270 true:345;true:153 | - | a,e | Perle,Perle | depart,arrive | true:90,true:90 true:180 false:270 true:345;true:270 | - | e,k | Perle,Friede,Friede | depart,turn right,arrive | true:270;false:90 true:180 true:270 true:345;true:153 | - | e,g | Perle,Heide,Heide | depart,turn left,arrive | true:270;false:90 true:180 true:270 true:345;true:18 | - | h,k | Heide,Friede | depart,arrive | true:16,true:90 true:180 true:270 true:345;true:153 | - | h,e | Heide,Perle,Perle | depart,turn right,arrive | true:16;true:90 true:180 true:270 true:345;true:270 | - | h,a | Heide,Perle,Perle | depart,turn left,arrive | true:16;true:90 true:180 true:270 true:345;true:90 | + | a,g | Perle,Heide,Heide | depart,turn right,arrive | true:90;true:90 true:195 false:270 true:345;true:18 | + | a,k | Perle,Friede,Friede | depart,turn left,arrive | true:90;true:90 true:195 false:270 true:345;true:153 | + | a,e | Perle,Perle | depart,arrive | true:90,true:90 true:195 false:270 true:345;true:270 | + | e,k | Perle,Friede,Friede | depart,turn right,arrive | true:270;false:90 true:195 true:270 true:345;true:153 | + | e,g | Perle,Heide,Heide | depart,turn left,arrive | true:270;false:90 true:195 true:270 true:345;true:18 | + | h,k | Heide,Friede | depart,arrive | true:16,true:90 true:195 true:270 true:345;true:153 | + | h,e | Heide,Perle,Perle | depart,turn right,arrive | true:16;true:90 true:195 true:270 true:345;true:270 | + | h,a | Heide,Perle,Perle | depart,turn left,arrive | true:16;true:90 true:195 true:270 true:345;true:90 | #http://www.openstreetmap.org/#map=19/52.53293/13.32956 Scenario: Curved Exit from Curved Road @@ -1006,8 +1006,8 @@ Feature: Simple Turns | waypoints | route | turns | | a,e | Heide,Heide,Heide | depart,continue uturn,arrive | | a,g | Heide,Fenn,Fenn | depart,turn right,arrive | - | a,h | Heide,Friede,Friede | depart,turn slight left,arrive | - | i,e | Perle,Heide,Heide | depart,turn right,arrive | + | a,h | Heide,Friede,Friede | depart,turn left,arrive | + | i,e | Perle,Heide,Heide | depart,turn sharp right,arrive | | i,h | Perle,Friede,Friede | depart,turn left,arrive | #http://www.openstreetmap.org/#map=19/52.48630/13.36017 diff --git a/features/testbot/penalty.feature b/features/testbot/penalty.feature index 4b906ccbf..bcb4d7a8b 100644 --- a/features/testbot/penalty.feature +++ b/features/testbot/penalty.feature @@ -26,6 +26,33 @@ Feature: Penalties | a | c | abc,abc | 20s +-1 | 200m +-1 | | d | f | def,def | 27s +-1 | 200m +-1 | + # Penalties not on the phantom nodes + Scenario: Traffic signals should incur a delay, without changing distance + Given the node map + """ + a b c d e + f g h i j + """ + + And the nodes + | node | highway | + | c | traffic_signals | + + And the ways + | nodes | + | ab | + | bcd | + | de | + | fg | + | ghi | + | ij | + + When I route I should get + | from | to | route | time | distance | + | a | e | ab,bcd,de | 47s +-1 | 400m +-1 | + | f | j | fg,ghi,ij | 40s +-1 | 400m +-1 | + + Scenario: Signal penalty should not depend on way type Given the node map """ diff --git a/include/engine/guidance/assemble_geometry.hpp b/include/engine/guidance/assemble_geometry.hpp index a9f72ba84..a81b55fc4 100644 --- a/include/engine/guidance/assemble_geometry.hpp +++ b/include/engine/guidance/assemble_geometry.hpp @@ -53,9 +53,9 @@ inline LegGeometry assembleGeometry(const datafacade::BaseDataFacade &facade, source_node.fwd_segment_position + (reversed_source ? 1 : 0); const auto source_node_id = reversed_source ? source_node.reverse_segment_id.id : source_node.forward_segment_id.id; - const auto source_gemetry_id = facade.GetGeometryIndex(source_node_id).id; + const auto source_geometry_id = facade.GetGeometryIndex(source_node_id).id; const std::vector source_geometry = - facade.GetUncompressedForwardGeometry(source_gemetry_id); + facade.GetUncompressedForwardGeometry(source_geometry_id); geometry.osm_node_ids.push_back( facade.GetOSMNodeIDOfNode(source_geometry[source_segment_start_coordinate])); @@ -102,9 +102,9 @@ inline LegGeometry assembleGeometry(const datafacade::BaseDataFacade &facade, const auto target_node_id = reversed_target ? target_node.reverse_segment_id.id : target_node.forward_segment_id.id; - const auto target_gemetry_id = facade.GetGeometryIndex(target_node_id).id; + const auto target_geometry_id = facade.GetGeometryIndex(target_node_id).id; const std::vector forward_datasources = - facade.GetUncompressedForwardDatasources(target_gemetry_id); + facade.GetUncompressedForwardDatasources(target_geometry_id); // FIXME if source and target phantoms are on the same segment then duration and weight // will be from one projected point till end of segment @@ -127,7 +127,7 @@ inline LegGeometry assembleGeometry(const datafacade::BaseDataFacade &facade, const auto target_segment_end_coordinate = target_node.fwd_segment_position + (reversed_target ? 0 : 1); const std::vector target_geometry = - facade.GetUncompressedForwardGeometry(target_gemetry_id); + facade.GetUncompressedForwardGeometry(target_geometry_id); geometry.osm_node_ids.push_back( facade.GetOSMNodeIDOfNode(target_geometry[target_segment_end_coordinate])); diff --git a/include/engine/routing_algorithms/routing_base.hpp b/include/engine/routing_algorithms/routing_base.hpp index 98f1ef8e4..0556f566e 100644 --- a/include/engine/routing_algorithms/routing_base.hpp +++ b/include/engine/routing_algorithms/routing_base.hpp @@ -151,6 +151,7 @@ void annotatePath(const FacadeT &facade, std::vector weight_vector; std::vector duration_vector; std::vector datasource_vector; + if (geometry_index.forward) { id_vector = facade.GetUncompressedForwardGeometry(geometry_index.id); @@ -165,6 +166,7 @@ void annotatePath(const FacadeT &facade, duration_vector = facade.GetUncompressedReverseDurations(geometry_index.id); datasource_vector = facade.GetUncompressedReverseDatasources(geometry_index.id); } + BOOST_ASSERT(id_vector.size() > 0); BOOST_ASSERT(datasource_vector.size() > 0); BOOST_ASSERT(weight_vector.size() == id_vector.size() - 1); @@ -308,24 +310,6 @@ void annotatePath(const FacadeT &facade, unpacked_path.front().duration_until_turn = std::max(unpacked_path.front().duration_until_turn - source_duration, 0); } - - // there is no equivalent to a node-based node in an edge-expanded graph. - // two equivalent routes may start (or end) at different node-based edges - // as they are added with the offset how much "weight" on the edge - // has already been traversed. Depending on offset one needs to remove - // the last node. - if (unpacked_path.size() > 1) - { - const std::size_t last_index = unpacked_path.size() - 1; - const std::size_t second_to_last_index = last_index - 1; - - if (unpacked_path[last_index].turn_via_node == - unpacked_path[second_to_last_index].turn_via_node) - { - unpacked_path.pop_back(); - } - BOOST_ASSERT(!unpacked_path.empty()); - } } template diff --git a/include/extractor/compressed_edge_container.hpp b/include/extractor/compressed_edge_container.hpp index ca00be864..dc247066f 100644 --- a/include/extractor/compressed_edge_container.hpp +++ b/include/extractor/compressed_edge_container.hpp @@ -10,6 +10,8 @@ #include #include +#include + namespace osrm { namespace extractor @@ -36,7 +38,11 @@ class CompressedEdgeContainer const EdgeWeight weight1, const EdgeWeight weight2, const EdgeDuration duration1, - const EdgeDuration duration2); + const EdgeDuration duration2, + // node-penalties can be added before/or after the traversal of an edge which + // depends on whether we traverse the link forwards or backwards. + const boost::optional node_weight_penalty = boost::none, + const boost::optional node_duration_penalty = boost::none); void AddUncompressedEdge(const EdgeID edge_id, const NodeID target_node, diff --git a/include/extractor/extraction_containers.hpp b/include/extractor/extraction_containers.hpp index 82387a8a6..aa95064ca 100644 --- a/include/extractor/extraction_containers.hpp +++ b/include/extractor/extraction_containers.hpp @@ -40,7 +40,7 @@ class ExtractionContainers using NameOffsets = std::vector; std::vector barrier_nodes; - std::vector traffic_lights; + std::vector traffic_signals; NodeIDVector used_node_id_list; NodeVector all_nodes_list; EdgeVector all_edges_list; diff --git a/include/extractor/extraction_turn.hpp b/include/extractor/extraction_turn.hpp index a4299f7cc..fba8dafd5 100644 --- a/include/extractor/extraction_turn.hpp +++ b/include/extractor/extraction_turn.hpp @@ -22,6 +22,14 @@ struct ExtractionTurn { } + ExtractionTurn(const bool has_traffic_light = false) + : angle(0), turn_type(guidance::TurnType::NoTurn), + direction_modifier(guidance::DirectionModifier::Straight), + has_traffic_light(has_traffic_light), weight(0.), duration(0.), source_restricted(false), + target_restricted(false) + { + } + const double angle; const guidance::TurnType::Enum turn_type; const guidance::DirectionModifier::Enum direction_modifier; diff --git a/include/extractor/graph_compressor.hpp b/include/extractor/graph_compressor.hpp index 200902348..a8772b170 100644 --- a/include/extractor/graph_compressor.hpp +++ b/include/extractor/graph_compressor.hpp @@ -1,6 +1,7 @@ #ifndef GEOMETRY_COMPRESSOR_HPP #define GEOMETRY_COMPRESSOR_HPP +#include "extractor/scripting_environment.hpp" #include "util/typedefs.hpp" #include "util/node_based_graph.hpp" @@ -24,6 +25,7 @@ class GraphCompressor public: void Compress(const std::unordered_set &barrier_nodes, const std::unordered_set &traffic_lights, + ScriptingEnvironment &scripting_environment, std::vector &turn_restrictions, util::NodeBasedDynamicGraph &graph, CompressedEdgeContainer &geometry_compressor); diff --git a/src/extractor/compressed_edge_container.cpp b/src/extractor/compressed_edge_container.cpp index c850949c1..67b9024b1 100644 --- a/src/extractor/compressed_edge_container.cpp +++ b/src/extractor/compressed_edge_container.cpp @@ -103,14 +103,17 @@ SegmentDuration CompressedEdgeContainer::ClipDuration(const SegmentDuration dura // ----------> via_node_id -----------> target_node_id // weight_1 weight_2 // duration_1 duration_2 -void CompressedEdgeContainer::CompressEdge(const EdgeID edge_id_1, - const EdgeID edge_id_2, - const NodeID via_node_id, - const NodeID target_node_id, - const EdgeWeight weight1, - const EdgeWeight weight2, - const EdgeDuration duration1, - const EdgeDuration duration2) +void CompressedEdgeContainer::CompressEdge( + const EdgeID edge_id_1, + const EdgeID edge_id_2, + const NodeID via_node_id, + const NodeID target_node_id, + const EdgeWeight weight1, + const EdgeWeight weight2, + const EdgeDuration duration1, + const EdgeDuration duration2, + const boost::optional node_weight_penalty, + const boost::optional node_duration_penalty) { // remove super-trivial geometries BOOST_ASSERT(SPECIAL_EDGEID != edge_id_1); @@ -151,9 +154,11 @@ void CompressedEdgeContainer::CompressEdge(const EdgeID edge_id_1, std::vector &edge_bucket_list1 = m_compressed_oneway_geometries[edge_bucket_id1]; + bool was_empty = edge_bucket_list1.empty(); + // note we don't save the start coordinate: it is implicitly given by edge 1 // weight1 is the distance to the (currently) last coordinate in the bucket - if (edge_bucket_list1.empty()) + if (was_empty) { edge_bucket_list1.emplace_back( OnewayCompressedEdge{via_node_id, ClipWeight(weight1), ClipDuration(duration1)}); @@ -162,6 +167,14 @@ void CompressedEdgeContainer::CompressEdge(const EdgeID edge_id_1, BOOST_ASSERT(0 < edge_bucket_list1.size()); BOOST_ASSERT(!edge_bucket_list1.empty()); + // if the via-node offers a penalty, we add the weight of the penalty as an artificial + // segment that references SPECIAL_NODEID + if (node_weight_penalty && node_duration_penalty) + { + edge_bucket_list1.emplace_back(OnewayCompressedEdge{ + via_node_id, ClipWeight(*node_weight_penalty), ClipDuration(*node_duration_penalty)}); + } + if (HasEntryForID(edge_id_2)) { // second edge is not atomic anymore diff --git a/src/extractor/edge_based_graph_factory.cpp b/src/extractor/edge_based_graph_factory.cpp index c06c313c1..b149434a1 100644 --- a/src/extractor/edge_based_graph_factory.cpp +++ b/src/extractor/edge_based_graph_factory.cpp @@ -168,6 +168,11 @@ NBGToEBG EdgeBasedGraphFactory::InsertEdgeBasedNode(const NodeID node_u, const N m_compressed_edge_container.GetBucketReference(edge_id_2)[segment_count - 1 - i] .node_id); const NodeID current_edge_target_coordinate_id = forward_geometry[i].node_id; + + // don't add node-segments for penalties + if (current_edge_target_coordinate_id == current_edge_source_coordinate_id) + continue; + BOOST_ASSERT(current_edge_target_coordinate_id != current_edge_source_coordinate_id); // build edges diff --git a/src/extractor/extraction_containers.cpp b/src/extractor/extraction_containers.cpp index 8ae7aa2ee..f775d7795 100644 --- a/src/extractor/extraction_containers.cpp +++ b/src/extractor/extraction_containers.cpp @@ -616,17 +616,17 @@ void ExtractionContainers::WriteNodes(storage::io::FileWriter &file_out) const util::UnbufferedLog log; log << "Writing traffic light nodes ... "; TIMER_START(write_nodes); - std::vector internal_traffic_lights; - for (const auto osm_id : traffic_lights) + std::vector internal_traffic_signals; + for (const auto osm_id : traffic_signals) { const auto node_id = mapExternalToInternalNodeID( used_node_id_list.begin(), used_node_id_list.end(), osm_id); if (node_id != SPECIAL_NODEID) { - internal_traffic_lights.push_back(node_id); + internal_traffic_signals.push_back(node_id); } } - storage::serialization::write(file_out, internal_traffic_lights); + storage::serialization::write(file_out, internal_traffic_signals); log << "ok, after " << TIMER_SEC(write_nodes) << "s"; } diff --git a/src/extractor/extractor.cpp b/src/extractor/extractor.cpp index 90eaa0ee0..8f5bacb0c 100644 --- a/src/extractor/extractor.cpp +++ b/src/extractor/extractor.cpp @@ -454,15 +454,16 @@ Extractor::BuildEdgeExpandedGraph(ScriptingEnvironment &scripting_environment, guidance::LaneDescriptionMap &turn_lane_map) { std::unordered_set barrier_nodes; - std::unordered_set traffic_lights; + std::unordered_set traffic_signals; auto node_based_graph = - LoadNodeBasedGraph(barrier_nodes, traffic_lights, coordinates, osm_node_ids); + LoadNodeBasedGraph(barrier_nodes, traffic_signals, coordinates, osm_node_ids); CompressedEdgeContainer compressed_edge_container; GraphCompressor graph_compressor; graph_compressor.Compress(barrier_nodes, - traffic_lights, + traffic_signals, + scripting_environment, turn_restrictions, *node_based_graph, compressed_edge_container); @@ -474,7 +475,7 @@ Extractor::BuildEdgeExpandedGraph(ScriptingEnvironment &scripting_environment, EdgeBasedGraphFactory edge_based_graph_factory(node_based_graph, compressed_edge_container, barrier_nodes, - traffic_lights, + traffic_signals, coordinates, osm_node_ids, scripting_environment.GetProfileProperties(), diff --git a/src/extractor/extractor_callbacks.cpp b/src/extractor/extractor_callbacks.cpp index d58119444..99bef5957 100644 --- a/src/extractor/extractor_callbacks.cpp +++ b/src/extractor/extractor_callbacks.cpp @@ -69,7 +69,7 @@ void ExtractorCallbacks::ProcessNode(const osmium::Node &input_node, } if (result_node.traffic_lights) { - external_memory.traffic_lights.push_back(id); + external_memory.traffic_signals.push_back(id); } } diff --git a/src/extractor/graph_compressor.cpp b/src/extractor/graph_compressor.cpp index ccd079fce..a3599b8d6 100644 --- a/src/extractor/graph_compressor.cpp +++ b/src/extractor/graph_compressor.cpp @@ -1,6 +1,8 @@ #include "extractor/graph_compressor.hpp" #include "extractor/compressed_edge_container.hpp" +#include "extractor/extraction_turn.hpp" +#include "extractor/guidance/intersection.hpp" #include "extractor/restriction.hpp" #include "extractor/restriction_compressor.hpp" @@ -19,7 +21,8 @@ namespace extractor { void GraphCompressor::Compress(const std::unordered_set &barrier_nodes, - const std::unordered_set &traffic_lights, + const std::unordered_set &traffic_signals, + ScriptingEnvironment &scripting_environment, std::vector &turn_restrictions, util::NodeBasedDynamicGraph &graph, CompressedEdgeContainer &geometry_compressor) @@ -50,6 +53,8 @@ void GraphCompressor::Compress(const std::unordered_set &barrier_nodes, std::for_each(turn_restrictions.begin(), turn_restrictions.end(), remember_via_nodes); { + const auto weight_multiplier = + scripting_environment.GetProfileProperties().GetWeightMultiplier(); util::UnbufferedLog log; util::Percent progress(log, original_number_of_nodes); @@ -184,13 +189,31 @@ void GraphCompressor::Compress(const std::unordered_set &barrier_nodes, graph.GetEdgeData(reverse_e2).lane_description_id = selectLaneID( rev_edge_data2.lane_description_id, rev_edge_data1.lane_description_id); + /* // Do not compress edge if it crosses a traffic signal. // This can't be done in CanCombineWith, becase we only store the - // traffic signals in the `traffic_lights` list, which EdgeData + // traffic signals in the `traffic signal` list, which EdgeData // doesn't have access to. - const bool has_node_penalty = traffic_lights.find(node_v) != traffic_lights.end(); + */ + const bool has_node_penalty = traffic_signals.find(node_v) != traffic_signals.end(); + boost::optional node_duration_penalty = boost::none; + boost::optional node_weight_penalty = boost::none; if (has_node_penalty) - continue; + { + // generate an artifical turn for the turn penalty generation + ExtractionTurn extraction_turn(true); + + extraction_turn.source_restricted = fwd_edge_data1.restricted; + extraction_turn.target_restricted = fwd_edge_data2.restricted; + + // we cannot handle this as node penalty, if it depends on turn direction + if (extraction_turn.source_restricted != extraction_turn.target_restricted) + continue; + + scripting_environment.ProcessTurn(extraction_turn); + node_duration_penalty = extraction_turn.duration * 10; + node_weight_penalty = extraction_turn.weight * weight_multiplier; + } // Get weights before graph is modified const auto forward_weight1 = fwd_edge_data1.weight; @@ -217,6 +240,14 @@ void GraphCompressor::Compress(const std::unordered_set &barrier_nodes, graph.GetEdgeData(forward_e1).duration += forward_duration2; graph.GetEdgeData(reverse_e1).duration += reverse_duration2; + if (node_weight_penalty && node_duration_penalty) + { + graph.GetEdgeData(forward_e1).weight += *node_weight_penalty; + graph.GetEdgeData(reverse_e1).weight += *node_weight_penalty; + graph.GetEdgeData(forward_e1).duration += *node_duration_penalty; + graph.GetEdgeData(reverse_e1).duration += *node_duration_penalty; + } + // extend e1's to targets of e2's graph.SetTarget(forward_e1, node_w); graph.SetTarget(reverse_e1, node_u); @@ -236,7 +267,9 @@ void GraphCompressor::Compress(const std::unordered_set &barrier_nodes, forward_weight1, forward_weight2, forward_duration1, - forward_duration2); + forward_duration2, + node_weight_penalty, + node_duration_penalty); geometry_compressor.CompressEdge(reverse_e1, reverse_e2, node_v, @@ -244,7 +277,9 @@ void GraphCompressor::Compress(const std::unordered_set &barrier_nodes, reverse_weight1, reverse_weight2, reverse_duration1, - reverse_duration2); + reverse_duration2, + node_weight_penalty, + node_duration_penalty); } } } diff --git a/unit_tests/extractor/graph_compressor.cpp b/unit_tests/extractor/graph_compressor.cpp index 9a6f3013d..95236feed 100644 --- a/unit_tests/extractor/graph_compressor.cpp +++ b/unit_tests/extractor/graph_compressor.cpp @@ -4,6 +4,8 @@ #include "util/node_based_graph.hpp" #include "util/typedefs.hpp" +#include "../unit_tests/mocks/mock_scripting_environment.hpp" + #include #include @@ -55,6 +57,7 @@ BOOST_AUTO_TEST_CASE(long_road_test) std::unordered_set traffic_lights; std::vector restrictions; CompressedEdgeContainer container; + test::MockScriptingEnvironment scripting_environment; std::vector edges = {MakeUnitEdge(0, 1), MakeUnitEdge(1, 0), @@ -70,7 +73,8 @@ BOOST_AUTO_TEST_CASE(long_road_test) BOOST_ASSERT(edges[4].data.IsCompatibleTo(edges[6].data)); Graph graph(5, edges); - compressor.Compress(barrier_nodes, traffic_lights, restrictions, graph, container); + compressor.Compress( + barrier_nodes, traffic_lights, scripting_environment, restrictions, graph, container); BOOST_CHECK_EQUAL(graph.FindEdge(0, 1), SPECIAL_EDGEID); BOOST_CHECK_EQUAL(graph.FindEdge(1, 2), SPECIAL_EDGEID); @@ -92,6 +96,7 @@ BOOST_AUTO_TEST_CASE(loop_test) std::unordered_set traffic_lights; std::vector restrictions; CompressedEdgeContainer container; + test::MockScriptingEnvironment scripting_environment; std::vector edges = {MakeUnitEdge(0, 1), MakeUnitEdge(0, 5), @@ -120,7 +125,8 @@ BOOST_AUTO_TEST_CASE(loop_test) BOOST_ASSERT(edges[10].data.IsCompatibleTo(edges[11].data)); Graph graph(6, edges); - compressor.Compress(barrier_nodes, traffic_lights, restrictions, graph, container); + compressor.Compress( + barrier_nodes, traffic_lights, scripting_environment, restrictions, graph, container); BOOST_CHECK_EQUAL(graph.FindEdge(5, 0), SPECIAL_EDGEID); BOOST_CHECK_EQUAL(graph.FindEdge(0, 1), SPECIAL_EDGEID); @@ -144,6 +150,7 @@ BOOST_AUTO_TEST_CASE(t_intersection) std::unordered_set traffic_lights; std::vector restrictions; CompressedEdgeContainer container; + test::MockScriptingEnvironment scripting_environment; std::vector edges = {MakeUnitEdge(0, 1), MakeUnitEdge(1, 0), @@ -159,7 +166,8 @@ BOOST_AUTO_TEST_CASE(t_intersection) BOOST_ASSERT(edges[4].data.IsCompatibleTo(edges[5].data)); Graph graph(4, edges); - compressor.Compress(barrier_nodes, traffic_lights, restrictions, graph, container); + compressor.Compress( + barrier_nodes, traffic_lights, scripting_environment, restrictions, graph, container); BOOST_CHECK(graph.FindEdge(0, 1) != SPECIAL_EDGEID); BOOST_CHECK(graph.FindEdge(1, 2) != SPECIAL_EDGEID); @@ -177,6 +185,7 @@ BOOST_AUTO_TEST_CASE(street_name_changes) std::unordered_set traffic_lights; std::vector restrictions; CompressedEdgeContainer container; + test::MockScriptingEnvironment scripting_environment; std::vector edges = { MakeUnitEdge(0, 1), MakeUnitEdge(1, 0), MakeUnitEdge(1, 2), MakeUnitEdge(2, 1)}; @@ -186,7 +195,8 @@ BOOST_AUTO_TEST_CASE(street_name_changes) BOOST_ASSERT(edges[2].data.IsCompatibleTo(edges[3].data)); Graph graph(5, edges); - compressor.Compress(barrier_nodes, traffic_lights, restrictions, graph, container); + compressor.Compress( + barrier_nodes, traffic_lights, scripting_environment, restrictions, graph, container); BOOST_CHECK(graph.FindEdge(0, 1) != SPECIAL_EDGEID); BOOST_CHECK(graph.FindEdge(1, 2) != SPECIAL_EDGEID); @@ -203,6 +213,7 @@ BOOST_AUTO_TEST_CASE(direction_changes) std::unordered_set traffic_lights; std::vector restrictions; CompressedEdgeContainer container; + test::MockScriptingEnvironment scripting_environment; std::vector edges = { MakeUnitEdge(0, 1), MakeUnitEdge(1, 0), MakeUnitEdge(1, 2), MakeUnitEdge(2, 1)}; @@ -210,7 +221,8 @@ BOOST_AUTO_TEST_CASE(direction_changes) edges[1].data.reversed = true; Graph graph(5, edges); - compressor.Compress(barrier_nodes, traffic_lights, restrictions, graph, container); + compressor.Compress( + barrier_nodes, traffic_lights, scripting_environment, restrictions, graph, container); BOOST_CHECK(graph.FindEdge(0, 1) != SPECIAL_EDGEID); BOOST_CHECK(graph.FindEdge(1, 2) != SPECIAL_EDGEID); diff --git a/unit_tests/mocks/mock_scripting_environment.hpp b/unit_tests/mocks/mock_scripting_environment.hpp new file mode 100644 index 000000000..51cd6dfba --- /dev/null +++ b/unit_tests/mocks/mock_scripting_environment.hpp @@ -0,0 +1,47 @@ +#ifndef MOCK_SCRIPTING_ENVIRONMENT_HPP_ +#define MOCK_SCRIPTING_ENVIRONMENT_HPP_ + +#include "extractor/extraction_segment.hpp" +#include "extractor/extraction_turn.hpp" +#include "extractor/profile_properties.hpp" +#include "extractor/scripting_environment.hpp" + +#include +#include +#include + +namespace osrm +{ + +namespace test +{ + +// a mock implementation of the scripting environment doing exactly nothing +class MockScriptingEnvironment : public extractor::ScriptingEnvironment +{ + + const extractor::ProfileProperties &GetProfileProperties() override final + { + static extractor::ProfileProperties properties; + return properties; + } + + std::vector GetNameSuffixList() override final { return {}; } + + std::vector GetRestrictions() override final { return {}; } + void ProcessTurn(extractor::ExtractionTurn &) override final {} + void ProcessSegment(extractor::ExtractionSegment &) override final {} + + void ProcessElements(const osmium::memory::Buffer &, + const extractor::RestrictionParser &, + std::vector> &, + std::vector> &, + std::vector &) override final + { + } +}; + +} // namespace test +} // namespace osrm + +#endif // MOCK_SCRIPTING_ENVIRONMENT_HPP_