MCPcopy Create free account
hub / github.com/Project-OSRM/osrm-backend / IsNodeIndependent

Function IsNodeIndependent

src/contractor/graph_contractor.cpp:466–501  ·  view source on GitHub ↗

* @brief Test if a node is independent. * * Two independent nodes can be contracted in parallel without influencing each other. * * A node is independent if there is no node with a lower priority less than 3 hops away * from it. (In case of equal priorities the node id is used as tie breaker.) The * next-nearest independent node must be at least 3 hops away: they can be processed at * the s

Source from the content-addressed store, hash-verified

464 * @return bool true if the node is independent.
465 */
466bool IsNodeIndependent(const ContractorGraph &graph,
467 const NodeID v,
468 const std::vector<float> &priorities)
469{
470 const float priority = priorities[v];
471 BOOST_ASSERT(priority >= 0);
472
473 for (const NodeID hop1 : GetNeighbours(graph, v))
474 {
475 // 1 hop away
476 const float hop1_priority = priorities[hop1];
477 BOOST_ASSERT(hop1_priority >= 0);
478
479 if (hop1_priority < priority || (hop1_priority == priority && hop1 < v))
480 {
481 return false;
482 }
483
484 for (auto e : graph.GetAdjacentEdgeRange(hop1))
485 {
486 // 2 hops away
487 const NodeID hop2 = graph.GetTarget(e);
488 // it is cheaper to evaluate a node twice than to do an expensive test here
489 if (hop2 == v)
490 continue;
491 const float hop2_priority = priorities[hop2];
492 BOOST_ASSERT(hop2_priority >= 0);
493
494 if (hop2_priority < priority || (hop2_priority == priority && hop2 < v))
495 {
496 return false;
497 }
498 }
499 }
500 return true;
501}
502
503} // namespace
504

Callers 1

contractGraphFunction · 0.85

Calls 3

GetNeighboursFunction · 0.85
GetAdjacentEdgeRangeMethod · 0.45
GetTargetMethod · 0.45

Tested by

no test coverage detected