| 231 | } // namespace restriction_graph_details |
| 232 | |
| 233 | RestrictionGraph 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 | |
| 276 | RestrictionGraph::RestrictionRange RestrictionGraph::GetRestrictions(RestrictionID id) const |
| 277 | { |