Boost logo

Boost Users :

From: Doug Gregor (dgregor_at_[hidden])
Date: 2004-12-03 13:45:22


On Dec 3, 2004, at 12:05 PM, Jean Utke wrote:

> Since I haven't gotten any reaction to this - after some more digging
> it seems the explanation lies with the changes made between
> revisions 1.17 and 1.21 of boost/graph/graphviz.hpp
> for instance for vertex printing:
> revision 1.17: line 254:
> out << *i;
> vs
> revision 1.21: line 263:
> out << get(vertex_index, *i);
>
> I read the change comment from CVS:
> ===
> Revision *1.18*
> /Tue Aug 12 01:15:37 2003 UTC/ (15 months, 3 weeks ago) by /jsiek/ :
> changed to print the vertex_index instead of the vertex_descriptor
> ===
> I understand how vertex_descriptor works, I am not sure about
> vertex_index, I have not yet fully traced it back through the
> templates.
> Can somebody please explain this to me?

The GraphViz writer needs to be able to generate unique labels for
each of the nodes. The easiest way to do that is to use the indices of
the vertices. This is required because descriptors don't necessarily
make good labels... it worked before for some graph types by accident.

To fix this, you would need to add a "vertex_index_t" property to the
vertices in your graph and set them to values in [0, num_vertices(g)),
usually like this:

   vertex_iterator vi, vi_end;
   int i = 0;
   for(tie(vi, vi_end) = vertices(g); vi != vi_end; ++vi, ++i)
     put(vertex_index, g, *vi, i);

Actually, you'll probably find that using BGL algorithms becomes a lot
easier after you've done this :)

The alternative suggested by Jeffrey Holle is easier, but only if you
don't need to remove vertices from your graph.

        Doug


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