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

Function constructRestrictionGraph

src/extractor/restriction_graph.cpp:233–274  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

231} // namespace restriction_graph_details
232
233RestrictionGraph constructRestrictionGraph(const std::vector<TurnRestriction> &turn_restrictions)
234{
235 util::UnbufferedLog log;
236 log << "Constructing restriction graph on " << turn_restrictions.size() << " restrictions...";
237 TIMER_START(construct_restriction_graph);
238
239 namespace rgd = restriction_graph_details;
240 RestrictionGraph rg;
241 rgd::buildGraph<rgd::pathBuilder>(rg, turn_restrictions);
242 rgd::buildGraph<rgd::transferBuilder>(rg, turn_restrictions);
243
244 // Reorder nodes so that via nodes are at the front. This makes it easier to represent the
245 // bijection between restriction graph via nodes and edge-based graph duplicate nodes.
246 std::vector<bool> is_via_node(rg.nodes.size(), false);
247 for (const auto &entry : rg.via_edge_to_node)
248 {
249 is_via_node[entry.second] = true;
250 }
251 std::vector<RestrictionID> ordering(rg.nodes.size());
252 std::iota(ordering.begin(), ordering.end(), 0);
253 std::partition(ordering.begin(), ordering.end(), [&](const auto i) { return is_via_node[i]; });
254 // Start renumbering
255 const auto permutation = util::orderingToPermutation(ordering);
256 util::inplacePermutation(rg.nodes.begin(), rg.nodes.end(), permutation);
257 std::for_each(rg.edges.begin(),
258 rg.edges.end(),
259 [&](auto &edge) { edge.target = permutation[edge.target]; });
260 rg.num_via_nodes = std::count(is_via_node.begin(), is_via_node.end(), true);
261 for (auto &entry : rg.via_edge_to_node)
262 {
263 entry.second = permutation[entry.second];
264 }
265 for (auto &entry : rg.start_edge_to_node)
266 {
267 entry.second = permutation[entry.second];
268 }
269
270 TIMER_STOP(construct_restriction_graph);
271 log << "ok, after " << TIMER_SEC(construct_restriction_graph) << "s";
272
273 return rg;
274}
275
276RestrictionGraph::RestrictionRange RestrictionGraph::GetRestrictions(RestrictionID id) const
277{

Callers 3

runMethod · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85

Calls 6

partitionFunction · 0.85
orderingToPermutationFunction · 0.85
inplacePermutationFunction · 0.85
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by 1

BOOST_AUTO_TEST_CASEFunction · 0.68