// 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 #include "graph.hpp" #include "digraph.hpp" #include "queue.hpp" namespace boost { namespace graph { namespace python { #define BGL_PYTHON_VISITOR dfs_visitor #define BGL_PYTHON_EVENTS_HEADER "dfs_events.hpp" #include "visitor.hpp" #undef BGL_PYTHON_EVENTS_HEADER #undef BGL_PYTHON_VISITOR template void depth_first_search (const Graph& g, const dfs_visitor& visitor, const vector_property_map* in_color) { typedef vector_property_map ColorMap; ColorMap color = in_color? *in_color : ColorMap(g.num_vertices(), g.get_vertex_index_map()); bool has_default_visitor = dynamic_cast::default_arg const*>(&visitor); if (has_default_visitor) { boost::depth_first_search(g, boost::dfs_visitor<>(), color); } else { boost::depth_first_search(g, typename dfs_visitor::ref(visitor), color); } } template void depth_first_visit (const Graph& g, typename Graph::Vertex s, const dfs_visitor& visitor, const vector_property_map* in_color) { typedef vector_property_map ColorMap; ColorMap color = in_color? *in_color : ColorMap(g.num_vertices(), g.get_vertex_index_map()); bool has_default_visitor = dynamic_cast::default_arg const*>(&visitor); if (has_default_visitor) { boost::depth_first_visit(g, s, boost::dfs_visitor<>(), color); } else { boost::depth_first_visit(g, s, typename dfs_visitor::ref(visitor), color); } } template void undirected_dfs (const Graph& g, const dfs_visitor& visitor, const vector_property_map* in_color, const vector_property_map* in_edge_color) { typedef vector_property_map ColorMap; typedef vector_property_map EdgeColorMap; ColorMap color = in_color? *in_color : ColorMap(g.num_vertices(), g.get_vertex_index_map()); EdgeColorMap edge_color = in_edge_color? *in_edge_color : EdgeColorMap(g.num_edges(), g.get_edge_index_map()); bool has_default_visitor = dynamic_cast::default_arg const*>(&visitor); if (has_default_visitor) { boost::undirected_dfs(g, boost::dfs_visitor<>(), color, edge_color); } else { boost::undirected_dfs(g, typename dfs_visitor::ref(visitor), color, edge_color); } } void export_depth_first_search() { using boost::python::arg; using boost::python::def; def("depth_first_search", &depth_first_search, (arg("graph"), arg("visitor") = dfs_visitor::default_arg(), arg("color_map") = (vector_property_map*)0)); def("depth_first_visit", &depth_first_visit, (arg("graph"), arg("root_vertex"), arg("visitor") = dfs_visitor::default_arg(), arg("color_map") = (vector_property_map*)0)); def("undirected_dfs", &undirected_dfs, (arg("graph"), arg("visitor") = dfs_visitor::default_arg(), arg("color_map") = (vector_property_map*)0, arg("edge_color_map") = (vector_property_map*)0)); def("depth_first_search", &depth_first_search, (arg("graph"), arg("visitor") = dfs_visitor::default_arg(), arg("color_map") = (vector_property_map*)0)); def("depth_first_visit", &depth_first_visit, (arg("graph"), arg("root_vertex"), arg("visitor") = dfs_visitor::default_arg(), arg("color_map") = (vector_property_map*)0)); } template void export_depth_first_search_in_graph() { dfs_visitor::declare("DFSVisitor", "DefaultDFSVisitor"); } template void export_depth_first_search_in_graph(); template void export_depth_first_search_in_graph(); } } } // end namespace boost::graph::python