From 4bc19a162166c025ba878cf77e959deab8cf1983 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Sun, 17 Apr 2005 23:50:43 +0000 Subject: [PATCH] boost/graph/cuthill_mckee_ordering.hpp, boost/graph/king_ordering.hpp: - Remove use of connected components, so we need only one color map running around - Provide simple overloads, requiring only the graph and the output iterator. boost/graph/detail/sparse_ordering.hpp: - Move out_degree_property_map here boost/graph/fruchterman_reingold.hpp: - Fix enumeration of pairs in grid_force_pairs to repulse vertices in adjacent grid cells (in addition to the current cell), so we don't get vertices forming crosses on grid lines. - Round up the number of rows/columns. libs/graph/doc/cuthill_mckee_ordering.html, libs/graph/doc/king_ordering.html: - Document new overloads libs/graph/doc/gursoy_atun_layout.html: - Add missing semicolon libs/graph/src/python/cuthill_mckee_ordering.cpp, libs/graph/test/cuthill_mckee_ordering.cpp: - Test and use the new overloads libs/graph/build/python/Jamfile, libs/graph/src/python/module.cpp, libs/graph/src/python/king_ordering.cpp: - Support King's ordering algorithm from Python libs/graph/example/python/vis.py: - By default, do a "progressive" Fruchterman-Reingold layout libs/graph/test/king_ordering.cpp: - Test new overload [SVN r28306] --- build/python/Jamfile | 1 + doc/cuthill_mckee_ordering.html | 21 ++- doc/gursoy_atun_layout.html | 2 +- doc/king_ordering.html | 43 ++++--- example/python/vis.py | 3 +- .../boost/graph/cuthill_mckee_ordering.hpp | 87 ++++++------- .../boost/graph/detail/sparse_ordering.hpp | 29 ++++- include/boost/graph/fruchterman_reingold.hpp | 64 ++++++++-- include/boost/graph/king_ordering.hpp | 120 +++++++++--------- src/python/cuthill_mckee_ordering.cpp | 47 +------ src/python/king_ordering.cpp | 39 ++++++ src/python/module.cpp | 2 + test/cuthill_mckee_ordering.cpp | 3 +- test/king_ordering.cpp | 7 +- 14 files changed, 274 insertions(+), 194 deletions(-) create mode 100644 src/python/king_ordering.cpp diff --git a/build/python/Jamfile b/build/python/Jamfile index 62d23a46..925ada8f 100644 --- a/build/python/Jamfile +++ b/build/python/Jamfile @@ -46,6 +46,7 @@ extension bgl ../../src/python/sequential_vertex_coloring.cpp # Sparse Matrix Ordering ../../src/python/cuthill_mckee_ordering.cpp + ../../src/python/king_ordering.cpp # ../../src/python/minimum_degree_ordering.cpp ../../src/python/circle_layout.cpp ../../src/python/fruchterman_reingold.cpp diff --git a/doc/cuthill_mckee_ordering.html b/doc/cuthill_mckee_ordering.html index 3fcfb5cf..d2e34e76 100644 --- a/doc/cuthill_mckee_ordering.html +++ b/doc/cuthill_mckee_ordering.html @@ -45,24 +45,33 @@ (1) template <class IncidenceGraph, class OutputIterator, class ColorMap, class DegreeMap> - void - cuthill_mckee_ordering(IncidenceGraph& g, + OutputIterator + cuthill_mckee_ordering(const IncidenceGraph& g, typename graph_traits<Graph>::vertex_descriptor s, OutputIterator inverse_permutation, ColorMap color, DegreeMap degree) (2) + template <class VertexListGraph, class OutputIterator> + OutputIterator + cuthill_mckee_ordering(const VertexIndexMap& G, OutputIterator inverse_permutation); + + template <class VertexListGraph, class OutputIterator, class VertexIndexMap> + OutputIterator + cuthill_mckee_ordering(const VertexIndexMap& G, OutputIterator inverse_permutation, + VertexIndexMap index_map); + template <class VertexListGraph, class OutputIterator, class ColorMap, class DegreeMap> - void - cuthill_mckee_ordering(VertexListGraph& G, OutputIterator inverse_permutation, + OutputIterator + cuthill_mckee_ordering(const VertexListGraph& G, OutputIterator inverse_permutation, ColorMap color, DegreeMap degree) (3) template <class IncidenceGraph, class OutputIterator, class ColorMap, class DegreeMap> - void - cuthill_mckee_ordering(IncidenceGraph& g, + OutputIterator + cuthill_mckee_ordering(const IncidenceGraph& g, std::deque< typename graph_traits<Graph>::vertex_descriptor > vertex_queue, OutputIterator inverse_permutation, diff --git a/doc/gursoy_atun_layout.html b/doc/gursoy_atun_layout.html index 9e663122..d4cc7fcc 100644 --- a/doc/gursoy_atun_layout.html +++ b/doc/gursoy_atun_layout.html @@ -436,7 +436,7 @@ class heart_topology
-
Copyright © 2004 +Copyright © 2004 Jeremiah Willcock, Indiana University ()
Doug Gregor, Indiana University ()
Andrew Lumsdaine, diff --git a/doc/king_ordering.html b/doc/king_ordering.html index 14d5bb31..6c96716f 100644 --- a/doc/king_ordering.html +++ b/doc/king_ordering.html @@ -45,29 +45,38 @@
   (1)
   template <class IncidenceGraph, class OutputIterator,
