Adjust method and function names

This commit is contained in:
Michael Krasnyk 2017-05-10 23:20:37 +02:00 committed by Patrick Niklaus
parent 9358aa1128
commit 12f47708cd
5 changed files with 80 additions and 65 deletions

View File

@ -55,9 +55,9 @@ struct PhantomNode
forward_duration_offset(0), reverse_duration_offset(0), forward_duration_offset(0), reverse_duration_offset(0),
packed_geometry_id(SPECIAL_GEOMETRYID), component{INVALID_COMPONENTID, false}, packed_geometry_id(SPECIAL_GEOMETRYID), component{INVALID_COMPONENTID, false},
fwd_segment_position(0), forward_travel_mode(TRAVEL_MODE_INACCESSIBLE), fwd_segment_position(0), forward_travel_mode(TRAVEL_MODE_INACCESSIBLE),
backward_travel_mode(TRAVEL_MODE_INACCESSIBLE), is_forward_valid_source(false), backward_travel_mode(TRAVEL_MODE_INACCESSIBLE), is_valid_forward_source(false),
is_forward_valid_target(false), is_reverse_valid_source(false), is_valid_forward_target(false), is_valid_reverse_source(false),
is_reverse_valid_target(false) is_valid_reverse_target(false)
{ {
} }
@ -105,21 +105,21 @@ struct PhantomNode
bool IsValid() const { return location.IsValid() && (name_id != INVALID_NAMEID); } bool IsValid() const { return location.IsValid() && (name_id != INVALID_NAMEID); }
bool IsForwardValidSource() const bool IsValidForwardSource() const
{ {
return forward_segment_id.enabled && is_forward_valid_source; return forward_segment_id.enabled && is_valid_forward_source;
} }
bool IsForwardValidTarget() const bool IsValidForwardTarget() const
{ {
return forward_segment_id.enabled && is_forward_valid_target; return forward_segment_id.enabled && is_valid_forward_target;
} }
bool IsReverseValidSource() const bool IsValidReverseSource() const
{ {
return reverse_segment_id.enabled && is_reverse_valid_source; return reverse_segment_id.enabled && is_valid_reverse_source;
} }
bool IsReverseValidTarget() const bool IsValidReverseTarget() const
{ {
return reverse_segment_id.enabled && is_reverse_valid_target; return reverse_segment_id.enabled && is_valid_reverse_target;
} }
bool operator==(const PhantomNode &other) const { return location == other.location; } bool operator==(const PhantomNode &other) const { return location == other.location; }
@ -134,10 +134,10 @@ struct PhantomNode
EdgeWeight reverse_duration, EdgeWeight reverse_duration,
EdgeWeight forward_duration_offset, EdgeWeight forward_duration_offset,
EdgeWeight reverse_duration_offset, EdgeWeight reverse_duration_offset,
bool is_forward_valid_source, bool is_valid_forward_source,
bool is_forward_valid_target, bool is_valid_forward_target,
bool is_reverse_valid_source, bool is_valid_reverse_source,
bool is_reverse_valid_target, bool is_valid_reverse_target,
const util::Coordinate location, const util::Coordinate location,
const util::Coordinate input_location) const util::Coordinate input_location)
: forward_segment_id{other.forward_segment_id}, : forward_segment_id{other.forward_segment_id},
@ -152,10 +152,10 @@ struct PhantomNode
input_location{input_location}, fwd_segment_position{other.fwd_segment_position}, input_location{input_location}, fwd_segment_position{other.fwd_segment_position},
forward_travel_mode{other.forward_travel_mode}, forward_travel_mode{other.forward_travel_mode},
backward_travel_mode{other.backward_travel_mode}, backward_travel_mode{other.backward_travel_mode},
is_forward_valid_source{is_forward_valid_source}, is_valid_forward_source{is_valid_forward_source},
is_forward_valid_target{is_forward_valid_target}, is_valid_forward_target{is_valid_forward_target},
is_reverse_valid_source{is_reverse_valid_source}, is_valid_reverse_source{is_valid_reverse_source},
is_reverse_valid_target{is_reverse_valid_target} is_valid_reverse_target{is_valid_reverse_target}
{ {
} }
@ -187,10 +187,10 @@ struct PhantomNode
extractor::TravelMode backward_travel_mode : 4; extractor::TravelMode backward_travel_mode : 4;
// is phantom node valid to be used as source or target // is phantom node valid to be used as source or target
private: private:
bool is_forward_valid_source : 1; bool is_valid_forward_source : 1;
bool is_forward_valid_target : 1; bool is_valid_forward_target : 1;
bool is_reverse_valid_source : 1; bool is_valid_reverse_source : 1;
bool is_reverse_valid_target : 1; bool is_valid_reverse_target : 1;
}; };
static_assert(sizeof(PhantomNode) == 72, "PhantomNode has more padding then expected"); static_assert(sizeof(PhantomNode) == 72, "PhantomNode has more padding then expected");

