This concept defines the visitor interface for breadth_first_search().
@@ -180,6 +180,27 @@ search tree and all of the adjacent vertices have been discovered
+To implement a model of the BFSVisitor concept in Python,
+create a new class that derives from the BFSVisitor type of
+the graph, which will be
+named GraphType.BFSVisitor. The events and syntax are
+the same as with visitors in C++. Here is an example for the
+Python bgl.Graph graph type:
+
+
+
+To implement a model of the BellmanFordVisitor concept in Python,
+create a new class that derives from the BellmanFordVisitor type of
+the graph, which will be
+named GraphType.BellmanFordVisitor. The events and syntax are
+the same as with visitors in C++. Here is an example for the
+Python bgl.Graph graph type:
+
+
+
+To implement a model of the DFSVisitor concept in Python,
+create a new class that derives from the DFSVisitor type of
+the graph, which will be
+named GraphType.DFSVisitor. The events and syntax are
+the same as with visitors in C++. Here is an example for the
+Python bgl.Graph graph type:
+
+
This concept defines the visitor interface for dijkstra_shortest_paths()
@@ -184,6 +184,29 @@ search tree and all of the adjacent vertices have been discovered
+
+To implement a model of the DijkstraVisitor concept in Python,
+create a new class that derives from the DijkstraVisitor type of
+the graph, which will be
+named GraphType.DijkstraVisitor. The events and syntax are
+the same as with visitors in C++. Here is an example for the
+Python bgl.Graph graph type:
+
+
- The source vertex where the search is started.
+ The source vertex where the search is started.
+
+ Python: The parameter is named root_vertex.
@@ -174,7 +178,11 @@ IN: visitor(BFSVisitor vis)
event-points specified by the BFS
Visitor concept. The visitor object is passed by value [1]. Default:
- bfs_visitor<null_visitor>
+ bfs_visitor<null_visitor>
+
+ Python: The parameter should be an object that derives from
+ the BFSVisitor type of the graph.
+
UTIL/OUT: color_map(ColorMap color)
@@ -198,7 +206,10 @@ UTIL/OUT: color_map(ColorMap color)
iterator_property_map created from a
std::vector of default_color_type of size
num_vertices(g) and using the i_map for the index
- map.
+ map.
+
+ Python: The color map must be a vertex_color_map for
+ the graph.
IN: vertex_index_map(VertexIndexMap i_map)
@@ -212,7 +223,9 @@ IN: vertex_index_map(VertexIndexMap i_map)
vertex descriptor type of the graph needs to be usable as the key
type of the map.
- Default:get(vertex_index, g)
+ Default:get(vertex_index, g)
+
+ Python: Unsupported parameter.
UTIL: buffer(Buffer& Q)
@@ -225,7 +238,11 @@ UTIL: buffer(Buffer& Q)
using a priority queue. The type Buffer must be a model of
Buffer. The value_type
of the buffer must be the vertex_descriptor type for the graph.
- Default:boost::queue
+ Default:boost::queue
+
+ Python: The buffer must derive from the Buffer type for the graph.
+
@@ -294,6 +311,11 @@ class used has VertexList and EdgeList set
to listS.
+
@@ -60,12 +60,16 @@ only reaches a small portion of the graph.
IN: IncidenceGraph& g
A directed or undirected graph. The graph type must
- be a model of Incidence Graph.
+ be a model of Incidence Graph.
+
+ Python: The parameter is named graph.
IN: vertex_descriptor s
- The source vertex where the search is started.
+ The source vertex where the search is started.
+
+ Python: The parameter is named root_vertex.
@@ -77,7 +81,10 @@ IN: visitor(BFSVisitor vis)
event-points specified by the BFS
Visitor concept. The visitor object is passed by value [1]. Default:
- bfs_visitor<null_visitor>
+ bfs_visitor<null_visitor>
+
+ Python: The parameter should be an object that derives from
+ the BFSVisitor type of the graph.
UTIL/OUT: color_map(ColorMap color)
@@ -88,7 +95,10 @@ UTIL/OUT: color_map(ColorMap color)
Property Map and its key type must be the graph's vertex
descriptor type and the value type of the color map must model
ColorValue.
- Default:get(vertex_color, g)
+ Default:get(vertex_color, g)
+
+ Python: The color map must be a vertex_color_map for
+ the graph.
UTIL: buffer(Buffer& Q)
@@ -100,7 +110,10 @@ UTIL: buffer(Buffer& Q)
For example Dijkstra's algorithm can be implemented
using a priority queue. The type Buffer must be a model of
Buffer.
- Default:boost::queue
+ Default:boost::queue
+
+ Python: The buffer must derive from the Buffer type for the graph.
diff --git a/doc/figs/python.gif b/doc/figs/python.gif
new file mode 100644
index 00000000..51f4ecac
Binary files /dev/null and b/doc/figs/python.gif differ
diff --git a/doc/figs/python_ico.gif b/doc/figs/python_ico.gif
new file mode 100644
index 00000000..58271ede
Binary files /dev/null and b/doc/figs/python_ico.gif differ
diff --git a/doc/python.html b/doc/python.html
new file mode 100644
index 00000000..1a2bce5b
--- /dev/null
+++ b/doc/python.html
@@ -0,0 +1,125 @@
+
+
+ Boost Graph Library: Python Bindings (Experimental)
+
+
+
+
+
The Boost Graph Library offers a wealth of graph algorithms and
+ data types for C++. These algorithms are flexible and efficient,
+ but the mechanisms employed to achieve this goal can result in
+ long compile times that slow the development cycle.
+
+
The Python bindings are build using the Boost.Python library. The bindings are
+ meant to strike a balance of usability, flexibility, and
+ efficiency, making it possible to rapidly develop useful systems
+ using the BGL in Python.
The Python bindings for the Graph library are experimental at
+ this time. The bindings may not work (but they probably do) and we
+ will not attempt to provide backward compatibility if the
+ interfaces change. If you have any ideas
To build the Python bindings, change to
+ the libs/graph/build/python subdirectory of Boost and
+ then follow the Boost
+ Build Instructions to build the Python extension module. The
+ end result will be a dynamic library (DLL, .so, etc.) that can be
+ loaded into Python via "import bgl". Note: For
+ this build to succeed, the graph library must work flawlessly on
+ the compile, including the new GraphViz parser, which tends
+ to break many popular compilers. For instance, recent versions of
+ GCC are okay but Visual C++ 7.1 will crash. We're working to
+ resolve the situation.
Our first
+ example illustrates the use of BGL graphs, graph
+ algorithms, and property maps from Python. The initial
+ step is to load the BGL-Python bindings:
+
+from bgl import *
+
+
+
Next, we load a GraphViz file containing the description of a
+ sample graph. The Graph type is an undirected
+ graph; file_kind is an enumerator with only two
+ potential values: adjlist, for an adjacency-list
+ representation, or graphviz, for a GraphViz file.
Assuming no exceptions have been thrown, we will have an
+ undirected graph loaded. We can immediately
+ call biconnected_components to compute the biconnected
+ components within the graph:
There are several interesting parts of the preceeding line. We
+ call the biconnected_components
+ algorithm with two parameters. The first is just the graph
+ itself. The second parameter is a property map from edges to an
+ integer value, which will be stored in the graph under the name
+ "label". Finally, the return value
+ of biconnected_components is a Python list containing the
+ articulation points of the graph.
+
+
Other kinds of property maps are available. In this case, we
+ create two property maps attaching strings to the vertices of the
+ graph. We then iterate over all vertices of the graph to set
+ default values for each vertex property.
+
+
+v_color = g.get_vertex_string_map("fillcolor")
+v_style = g.get_vertex_string_map("style")
+for v in g.vertices:
+ v_color[v] = "white"
+ v_style[v] = "filled"
+
+
+
Lastly, we mark all of the articulation points red and write
+ out the result in GraphViz format.
+
+
+for v in art_points:
+ v_color[v] = "red"
+
+g.write_graphviz("biconnected_components_out.dot")
+