11/* PGR-GNU*****************************************************************
2- File: ordering .hpp
2+ File: sloanOrdering .hpp
33
44Generated with Template by:
5- Copyright (c) 2015 pgRouting developers
5+ Copyright (c) 2022 pgRouting developers
66Mail: project@pgrouting.org
77
88Developer:
9- Copyright (c) 2025 Bipasha Gayary
9+ Copyright (c) 2025 Shobhit Chaurasia
1010Mail: bipashagayary at gmail.com
1111
1212------
@@ -25,70 +25,101 @@ You should have received a copy of the GNU General Public License
2525along with this program; if not, write to the Free Software
2626Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2727
28- ********************************************************************PGR-GNU*/
28+ ********************************************************************PGR-GNU*/
2929
30- #ifndef INCLUDE_ORDERING_ORDERING_HPP_
31- #define INCLUDE_ORDERING_ORDERING_HPP_
30+ #ifndef INCLUDE_ORDERING_SLOANORDERING_HPP_
31+ #define INCLUDE_ORDERING_SLOANORDERING_HPP_
3232#pragma once
3333
34+ #include < algorithm>
3435#include < vector>
35- #include < limits>
36- #include < iterator>
37- #include < utility>
36+ #include < map>
37+ #include < cstdint>
3838
39- #include < boost/config.hpp>
40- #include < boost/graph/adjacency_list.hpp>
4139#include < boost/property_map/property_map.hpp>
40+ #include < boost/graph/graph_traits.hpp>
41+ #include < boost/property_map/vector_property_map.hpp>
42+ #include < boost/type_traits.hpp>
43+ #include < boost/graph/adjacency_list.hpp>
4244#include < boost/graph/sloan_ordering.hpp>
4345
4446#include " cpp_common/base_graph.hpp"
4547#include " cpp_common/interruption.hpp"
48+ #include " cpp_common/messages.hpp"
4649
50+ #include " c_types/ii_t_rt.h"
4751
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-
52+ namespace pgrouting {
53+ namespace functions {
6254
6355template <class G >
64- std::vector<std::vector<int64_t >>
65- sloan (G &graph) {
66- CHECK_FOR_INTERRUPTS ();
67-
68- std::pair<typename G::V, typename G::V> starting_nodes = boost::sloan_starting_nodes (graph.graph );
69-
70- std::vector<typename G::V> inv_perm (graph.num_vertices ());
71-
72- boost::sloan_ordering (
73- graph.graph ,
74- inv_perm.begin (),
75- boost::get (boost::vertex_color_t (), graph.graph ),
76- boost::make_degree_map (graph.graph ),
77- starting_nodes.first ,
78- starting_nodes.second );
79-
80- CHECK_FOR_INTERRUPTS ();
81-
82- std::vector<int64_t > result;
83- result.reserve (inv_perm.size ());
84-
85- for (const auto & vertex_desc : inv_perm) {
86- result.push_back (graph[vertex_desc].id );
87- }
88-
89- return result;
90- } // namespace ordering
91-
56+ class sloanOrdering : public Pgr_messages {
57+ public:
58+ typedef typename G::V V;
59+ typedef typename G::E E;
60+ typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS> Graph;
61+ typedef boost::graph_traits<Graph>::vertices_size_type size_type;
62+ typedef boost::graph_traits<Graph>::vertex_descriptor Vertex;
63+
64+ std::vector<II_t_rt>
65+ sloanOrdering (G &graph) {
66+ std::vector<II_t_rt>results;
67+
68+ // map which store the indices with their nodes.
69+ auto i_map = boost::get (boost::vertex_index, graph.graph );
70+
71+ // vector which will store the order of the indices.
72+ std::vector<Vertex> inv_perm (boost::num_vertices (graph.graph ));
73+
74+ // vector which will store the color of all the vertices in the graph
75+ std::vector <boost::default_color_type> colors (boost::num_vertices (graph.graph ));
76+
77+ // An iterator property map which records the color of each vertex
78+ auto color_map = boost::make_iterator_property_map (&colors[0 ], i_map, colors[0 ]);
79+
80+ // map which store the degree of each vertex.
81+ auto out_deg = boost::make_out_degree_map (graph.graph );
82+
83+ /* abort in case of an interruption occurs (e.g. the query is being cancelled) */
84+ CHECK_FOR_INTERRUPTS ();
85+
86+ try {
87+ boost::sloan_ordering (graph.graph , inv_perm.rbegin (), color_map, out_deg);
88+ } catch (boost::exception const & ex) {
89+ (void )ex;
90+ throw ;
91+ } catch (std::exception &e) {
92+ (void )e;
93+ throw ;
94+ } catch (...) {
95+ throw ;
96+ }
97+
98+ results = get_results (inv_perm, graph);
99+
100+ return results;
101+ }
102+
103+ // @}
104+
105+ private:
106+ std::vector <II_t_rt> get_results (
107+ std::vector <size_type> & inv_perm,
108+ const G &graph) {
109+ std::vector <II_t_rt> results;
110+
111+ for (std::vector<Vertex>::const_iterator i = inv_perm.begin ();
112+ i != inv_perm.end (); ++i) {
113+ log << inv_perm[*i] << " " ;
114+ auto seq = graph[*i].id ;
115+ results.push_back ({{seq}, {static_cast <int64_t >(graph.graph [*i].id )}});
116+ seq++;
117+ }
118+
119+ return results;
120+ }
121+ };
122+ } // namespace functions
92123} // namespace pgrouting
93124
94- #endif // INCLUDE_ORDERING_ORDERING_HPP_
125+ #endif // INCLUDE_ORDERING_SLOANORDERING_HPP_
0 commit comments