-            class ColorMap, class DegreeMap>
-  void 
-  king_ordering(IncidenceGraph& g,
-                         typename graph_traits<Graph>::vertex_descriptor s,
-                         OutputIterator inverse_permutation, 
-                         ColorMap color, DegreeMap degree)
+            class ColorMap, class DegreeMap, class VertexIndexMap>
+  OutputIterator
+  king_ordering(const IncidenceGraph& g,
+                typename graph_traits<Graph>::vertex_descriptor s,
+                OutputIterator inverse_permutation, 
+                ColorMap color, DegreeMap degree, VertexIndexMap index_map);
 
   (2)
+  template <class IncidenceGraph, class OutputIterator>
+  OutputIterator
+  king_ordering(const IncidenceGraph& g, OutputIterator inverse_permutation);
+
+  template <class IncidenceGraph, class OutputItrator, class VertexIndexMap>
+  OutputIterator
+  king_ordering(const IncidenceGraph& g, OutputIterator inverse_permutation,
+                VertexIndexMap index_map);
+
   template <class VertexListGraph, class OutputIterator, 
-            class ColorMap, class DegreeMap>
-  void 
-  king_ordering(VertexListGraph& G, OutputIterator inverse_permutation, 
-                         ColorMap color, DegreeMap degree)
+            class ColorMap, class DegreeMap, class VertexIndexMap>
+  OutputIterator
+  king_ordering(const VertexListGraph& G, OutputIterator inverse_permutation, 
+                ColorMap color, DegreeMap degree, VertexIndexMap index_map);
                          
   (3)
   template <class IncidenceGraph, class OutputIterator,
-            class ColorMap, class DegreeMap>
-  void 
-  king_ordering(IncidenceGraph& g,
-    			 std::deque< typename
-			 graph_traits<Graph>::vertex_descriptor > vertex_queue,
-                         OutputIterator permutation, 
-                         ColorMap color, DegreeMap degree)
+            class ColorMap, class DegreeMap, class VertexIndexMap>
+  OutputIterator
+  king_ordering(const IncidenceGraph& g,
+    		std::deque< typename
+		graph_traits<Graph>::vertex_descriptor > vertex_queue,
+                OutputIterator permutation, 
+                ColorMap color, DegreeMap degree, VertexIndexMap index_map);
 
