|
Boost Users : |
Subject: Re: [Boost-users] [BGL] Change order of edge iterator
From: Andrew Sutton (asutton.list_at_[hidden])
Date: 2010-08-23 09:31:27
> tie(edge_iter1, edges_end1) = edges(g); sort(edge_iter1, edges_end1,
> ordering_1());
>
> tie(edge_iter2, edges_end2) = edges(g); sort(edge_iter2, edges_end2,
> ordering_2());
>
> tie(edge_iter3, edges_end3) = edges(g); sort(edge_iter3, edges_end3,
> ordering_3());
>
> (ordering_x() specified by some struct)
>
> Then I would have 3 different orderings of the edges available.
>
> Would this work or should I use an iterator adapter,
> or create a map and (if its possible) obtain an iterator from the mapping,
> or something else.
>
I think your best bet may be simply sorting a vector of iterators:
pair<Iter, Iter> rng = edgesg);
vector<Iter> iters(num_edges(g));
for(vector<Iter> i = iters.begin() ; rng.first != rng.second; ++i,
++rng.first) {
*i = rng.first;
}
// For example:
sort(iters.begin(), iters.end(), ordering_1());
// Iterating edges (in c++0x, for brevity).
for(auto i = iters.begin(); i != end; ++i) {
// **i should be a vertex descriptor.
cout << g[**i] << "\n";
}
There's probably a more concise way to implement that population of the
vectors using std::generate. You should have more freedom to sort the vector
of iterators as you see fit.
Andrew Sutton
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