Boost logo

Boost Users :

Subject: Re: [Boost-users] [Graph] Need help with Subgraph and adjacent_vertices.
From: Trevor Harmon (Trevor.W.Harmon_at_[hidden])
Date: 2010-04-06 14:41:48


On Apr 5, 2010, at 2:59 PM, Marcus Fontaine wrote:

> The following code demonstrates the problem; the adjacent vertices
> to 4
> in subG should be 2 and 3. However, I get 5 when I run the program.

I believe the problem has something to do with the way you are adding
vertices to the subgraph. Try printing out the vertices of the subgraph:

   typedef graph_traits<Graph>::vertex_descriptor Vertex;
   typedef graph_traits<Graph>::vertex_iterator VertexIterator;
   std::pair<VertexIterator, VertexIterator> vp;
   for (vp = vertices(subG); vp.first != vp.second; ++vp.first) {
     Vertex vertex = *vp.first;
     cout << "vertex: " << vertex << endl;
   }

And you will get:

vertex: 0
vertex: 1
vertex: 2
vertex: 3
vertex: 4
vertex: 5

This is probably not what you were expecting.

Trevor


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