diff --git a/build/python/Jamfile b/build/python/Jamfile index e14149f0..45a1f2a2 100644 --- a/build/python/Jamfile +++ b/build/python/Jamfile @@ -22,5 +22,6 @@ extension bgl ../../src/python/done.cpp ../../src/python/breadth_first_search.cpp ../../src/python/dijkstra_shortest_paths.cpp + ../../src/python/biconnected_components.cpp ../../../python/build/boost_python # dependencies ; diff --git a/src/python/basic_graph.hpp b/src/python/basic_graph.hpp index 14cfeb5a..e41d4b4a 100644 --- a/src/python/basic_graph.hpp +++ b/src/python/basic_graph.hpp @@ -354,10 +354,40 @@ add_edge(typename basic_graph::vertex_descriptor u, typename basic_graph::vertex_descriptor v, basic_graph& g) { return std::make_pair(g.add_edge(u, v), true); } - + template void export_basic_graph(const char* name); +template +typename basic_graph::VertexIndexMap +get(vertex_index_t, const basic_graph& g) +{ return g.get_vertex_index_map(); } + +template +typename basic_graph::EdgeIndexMap +get(edge_index_t, const basic_graph& g) +{ return g.get_edge_index_map(); } + } } } // end namespace boost::graph::python +#if 0 +namespace boost { + template + struct property_map, vertex_index_t> + { + typedef typename graph::python::basic_graph::VertexIndexMap + type; + typedef type const_type; + }; + + template + struct property_map, edge_index_t> + { + typedef typename graph::python::basic_graph::EdgeIndexMap + type; + typedef type const_type; + }; +} +#endif + #endif // BOOST_GRAPH_BASIC_GRAPH_HPP diff --git a/src/python/biconnected_components.cpp b/src/python/biconnected_components.cpp new file mode 100644 index 00000000..222f7c3c --- /dev/null +++ b/src/python/biconnected_components.cpp @@ -0,0 +1,69 @@ +// 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 +biconnected_components + (Graph& g, + const vector_property_map* in_component) +{ + typedef vector_property_map ComponentMap; + + ComponentMap component = + in_component? *in_component : g.template get_edge_map("bicomponent"); + + std::list art_points; + boost::biconnected_components(g, component, std::back_inserter(art_points), + g.get_vertex_index_map()); + boost::python::list result; + for (typename std::list::iterator i + = art_points.begin(); i != art_points.end(); ++i) + result.append(*i); + return result; +} + +template +boost::python::list +articulation_points(const Graph& g) +{ + std::list art_points; + boost::python::list result; + boost::articulation_points(g, std::back_inserter(art_points)); + for (typename std::list::iterator i + = art_points.begin(); i != art_points.end(); ++i) + result.append(*i); + return result; +} + +void export_biconnected_components() +{ + using boost::python::arg; + + def("biconnected_components", &biconnected_components, + (arg("graph"), + arg("component_map") = + (vector_property_map*)0)); + def("articulation_points", &articulation_points, (arg("graph"))); + + def("biconnected_components", &biconnected_components, + (arg("graph"), + arg("component_map") = + (vector_property_map*)0)); + def("articulation_points", &articulation_points, (arg("graph"))); +} + +} } } // end namespace boost::graph::python diff --git a/src/python/module.cpp b/src/python/module.cpp index bf16be7d..55066120 100644 --- a/src/python/module.cpp +++ b/src/python/module.cpp @@ -10,7 +10,7 @@ #include "graph.hpp" #include "digraph.hpp" #include -#include "point2d.hpp" +// #include "point2d.hpp" namespace boost { namespace graph { namespace python { @@ -23,6 +23,7 @@ extern void export_breadth_first_search(); extern void export_dijkstra_shortest_paths(); template void export_breadth_first_search_in_graph(); template void export_dijkstra_shortest_paths_in_graph(); +extern void export_biconnected_components(); template void export_in_graph() @@ -44,10 +45,12 @@ BOOST_PYTHON_MODULE(bgl) .value("black", color_traits::black()) ; - enum_("Point2D") +#if 0 + class_("Point2D") .def("x", &point2d::x) .def("y", &point2d::y) ; +#endif export_Graph(); export_Digraph(); @@ -56,6 +59,7 @@ BOOST_PYTHON_MODULE(bgl) export_done(); export_breadth_first_search(); export_dijkstra_shortest_paths(); + export_biconnected_components(); } template void export_in_graph(); diff --git a/test/python/biconnected_components.py b/test/python/biconnected_components.py new file mode 100644 index 00000000..f55b27a0 --- /dev/null +++ b/test/python/biconnected_components.py @@ -0,0 +1,21 @@ +# 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 + +import bgl + +g = bgl.Graph("biconnected_components.dot", bgl.file_kind.graphviz) +art_points = bgl.biconnected_components(g, g.get_edge_int_map("label")); +g.write_graphviz("biconnected_components_out.dot") + +print "Articulation points: ", +node_id = g.get_vertex_string_map("node_id") +for v in art_points: + print node_id[v], + print " ", +print ""