diff --git a/docqueries/ordering/kingOrdering.pg b/docqueries/ordering/kingOrdering.pg index b9d9fd58f8..5fb94f043d 100644 --- a/docqueries/ordering/kingOrdering.pg +++ b/docqueries/ordering/kingOrdering.pg @@ -5,3 +5,26 @@ SELECT * FROM pgr_kingOrdering( 'SELECT id, source, target, cost, reverse_cost FROM edges' ); /* -- q2 */ + +CREATER TABLE kot AS ( +id SERIAL, +source BIGINT, +target BIGINT, +cost BIGINT defult 1) +; + +INSERT INTO kot (source, target) VALUES +(0, 3), +(0, 5), +(1, 2), +(1, 4), +(1, 6), +(1, 9), +(2, 3), +(2, 4), +(3, 5), +(3, 8), +(4, 6), +(5, 6), +(5, 7), +(6, 7); \ No newline at end of file diff --git a/include/ordering/ordering.hpp b/include/ordering/ordering.hpp index d6b9742cfd..0c689751ba 100644 --- a/include/ordering/ordering.hpp +++ b/include/ordering/ordering.hpp @@ -35,6 +35,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include +#include #include #include @@ -52,34 +53,66 @@ namespace pgrouting { template std::vector kingOrdering(G &graph) { - typedef boost::adjacency_list>> - Graph; - typedef boost::graph_traits::vertex_descriptor Vertex; + using V = typename G::V; + using B_G = typename G::B_G; + using vertices_size_type = typename boost::graph_traits::vertices_size_type; - std::vector results; + size_t n = boost::num_vertices(graph.graph); + std::vector results(n); auto index_map = boost::get(boost::vertex_index, graph.graph); - auto color_map = boost::get(boost::vertex_color, graph.graph); + std::vector colors(n); + auto color_map = boost::make_iterator_property_map(colors.begin(), index_map); auto degree_map = boost::make_degree_map(graph.graph); + std::vector inv_perm(n); - std::vector inv_perm(boost::num_vertices(graph.graph)); CHECK_FOR_INTERRUPTS(); - - boost::king_ordering(graph.graph, inv_perm.rbegin(), color_map, degree_map, index_map); - for (std::vector::const_iterator i = inv_perm.begin(); i != inv_perm.end(); ++i) { - auto seq = graph[*i].id; - results.push_back({{seq}, {static_cast(graph.graph[*i].id)}}); - seq++; + boost::king_ordering(graph.graph, inv_perm. rbegin(), color_map, degree_map, index_map); + size_t j = 0; + for (auto i = inv_perm.begin(); i != inv_perm.end(); ++i, ++j) { + results[j] = static_cast(index_map[*i]); } + + throw(std::to_string(results.size())); return results; } template -std::vector> +std::vector minDegreeOrdering(G &graph) { + using B_G = typename G::B_G; + using vertices_size_type = typename boost::graph_traits::vertices_size_type; + + size_t n = boost::num_vertices(graph.graph); + std::vector results(n); + + auto index_map = boost::get(boost::vertex_index, graph.graph); + + std::vector degree(n, 0); + auto degree_map = boost::make_iterator_property_map(degree.begin(), index_map); + + std::vector supernode_sizes(n, 1); + auto supernode_map = boost::make_iterator_property_map(supernode_sizes.begin(), index_map); + + std::vector perm(n); + std::vector inv_perm(n); + CHECK_FOR_INTERRUPTS(); + + boost::minimum_degree_ordering( + graph.graph, + degree_map, + inv_perm.data(), + perm.data(), + supernode_map, + 0, + index_map); + + for (size_t i = 0; i < n; ++i) { + results[i] = static_cast(inv_perm[i]); + } + + return results; } } // namespace pgrouting diff --git a/just_to_start_week6 b/just_to_start_week6 deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/src/ordering/ordering_driver.cpp b/src/ordering/ordering_driver.cpp index a119f92b3c..b28be8863f 100644 --- a/src/ordering/ordering_driver.cpp +++ b/src/ordering/ordering_driver.cpp @@ -81,26 +81,22 @@ do_ordering( } hint = ""; - std::vectorresults; + std::vector results; UndirectedGraph undigraph; undigraph.insert_edges(edges); - #if 0 if (which == 0) { results = minDegreeOrdering(undigraph); } else if (which ==1) { results = kingOrdering(undigraph); } - #endif auto count = results.size(); -#if 0 if (count == 0) { *err_msg = to_pg_msg("No results found \n"); *return_tuples = NULL; *return_count = 0; return; } -#endif (*return_tuples) = pgr_alloc(count, (*return_tuples)); for (size_t i = 0; i < count; i++) {