
Hi John, On Jun 1, 2006, at 4:02 AM, John Reid wrote:
I was trying to build a graph from an edge list and ran into some problems. The following code throws an exception on write_graphviz (). I think it is because there's no property map called node_id in the graph.
import boost.graph as bgl edges = [ ( 'a', 'b' ), ( 'b', 'c' ), ( 'c', 'a' ) ] g = bgl.Graph( edges ) g.write_graphviz( 'bind-copy.dot' )
I get the following: Traceback (most recent call last): File "<stdin>", line 1, in ? KeyError: 'node_id'
I couldn't manage to generate the node_id property map automatically. So after you have built the graph with the edge list constructor how do you know which vertex is which?
Your code above should work properly, but doesn't due to several bugs in the BGL-Python bindings. I have now fixed these bugs in Subversion. In particular: - There is now a name_map parameter for the edge list constructor, which defaults to "node_id". If name_map is not the empty string, the constructor creates a vertex property map g.vertex_properties [name_map] that gives the name of each vertex, e.g., 'a', 'b', or 'c', in your example. - If write_graphviz cannot find the node_id map, it will just use the vertex indices as identifiers in the GraphViz output file. Thanksf or reporting these problems! Doug