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

Method RecursiveBisection

src/partitioner/recursive_bisection.cpp:22–105  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20{
21
22RecursiveBisection::RecursiveBisection(BisectionGraph &bisection_graph_,
23 const std::size_t maximum_cell_size,
24 const double balance,
25 const double boundary_factor,
26 const std::size_t num_optimizing_cuts,
27 const std::size_t small_component_size)
28 : bisection_graph(bisection_graph_), internal_state(bisection_graph_)
29{
30 auto components = internal_state.PrePartitionWithSCC(small_component_size);
31 BOOST_ASSERT(!components.empty());
32
33 // Parallelize recursive bisection trees. Root cut happens serially (well, this is a lie:
34 // since we handle big components in parallel, too. But we don't know this and
35 // don't have to. TBB's scheduler handles nested parallelism just fine).
36 //
37 // [ | ]
38 // / \ root cut
39 // [ | ] [ | ]
40 // / \ / \ descend, do cuts in parallel
41 //
42 // https://www.threadingbuildingblocks.org/docs/help/index.htm#reference/algorithms/parallel_do_func.html
43
44 struct TreeNode
45 {
46 BisectionGraphView graph;
47 std::uint64_t depth;
48 };
49
50 // Build a recursive bisection tree for all big components independently in parallel.
51 // Last GraphView is all small components: skip for bisection.
52 auto first = begin(components);
53 auto last = end(components) - 1;
54
55 // We construct the trees on the fly: the root node is the entry point.
56 // All tree branches depend on the actual cut and will be generated while descending.
57 std::vector<TreeNode> forest;
58 forest.reserve(last - first);
59
60 std::transform(first,
61 last,
62 std::back_inserter(forest),
63 [this](auto graph)
64 { return TreeNode{std::move(graph), internal_state.SCCDepth()}; });
65
66 using Feeder = tbb::feeder<TreeNode>;
67
68 TIMER_START(bisection);
69
70 // Bisect graph into two parts. Get partition point and recurse left and right in parallel.
71 tbb::parallel_for_each(
72 begin(forest),
73 end(forest),
74 [&](const TreeNode &node, Feeder &feeder)
75 {
76 const auto cut =
77 computeInertialFlowCut(node.graph, num_optimizing_cuts, balance, boundary_factor);
78 const auto center = internal_state.ApplyBisection(
79 node.graph.Begin(), node.graph.End(), node.depth, cut.flags);

Callers

nothing calls this directly

Calls 11

computeInertialFlowCutFunction · 0.85
LogClass · 0.85
PrePartitionWithSCCMethod · 0.80
ApplyBisectionMethod · 0.80
addMethod · 0.80
emptyMethod · 0.45
reserveMethod · 0.45
SCCDepthMethod · 0.45
BeginMethod · 0.45
EndMethod · 0.45
NumberOfNodesMethod · 0.45

Tested by

no test coverage detected