diff --git a/example/python/vis.py b/example/python/vis.py index c40337ad..5624de5b 100644 --- a/example/python/vis.py +++ b/example/python/vis.py @@ -681,7 +681,8 @@ class GraphEditorWindow(wx.Frame): def FruchtermanReingoldLayout(self, event): bgl.fruchterman_reingold_force_directed_layout(self.canvas.graph, self.canvas.position_map, - width=100, height=100) + width=100, height=100, + progressive=True) self.canvas.update_layout() def KamadaKawaiLayout(self, event): diff --git a/include/boost/graph/cuthill_mckee_ordering.hpp b/include/boost/graph/cuthill_mckee_ordering.hpp index 20bd174d..2b036f51 100644 --- a/include/boost/graph/cuthill_mckee_ordering.hpp +++ b/include/boost/graph/cuthill_mckee_ordering.hpp @@ -83,7 +83,7 @@ namespace boost { template OutputIterator - cuthill_mckee_ordering(Graph& g, + cuthill_mckee_ordering(const Graph& g, std::deque< typename graph_traits::vertex_descriptor > vertex_queue, OutputIterator permutation, @@ -128,7 +128,7 @@ namespace boost { template OutputIterator - cuthill_mckee_ordering(Graph& g, + cuthill_mckee_ordering(const Graph& g, typename graph_traits::vertex_descriptor s, OutputIterator permutation, ColorMap color, DegreeMap degree) @@ -144,61 +144,62 @@ namespace boost { // This is the version of CM which selects its own starting vertex template < class Graph, class OutputIterator, - class Color, class Degree > + class ColorMap, class DegreeMap> OutputIterator - cuthill_mckee_ordering(Graph& G, OutputIterator permutation, - Color color, Degree degree) + cuthill_mckee_ordering(const Graph& G, OutputIterator permutation, + ColorMap color, DegreeMap degree) { + if (vertices(G).first == vertices(G).second) + return permutation; typedef typename boost::graph_traits::vertex_descriptor Vertex; typedef typename boost::graph_traits::vertex_iterator VerIter; + typedef typename property_traits::value_type ColorValue; + typedef color_traits Color; - VerIter ri = vertices(G).first; - Vertex r = *ri; - Vertex s; - - // Check the number of connected components in G. - std::vector c( num_vertices( G ) ); std::deque vertex_queue; - int num = boost::connected_components(G, &c[0]); + // Mark everything white + BGL_FORALL_VERTICES_T(v, G, Graph) put(color, v, Color::white()); - // Common case: we only have one set. - if( num <= 1 ) { - s = find_starting_node(G, r, color, degree); - vertex_queue.push_front( s ); - - } else { - // We seem to have more than one disjoint set. So, find good - // starting nodes within each of the subgraphs, and then add - // these starting nodes to our vertex queue. - int num_considered = 0; - std::vector sets_considered( num ); - std::fill( sets_considered.begin(), sets_considered.end(), 0 ); // Sanity - - for( unsigned int i = 0; i < c.size(); ++i ) { - // If it's the first time we've considered this set, - // then find a good pseudo peripheral node for it. - // Otherwise, keep going until we've considered all of - // the sets. - if( sets_considered[c[i]] == 0 ) { - ++num_considered; - s = find_starting_node(G, i, color, - degree); - assert( c[s] == c[i] ); - vertex_queue.push_back( s ); - - if( num_considered >= num ) { - break; - } - } - ++(sets_considered[c[i]]); + // Find one vertex from each connected component + BGL_FORALL_VERTICES_T(v, G, Graph) { + if (get(color, v) != Color::white()) { + depth_first_visit(G, v, dfs_visitor<>(), color); + vertex_queue.push_back(v); } } + + // Find starting nodes for all vertices + // TBD: How to do this with a directed graph? + for (typename std::deque::iterator i = vertex_queue.begin(); + i != vertex_queue.end(); ++i) + *i = find_starting_node(G, *i, color, degree); + return cuthill_mckee_ordering(G, vertex_queue, permutation, - color, degree); + color, degree); } + template + OutputIterator + cuthill_mckee_ordering(const Graph& G, OutputIterator permutation, + VertexIndexMap index_map) + { + if (vertices(G).first == vertices(G).second) + return permutation; + + typedef out_degree_property_map DegreeMap; + std::vector colors(num_vertices(G)); + return cuthill_mckee_ordering(G, permutation, + make_iterator_property_map(&colors[0], + index_map), + make_out_degree_map(G)); + } + + template + inline OutputIterator + cuthill_mckee_ordering(const Graph& G, OutputIterator permutation) + { return cuthill_mckee_ordering(G, permutation, get(vertex_index, G)); } } // namespace boost diff --git a/include/boost/graph/detail/sparse_ordering.hpp b/include/boost/graph/detail/sparse_ordering.hpp index 09da8de2..11bc082a 100644 --- a/include/boost/graph/detail/sparse_ordering.hpp +++ b/include/boost/graph/detail/sparse_ordering.hpp @@ -38,8 +38,8 @@ #include #include #include -#include -#include +#include +#include namespace boost { @@ -154,7 +154,7 @@ namespace boost { typename boost::graph_traits::vertex_iterator ui, ui_end; for (tie(ui, ui_end) = vertices(G); ui != ui_end; ++ui) - put(color, *ui, Color::white()); + if (get(color, *ui) != Color::red()) put(color, *ui, Color::white()); breadth_first_visit(G, u, buffer(Q).color_map(color)); ecc = Q.eccentricity(); @@ -185,6 +185,29 @@ namespace boost { return x; } +template +class out_degree_property_map + : public put_get_helper::degree_size_type, + out_degree_property_map > +{ +public: + typedef typename graph_traits::vertex_descriptor key_type; + typedef typename graph_traits::degree_size_type value_type; + typedef value_type reference; + typedef readable_property_map_tag category; + out_degree_property_map(const Graph& g) : m_g(g) { } + value_type operator[](const key_type& v) const { + return out_degree(v, m_g); + } +private: + const Graph& m_g; +}; +template +inline out_degree_property_map +make_out_degree_map(const Graph& g) { + return out_degree_property_map(g); +} + } // namespace boost diff --git a/include/boost/graph/fruchterman_reingold.hpp b/include/boost/graph/fruchterman_reingold.hpp index c3e9d967..88c21505 100644 --- a/include/boost/graph/fruchterman_reingold.hpp +++ b/include/boost/graph/fruchterman_reingold.hpp @@ -106,30 +106,68 @@ struct grid_force_pairs typedef std::list bucket_t; typedef std::vector buckets_t; - std::size_t columns = std::size_t(width / two_k); - std::size_t rows = std::size_t(height / two_k); - if (columns == 0) columns = 1; - if (rows == 0) rows = 1; + std::size_t columns = std::size_t(width / two_k + Dim(1)); + std::size_t rows = std::size_t(height / two_k + Dim(1)); buckets_t buckets(rows * columns); vertex_iterator v, v_end; for (tie(v, v_end) = vertices(g); v != v_end; ++v) { - std::size_t column = std::size_t((position[*v].x - width / 2) / two_k); - std::size_t row = std::size_t((position[*v].y - height / 2) / two_k); + std::size_t column = std::size_t((position[*v].x + width / 2) / two_k); + std::size_t row = std::size_t((position[*v].y + height / 2) / two_k); if (column >= columns) column = columns - 1; if (row >= rows) row = rows - 1; buckets[row * columns + column].push_back(*v); } - typedef typename buckets_t::iterator buckets_iterator; - for (buckets_iterator i = buckets.begin(); i != buckets.end(); ++i) { - typedef typename bucket_t::iterator bucket_iterator; - for (bucket_iterator u = i->begin(); u != i->end(); ++u) { - for (bucket_iterator v = i->begin(); v != i->end(); ++v) { - if (*u != *v) apply_force(*u, *v); + for (std::size_t row = 0; row < rows; ++row) + for (std::size_t column = 0; column < columns; ++column) { + bucket_t& bucket = buckets[row * columns + column]; + typedef typename bucket_t::iterator bucket_iterator; + for (bucket_iterator u = bucket.begin(); u != bucket.end(); ++u) { + // Repulse vertices in this bucket + bucket_iterator v = u; + for (++v; v != bucket.end(); ++v) { + apply_force(*u, *v); + apply_force(*v, *u); + } + + // Repulse vertices in the bucket to the right + if (column < columns - 1) { + bucket_t& r_bucket = buckets[row * columns + column + 1]; + for (v = r_bucket.begin(); v != r_bucket.end(); ++v) { + apply_force(*u, *v); + apply_force(*v, *u); + } + } + + // Repulse vertices in bucket below + if (row < rows - 1) { + bucket_t& b_bucket = buckets[(row + 1) * columns + column]; + for (v = b_bucket.begin(); v != b_bucket.end(); ++v) { + apply_force(*u, *v); + apply_force(*v, *u); + } + } + + // Repulse vertices in bucket below and to the right + if (column < columns - 1 && row < rows - 1) { + bucket_t& br_bucket = buckets[(row + 1) * columns + column + 1]; + for (v = br_bucket.begin(); v != br_bucket.end(); ++v) { + apply_force(*u, *v); + apply_force(*v, *u); + } + } + + // Repulse vertices in bucket above and to the right + if (column < columns - 1 && row > 0) { + bucket_t& ur_bucket = buckets[(row - 1) * columns + column + 1]; + for (v = ur_bucket.begin(); v != ur_bucket.end(); ++v) { + apply_force(*u, *v); + apply_force(*v, *u); + } + } } } - } } private: diff --git a/include/boost/graph/king_ordering.hpp b/include/boost/graph/king_ordering.hpp index 19007e36..10c71150 100644 --- a/include/boost/graph/king_ordering.hpp +++ b/include/boost/graph/king_ordering.hpp @@ -215,20 +215,20 @@ namespace boost { } // namespace detail - template + template OutputIterator - king_ordering(Graph& g, - std::deque< typename - graph_traits::vertex_descriptor > vertex_queue, - OutputIterator permutation, - ColorMap color, DegreeMap degree) + king_ordering(const Graph& g, + std::deque< typename graph_traits::vertex_descriptor > + vertex_queue, + OutputIterator permutation, + ColorMap color, DegreeMap degree, + VertexIndexMap index_map) { typedef typename property_traits::value_type DS; typedef typename property_traits::value_type ColorValue; typedef color_traits Color; typedef typename graph_traits::vertex_descriptor Vertex; - typedef typename property_map::const_type VertexIndexMap; typedef iterator_property_map::iterator, VertexIndexMap, DS, DS&> PseudoDegreeMap; typedef indirect_cmp > Compare; typedef typename boost::sparse::sparse_ordering_queue queue; @@ -237,7 +237,7 @@ namespace boost { typedef typename graph_traits::vertices_size_type vertices_size_type; std::vector pseudo_degree_vec(num_vertices(g)); - PseudoDegreeMap pseudo_degree(pseudo_degree_vec.begin(), get(vertex_index, g)); + PseudoDegreeMap pseudo_degree(pseudo_degree_vec.begin(), index_map); typename graph_traits::vertex_iterator ui, ui_end; queue Q; @@ -257,7 +257,7 @@ namespace boost { std::vector loc(num_vertices(g)); //create the visitor - Visitor vis(&permutation, &Q, comp, pseudo_degree, loc, colors, get(vertex_index, g)); + Visitor vis(&permutation, &Q, comp, pseudo_degree, loc, colors, index_map); while( !vertex_queue.empty() ) { Vertex s = vertex_queue.front(); @@ -273,77 +273,77 @@ namespace boost { // This is the case where only a single starting vertex is supplied. template + class ColorMap, class DegreeMap, typename VertexIndexMap> OutputIterator - king_ordering(Graph& g, - typename graph_traits::vertex_descriptor s, - OutputIterator permutation, - ColorMap color, DegreeMap degree) + king_ordering(const Graph& g, + typename graph_traits::vertex_descriptor s, + OutputIterator permutation, + ColorMap color, DegreeMap degree, VertexIndexMap index_map) { std::deque< typename graph_traits::vertex_descriptor > vertex_queue; vertex_queue.push_front( s ); - return king_ordering(g, vertex_queue, permutation, color, degree); - + return king_ordering(g, vertex_queue, permutation, color, degree, + index_map); } template < class Graph, class OutputIterator, - class Color, class Degree > + class ColorMap, class DegreeMap, class VertexIndexMap> OutputIterator - king_ordering(Graph& G, OutputIterator permutation, - Color color, Degree degree) + king_ordering(const Graph& G, OutputIterator permutation, + ColorMap color, DegreeMap degree, VertexIndexMap index_map) { + if (vertices(G).first == vertices(G).second) + return permutation; + typedef typename boost::graph_traits::vertex_descriptor Vertex; typedef typename boost::graph_traits::vertex_iterator VerIter; + typedef typename property_traits::value_type ColorValue; + typedef color_traits Color; - VerIter ri = vertices(G).first; - Vertex r = *ri; - Vertex s; - - // Check the number of connected components in G. - std::vector c( num_vertices( G ) ); std::deque vertex_queue; - int num = boost::connected_components(G, &c[0]); + // Mark everything white + BGL_FORALL_VERTICES_T(v, G, Graph) put(color, v, Color::white()); - // Common case: we only have one set. - if( num <= 1 ) { - s = find_starting_node(G, r, color, degree); - vertex_queue.push_front( s ); - - } else { - // We seem to have more than one disjoint set. So, find good - // starting nodes within each of the subgraphs, and then add - // these starting nodes to our vertex queue. - int num_considered = 0; - std::vector sets_considered( num ); - std::fill( sets_considered.begin(), sets_considered.end(), 0 ); // Sanity - - for( unsigned int i = 0; i < c.size(); ++i ) { - // If it's the first time we've considered this set, - // then find a good pseudo peripheral node for it. - // Otherwise, keep going until we've considered all of - // the sets. - if( sets_considered[c[i]] == 0 ) { - ++num_considered; - - s = find_starting_node(G, i, color, degree); - - assert( c[s] == c[i] ); - vertex_queue.push_back( s ); - - if( num_considered >= num ) { - break; - } - } - ++(sets_considered[c[i]]); + // Find one vertex from each connected component + BGL_FORALL_VERTICES_T(v, G, Graph) { + if (get(color, v) != Color::white()) { + depth_first_visit(G, v, dfs_visitor<>(), color); + vertex_queue.push_back(v); } } - return king_ordering(G, vertex_queue, permutation, - color, degree); + + // Find starting nodes for all vertices + // TBD: How to do this with a directed graph? + for (typename std::deque::iterator i = vertex_queue.begin(); + i != vertex_queue.end(); ++i) + *i = find_starting_node(G, *i, color, degree); + + return king_ordering(G, vertex_queue, permutation, color, degree, + index_map); } + template + OutputIterator + king_ordering(const Graph& G, OutputIterator permutation, + VertexIndexMap index_map) + { + if (vertices(G).first == vertices(G).second) + return permutation; + + typedef out_degree_property_map DegreeMap; + std::vector colors(num_vertices(G)); + return king_ordering(G, permutation, + make_iterator_property_map(&colors[0], index_map), + make_out_degree_map(G), index_map); + } + + template + inline OutputIterator + king_ordering(const Graph& G, OutputIterator permutation) + { return king_ordering(G, permutation, get(vertex_index, G)); } } // namespace boost diff --git a/src/python/cuthill_mckee_ordering.cpp b/src/python/cuthill_mckee_ordering.cpp index 16c8157f..8d9cce4e 100644 --- a/src/python/cuthill_mckee_ordering.cpp +++ b/src/python/cuthill_mckee_ordering.cpp @@ -15,47 +15,14 @@ namespace boost { namespace graph { namespace python { -template -class out_degree_property_map - : public put_get_helper::degree_size_type, - out_degree_property_map > -{ -public: - typedef typename graph_traits::vertex_descriptor key_type; - typedef typename graph_traits::degree_size_type value_type; - typedef value_type reference; - typedef readable_property_map_tag category; - out_degree_property_map(const Graph& g) : m_g(g) { } - value_type operator[](const key_type& v) const { - return out_degree(v, m_g); - } -private: - const Graph& m_g; -}; -template -inline out_degree_property_map -make_out_degree_map(const Graph& g) { - return out_degree_property_map(g); -} - - template boost::python::list -cuthill_mckee_ordering - (const Graph& g, - const vector_property_map* in_color) +cuthill_mckee_ordering(const Graph& g) { - typedef vector_property_map ColorMap; - - ColorMap color = - in_color? *in_color : ColorMap(g.num_vertices(), g.get_vertex_index_map()); - std::list ordering; boost::python::list result; boost::cuthill_mckee_ordering(g, std::back_inserter(ordering), - color, make_out_degree_map(g)); + g.get_vertex_index_map()); for (typename std::list::iterator i = ordering.begin(); i != ordering.end(); ++i) result.append(*i); @@ -66,15 +33,7 @@ void export_cuthill_mckee_ordering() { using boost::python::arg; using boost::python::def; - - def("cuthill_mckee_ordering", &cuthill_mckee_ordering, - (arg("graph"), - arg("color_map") = - (vector_property_map*)0)); - def("cuthill_mckee_ordering", &cuthill_mckee_ordering, - (arg("graph"), - arg("color_map") = - (vector_property_map*)0)); + def("cuthill_mckee_ordering", &cuthill_mckee_ordering, arg("graph")); } } } } // end namespace boost::graph::python diff --git a/src/python/king_ordering.cpp b/src/python/king_ordering.cpp new file mode 100644 index 00000000..c8a94a87 --- /dev/null +++ b/src/python/king_ordering.cpp @@ -0,0 +1,39 @@ +// Copyright 2005 The Trustees of Indiana University. + +// Use, modification and distribution is subject to the Boost Software +// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Authors: Douglas Gregor +// Andrew Lumsdaine +#include +#include "graph.hpp" +#include "digraph.hpp" +#include +#include +#include + +namespace boost { namespace graph { namespace python { + +template +boost::python::list +king_ordering(const Graph& g) +{ + std::list ordering; + boost::python::list result; + boost::king_ordering(g, std::back_inserter(ordering), + g.get_vertex_index_map()); + for (typename std::list::iterator i + = ordering.begin(); i != ordering.end(); ++i) + result.append(*i); + return result; +} + +void export_king_ordering() +{ + using boost::python::arg; + using boost::python::def; + def("king_ordering", &king_ordering, arg("graph")); +} + +} } } // end namespace boost::graph::python diff --git a/src/python/module.cpp b/src/python/module.cpp index 3ba84d59..ccfe303b 100644 --- a/src/python/module.cpp +++ b/src/python/module.cpp @@ -36,6 +36,7 @@ extern void export_biconnected_components(); extern void export_incremental_components(); extern void export_topological_sort(); extern void export_cuthill_mckee_ordering(); +extern void export_king_ordering(); //extern void export_minimum_degree_ordering(); extern void export_sequential_vertex_coloring(); extern void export_betweenness_centrality(); @@ -119,6 +120,7 @@ BOOST_PYTHON_MODULE(bgl) // Sparse Matrix Ordering export_cuthill_mckee_ordering(); + export_king_ordering(); // export_minimum_degree_ordering(); // Other algorithms diff --git a/test/cuthill_mckee_ordering.cpp b/test/cuthill_mckee_ordering.cpp index 11a6de36..9812077f 100644 --- a/test/cuthill_mckee_ordering.cpp +++ b/test/cuthill_mckee_ordering.cpp @@ -127,8 +127,7 @@ int main(int , char* []) { //reverse cuthill_mckee_ordering - cuthill_mckee_ordering(G, inv_perm.rbegin(), get(vertex_color, G), - make_degree_map(G)); + cuthill_mckee_ordering(G, inv_perm.rbegin()); cout << "Reverse Cuthill-McKee ordering:" << endl; cout << " "; diff --git a/test/king_ordering.cpp b/test/king_ordering.cpp index f35dcc48..56831990 100644 --- a/test/king_ordering.cpp +++ b/test/king_ordering.cpp @@ -92,7 +92,7 @@ int main(int , char* []) Vertex s = vertex(6, G); //king_ordering king_ordering(G, s, inv_perm.rbegin(), get(vertex_color, G), - get(vertex_degree, G)); + get(vertex_degree, G), get(vertex_index, G)); cout << "King ordering starting at: " << s << endl; cout << " "; for (std::vector::const_iterator i = inv_perm.begin(); @@ -110,7 +110,7 @@ int main(int , char* []) Vertex s = vertex(0, G); //king_ordering king_ordering(G, s, inv_perm.rbegin(), get(vertex_color, G), - get(vertex_degree, G)); + get(vertex_degree, G), get(vertex_index, G)); cout << "King ordering starting at: " << s << endl; cout << " "; for (std::vector::const_iterator i=inv_perm.begin(); @@ -127,8 +127,7 @@ int main(int , char* []) { //king_ordering - king_ordering(G, inv_perm.rbegin(), get(vertex_color, G), - make_degree_map(G)); + king_ordering(G, inv_perm.rbegin()); cout << "King ordering:" << endl; cout << " ";