* @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
| 464 | * @return bool true if the node is independent. |
| 465 | */ |
| 466 | bool 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 |
no test coverage detected