Make edge metrics strongly typed (#6421)
This change takes the existing typedefs for weight, duration and distance, and makes them proper types, using the existing Alias functionality. Primarily this is to prevent bugs where the metrics are switched, but it also adds additional documentation. For example, it now makes it clear (despite the naming of variables) that most of the trip algorithm is running on the duration metric. I've not made any changes to the casts performed between metrics and numeric types, they now just more explicit.
This commit is contained in:
@@ -78,7 +78,8 @@ int Contractor::Run()
|
||||
// Convert node weights for oneway streets to INVALID_EDGE_WEIGHT
|
||||
for (auto &weight : node_weights)
|
||||
{
|
||||
weight = (weight & 0x80000000) ? INVALID_EDGE_WEIGHT : weight;
|
||||
weight = (from_alias<EdgeWeight::value_type>(weight) & 0x80000000) ? INVALID_EDGE_WEIGHT
|
||||
: weight;
|
||||
}
|
||||
|
||||
// Contracting the edge-expanded graph
|
||||
|
||||
@@ -170,8 +170,8 @@ void ContractNode(ContractorThreadData *data,
|
||||
}
|
||||
|
||||
heap.Clear();
|
||||
heap.Insert(source, 0, ContractorHeapData{});
|
||||
EdgeWeight max_weight = 0;
|
||||
heap.Insert(source, {0}, ContractorHeapData{});
|
||||
EdgeWeight max_weight = {0};
|
||||
unsigned number_of_targets = 0;
|
||||
|
||||
for (auto out_edge : graph.GetAdjacentEdgeRange(node))
|
||||
@@ -199,7 +199,7 @@ void ContractNode(ContractorThreadData *data,
|
||||
// CAREFUL: This only works due to the independent node-setting. This
|
||||
// guarantees that source is not connected to another node that is
|
||||
// contracted
|
||||
node_weights[source] = path_weight + 1;
|
||||
node_weights[source] = path_weight + EdgeWeight{1};
|
||||
BOOST_ASSERT(stats != nullptr);
|
||||
stats->edges_added_count += 2;
|
||||
stats->original_edges_added_count +=
|
||||
|
||||
Reference in New Issue
Block a user