Compute correct speed values in tile plugin

This commit is contained in:
Michael Krasnyk 2017-03-09 09:05:09 +01:00 committed by Patrick Niklaus
parent bf6b571455
commit 0a13390ab0
5 changed files with 72 additions and 20 deletions

View File

@ -3,6 +3,11 @@
- Internals
- Shared memory notification via conditional variables on Linux or semaphore queue on OS X and Windows with a limit of 128 OSRM Engine instances
# 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

View File

@ -22,7 +22,8 @@ struct TurnData final
const util::Coordinate coordinate;
const int in_angle;
const int turn_angle;
const int weight;
const EdgeWeight weight;
const EdgeWeight duration;
};
using RTreeLeaf = datafacade::BaseDataFacade::RTreeLeaf;

View File

@ -421,6 +421,8 @@ void encodeVectorTile(const datafacade::ContiguousInternalMemoryDataFacadeBase &
for (const auto &edge_index : sorted_edge_indexes)
{
const auto &edge = edges[edge_index];
// Weight values
const auto forward_weight_vector =
facade.GetUncompressedForwardWeights(edge.packed_geometry_id);
const auto reverse_weight_vector =
@ -428,8 +430,20 @@ void encodeVectorTile(const datafacade::ContiguousInternalMemoryDataFacadeBase &
const auto forward_weight = forward_weight_vector[edge.fwd_segment_position];
const auto reverse_weight = reverse_weight_vector[reverse_weight_vector.size() -
edge.fwd_segment_position - 1];
use_line_value(reverse_weight);
use_line_value(forward_weight);
use_line_value(reverse_weight);
// Duration values
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_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
@ -450,6 +464,10 @@ void encodeVectorTile(const datafacade::ContiguousInternalMemoryDataFacadeBase &
facade.GetUncompressedForwardWeights(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 =
@ -458,6 +476,11 @@ void encodeVectorTile(const datafacade::ContiguousInternalMemoryDataFacadeBase &
const auto reverse_weight =
reverse_weight_vector[reverse_weight_vector.size() -
edge.fwd_segment_position - 1];
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];
const auto forward_datasource =
forward_datasource_vector[edge.fwd_segment_position];
const auto reverse_datasource =
@ -484,6 +507,7 @@ void encodeVectorTile(const datafacade::ContiguousInternalMemoryDataFacadeBase &
&max_datasource_id,
&used_line_ints](const FixedLine &tile_line,
const std::uint32_t speed_kmh,
const std::size_t weight,
const std::size_t duration,
const DatasourceID datasource,
const std::size_t name_idx,
@ -519,10 +543,13 @@ void encodeVectorTile(const datafacade::ContiguousInternalMemoryDataFacadeBase &
(edge.component.is_tiny ? 0 : 1)); // is_small feature
field.add_element(2); // "datasource" tag key offset
field.add_element(130 + datasource); // datasource value offset
field.add_element(3); // "duration" tag key offset
field.add_element(3); // "weight" tag key offset
field.add_element(130 + max_datasource_id + 1 +
weight); // weight value offset
field.add_element(4); // "duration" tag key offset
field.add_element(130 + max_datasource_id + 1 +
duration); // duration value offset
field.add_element(4); // "name" tag key offset
field.add_element(5); // "name" tag key offset
field.add_element(130 + max_datasource_id + 1 + used_line_ints.size() +
name_idx); // name value offset
@ -537,14 +564,14 @@ void encodeVectorTile(const datafacade::ContiguousInternalMemoryDataFacadeBase &
};
// If this is a valid forward edge, go ahead and add it to the tile
if (forward_weight != 0 && edge.forward_segment_id.enabled)
if (forward_duration != 0 && edge.forward_segment_id.enabled)
{
std::int32_t start_x = 0;
std::int32_t start_y = 0;
// Calculate the speed for this line
std::uint32_t speed_kmh =
static_cast<std::uint32_t>(round(length / forward_weight * 10 * 3.6));
static_cast<std::uint32_t>(round(length / forward_duration * 10 * 3.6));
auto tile_line = coordinatesToTileLine(a, b, tile_bbox);
if (!tile_line.empty())
@ -552,6 +579,7 @@ void encodeVectorTile(const datafacade::ContiguousInternalMemoryDataFacadeBase &
encode_tile_line(tile_line,
speed_kmh,
line_int_offsets[forward_weight],
line_int_offsets[forward_duration],
forward_datasource,
name_offset,
start_x,
@ -561,14 +589,14 @@ void encodeVectorTile(const datafacade::ContiguousInternalMemoryDataFacadeBase &
// Repeat the above for the coordinates reversed and using the `reverse`
// properties
if (reverse_weight != 0 && edge.reverse_segment_id.enabled)
if (reverse_duration != 0 && edge.reverse_segment_id.enabled)
{
std::int32_t start_x = 0;
std::int32_t start_y = 0;
// Calculate the speed for this line
std::uint32_t speed_kmh =
static_cast<std::uint32_t>(round(length / reverse_weight * 10 * 3.6));
static_cast<std::uint32_t>(round(length / reverse_duration * 10 * 3.6));
auto tile_line = coordinatesToTileLine(b, a, tile_bbox);
if (!tile_line.empty())
@ -576,6 +604,7 @@ void encodeVectorTile(const datafacade::ContiguousInternalMemoryDataFacadeBase &
encode_tile_line(tile_line,
speed_kmh,
line_int_offsets[reverse_weight],
line_int_offsets[reverse_duration],
reverse_datasource,
name_offset,
start_x,
@ -591,6 +620,7 @@ void encodeVectorTile(const datafacade::ContiguousInternalMemoryDataFacadeBase &
line_layer_writer.add_string(util::vector_tile::KEY_TAG, "speed");
line_layer_writer.add_string(util::vector_tile::KEY_TAG, "is_small");
line_layer_writer.add_string(util::vector_tile::KEY_TAG, "datasource");
line_layer_writer.add_string(util::vector_tile::KEY_TAG, "weight");
line_layer_writer.add_string(util::vector_tile::KEY_TAG, "duration");
line_layer_writer.add_string(util::vector_tile::KEY_TAG, "name");
@ -663,9 +693,9 @@ void encodeVectorTile(const datafacade::ContiguousInternalMemoryDataFacadeBase &
[&](const routing_algorithms::TurnData &t) {
auto angle_idx = use_point_int_value(t.in_angle);
auto turn_idx = use_point_int_value(t.turn_angle);
auto weight_idx =
use_point_float_value(t.weight / 10.0); // Note conversion to float here
return std::make_tuple(t.coordinate, angle_idx, turn_idx, weight_idx);
auto duration_idx =
use_point_float_value(t.duration / 10.0); // Note conversion to float here
return std::make_tuple(t.coordinate, angle_idx, turn_idx, duration_idx);
});
// Now write the points layer for turn penalty data:

View File

@ -83,6 +83,7 @@ getTileTurns(const datafacade::ContiguousInternalMemoryDataFacade<algorithm::CH>
// vw is the "exit"
std::vector<contractor::QueryEdge::EdgeData> unpacked_shortcut;
std::vector<EdgeWeight> approach_weight_vector;
std::vector<EdgeWeight> approach_duration_vector;
// Make sure we traverse the startnodes in a consistent order
// to ensure identical PBF encoding on all platforms.
@ -164,16 +165,25 @@ getTileTurns(const datafacade::ContiguousInternalMemoryDataFacade<algorithm::CH>
approach_weight_vector = facade.GetUncompressedForwardWeights(
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.
@ -182,7 +192,8 @@ getTileTurns(const datafacade::ContiguousInternalMemoryDataFacade<algorithm::CH>
// intersections include stop signs, traffic signals and other
// penalties, but at this stage, we can't divide those out, so we just
// treat the whole lot as the "turn cost" that we'll stick on the map.
const auto turn_cost = data.weight - sum_node_weight;
const auto turn_weight = data.weight - sum_node_weight;
const auto turn_duration = data.duration - sum_node_duration;
// Find the three nodes that make up the turn movement)
const auto node_from = startnode;
@ -214,7 +225,8 @@ getTileTurns(const datafacade::ContiguousInternalMemoryDataFacade<algorithm::CH>
// Save everything we need to later add all the points to the tile.
// We need the coordinate of the intersection, the angle in, the turn
// angle and the turn cost.
all_turn_data.push_back(TurnData{coord_via, angle_in, turn_angle, turn_cost});
all_turn_data.push_back(
TurnData{coord_via, angle_in, turn_angle, turn_weight, turn_duration});
}
}
}

View File

@ -55,7 +55,7 @@ BOOST_AUTO_TEST_CASE(test_tile)
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
BOOST_CHECK_LT(*iter++, 128); // speed value
@ -66,10 +66,12 @@ BOOST_AUTO_TEST_CASE(test_tile)
iter++;
BOOST_CHECK_EQUAL(*iter++, 2); // data source key
*iter++; // skip value check, can be valud uint32
BOOST_CHECK_EQUAL(*iter++, 3); // duration key
BOOST_CHECK_EQUAL(*iter++, 3); // weight key
BOOST_CHECK_GT(*iter++, 130); // weight value
BOOST_CHECK_EQUAL(*iter++, 4); // duration key
BOOST_CHECK_GT(*iter++, 130); // duration value
// name
BOOST_CHECK_EQUAL(*iter++, 4);
BOOST_CHECK_EQUAL(*iter++, 5);
BOOST_CHECK_GT(*iter++, 130);
BOOST_CHECK(iter == value_end);
// geometry
@ -138,7 +140,7 @@ BOOST_AUTO_TEST_CASE(test_tile)
}
}
BOOST_CHECK_EQUAL(number_of_speed_keys, 5);
BOOST_CHECK_EQUAL(number_of_speed_keys, 6);
BOOST_CHECK_GT(number_of_speed_values, 128); // speed value resolution
tile_message.next();
@ -399,7 +401,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++);
@ -408,10 +410,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