Lazily generate optional route path data (#6045)
Currently route results are annotated with additional path information, such as geometries, turn-by-turn steps and other metadata. These annotations are generated if they are not requested or returned in the response. Datasets needed to generate these annotations are loaded and available to the OSRM process even when unused. This commit is a first step towards making the loading of these datasets optional. We refactor the code so that route annotations are only generated if explicitly requested and needed in the response. Specifically, we change the following annotations to be lazily generated: - Turn-by-turn steps - Route Overview geometry - Route segment metadata For example. a /route/v1 request with steps=false&overview=false&annotations=false would no longer call the following data facade methods: - GetOSMNodeIDOfNode - GetTurnInstructionForEdgeID - GetNameIndex - GetNameForID - GetRefForID - GetTurnInstructionForEdgeID - GetClassData - IsLeftHandDriving - GetTravelMode - IsSegregated - PreTurnBearing - PostTurnBearing - HasLaneData - GetLaneData - GetEntryClass Requests that include segment metadata and/or overview geometry but not turn-by-turn instructions will also benefit from this, although there is some interdependency with the step instructions - a call to GetTurnInstructionForEdgeID is still required. Requests for OSM annotations will understandably still need to call GetOSMNodeIDOfNode. Making these changes unlocks the optional loading of data contained in the following OSRM files: - osrm.names - osrm.icd - osrm.nbg_nodes (partial) - osrm.ebg_nodes (partial) - osrm.edges
This commit is contained in:
@@ -19,8 +19,8 @@ BOOST_AUTO_TEST_CASE(unchanged_collapse_route_result)
|
||||
PhantomNode target;
|
||||
source.forward_segment_id = {1, true};
|
||||
target.forward_segment_id = {6, true};
|
||||
PathData pathy{0, 2, 17, false, 2, 3, 4, 5, 0, {}, 4, 2, {}, 2, {1.0}, {1.0}, false};
|
||||
PathData kathy{0, 1, 16, false, 1, 2, 3, 4, 1, {}, 3, 1, {}, 1, {2.0}, {3.0}, false};
|
||||
PathData pathy{0, 2, 2, 3, 4, 5, 2, boost::none};
|
||||
PathData kathy{0, 1, 1, 2, 3, 4, 1, boost::none};
|
||||
InternalRouteResult one_leg_result;
|
||||
one_leg_result.unpacked_path_segments = {{pathy, kathy}};
|
||||
one_leg_result.segment_end_coordinates = {PhantomNodes{source, target}};
|
||||
@@ -37,13 +37,11 @@ BOOST_AUTO_TEST_CASE(unchanged_collapse_route_result)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(two_legs_to_one_leg)
|
||||
{
|
||||
// from_edge_based_node, turn_via_node, name_id, is_segregated, weight_until_turn,
|
||||
// weight_of_turn,
|
||||
// duration_until_turn, duration_of_turn, turn_instruction, lane_data, travel_mode, classes,
|
||||
// entry_class, datasource_id, pre_turn_bearing, post_turn_bearing, left_hand
|
||||
PathData pathy{0, 2, 17, false, 2, 3, 4, 5, 0, {}, 4, 2, {}, 2, {1.0}, {1.0}, false};
|
||||
PathData kathy{0, 1, 16, false, 1, 2, 3, 4, 1, {}, 3, 1, {}, 1, {2.0}, {3.0}, false};
|
||||
PathData cathy{0, 3, 16, false, 1, 2, 3, 4, 1, {}, 3, 1, {}, 1, {2.0}, {3.0}, false};
|
||||
// from_edge_based_node, turn_via_node, weight_until_turn, weight_of_turn,
|
||||
// duration_until_turn, duration_of_turn, datasource_id, turn_edge
|
||||
PathData pathy{0, 2, 2, 3, 4, 5, 2, boost::none};
|
||||
PathData kathy{0, 1, 1, 2, 3, 4, 1, boost::none};
|
||||
PathData cathy{0, 3, 1, 2, 3, 4, 1, boost::none};
|
||||
PhantomNode node_1;
|
||||
PhantomNode node_2;
|
||||
PhantomNode node_3;
|
||||
@@ -73,11 +71,11 @@ BOOST_AUTO_TEST_CASE(two_legs_to_one_leg)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(three_legs_to_two_legs)
|
||||
{
|
||||
PathData pathy{0, 2, 17, false, 2, 3, 4, 5, 0, {}, 4, 2, {}, 2, {1.0}, {1.0}, false};
|
||||
PathData kathy{0, 1, 16, false, 1, 2, 3, 4, 1, {}, 3, 1, {}, 1, {2.0}, {3.0}, false};
|
||||
PathData qathy{0, 5, 16, false, 1, 2, 3, 4, 1, {}, 3, 1, {}, 1, {2.0}, {3.0}, false};
|
||||
PathData cathy{0, 3, 16, false, 1, 2, 3, 4, 1, {}, 3, 1, {}, 1, {2.0}, {3.0}, false};
|
||||
PathData mathy{0, 4, 18, false, 8, 9, 13, 4, 2, {}, 4, 2, {}, 2, {3.0}, {1.0}, false};
|
||||
PathData pathy{0, 2, 2, 3, 4, 5, 2, boost::none};
|
||||
PathData kathy{0, 1, 1, 2, 3, 4, 1, boost::none};
|
||||
PathData qathy{0, 5, 1, 2, 3, 4, 1, boost::none};
|
||||
PathData cathy{0, 3, 1, 2, 3, 4, 1, boost::none};
|
||||
PathData mathy{0, 4, 8, 9, 13, 4, 2, boost::none};
|
||||
PhantomNode node_1;
|
||||
PhantomNode node_2;
|
||||
PhantomNode node_3;
|
||||
@@ -117,9 +115,9 @@ BOOST_AUTO_TEST_CASE(three_legs_to_two_legs)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(two_legs_to_two_legs)
|
||||
{
|
||||
PathData pathy{0, 2, 17, false, 2, 3, 4, 5, 0, {}, 4, 2, {}, 2, {1.0}, {1.0}, false};
|
||||
PathData kathy{0, 1, 16, false, 1, 2, 3, 4, 1, {}, 3, 1, {}, 1, {2.0}, {3.0}, false};
|
||||
PathData cathy{0, 3, 16, false, 1, 2, 3, 4, 1, {}, 3, 1, {}, 1, {2.0}, {3.0}, false};
|
||||
PathData pathy{0, 2, 2, 3, 4, 5, 2, boost::none};
|
||||
PathData kathy{0, 1, 1, 2, 3, 4, 1, boost::none};
|
||||
PathData cathy{0, 3, 1, 2, 3, 4, 1, boost::none};
|
||||
PhantomNode node_1;
|
||||
PhantomNode node_2;
|
||||
PhantomNode node_3;
|
||||
|
||||
@@ -92,7 +92,7 @@ BOOST_AUTO_TEST_CASE(trim_short_segments)
|
||||
{FloatLongitude{-73.981495}, FloatLatitude{40.768275}}};
|
||||
geometry.segment_offsets = {0, 2};
|
||||
geometry.segment_distances = {1.9076601161280742};
|
||||
geometry.osm_node_ids = {OSMNodeID{0}, OSMNodeID{1}, OSMNodeID{2}};
|
||||
geometry.node_ids = {NodeID{0}, NodeID{1}, NodeID{2}};
|
||||
geometry.annotations = {{1.9076601161280742, 0.2, 0.2, 0}, {0, 0, 0, 0}};
|
||||
|
||||
trimShortSegments(steps, geometry);
|
||||
@@ -102,7 +102,7 @@ BOOST_AUTO_TEST_CASE(trim_short_segments)
|
||||
BOOST_CHECK_EQUAL(geometry.segment_offsets.back(), 1);
|
||||
BOOST_CHECK_EQUAL(geometry.annotations.size(), 1);
|
||||
BOOST_CHECK_EQUAL(geometry.locations.size(), 2);
|
||||
BOOST_CHECK_EQUAL(geometry.osm_node_ids.size(), 2);
|
||||
BOOST_CHECK_EQUAL(geometry.node_ids.size(), 2);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
Reference in New Issue
Block a user