View File

@ -41,43 +41,24 @@ bool needsLoopForward(const PhantomNode &source_phantom, const PhantomNode &targ
bool needsLoopBackwards(const PhantomNode &source_phantom, const PhantomNode &target_phantom); bool needsLoopBackwards(const PhantomNode &source_phantom, const PhantomNode &target_phantom);
template <bool DIRECTION> void insertSourceInHeap(SearchEngineData<ch::Algorithm>::ManyToManyQueryHeap &heap,
void insertNodesInHeap(SearchEngineData<ch::Algorithm>::ManyToManyQueryHeap &heap, const PhantomNode &phantom_node);
const PhantomNode &phantom_node)
{
BOOST_ASSERT(phantom_node.IsValid());
const auto weight_sign = DIRECTION == FORWARD_DIRECTION ? -1 : 1; void insertTargetInHeap(SearchEngineData<ch::Algorithm>::ManyToManyQueryHeap &heap,
if ((DIRECTION == FORWARD_DIRECTION && phantom_node.IsForwardValidSource()) || const PhantomNode &phantom_node);
(DIRECTION == REVERSE_DIRECTION && phantom_node.IsForwardValidTarget()))
{
heap.Insert(
phantom_node.forward_segment_id.id,
weight_sign * phantom_node.GetForwardWeightPlusOffset(),
{phantom_node.forward_segment_id.id, weight_sign * phantom_node.GetForwardDuration()});
}
if ((DIRECTION == FORWARD_DIRECTION && phantom_node.IsReverseValidSource()) ||
(DIRECTION == REVERSE_DIRECTION && phantom_node.IsReverseValidTarget()))
{
heap.Insert(
phantom_node.reverse_segment_id.id,
weight_sign * phantom_node.GetReverseWeightPlusOffset(),
{phantom_node.reverse_segment_id.id, weight_sign * phantom_node.GetReverseDuration()});
}
}
template <typename Heap> template <typename Heap>
void insertNodesInHeaps(Heap &forward_heap, Heap &reverse_heap, const PhantomNodes &nodes) void insertNodesInHeaps(Heap &forward_heap, Heap &reverse_heap, const PhantomNodes &nodes)
{ {
const auto &source = nodes.source_phantom; const auto &source = nodes.source_phantom;
if (source.IsForwardValidSource()) if (source.IsValidForwardSource())
{ {
forward_heap.Insert(source.forward_segment_id.id, forward_heap.Insert(source.forward_segment_id.id,
-source.GetForwardWeightPlusOffset(), -source.GetForwardWeightPlusOffset(),
source.forward_segment_id.id); source.forward_segment_id.id);
} }
if (source.IsReverseValidSource()) if (source.IsValidReverseSource())
{ {
forward_heap.Insert(source.reverse_segment_id.id, forward_heap.Insert(source.reverse_segment_id.id,
-source.GetReverseWeightPlusOffset(), -source.GetReverseWeightPlusOffset(),
@ -85,14 +66,14 @@ void insertNodesInHeaps(Heap &forward_heap, Heap &reverse_heap, const PhantomNod
} }
const auto &target = nodes.target_phantom; const auto &target = nodes.target_phantom;
if (target.IsForwardValidTarget()) if (target.IsValidForwardTarget())
{ {
reverse_heap.Insert(target.forward_segment_id.id, reverse_heap.Insert(target.forward_segment_id.id,
target.GetForwardWeightPlusOffset(), target.GetForwardWeightPlusOffset(),
target.forward_segment_id.id); target.forward_segment_id.id);
} }
if (target.IsReverseValidTarget()) if (target.IsValidReverseTarget())
{ {
reverse_heap.Insert(target.reverse_segment_id.id, reverse_heap.Insert(target.reverse_segment_id.id,
target.GetReverseWeightPlusOffset(), target.GetReverseWeightPlusOffset(),

View File

@ -176,7 +176,7 @@ manyToManySearch(SearchEngineData<Algorithm> &engine_working_data,
const auto search_target_phantom = [&](const PhantomNode &phantom) { const auto search_target_phantom = [&](const PhantomNode &phantom) {
// clear heap and insert target nodes // clear heap and insert target nodes
query_heap.Clear(); query_heap.Clear();
insertNodesInHeap<REVERSE_DIRECTION>(query_heap, phantom); insertTargetInHeap(query_heap, phantom);
// explore search space // explore search space
while (!query_heap.Empty()) while (!query_heap.Empty())
@ -191,7 +191,7 @@ manyToManySearch(SearchEngineData<Algorithm> &engine_working_data,
const auto search_source_phantom = [&](const PhantomNode &phantom) { const auto search_source_phantom = [&](const PhantomNode &phantom) {
// clear heap and insert source nodes // clear heap and insert source nodes
query_heap.Clear(); query_heap.Clear();
insertNodesInHeap<FORWARD_DIRECTION>(query_heap, phantom); insertSourceInHeap(query_heap, phantom);
// explore search space // explore search space
while (!query_heap.Empty()) while (!query_heap.Empty())

View File

@ -9,7 +9,7 @@ namespace routing_algorithms
bool needsLoopForward(const PhantomNode &source_phantom, const PhantomNode &target_phantom) bool needsLoopForward(const PhantomNode &source_phantom, const PhantomNode &target_phantom)
{ {
return source_phantom.IsForwardValidSource() && target_phantom.IsForwardValidTarget() && return source_phantom.IsValidForwardSource() && target_phantom.IsValidForwardTarget() &&
source_phantom.forward_segment_id.id == target_phantom.forward_segment_id.id && source_phantom.forward_segment_id.id == target_phantom.forward_segment_id.id &&
source_phantom.GetForwardWeightPlusOffset() > source_phantom.GetForwardWeightPlusOffset() >
target_phantom.GetForwardWeightPlusOffset(); target_phantom.GetForwardWeightPlusOffset();
@ -17,12 +17,46 @@ bool needsLoopForward(const PhantomNode &source_phantom, const PhantomNode &targ
bool needsLoopBackwards(const PhantomNode &source_phantom, const PhantomNode &target_phantom) bool needsLoopBackwards(const PhantomNode &source_phantom, const PhantomNode &target_phantom)
{ {
return source_phantom.IsReverseValidSource() && target_phantom.IsReverseValidTarget() && return source_phantom.IsValidReverseSource() && target_phantom.IsValidReverseTarget() &&
source_phantom.reverse_segment_id.id == target_phantom.reverse_segment_id.id && source_phantom.reverse_segment_id.id == target_phantom.reverse_segment_id.id &&
source_phantom.GetReverseWeightPlusOffset() > source_phantom.GetReverseWeightPlusOffset() >
target_phantom.GetReverseWeightPlusOffset(); target_phantom.GetReverseWeightPlusOffset();
} }
void insertSourceInHeap(SearchEngineData<ch::Algorithm>::ManyToManyQueryHeap &heap,
const PhantomNode &phantom_node)
{
if (phantom_node.IsValidForwardSource())
{
heap.Insert(phantom_node.forward_segment_id.id,
-phantom_node.GetForwardWeightPlusOffset(),
{phantom_node.forward_segment_id.id, -phantom_node.GetForwardDuration()});
}
if (phantom_node.IsValidReverseSource())
{
heap.Insert(phantom_node.reverse_segment_id.id,
-phantom_node.GetReverseWeightPlusOffset(),
{phantom_node.reverse_segment_id.id, -phantom_node.GetReverseDuration()});
}
}
void insertTargetInHeap(SearchEngineData<ch::Algorithm>::ManyToManyQueryHeap &heap,
const PhantomNode &phantom_node)
{
if (phantom_node.IsValidForwardTarget())
{
heap.Insert(phantom_node.forward_segment_id.id,
phantom_node.GetForwardWeightPlusOffset(),
{phantom_node.forward_segment_id.id, phantom_node.GetForwardDuration()});
}
if (phantom_node.IsValidReverseTarget())
{
heap.Insert(phantom_node.reverse_segment_id.id,
phantom_node.GetReverseWeightPlusOffset(),
{phantom_node.reverse_segment_id.id, phantom_node.GetReverseDuration()});
}
}
} // namespace routing_algorithms } // namespace routing_algorithms
} // namespace engine } // namespace engine
} // namespace osrm } // namespace osrm

View File

@ -233,9 +233,9 @@ shortestPathSearch(SearchEngineData<Algorithm> &engine_working_data,
int total_weight_to_forward = 0; int total_weight_to_forward = 0;
int total_weight_to_reverse = 0; int total_weight_to_reverse = 0;
bool search_from_forward_node = bool search_from_forward_node =
phantom_nodes_vector.front().source_phantom.IsForwardValidSource(); phantom_nodes_vector.front().source_phantom.IsValidForwardSource();
bool search_from_reverse_node = bool search_from_reverse_node =
phantom_nodes_vector.front().source_phantom.IsReverseValidSource(); phantom_nodes_vector.front().source_phantom.IsValidReverseSource();
std::vector<NodeID> prev_packed_leg_to_forward; std::vector<NodeID> prev_packed_leg_to_forward;
std::vector<NodeID> prev_packed_leg_to_reverse; std::vector<NodeID> prev_packed_leg_to_reverse;
@ -259,11 +259,11 @@ shortestPathSearch(SearchEngineData<Algorithm> &engine_working_data,
const auto &source_phantom = phantom_node_pair.source_phantom; const auto &source_phantom = phantom_node_pair.source_phantom;
const auto &target_phantom = phantom_node_pair.target_phantom; const auto &target_phantom = phantom_node_pair.target_phantom;
bool search_to_forward_node = target_phantom.IsForwardValidTarget(); bool search_to_forward_node = target_phantom.IsValidForwardTarget();
bool search_to_reverse_node = target_phantom.IsReverseValidTarget(); bool search_to_reverse_node = target_phantom.IsValidReverseTarget();
BOOST_ASSERT(!search_from_forward_node || source_phantom.IsForwardValidSource()); BOOST_ASSERT(!search_from_forward_node || source_phantom.IsValidForwardSource());
BOOST_ASSERT(!search_from_reverse_node || source_phantom.IsReverseValidSource()); BOOST_ASSERT(!search_from_reverse_node || source_phantom.IsValidReverseSource());
if (search_to_reverse_node || search_to_forward_node) if (search_to_reverse_node || search_to_forward_node)
{ {
@ -285,9 +285,9 @@ shortestPathSearch(SearchEngineData<Algorithm> &engine_working_data,
packed_leg_to_forward); packed_leg_to_forward);
// if only the reverse node is valid (e.g. when using the match plugin) we // if only the reverse node is valid (e.g. when using the match plugin) we
// actually need to move // actually need to move
if (!target_phantom.IsForwardValidTarget()) if (!target_phantom.IsValidForwardTarget())
{ {
BOOST_ASSERT(target_phantom.IsReverseValidTarget()); BOOST_ASSERT(target_phantom.IsValidReverseTarget());
new_total_weight_to_reverse = new_total_weight_to_forward; new_total_weight_to_reverse = new_total_weight_to_forward;
packed_leg_to_reverse = std::move(packed_leg_to_forward); packed_leg_to_reverse = std::move(packed_leg_to_forward);
new_total_weight_to_forward = INVALID_EDGE_WEIGHT; new_total_weight_to_forward = INVALID_EDGE_WEIGHT;
@ -297,7 +297,7 @@ shortestPathSearch(SearchEngineData<Algorithm> &engine_working_data,
// Below we have to check if new_total_weight_to_forward is invalid. // Below we have to check if new_total_weight_to_forward is invalid.
// This prevents use-after-move on packed_leg_to_forward. // This prevents use-after-move on packed_leg_to_forward.
} }
else if (target_phantom.IsReverseValidTarget()) else if (target_phantom.IsValidReverseTarget())
{ {
new_total_weight_to_reverse = new_total_weight_to_forward; new_total_weight_to_reverse = new_total_weight_to_forward;
packed_leg_to_reverse = packed_leg_to_forward; packed_leg_to_reverse = packed_leg_to_forward;
@ -385,7 +385,7 @@ shortestPathSearch(SearchEngineData<Algorithm> &engine_working_data,
if (new_total_weight_to_forward != INVALID_EDGE_WEIGHT) if (new_total_weight_to_forward != INVALID_EDGE_WEIGHT)
{ {
BOOST_ASSERT(target_phantom.IsForwardValidTarget()); BOOST_ASSERT(target_phantom.IsValidForwardTarget());
packed_leg_to_forward_begin.push_back(total_packed_path_to_forward.size()); packed_leg_to_forward_begin.push_back(total_packed_path_to_forward.size());
total_packed_path_to_forward.insert(total_packed_path_to_forward.end(), total_packed_path_to_forward.insert(total_packed_path_to_forward.end(),
@ -402,7 +402,7 @@ shortestPathSearch(SearchEngineData<Algorithm> &engine_working_data,
if (new_total_weight_to_reverse != INVALID_EDGE_WEIGHT) if (new_total_weight_to_reverse != INVALID_EDGE_WEIGHT)
{ {
BOOST_ASSERT(target_phantom.IsReverseValidTarget()); BOOST_ASSERT(target_phantom.IsValidReverseTarget());
packed_leg_to_reverse_begin.push_back(total_packed_path_to_reverse.size()); packed_leg_to_reverse_begin.push_back(total_packed_path_to_reverse.size());
total_packed_path_to_reverse.insert(total_packed_path_to_reverse.end(), total_packed_path_to_reverse.insert(total_packed_path_to_reverse.end(),