|
Boost Users : |
Subject: Re: [Boost-users] Boost Graph: edge indices
From: Gábor Szuromi (kukkerman_at_[hidden])
Date: 2010-04-01 08:31:37
Hi!
The edge_index internal property map is not created by default, so you
have to define it explicitly:
typedef adjacency_list<vecS, vecS, directedS, Foo*,
property<edge_index_t, std::size_t> > MyGraph;
typedef property_map<MyGraph, edge_index_t>::type MyEdgeIndexMap;
...
// Retrieve the edge index map associated with the graph
MyEdgeIndexMap emap = get(edge_index, g);
...
// Convert the edge descriptor to an integer value
cout << index[ get(emap, e, g) ] << endl;
The vertex descriptor is an integer value so it works with operator[],
but edge descriptor is an std::pair<>, so you have to convert it to an
integer with the appropriate edge index map. This leaves only one
question: how do you use bundled edge properties along with edge index
map?
Cheers,
Gabe
On Thu, Apr 1, 2010 at 3:19 AM, Trevor Harmon <Trevor.W.Harmon_at_[hidden]> 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]".
>
> 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...)
>
> Thanks for any help,
>
> Trevor
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
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