[Lemon-user] Iterate through weighted edges

Pierre Moulon pmoulon at gmail.com
Mon Feb 14 11:42:54 CET 2011


Hello,

I'm trying to discover how to use lemon. I really like it's clear interface
!

I want to create a graph with weighted edges and iterate through outgoing
edges of a given node with ascending weights.

I give an example (that do not work as I want) :

TEST(GRAPH, testWeightedEdges)
{
  using namespace lemon;
  ListDigraph g;
  ListDigraph::NodeMap< int > coord(g);
  ListDigraph::ArcMap<int> length(g);

  typedef ListDigraph::Node Node;
  typedef ListDigraph::NodeIt NodeIt;
  typedef ListDigraph::Arc Arc;

  ListDigraph::NodeMap<int> coords(g);

  Node n1 = g.addNode();
  Node n2 = g.addNode();
  Node n3 = g.addNode();

  coords[n1] = 1;
  coords[n2] = 2;
  coords[n3] = 3;

  Arc arc1 = g.addArc(n1, n2);
  Arc arc3 = g.addArc(n1, n2);
  Arc arc4 = g.addArc(n1, n3);

  //ListDigraph::ArcMap<int> length(g);
  length[arc1] = 1.0;
  length[arc3] = 2.0;
  length[arc4] = 3.0;

  int count = 0;
  for (ListDigraph::OutArcIt a(g, n1); a!=INVALID; ++a)
  {
    ++count;
    Node ns= g.source(a);
    Node nd = g.target(a);
    cout << coords[ns] << "," << coords[nd] << "\t/ arc length : " <<
length[a] << endl;
  }
}

/////////////
It gives me as output :

1,3 / arc length 3
1,2 / arc length 2
1,2 / arc length 1

While the result I want is the following :
1,2 / arc length 1
1,2 / arc length 2
1,3 / arc length 3

Does someone could give me a tips to iterate through weighted edges (with
ascending weights).

Thanks in advance
Regards,
Pierre
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lemon.cs.elte.hu/pipermail/lemon-user/attachments/20110214/c3acc78c/attachment.html>


More information about the Lemon-user mailing list