Getting edge properties (including bound vertices) from boost :: adjacency_list

So, I had to go through the Boost documentation for an hour today. I have to be blind. I have, I hope, a simple question:

How do you get the appropriate vertices for an edge with boost :: adjacency_list?

I have the following code that I am trying to figure out:

typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS> Graph;
typedef boost::graph_traits<Graph>::edge_iterator EdgeIterator;
typedef std::pair<EdgeIterator, EdgeIterator> EdgePair;

EdgePair ep;
for (ep = edges(g); ep.first != ep.second; ++ep.first)
{
    // Get the two vertices that are joined by this edge...
}

Does anyone know how to do this?

thank

+5
source share
1 answer

You can find the functions that you need in this page (in the "Non-Member Functions" section). You need sourceand target.

typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS> Graph;
typedef boost::graph_traits<Graph>::edge_iterator EdgeIterator;
typedef std::pair<EdgeIterator, EdgeIterator> EdgePair;
typedef boost::graph_traits<Graph>::vertex_descriptor VertexDescriptor;

EdgePair ep;
VertexDescriptor u,v;
for (ep = edges(g); ep.first != ep.second; ++ep.first)
{
    // Get the two vertices that are joined by this edge...
    u=source(*ep.first,g);
    v=target(*ep.first,g);
}
+8
source

All Articles