Rename increasingly inaccuratly named distance member of QueryEdge to weight

This commit is contained in:
Patrick Niklaus
2016-05-12 18:50:10 +02:00
committed by Patrick Niklaus
parent 1d994da12b
commit b8795c7341
13 changed files with 253 additions and 260 deletions
@@ -29,10 +29,10 @@ class ManyToManyRouting final
struct NodeBucket
{
unsigned target_id; // essentially a row in the distance matrix
EdgeWeight distance;
NodeBucket(const unsigned target_id, const EdgeWeight distance)
: target_id(target_id), distance(distance)
unsigned target_id; // essentially a row in the weight matrix
EdgeWeight weight;
NodeBucket(const unsigned target_id, const EdgeWeight weight)
: target_id(target_id), weight(weight)
{
}
};
@@ -68,7 +68,7 @@ class ManyToManyRouting final
unsigned column_idx = 0;
const auto search_target_phantom = [&](const PhantomNode &phantom) {
query_heap.Clear();
// insert target(s) at distance 0
// insert target(s) at weight 0
if (phantom.forward_segment_id.enabled)
{
@@ -95,7 +95,7 @@ class ManyToManyRouting final
unsigned row_idx = 0;
const auto search_source_phantom = [&](const PhantomNode &phantom) {
query_heap.Clear();
// insert target(s) at distance 0
// insert target(s) at weight 0
if (phantom.forward_segment_id.enabled)
{
@@ -166,7 +166,7 @@ class ManyToManyRouting final
std::vector<EdgeWeight> &result_table) const
{
const NodeID node = query_heap.DeleteMin();
const int source_distance = query_heap.GetKey(node);
const int source_weight = query_heap.GetKey(node);
// check if each encountered node has an entry
const auto bucket_iterator = search_space_with_buckets.find(node);
@@ -178,30 +178,30 @@ class ManyToManyRouting final
{
// get target id from bucket entry
const unsigned column_idx = current_bucket.target_id;
const int target_distance = current_bucket.distance;
auto &current_distance = result_table[row_idx * number_of_targets + column_idx];
// check if new distance is better
const EdgeWeight new_distance = source_distance + target_distance;
if (new_distance < 0)
const int target_weight = current_bucket.weight;
auto &current_weight = result_table[row_idx * number_of_targets + column_idx];
// check if new weight is better
const EdgeWeight new_weight = source_weight + target_weight;
if (new_weight < 0)
{
const EdgeWeight loop_weight = super::GetLoopWeight(facade, node);
const int new_distance_with_loop = new_distance + loop_weight;
if (loop_weight != INVALID_EDGE_WEIGHT && new_distance_with_loop >= 0)
const int new_weight_with_loop = new_weight + loop_weight;
if (loop_weight != INVALID_EDGE_WEIGHT && new_weight_with_loop >= 0)
{
current_distance = std::min(current_distance, new_distance_with_loop);
current_weight = std::min(current_weight, new_weight_with_loop);
}
}
else if (new_distance < current_distance)
else if (new_weight < current_weight)
{
result_table[row_idx * number_of_targets + column_idx] = new_distance;
result_table[row_idx * number_of_targets + column_idx] = new_weight;
}
}
}
if (StallAtNode<true>(facade, node, source_distance, query_heap))
if (StallAtNode<true>(facade, node, source_weight, query_heap))
{
return;
}
RelaxOutgoingEdges<true>(facade, node, source_distance, query_heap);
RelaxOutgoingEdges<true>(facade, node, source_weight, query_heap);
}
void BackwardRoutingStep(const DataFacadeT &facade,
@@ -210,23 +210,23 @@ class ManyToManyRouting final
SearchSpaceWithBuckets &search_space_with_buckets) const
{
const NodeID node = query_heap.DeleteMin();
const int target_distance = query_heap.GetKey(node);
const int target_weight = query_heap.GetKey(node);
// store settled nodes in search space bucket
search_space_with_buckets[node].emplace_back(column_idx, target_distance);
search_space_with_buckets[node].emplace_back(column_idx, target_weight);
if (StallAtNode<false>(facade, node, target_distance, query_heap))
if (StallAtNode<false>(facade, node, target_weight, query_heap))
{
return;
}
RelaxOutgoingEdges<false>(facade, node, target_distance, query_heap);
RelaxOutgoingEdges<false>(facade, node, target_weight, query_heap);
}
template <bool forward_direction>
inline void RelaxOutgoingEdges(const DataFacadeT &facade,
const NodeID node,
const EdgeWeight distance,
const EdgeWeight weight,
QueryHeap &query_heap) const
{
for (auto edge : facade.GetAdjacentEdgeRange(node))
@@ -236,22 +236,22 @@ class ManyToManyRouting final
if (direction_flag)
{
const NodeID to = facade.GetTarget(edge);
const int edge_weight = data.distance;
const int edge_weight = data.weight;
BOOST_ASSERT_MSG(edge_weight > 0, "edge_weight invalid");
const int to_distance = distance + edge_weight;
const int to_weight = weight + edge_weight;
// New Node discovered -> Add to Heap + Node Info Storage
if (!query_heap.WasInserted(to))
{
query_heap.Insert(to, to_distance, node);
query_heap.Insert(to, to_weight, node);
}
// Found a shorter Path -> Update distance
else if (to_distance < query_heap.GetKey(to))
// Found a shorter Path -> Update weight
else if (to_weight < query_heap.GetKey(to))
{
// new parent
query_heap.GetData(to).parent = node;
query_heap.DecreaseKey(to, to_distance);
query_heap.DecreaseKey(to, to_weight);
}
}
}
@@ -261,7 +261,7 @@ class ManyToManyRouting final
template <bool forward_direction>
inline bool StallAtNode(const DataFacadeT &facade,
const NodeID node,
const EdgeWeight distance,
const EdgeWeight weight,
QueryHeap &query_heap) const
{
for (auto edge : facade.GetAdjacentEdgeRange(node))
@@ -271,11 +271,11 @@ class ManyToManyRouting final
if (reverse_flag)
{
const NodeID to = facade.GetTarget(edge);
const int edge_weight = data.distance;
const int edge_weight = data.weight;
BOOST_ASSERT_MSG(edge_weight > 0, "edge_weight invalid");
if (query_heap.WasInserted(to))
{
if (query_heap.GetKey(to) + edge_weight < distance)
if (query_heap.GetKey(to) + edge_weight < weight)
{
return true;
}