[graph] Newbie question: iterator shows vertices not added, always lo .. hi
Hi,
I am new to the Boost graph library and trying to learn from examples in
the documentation. I would like to ask about the simple vertex
iterator's behavior. Below is sample code. In a nutshell, the program
adds some edges to a Boost graph, then prints the vertices. The vertex
numbers added are not contiguous: the loop basically adds edges between
vertices 0, 1, 2, 6, and 7; no edges are added for vertices 3, 4, 5.
Then I use a vertex iterator to show tine in- and out-degree of each
vertex.
My expectation was that the iterator would only show me the vertices for
which I added edges, but instead it shows vertices from 0..7,
essentially from the low value to the high value. This seems to be a
feature, but I don't know where to look to find an explanation. Perhaps
this behavior is dictated by my choices of data structures vecS?
So far I have been relying on the online documentation, which I find to
be quite difficult to use. For example, the web site doesn't seem to
have a comprehensive index to Boost generic types and functions, just
that alone would be an enormous help.
Is the Boost book is (substantially?) better than using the online docs,
or is it just the same content on paper?
Please advise, thanks for your help.
chris...
--------
[code]
#include <iostream> // for std::cout
#include <utility> // for std::pair
#include <algorithm> // for std::for_each
#include
My expectation was that the iterator would only show me the vertices for which I added edges, but instead it shows vertices from 0..7, essentially from the low value to the high value. This seems to be a feature, but I don't know where to look to find an explanation.
It certainly is a feature. There are many cases when you want to know
about ALL of the vertices, not just the ones with edges connected to
them.
It sounds like you are actually interested in an edge iterator instead
of a vertex iterator. Here's some example code that demonstrates an
edge iterator. Just paste this into your code before the return
statement. It loops through every edge in your graph, and outputs the
source and destination vertices in this form: "X <--> Y". (where X and
Y are vertex numbers)
[code]
typedef boost::graph_traits<Graph>::edge_iterator edge_iter;
std::pair
participants (2)
-
Chris Lott
-
Phillip Jones