|
Boost Users : |
Subject: Re: [Boost-users] Boost Graph: edge indices
From: Jeremiah Willcock (jewillco_at_[hidden])
Date: 2010-04-01 09:42:51
On Wed, 31 Mar 2010, Trevor Harmon wrote:
> Hi,
>
> In the Boost Graph library, vertices have an index (vertex_index_t), and I
> was under the impression that edges have one, too. At least, there's a
> predefined type called edge_index_t. However, I can't figure out how to
> access an edge's index. For example, consider a graph defined like:
>
> typedef adjacency_list<vecS, vecS, directedS, Foo*> MyGraph;
> typedef graph_traits<MyGraph>::vertex_descriptor Vertex;
> typedef graph_traits<MyGraph>::edge_descriptor Edge;
>
> And let's say I've got a vertex descriptor called "u". I can iterate over u's
> outgoing edges like this:
>
> typedef graph_traits<MyGraph>::out_edge_iterator out_iter;
> std::pair<out_iter, out_iter> outp;
> for (outp = out_edges(u, g); outp.first != outp.second; ++outp.first) {
> Edge e = *outp.first;
> Vertex v = target(e, g);
> cout << index[v] << std::endl; // Works fine
> cout << index[e] << std::endl; // Compiler error
> }
>
> In this example, index[v] works as expected, but index[e] gives me a compiler
> error: "no match for ¡operator[]¢ in ¡index[e]".
What is index here? That doesn't appear to be declared.
> Perhaps my graph typedef needs to be changed so that its edges have a
> property map for edge_index_t, although I'm not sure how to do that. (And
> anyway I wouldn't expect vertices to have indices by default but edges
> not...)
See Gabor's reply about creating the index map, but note that you need to
fill it in. The reason vertices have indices automatically in your graph
is that you used vecS as the vertex container and so vertices are just
indexes into the vector. If you had used listS for your vertex container
you wouldn't have a vertex_index_map either. If you have a read-only
graph, compressed_sparse_row_graph provides edge indices automatically. I
do not believe any of the read-write graph types have them built-in.
-- Jeremiah Willcock
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