From 66cc99703cac71fefd15794e730943c092738c83 Mon Sep 17 00:00:00 2001 From: Michael Krasnyk Date: Thu, 9 Mar 2017 09:05:09 +0100 Subject: [PATCH] Compute correct speed values in tile plugin --- CHANGELOG.md | 5 +++ src/engine/plugins/tile.cpp | 74 ++++++++++++++++++++++++++++++------- unit_tests/library/tile.cpp | 41 +++++++++++++++----- 3 files changed, 97 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c1c0704f5..09c04015c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,9 @@ +# 5.6.3 + - Changes from 5.6.0 + - Bugfixes + - #3790 Fix incorrect speed values in tile plugin + # 5.6.2 - Changes from 5.6.0 - Bugfixes diff --git a/src/engine/plugins/tile.cpp b/src/engine/plugins/tile.cpp index e3cb1ee5f..c83f1370c 100644 --- a/src/engine/plugins/tile.cpp +++ b/src/engine/plugins/tile.cpp @@ -79,9 +79,10 @@ struct TurnData final TurnData(const util::Coordinate coordinate_, const std::size_t _in, const std::size_t _out, - const std::size_t _weight) + const std::size_t _weight, + const std::size_t _duration) : coordinate(std::move(coordinate_)), in_angle_offset(_in), turn_angle_offset(_out), - weight_offset(_weight) + weight_offset(_weight), duration_offset(_duration) { } @@ -89,6 +90,7 @@ struct TurnData final const std::size_t in_angle_offset; const std::size_t turn_angle_offset; const std::size_t weight_offset; + const std::size_t duration_offset; }; using FixedPoint = Point; @@ -457,6 +459,7 @@ Status TilePlugin::HandleRequest(const std::shared_ptr unpacked_shortcut; std::vector approach_weight_vector; + std::vector approach_duration_vector; // Make sure we traverse the startnodes in a consistent order // to ensure identical PBF encoding on all platforms. @@ -539,16 +542,25 @@ Status TilePlugin::HandleRequest(const std::shared_ptrGetUncompressedForwardWeights( edge_based_node_info[approachedge.edge_based_node_id] .packed_geometry_id); + approach_duration_vector = facade->GetUncompressedForwardDurations( + edge_based_node_info[approachedge.edge_based_node_id] + .packed_geometry_id); } else { approach_weight_vector = facade->GetUncompressedReverseWeights( edge_based_node_info[approachedge.edge_based_node_id] .packed_geometry_id); + approach_duration_vector = facade->GetUncompressedReverseDurations( + edge_based_node_info[approachedge.edge_based_node_id] + .packed_geometry_id); } const auto sum_node_weight = std::accumulate(approach_weight_vector.begin(), approach_weight_vector.end(), EdgeWeight{0}); + const auto sum_node_duration = std::accumulate(approach_duration_vector.begin(), + approach_duration_vector.end(), + EdgeWeight{0}); // The edge.weight is the whole edge weight, which includes the turn // cost. @@ -557,7 +569,8 @@ Status TilePlugin::HandleRequest(const std::shared_ptrGetUncompressedForwardWeights(edge.packed_geometry_id); const auto reverse_weight_vector = @@ -679,8 +696,20 @@ Status TilePlugin::HandleRequest(const std::shared_ptrGetUncompressedForwardDurations(edge.packed_geometry_id); + const auto reverse_duration_vector = + facade->GetUncompressedReverseDurations(edge.packed_geometry_id); + const auto forward_duration = forward_duration_vector[edge.fwd_segment_position]; + const auto reverse_duration = + reverse_duration_vector[reverse_duration_vector.size() - + edge.fwd_segment_position - 1]; + use_line_value(forward_duration); + use_line_value(reverse_duration); } // Begin the layer features block @@ -701,6 +730,10 @@ Status TilePlugin::HandleRequest(const std::shared_ptrGetUncompressedForwardWeights(edge.packed_geometry_id); const auto reverse_weight_vector = facade->GetUncompressedReverseWeights(edge.packed_geometry_id); + const auto forward_duration_vector = + facade->GetUncompressedForwardDurations(edge.packed_geometry_id); + const auto reverse_duration_vector = + facade->GetUncompressedReverseDurations(edge.packed_geometry_id); const auto forward_datasource_vector = facade->GetUncompressedForwardDatasources(edge.packed_geometry_id); const auto reverse_datasource_vector = @@ -709,6 +742,11 @@ Status TilePlugin::HandleRequest(const std::shared_ptr(round(length / forward_weight * 10 * 3.6)); + static_cast(round(length / forward_duration * 10 * 3.6)); auto tile_line = coordinatesToTileLine(a, b, tile_bbox); if (!tile_line.empty()) @@ -803,6 +845,7 @@ Status TilePlugin::HandleRequest(const std::shared_ptr(round(length / reverse_weight * 10 * 3.6)); + static_cast(round(length / reverse_duration * 10 * 3.6)); auto tile_line = coordinatesToTileLine(b, a, tile_bbox); if (!tile_line.empty()) @@ -827,6 +870,7 @@ Status TilePlugin::HandleRequest(const std::shared_ptr 700); } @@ -236,6 +240,7 @@ BOOST_AUTO_TEST_CASE(test_tile_turns) std::vector found_bearing_in_indexes; std::vector found_turn_angles_indexes; std::vector found_penalties_indexes; + std::vector found_weight_indexes; const auto check_turn_feature = [&](protozero::pbf_reader feature_message) { feature_message.next(); // advance parser to first entry @@ -250,7 +255,7 @@ BOOST_AUTO_TEST_CASE(test_tile_turns) BOOST_CHECK_EQUAL(feature_message.tag(), util::vector_tile::FEATURE_ATTRIBUTES_TAG); // properties auto feature_iter_pair = feature_message.get_packed_uint32(); - BOOST_CHECK_EQUAL(std::distance(feature_iter_pair.begin(), feature_iter_pair.end()), 6); + BOOST_CHECK_EQUAL(std::distance(feature_iter_pair.begin(), feature_iter_pair.end()), 8); auto iter = feature_iter_pair.begin(); BOOST_CHECK_EQUAL(*iter++, 0); // bearing_in key found_bearing_in_indexes.push_back(*iter++); @@ -258,6 +263,8 @@ BOOST_AUTO_TEST_CASE(test_tile_turns) found_turn_angles_indexes.push_back(*iter++); BOOST_CHECK_EQUAL(*iter++, 2); // cost key found_penalties_indexes.push_back(*iter++); // skip value check, can be valud uint32 + BOOST_CHECK_EQUAL(*iter++, 3); // weight key + found_weight_indexes.push_back(*iter++); // skip value check, can be valud uint32 BOOST_CHECK(iter == feature_iter_pair.end()); // geometry feature_message.next(); @@ -333,6 +340,18 @@ BOOST_AUTO_TEST_CASE(test_tile_turns) 0, 0, 0, 0, 0, 0, .1f, .1f, .3f, .4f, 1.2f, 1.9f, 5.3f, 5.5f, 5.8f, 7.1f, 7.2f, 7.2f}; BOOST_CHECK(actual_turn_penalties == expected_turn_penalties); + // Verify that we got the expected turn penalties + std::vector actual_turn_weights; + for (const auto &i : found_weight_indexes) + { + BOOST_CHECK(float_vals.count(i) == 1); + actual_turn_weights.push_back(float_vals[i]); + } + std::sort(actual_turn_weights.begin(), actual_turn_weights.end()); + const std::vector expected_turn_weights = { + 0, 0, 0, 0, 0, 0, .1f, .1f, .3f, .4f, 1.2f, 1.9f, 5.3f, 5.5f, 5.8f, 7.1f, 7.2f, 7.2f}; + BOOST_CHECK(actual_turn_weights == expected_turn_weights); + // Verify the expected turn angles std::vector actual_turn_angles; for (const auto &i : found_turn_angles_indexes) @@ -401,7 +420,7 @@ BOOST_AUTO_TEST_CASE(test_tile_speeds) auto property_iter_pair = feature_message.get_packed_uint32(); auto value_begin = property_iter_pair.begin(); auto value_end = property_iter_pair.end(); - BOOST_CHECK_EQUAL(std::distance(value_begin, value_end), 10); + BOOST_CHECK_EQUAL(std::distance(value_begin, value_end), 12); auto iter = value_begin; BOOST_CHECK_EQUAL(*iter++, 0); // speed key found_speed_indexes.push_back(*iter++); @@ -410,10 +429,12 @@ BOOST_AUTO_TEST_CASE(test_tile_speeds) found_component_indexes.push_back(*iter++); BOOST_CHECK_EQUAL(*iter++, 2); // data source key found_datasource_indexes.push_back(*iter++); - BOOST_CHECK_EQUAL(*iter++, 3); // duration key + BOOST_CHECK_EQUAL(*iter++, 3); // weight key + found_duration_indexes.push_back(*iter++); + BOOST_CHECK_EQUAL(*iter++, 4); // duration key found_duration_indexes.push_back(*iter++); // name - BOOST_CHECK_EQUAL(*iter++, 4); + BOOST_CHECK_EQUAL(*iter++, 5); found_name_indexes.push_back(*iter++); BOOST_CHECK(iter == value_end); // geometry