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:
@@ -25,70 +25,63 @@ 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 < map>
37+ #include < cstdint>
3638#include < iterator>
37- #include < utility>
3839
39- #include < boost/config.hpp>
40- #include < boost/graph/adjacency_list.hpp>
4140#include < boost/property_map/property_map.hpp>
41+ #include < boost/graph/graph_traits.hpp>
42+ #include < boost/property_map/vector_property_map.hpp>
43+ #include < boost/type_traits.hpp>
44+ #include < boost/graph/adjacency_list.hpp>
4245#include < boost/graph/sloan_ordering.hpp>
4346
4447#include " cpp_common/base_graph.hpp"
4548#include " cpp_common/interruption.hpp"
49+ #include " cpp_common/messages.hpp"
4650
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-
51+ namespace pgrouting {
6252
6353template <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 );
54+ std::vector<int64_t >
55+ sloanOrdering (G &graph) {
56+ typedef boost::adjacency_list<
57+ boost::vecS,
58+ boost::vecS,
59+ boost::undirectedS,
60+ boost::property<boost::vertex_color_t , boost::default_color_type,
61+ boost::property<boost::vertex_degree_t , int ,
62+ boost::property<boost::vertex_priority_t , int >>>> GraphType;
63+ typedef typename boost::graph_traits<typename G::graph_t >::vertex_descriptor Vertex;
64+ std::vector<int64_t >results;
6965
70- std::vector<typename G::V> inv_perm (graph.num_vertices ());
66+ auto i_map = boost::get (boost::vertex_index, graph.graph );
67+ auto color_map = boost::get (boost::vertex_color, graph.graph );
68+ auto degree_map = boost::make_degree_map (graph.graph );
69+ auto priority_map = boost::get (boost::vertex_priority, graph.graph );
7170
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 );
71+ std::vector<Vertex> inv_perm (boost::num_vertices (graph.graph ));
7972
80- CHECK_FOR_INTERRUPTS ();
73+ CHECK_FOR_INTERRUPTS ();
8174
82- std::vector<int64_t > result;
83- result.reserve (inv_perm.size ());
75+ boost::sloan_ordering (graph.graph , inv_perm.rbegin (), color_map, degree_map, priority_map, i_map);
8476
85- for (const auto & vertex_desc : inv_perm) {
86- result.push_back (graph[vertex_desc].id );
87- }
77+ for (typename std::vector<Vertex>::const_iterator i = inv_perm.begin (); i != inv_perm.end (); ++i) {
78+ auto seq = graph[*i].id ;
79+ results.push_back (static_cast <int64_t >(graph[*i].id ));
80+ seq++;}
8881
89- return result ;
90- } // namespace ordering
82+ return results ;
83+ }
9184
9285} // namespace pgrouting
9386
94- #endif // INCLUDE_ORDERING_ORDERING_HPP_
87+ #endif // INCLUDE_ORDERING_SLOANORDERING_HPP_
0 commit comments