|
Boost Users : |
Subject: Re: [Boost-users] [graph] Newbie question: iterator shows vertices not added, always lo .. hi
From: Phillip Jones (pjones13_at_[hidden])
Date: 2008-10-21 15:14:59
> 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<edge_iter, edge_iter> ep; // edge pair
for (ep = edges(g); ep.first != ep.second; ++ep.first) {
edge_iter iter = ep.first;
boost::graph_traits<Graph>::edge_descriptor e = *iter;
std::cout << boost::source(e, g)
<< " <--> "
<< boost::target(e, g) << std::endl;
}
[/code]
I've also had a hard time with the boost documentation. It's usually
in there somewhere, just takes some digging.
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