Switch code to use packed vector for segment weights/durations
This commit is contained in:
committed by
Patrick Niklaus
parent
5c61f00ffa
commit
3599d1db8e
@@ -74,6 +74,26 @@ unsigned CompressedEdgeContainer::GetZippedPositionForReverseID(const EdgeID edg
|
||||
return map_iterator->second;
|
||||
}
|
||||
|
||||
SegmentWeight CompressedEdgeContainer::ClipWeight(const SegmentWeight weight)
|
||||
{
|
||||
if (weight >= INVALID_SEGMENT_WEIGHT)
|
||||
{
|
||||
clipped_weights++;
|
||||
return MAX_SEGMENT_WEIGHT;
|
||||
}
|
||||
return weight;
|
||||
}
|
||||
|
||||
SegmentDuration CompressedEdgeContainer::ClipDuration(const SegmentDuration duration)
|
||||
{
|
||||
if (duration >= INVALID_SEGMENT_DURATION)
|
||||
{
|
||||
clipped_weights++;
|
||||
return MAX_SEGMENT_DURATION;
|
||||
}
|
||||
return duration;
|
||||
}
|
||||
|
||||
// Adds info for a compressed edge to the container. edge_id_2
|
||||
// has been removed from the graph, so we have to save These edges/nodes
|
||||
// have already been trimmed from the graph, this function just stores
|
||||
@@ -87,10 +107,10 @@ void CompressedEdgeContainer::CompressEdge(const EdgeID edge_id_1,
|
||||
const EdgeID edge_id_2,
|
||||
const NodeID via_node_id,
|
||||
const NodeID target_node_id,
|
||||
EdgeWeight weight1,
|
||||
EdgeWeight weight2,
|
||||
EdgeDuration duration1,
|
||||
EdgeDuration duration2)
|
||||
const EdgeWeight weight1,
|
||||
const EdgeWeight weight2,
|
||||
const EdgeDuration duration1,
|
||||
const EdgeDuration duration2)
|
||||
{
|
||||
// remove super-trivial geometries
|
||||
BOOST_ASSERT(SPECIAL_EDGEID != edge_id_1);
|
||||
@@ -131,34 +151,12 @@ void CompressedEdgeContainer::CompressEdge(const EdgeID edge_id_1,
|
||||
std::vector<OnewayCompressedEdge> &edge_bucket_list1 =
|
||||
m_compressed_oneway_geometries[edge_bucket_id1];
|
||||
|
||||
const auto clip_weight = [&](const SegmentWeight weight) {
|
||||
if (weight >= INVALID_SEGMENT_WEIGHT)
|
||||
{
|
||||
clipped_weights++;
|
||||
return INVALID_SEGMENT_WEIGHT - 1;
|
||||
}
|
||||
return weight;
|
||||
};
|
||||
const auto clip_duration = [&](const SegmentDuration duration) {
|
||||
if (duration >= INVALID_SEGMENT_DURATION)
|
||||
{
|
||||
clipped_weights++;
|
||||
return INVALID_SEGMENT_DURATION - 1;
|
||||
}
|
||||
return duration;
|
||||
};
|
||||
|
||||
// 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())
|
||||
{
|
||||
weight1 = clip_weight(weight1);
|
||||
duration1 = clip_duration(duration1);
|
||||
|
||||
edge_bucket_list1.emplace_back(
|
||||
OnewayCompressedEdge{via_node_id,
|
||||
static_cast<SegmentWeight>(weight1),
|
||||
static_cast<SegmentDuration>(duration1)});
|
||||
OnewayCompressedEdge{via_node_id, ClipWeight(weight1), ClipDuration(duration1)});
|
||||
}
|
||||
|
||||
BOOST_ASSERT(0 < edge_bucket_list1.size());
|
||||
@@ -188,14 +186,9 @@ void CompressedEdgeContainer::CompressEdge(const EdgeID edge_id_1,
|
||||
}
|
||||
else
|
||||
{
|
||||
weight2 = clip_weight(weight2);
|
||||
duration2 = clip_duration(duration2);
|
||||
|
||||
// we are certain that the second edge is atomic.
|
||||
edge_bucket_list1.emplace_back(
|
||||
OnewayCompressedEdge{target_node_id,
|
||||
static_cast<SegmentWeight>(weight2),
|
||||
static_cast<SegmentDuration>(duration2)});
|
||||
OnewayCompressedEdge{target_node_id, ClipWeight(weight2), ClipDuration(duration2)});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -238,7 +231,8 @@ void CompressedEdgeContainer::AddUncompressedEdge(const EdgeID edge_id,
|
||||
// Don't re-add this if it's already in there.
|
||||
if (edge_bucket_list.empty())
|
||||
{
|
||||
edge_bucket_list.emplace_back(OnewayCompressedEdge{target_node_id, weight, duration});
|
||||
edge_bucket_list.emplace_back(
|
||||
OnewayCompressedEdge{target_node_id, ClipWeight(weight), ClipDuration(duration)});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,9 +266,9 @@ unsigned CompressedEdgeContainer::ZipEdges(const EdgeID f_edge_id, const EdgeID
|
||||
constexpr DatasourceID LUA_SOURCE = 0;
|
||||
|
||||
segment_data->nodes.emplace_back(first_node.node_id);
|
||||
segment_data->fwd_weights.emplace_back(INVALID_EDGE_WEIGHT);
|
||||
segment_data->fwd_weights.emplace_back(INVALID_SEGMENT_WEIGHT);
|
||||
segment_data->rev_weights.emplace_back(first_node.weight);
|
||||
segment_data->fwd_durations.emplace_back(INVALID_EDGE_WEIGHT);
|
||||
segment_data->fwd_durations.emplace_back(INVALID_SEGMENT_DURATION);
|
||||
segment_data->rev_durations.emplace_back(first_node.duration);
|
||||
segment_data->datasources.emplace_back(LUA_SOURCE);
|
||||
|
||||
@@ -297,9 +291,9 @@ unsigned CompressedEdgeContainer::ZipEdges(const EdgeID f_edge_id, const EdgeID
|
||||
|
||||
segment_data->nodes.emplace_back(last_node.node_id);
|
||||
segment_data->fwd_weights.emplace_back(last_node.weight);
|
||||
segment_data->rev_weights.emplace_back(INVALID_EDGE_WEIGHT);
|
||||
segment_data->rev_weights.emplace_back(INVALID_SEGMENT_WEIGHT);
|
||||
segment_data->fwd_durations.emplace_back(last_node.duration);
|
||||
segment_data->rev_durations.emplace_back(INVALID_EDGE_WEIGHT);
|
||||
segment_data->rev_durations.emplace_back(INVALID_SEGMENT_DURATION);
|
||||
segment_data->datasources.emplace_back(LUA_SOURCE);
|
||||
|
||||
return zipped_geometry_id;
|
||||
|
||||
@@ -487,6 +487,8 @@ Extractor::BuildEdgeExpandedGraph(ScriptingEnvironment &scripting_environment,
|
||||
config.turn_penalties_index_path,
|
||||
config.cnbg_ebg_graph_mapping_output_path);
|
||||
|
||||
compressed_edge_container.PrintStatistics();
|
||||
|
||||
// The osrm-partition tool requires the compressed node based graph with an embedding.
|
||||
//
|
||||
// The `Run` function above re-numbers non-reverse compressed node based graph edges
|
||||
|
||||
+59
-33
@@ -351,14 +351,29 @@ void Storage::PopulateLayout(DataLayout &layout)
|
||||
const auto number_of_compressed_geometries = reader.ReadVectorSize<NodeID>();
|
||||
layout.SetBlockSize<NodeID>(DataLayout::GEOMETRIES_NODE_LIST,
|
||||
number_of_compressed_geometries);
|
||||
layout.SetBlockSize<SegmentWeight>(DataLayout::GEOMETRIES_FWD_WEIGHT_LIST,
|
||||
number_of_compressed_geometries);
|
||||
layout.SetBlockSize<SegmentWeight>(DataLayout::GEOMETRIES_REV_WEIGHT_LIST,
|
||||
number_of_compressed_geometries);
|
||||
layout.SetBlockSize<SegmentDuration>(DataLayout::GEOMETRIES_FWD_DURATION_LIST,
|
||||
number_of_compressed_geometries);
|
||||
layout.SetBlockSize<SegmentDuration>(DataLayout::GEOMETRIES_REV_DURATION_LIST,
|
||||
number_of_compressed_geometries);
|
||||
|
||||
reader.ReadElementCount64(); // number of segments
|
||||
const auto number_of_segment_weight_blocks =
|
||||
reader.ReadVectorSize<extractor::SegmentDataView::SegmentWeightVector::block_type>();
|
||||
|
||||
reader.ReadElementCount64(); // number of segments
|
||||
auto number_of_rev_weight_blocks =
|
||||
reader.ReadVectorSize<extractor::SegmentDataView::SegmentWeightVector::block_type>();
|
||||
BOOST_ASSERT(number_of_rev_weight_blocks == number_of_segment_weight_blocks);
|
||||
(void)number_of_rev_weight_blocks;
|
||||
|
||||
reader.ReadElementCount64(); // number of segments
|
||||
const auto number_of_segment_duration_blocks =
|
||||
reader.ReadVectorSize<extractor::SegmentDataView::SegmentDurationVector::block_type>();
|
||||
|
||||
layout.SetBlockSize<extractor::SegmentDataView::SegmentWeightVector::block_type>(
|
||||
DataLayout::GEOMETRIES_FWD_WEIGHT_LIST, number_of_segment_weight_blocks);
|
||||
layout.SetBlockSize<extractor::SegmentDataView::SegmentWeightVector::block_type>(
|
||||
DataLayout::GEOMETRIES_REV_WEIGHT_LIST, number_of_segment_weight_blocks);
|
||||
layout.SetBlockSize<extractor::SegmentDataView::SegmentDurationVector::block_type>(
|
||||
DataLayout::GEOMETRIES_FWD_DURATION_LIST, number_of_segment_duration_blocks);
|
||||
layout.SetBlockSize<extractor::SegmentDataView::SegmentDurationVector::block_type>(
|
||||
DataLayout::GEOMETRIES_REV_DURATION_LIST, number_of_segment_duration_blocks);
|
||||
layout.SetBlockSize<DatasourceID>(DataLayout::DATASOURCES_LIST,
|
||||
number_of_compressed_geometries);
|
||||
}
|
||||
@@ -658,35 +673,47 @@ void Storage::PopulateData(const DataLayout &layout, char *memory_ptr)
|
||||
util::vector_view<unsigned> geometry_begin_indices(
|
||||
geometries_index_ptr, layout.num_entries[storage::DataLayout::GEOMETRIES_INDEX]);
|
||||
|
||||
auto num_entries = layout.num_entries[storage::DataLayout::GEOMETRIES_NODE_LIST];
|
||||
|
||||
auto geometries_node_list_ptr =
|
||||
layout.GetBlockPtr<NodeID, true>(memory_ptr, storage::DataLayout::GEOMETRIES_NODE_LIST);
|
||||
util::vector_view<NodeID> geometry_node_list(
|
||||
geometries_node_list_ptr,
|
||||
layout.num_entries[storage::DataLayout::GEOMETRIES_NODE_LIST]);
|
||||
util::vector_view<NodeID> geometry_node_list(geometries_node_list_ptr, num_entries);
|
||||
|
||||
auto geometries_fwd_weight_list_ptr = layout.GetBlockPtr<SegmentWeight, true>(
|
||||
memory_ptr, storage::DataLayout::GEOMETRIES_FWD_WEIGHT_LIST);
|
||||
util::vector_view<SegmentWeight> geometry_fwd_weight_list(
|
||||
geometries_fwd_weight_list_ptr,
|
||||
layout.num_entries[storage::DataLayout::GEOMETRIES_FWD_WEIGHT_LIST]);
|
||||
auto geometries_fwd_weight_list_ptr =
|
||||
layout.GetBlockPtr<extractor::SegmentDataView::SegmentWeightVector::block_type, true>(
|
||||
memory_ptr, storage::DataLayout::GEOMETRIES_FWD_WEIGHT_LIST);
|
||||
extractor::SegmentDataView::SegmentWeightVector geometry_fwd_weight_list(
|
||||
util::vector_view<extractor::SegmentDataView::SegmentWeightVector::block_type>(
|
||||
geometries_fwd_weight_list_ptr,
|
||||
layout.num_entries[storage::DataLayout::GEOMETRIES_FWD_WEIGHT_LIST]),
|
||||
num_entries);
|
||||
|
||||
auto geometries_rev_weight_list_ptr = layout.GetBlockPtr<SegmentWeight, true>(
|
||||
memory_ptr, storage::DataLayout::GEOMETRIES_REV_WEIGHT_LIST);
|
||||
util::vector_view<SegmentWeight> geometry_rev_weight_list(
|
||||
geometries_rev_weight_list_ptr,
|
||||
layout.num_entries[storage::DataLayout::GEOMETRIES_REV_WEIGHT_LIST]);
|
||||
auto geometries_rev_weight_list_ptr =
|
||||
layout.GetBlockPtr<extractor::SegmentDataView::SegmentWeightVector::block_type, true>(
|
||||
memory_ptr, storage::DataLayout::GEOMETRIES_REV_WEIGHT_LIST);
|
||||
extractor::SegmentDataView::SegmentWeightVector geometry_rev_weight_list(
|
||||
util::vector_view<extractor::SegmentDataView::SegmentWeightVector::block_type>(
|
||||
geometries_rev_weight_list_ptr,
|
||||
layout.num_entries[storage::DataLayout::GEOMETRIES_REV_WEIGHT_LIST]),
|
||||
num_entries);
|
||||
|
||||
auto geometries_fwd_duration_list_ptr = layout.GetBlockPtr<SegmentDuration, true>(
|
||||
memory_ptr, storage::DataLayout::GEOMETRIES_FWD_DURATION_LIST);
|
||||
util::vector_view<SegmentDuration> geometry_fwd_duration_list(
|
||||
geometries_fwd_duration_list_ptr,
|
||||
layout.num_entries[storage::DataLayout::GEOMETRIES_FWD_DURATION_LIST]);
|
||||
auto geometries_fwd_duration_list_ptr =
|
||||
layout.GetBlockPtr<extractor::SegmentDataView::SegmentDurationVector::block_type, true>(
|
||||
memory_ptr, storage::DataLayout::GEOMETRIES_FWD_DURATION_LIST);
|
||||
extractor::SegmentDataView::SegmentDurationVector geometry_fwd_duration_list(
|
||||
util::vector_view<extractor::SegmentDataView::SegmentDurationVector::block_type>(
|
||||
geometries_fwd_duration_list_ptr,
|
||||
layout.num_entries[storage::DataLayout::GEOMETRIES_FWD_DURATION_LIST]),
|
||||
num_entries);
|
||||
|
||||
auto geometries_rev_duration_list_ptr = layout.GetBlockPtr<SegmentDuration, true>(
|
||||
memory_ptr, storage::DataLayout::GEOMETRIES_REV_DURATION_LIST);
|
||||
util::vector_view<SegmentDuration> geometry_rev_duration_list(
|
||||
geometries_rev_duration_list_ptr,
|
||||
layout.num_entries[storage::DataLayout::GEOMETRIES_REV_DURATION_LIST]);
|
||||
auto geometries_rev_duration_list_ptr =
|
||||
layout.GetBlockPtr<extractor::SegmentDataView::SegmentDurationVector::block_type, true>(
|
||||
memory_ptr, storage::DataLayout::GEOMETRIES_REV_DURATION_LIST);
|
||||
extractor::SegmentDataView::SegmentDurationVector geometry_rev_duration_list(
|
||||
util::vector_view<extractor::SegmentDataView::SegmentDurationVector::block_type>(
|
||||
geometries_rev_duration_list_ptr,
|
||||
layout.num_entries[storage::DataLayout::GEOMETRIES_REV_DURATION_LIST]),
|
||||
num_entries);
|
||||
|
||||
auto datasources_list_ptr = layout.GetBlockPtr<DatasourceID, true>(
|
||||
memory_ptr, storage::DataLayout::DATASOURCES_LIST);
|
||||
@@ -722,8 +749,7 @@ void Storage::PopulateData(const DataLayout &layout, char *memory_ptr)
|
||||
extractor::PackedOSMIDsView osm_node_ids(
|
||||
util::vector_view<extractor::PackedOSMIDsView::block_type>(
|
||||
osmnodeid_ptr, layout.num_entries[DataLayout::OSM_NODE_ID_LIST]),
|
||||
layout.num_entries[DataLayout::OSM_NODE_ID_LIST] *
|
||||
extractor::PackedOSMIDsView::BLOCK_ELEMENTS);
|
||||
layout.num_entries[DataLayout::COORDINATE_LIST]);
|
||||
|
||||
extractor::files::readNodes(config.node_based_nodes_data_path, coordinates, osm_node_ids);
|
||||
}
|
||||
|
||||
+23
-7
@@ -81,14 +81,22 @@ template <typename T> inline bool is_aligned(const void *pointer)
|
||||
}
|
||||
|
||||
// Returns duration in deci-seconds
|
||||
inline EdgeWeight convertToDuration(double speed_in_kmh, double distance_in_meters)
|
||||
inline SegmentDuration convertToDuration(double speed_in_kmh, double distance_in_meters)
|
||||
{
|
||||
if (speed_in_kmh <= 0.)
|
||||
return MAXIMAL_EDGE_DURATION;
|
||||
return INVALID_SEGMENT_DURATION;
|
||||
|
||||
const auto speed_in_ms = speed_in_kmh / 3.6;
|
||||
const auto duration = distance_in_meters / speed_in_ms;
|
||||
return std::max(1, boost::numeric_cast<EdgeWeight>(std::round(duration * 10.)));
|
||||
auto segment_duration = std::max<SegmentDuration>(
|
||||
1, boost::numeric_cast<SegmentDuration>(std::round(duration * 10.)));
|
||||
if (segment_duration >= INVALID_SEGMENT_DURATION)
|
||||
{
|
||||
util::Log(logWARNING) << "Clamping segment duration " << segment_duration << " to "
|
||||
<< MAX_SEGMENT_DURATION;
|
||||
segment_duration = MAX_SEGMENT_DURATION;
|
||||
}
|
||||
return segment_duration;
|
||||
}
|
||||
|
||||
#if !defined(NDEBUG)
|
||||
@@ -182,11 +190,19 @@ updateSegmentData(const UpdaterConfig &config,
|
||||
}
|
||||
|
||||
if (rate <= 0.)
|
||||
return INVALID_EDGE_WEIGHT;
|
||||
return INVALID_SEGMENT_WEIGHT;
|
||||
|
||||
const auto weight_multiplier = profile_properties.GetWeightMultiplier();
|
||||
const auto weight = distance_in_meters / rate;
|
||||
return std::max(1, boost::numeric_cast<EdgeWeight>(std::round(weight * weight_multiplier)));
|
||||
auto segment_weight = std::max<SegmentWeight>(
|
||||
1, boost::numeric_cast<SegmentWeight>(std::round(weight * weight_multiplier)));
|
||||
if (segment_weight >= INVALID_SEGMENT_WEIGHT)
|
||||
{
|
||||
util::Log(logWARNING) << "Clamping segment weight " << segment_weight << " to "
|
||||
<< MAX_SEGMENT_WEIGHT;
|
||||
segment_weight = MAX_SEGMENT_WEIGHT;
|
||||
}
|
||||
return segment_weight;
|
||||
};
|
||||
|
||||
// The check here is enabled by the `--edge-weight-updates-over-factor` flag it logs a
|
||||
@@ -739,7 +755,7 @@ Updater::LoadAndUpdateEdgeExpandedGraph(std::vector<extractor::EdgeBasedEdge> &e
|
||||
const auto weights = segment_data.GetForwardWeights(geometry_id.id);
|
||||
for (const auto weight : weights)
|
||||
{
|
||||
if (weight == INVALID_EDGE_WEIGHT)
|
||||
if (weight == INVALID_SEGMENT_WEIGHT)
|
||||
{
|
||||
new_weight = INVALID_EDGE_WEIGHT;
|
||||
break;
|
||||
@@ -754,7 +770,7 @@ Updater::LoadAndUpdateEdgeExpandedGraph(std::vector<extractor::EdgeBasedEdge> &e
|
||||
const auto weights = segment_data.GetReverseWeights(geometry_id.id);
|
||||
for (const auto weight : weights)
|
||||
{
|
||||
if (weight == INVALID_EDGE_WEIGHT)
|
||||
if (weight == INVALID_SEGMENT_WEIGHT)
|
||||
{
|
||||
new_weight = INVALID_EDGE_WEIGHT;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user