|
| 1 | +/*PGR-GNU***************************************************************** |
| 2 | +File: ordering.hpp |
| 3 | +
|
| 4 | +Generated with Template by: |
| 5 | +Copyright (c) 2015 pgRouting developers |
| 6 | +Mail: project@pgrouting.org |
| 7 | +
|
| 8 | +Developer: |
| 9 | +Copyright (c) 2025 Bipasha Gayary |
| 10 | +Mail: bipashagayary at gmail.com |
| 11 | +
|
| 12 | +------ |
| 13 | +
|
| 14 | +This program is free software; you can redistribute it and/or modify |
| 15 | +it under the terms of the GNU General Public License as published by |
| 16 | +the Free Software Foundation; either version 2 of the License, or |
| 17 | +(at your option) any later version. |
| 18 | +
|
| 19 | +This program is distributed in the hope that it will be useful, |
| 20 | +but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | +GNU General Public License for more details. |
| 23 | +
|
| 24 | +You should have received a copy of the GNU General Public License |
| 25 | +along with this program; if not, write to the Free Software |
| 26 | +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 27 | +
|
| 28 | + ********************************************************************PGR-GNU*/ |
| 29 | + |
| 30 | +#ifndef INCLUDE_ORDERING_ORDERING_HPP_ |
| 31 | +#define INCLUDE_ORDERING_ORDERING_HPP_ |
| 32 | +#pragma once |
| 33 | + |
| 34 | +#include <vector> |
| 35 | +#include <limits> |
| 36 | +#include <iterator> |
| 37 | + |
| 38 | + |
| 39 | +#include <boost/config.hpp> |
| 40 | +#include <boost/graph/adjacency_list.hpp> |
| 41 | +#include <boost/property_map/property_map.hpp> |
| 42 | +#include <boost/graph/sloan_ordering.hpp> |
| 43 | + |
| 44 | +#include "cpp_common/base_graph.hpp" |
| 45 | +#include "cpp_common/interruption.hpp" |
| 46 | + |
| 47 | + |
| 48 | +namespace pgrouting { |
| 49 | +namespace detail { |
| 50 | + |
| 51 | +template <typename T> |
| 52 | +struct inf_plus { |
| 53 | + T operator()(const T& a, const T& b) const { |
| 54 | + T inf = (std::numeric_limits<T>::max)(); |
| 55 | + if (a == inf || b == inf) return inf; |
| 56 | + return a + b; |
| 57 | + } |
| 58 | +}; |
| 59 | + |
| 60 | +} // namespace detail |
| 61 | + |
| 62 | + |
| 63 | +template <class G> |
| 64 | +std::vector<std::vector<int64_t>> |
| 65 | +sloan(G &graph) { |
| 66 | + |
| 67 | + CHECK_FOR_INTERRUPTS(); |
| 68 | + |
| 69 | + std::pair<typename G::V, typename G::V> starting_nodes = |
| 70 | + boost::sloan_starting_nodes(graph.graph); |
| 71 | + |
| 72 | + std::vector<typename G::V> inv_perm(graph.num_vertices()); |
| 73 | + |
| 74 | + boost::sloan_ordering( |
| 75 | + graph.graph, |
| 76 | + inv_perm.begin(), |
| 77 | + boost::get(boost::vertex_color_t(), graph.graph), |
| 78 | + boost::make_degree_map(graph.graph), |
| 79 | + starting_nodes.first, |
| 80 | + starting_nodes.second |
| 81 | + ); |
| 82 | + |
| 83 | + CHECK_FOR_INTERRUPTS(); |
| 84 | + |
| 85 | + std::vector<int64_t> result; |
| 86 | + result.reserve(inv_perm.size()); |
| 87 | + |
| 88 | + for (const auto& vertex_desc : inv_perm) { |
| 89 | + result.push_back(graph[vertex_desc].id); |
| 90 | + } |
| 91 | + |
| 92 | + return result; |
| 93 | +} // namespace ordering |
| 94 | + |
| 95 | +} // namespace pgrouting |
| 96 | + |
| 97 | +#endif // INCLUDE_ORDERING_ORDERING_HPP_ |
0 commit comments