[Lemon-user] Iterate through weighted edges

Pierre Moulon pmoulon at gmail.com
Mon Feb 14 13:34:25 CET 2011


Hi,

Thanks for the code explaination.

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 ?

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
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lemon.cs.elte.hu/pipermail/lemon-user/attachments/20110214/a80b1f5c/attachment.html>


More information about the Lemon-user mailing list