mirror of
https://github.com/boostorg/graph.git
synced 2026-01-28 19:22:11 +00:00
src/python/graphviz.cpp, src/python/module.cpp:
- Export GraphViz exceptions to Python src/python/module.cpp: - Support directed graphs example/python/vis.py: - Support directed graphs [SVN r27890]
This commit is contained in:
@@ -40,6 +40,13 @@ void export_circle_graph_layout()
|
||||
arg("position") =
|
||||
(vector_property_map<point2d, Graph::VertexIndexMap>*)0,
|
||||
arg("radius") = 250.0));
|
||||
|
||||
def("circle_graph_layout",
|
||||
&circle_graph_layout<Digraph>,
|
||||
(arg("graph"),
|
||||
arg("position") =
|
||||
(vector_property_map<point2d, Digraph::VertexIndexMap>*)0,
|
||||
arg("radius") = 250.0));
|
||||
}
|
||||
|
||||
} } } // end namespace boost::graph::python
|
||||
|
||||
@@ -8,7 +8,9 @@
|
||||
// Andrew Lumsdaine
|
||||
#include "basic_graph.hpp"
|
||||
#include <boost/graph/graphviz.hpp>
|
||||
#include <boost/python.hpp>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
namespace boost { namespace graph { namespace python {
|
||||
|
||||
@@ -35,6 +37,61 @@ basic_graph<DirectedS>::write_graphviz(const std::string& filename,
|
||||
boost::write_graphviz(out, *this, dp, node_id, get_vertex_index_map());
|
||||
}
|
||||
|
||||
template<typename E>
|
||||
class translate_exception
|
||||
{
|
||||
explicit translate_exception(boost::python::object type) : type(type) { }
|
||||
|
||||
public:
|
||||
template<typename Base>
|
||||
static void declare(const char* name)
|
||||
{
|
||||
using boost::python::class_;
|
||||
using boost::python::bases;
|
||||
|
||||
declare(class_<E, bases<Base> >(name));
|
||||
}
|
||||
|
||||
static void declare(boost::python::object type)
|
||||
{
|
||||
using boost::python::register_exception_translator;
|
||||
register_exception_translator<E>(translate_exception(type));
|
||||
}
|
||||
|
||||
void operator()(const E& e) const
|
||||
{
|
||||
using boost::python::object;
|
||||
PyErr_SetObject(type.ptr(), object(e).ptr());
|
||||
}
|
||||
|
||||
private:
|
||||
boost::python::object type;
|
||||
};
|
||||
|
||||
void export_graphviz()
|
||||
{
|
||||
using boost::python::class_;
|
||||
using boost::python::bases;
|
||||
using boost::python::init;
|
||||
using boost::python::no_init;
|
||||
using boost::python::object;
|
||||
|
||||
object ge_type =
|
||||
class_<graph_exception, noncopyable >("graph_exception", no_init);
|
||||
translate_exception<graph_exception>::declare(ge_type);
|
||||
|
||||
object bpe_type =
|
||||
class_<bad_parallel_edge, bases<graph_exception> >("bad_parallel_edge",
|
||||
no_init)
|
||||
.def(init<std::string, std::string>());
|
||||
translate_exception<bad_parallel_edge>::declare(bpe_type);
|
||||
|
||||
translate_exception<directed_graph_error>
|
||||
::declare<graph_exception>("directed_graph_error");
|
||||
translate_exception<undirected_graph_error>
|
||||
::declare<graph_exception>("undirected_graph_error");
|
||||
}
|
||||
|
||||
// Explicit instantiations
|
||||
template
|
||||
void
|
||||
|
||||
@@ -17,8 +17,7 @@ namespace boost { namespace graph { namespace python {
|
||||
|
||||
extern void export_Graph();
|
||||
extern void export_Digraph();
|
||||
extern void export_betweenness_centrality();
|
||||
extern void export_page_rank();
|
||||
extern void export_graphviz();
|
||||
extern void export_breadth_first_search();
|
||||
extern void export_depth_first_search();
|
||||
extern void export_dijkstra_shortest_paths();
|
||||
@@ -30,7 +29,7 @@ template<typename Graph> void export_depth_first_search_in_graph();
|
||||
template<typename Graph> void export_dijkstra_shortest_paths_in_graph();
|
||||
template<typename Graph> void export_dag_shortest_paths_in_graph();
|
||||
template<typename Graph> void export_bellman_ford_shortest_paths_in_graph();
|
||||
template<typename Graph> void export_prim_minimum_spanning_tree_in_graph();
|
||||
template<typename Graph> void export_prim_minimum_spanning_tree_in_graph();
|
||||
extern void export_connected_components();
|
||||
extern void export_strong_components();
|
||||
extern void export_biconnected_components();
|
||||
@@ -39,6 +38,8 @@ extern void export_topological_sort();
|
||||
extern void export_cuthill_mckee_ordering();
|
||||
//extern void export_minimum_degree_ordering();
|
||||
extern void export_sequential_vertex_coloring();
|
||||
extern void export_betweenness_centrality();
|
||||
extern void export_page_rank();
|
||||
extern void export_circle_graph_layout();
|
||||
extern void export_fruchterman_reingold_force_directed_layout();
|
||||
extern void export_kamada_kawai_spring_layout();
|
||||
@@ -99,8 +100,7 @@ BOOST_PYTHON_MODULE(bgl)
|
||||
|
||||
export_Graph();
|
||||
export_Digraph();
|
||||
export_betweenness_centrality();
|
||||
export_page_rank();
|
||||
export_graphviz();
|
||||
// Core Algorithm Patterns
|
||||
export_breadth_first_search();
|
||||
export_depth_first_search();
|
||||
@@ -125,6 +125,8 @@ BOOST_PYTHON_MODULE(bgl)
|
||||
export_topological_sort();
|
||||
export_transitive_closure();
|
||||
export_sequential_vertex_coloring();
|
||||
export_betweenness_centrality();
|
||||
export_page_rank();
|
||||
|
||||
// Layout Algorithms
|
||||
export_circle_graph_layout();
|
||||
|
||||
Reference in New Issue
Block a user