@@ -35,6 +35,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
3535#include < limits>
3636#include < iterator>
3737#include < utility>
38+ #include < string>
3839
3940#include < boost/config.hpp>
4041#include < boost/graph/adjacency_list.hpp>
@@ -52,34 +53,66 @@ namespace pgrouting {
5253template <class G >
5354std::vector<int64_t >
5455kingOrdering (G &graph) {
55- typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS,
56- boost::property<boost::vertex_color_t , boost::default_color_type,
57- boost::property<boost::vertex_degree_t , int >>>
58- Graph;
59- typedef boost::graph_traits<Graph>::vertex_descriptor Vertex;
56+ using V = typename G::V;
57+ using B_G = typename G::B_G;
58+ using vertices_size_type = typename boost::graph_traits<B_G>::vertices_size_type;
6059
61- std::vector<int64_t > results;
60+ size_t n = boost::num_vertices (graph.graph );
61+ std::vector<int64_t > results (n);
6262
6363 auto index_map = boost::get (boost::vertex_index, graph.graph );
64- auto color_map = boost::get (boost::vertex_color, graph.graph );
64+ std::vector<vertices_size_type> colors (n);
65+ auto color_map = boost::make_iterator_property_map (colors.begin (), index_map);
6566 auto degree_map = boost::make_degree_map (graph.graph );
67+ std::vector<V> inv_perm (n);
6668
67- std::vector<Vertex> inv_perm (boost::num_vertices (graph.graph ));
6869 CHECK_FOR_INTERRUPTS ();
69-
70- boost::king_ordering (graph.graph , inv_perm.rbegin (), color_map, degree_map, index_map);
71- for (std::vector<Vertex>::const_iterator i = inv_perm.begin (); i != inv_perm.end (); ++i) {
72- auto seq = graph[*i].id ;
73- results.push_back ({{seq}, {static_cast <int64_t >(graph.graph [*i].id )}});
74- seq++;
70+ boost::king_ordering (graph.graph , inv_perm. rbegin (), color_map, degree_map, index_map);
71+ size_t j = 0 ;
72+ for (auto i = inv_perm.begin (); i != inv_perm.end (); ++i, ++j) {
73+ results[j] = static_cast <int64_t >(index_map[*i]);
7574 }
75+
76+ throw (std::to_string (results.size ()));
7677 return results;
7778}
7879
7980template <class G >
80- std::vector<std::vector< int64_t > >
81+ std::vector<int64_t >
8182minDegreeOrdering (G &graph) {
83+ using B_G = typename G::B_G;
84+ using vertices_size_type = typename boost::graph_traits<B_G>::vertices_size_type;
85+
86+ size_t n = boost::num_vertices (graph.graph );
87+ std::vector<int64_t > results (n);
88+
89+ auto index_map = boost::get (boost::vertex_index, graph.graph );
90+
91+ std::vector<vertices_size_type> degree (n, 0 );
92+ auto degree_map = boost::make_iterator_property_map (degree.begin (), index_map);
93+
94+ std::vector<vertices_size_type> supernode_sizes (n, 1 );
95+ auto supernode_map = boost::make_iterator_property_map (supernode_sizes.begin (), index_map);
96+
97+ std::vector<vertices_size_type> perm (n);
98+ std::vector<vertices_size_type> inv_perm (n);
99+
82100 CHECK_FOR_INTERRUPTS ();
101+
102+ boost::minimum_degree_ordering (
103+ graph.graph ,
104+ degree_map,
105+ inv_perm.data (),
106+ perm.data (),
107+ supernode_map,
108+ 0 ,
109+ index_map);
110+
111+ for (size_t i = 0 ; i < n; ++i) {
112+ results[i] = static_cast <int64_t >(inv_perm[i]);
113+ }
114+
115+ return results;
83116}
84117
85118} // namespace pgrouting
0 commit comments