Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost Graph: edge indices
From: Trevor Harmon (Trevor.W.Harmon_at_[hidden])
Date: 2010-04-02 19:53:49


On Apr 1, 2010, at 5:31 AM, Gábor Szuromi wrote:

> 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;

A follow-up question, if I may... It seems like an awful lot of setup
is required just to iterate through the edge indices. For example,
here's what I'm doing now:

typedef property_map<MyGraph, vertex_index_t>::type IndexMap;
IndexMap index = get(vertex_index, g);
typedef graph_traits<MyGraph>::edge_iterator edge_iter;
std::pair<edge_iter, edge_iter> ep;
EdgeIndexMap edgeIndexMap = get(edge_index, g);
for (ep = edges(g); ep.first != ep.second; ++ep.first) {
        Edge edge = *ep.first;
        cout << index[get(edgeIndexMap, edge)] + " ";
}

Is there any way to simplify the above code? That's a lot of typing
for such a basic task... Thanks,

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