Boost logo

Boost Users :

From: Ronald Garcia (garcia_at_[hidden])
Date: 2007-09-19 11:01:45


Hi Brian,
On Sep 19, 2007, at 10:41 AM, Brian Stadler wrote:

>
> Code for writing is very simple. I dont use this code unless I am
> doing testing.
>
> ofstream fo(filename.c_str());
> write_graphviz(fo, [graph here]);
> fo.close();
>

> The function you speak of is listed on http://boost.org/libs/graph/
> doc/write-graphviz.html. It is included with 1.33.1.
>

Based on my reading of the write_graphviz docs, it seems that the
function that I suggested will get you the results that you want.
Also, I should mention that you don't need to keep the
dynamic_properties object around to get the vertex names. They are
also available directly from the internal vertex_name property map of
your graph. You could use one of the versions of write_graphviz that
takes a VertexID argument instead.

> To be honest, I wish read_graphviz() did not require a dynamic
> properties object. If one wants to read a very simple dot file
> without any extra stuff then they basically have to create a fake
> dp object just to do this.

Bear in mind that the graphs you are parsing with read_graphviz are a
special case: The names of the vertices happen to be integral
numbers. In general, graphviz graphs can have almost arbitrary
string identifiers as node id's. Even though node id's do not have
to be in quotes, they're still just character strings as far as the
DOT language is concerned. I think that in the most common-cases:
1) the names of graph nodes are arbitrary strings (not integers)
2) the consumer of the DOT-specified graph cares about those names

The dynamic_properties object at the least guarantees that you can
associate the names of the vertices with the vertices that are
created in your graph object. The problem that you have been having
that you originally reported is that you were indeed losing the node
name information (the string representations of integers) when you
were writing out your graphs using write_graphviz. That information
is preserved in the vertex_name property map that you passed along to
dynamic_properties, and also in the dynamic_properties

>
> Quick note, I changed the dot files I was reading in from the
> original post to the following, which is the way the boost library
> outputs them.
>
> graph G {
> "0";
> "1";
> "2";
> "0" -- "1";
> "0" -- "2";
> "1" -- "2";
> }
>
> Vertices are quoted but boost is able to handle it correctly.

This is actually a good demonstration of how graphviz node id's are
really strings, not numbers. The version of the graph output by
write_graphviz may be textually different (because of the addition of
quotation marks), but as far as any DOT tool is concerned, it's the
same graph.

HTH,
ron



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net