[Lemon-user] Iterate through weighted edges
Alpár Jüttner
alpar at cs.elte.hu
Mon Feb 14 13:48:47 CET 2011
Hi,
>
> By the way, if I insert the edges in a descending order and do not
> modify the graph,
> I think the edges will remain in ascending order at the iteration
> through weighted edges ?
The graph concept does not fix the iteration order. ListDigraph
currently works in this way, but you shouldn't assume this in general.
The only thing ensured is that if you iterate through a set of items
twice and you do not change the graph in between, then you will get back
the items in the same order.
Regards,
Alpár
> Regards,
> Pierre
>
> 2011/2/14 Alpár Jüttner <alpar at cs.elte.hu>
> Hi,
> >
> > I want to create a graph with weighted edges and iterate
> through
> > outgoing edges of a given node with ascending weights.
>
>
> Unfortunately you must somehow sort the edges by hand in this
> case.
>
> For example:
>
> std::multimap<double,ListDigraph::Arc> m;
> for (ListDigraph::OutArcIt a(g, n1); a!=INVALID; ++a)
>
> m.insert(std::pair<double,ListDigraph::Arc>(length,a));
>
> int count = 0;
> for (std::multimap<double,ListDigraph::Arc>::iterator i =
> m.begin();i!=m.end;++i)
> {
> ++count;
> ListDigraph::Arc a = i->second;
> Node ns= g.source(a);
> Node nd = g.target(a);
> cout << coords[ns] << "," << coords[nd] << "\t/ arc length :
> "
> << length[a] << endl;
> }
>
>
> Regards,
> Alpár
>
>
>
>
>
More information about the Lemon-user
mailing list