3

Suppose that I have an Edge. How can I easily find which two nodes it connects? The documentation of LEMON is so sparse, I could not find info on this.

Artem Zankovich
  • 2,319
  • 20
  • 36
szali
  • 498
  • 3
  • 11

2 Answers2

2

You can use source and target to find the nodes an edge connects, it works like this

ListDigraph graph;
ListDigraph::Arc edge;
ListDigraph::Node a1,a2;
a1 = graph.source(edge);
a2 = graph.target(edge);
vigenere
  • 197
  • 3
  • 15
  • Thanks! I thought the edge itself could tell its endpoints, but turns out I need the graph. – szali Jun 20 '13 at 13:43
0

In case anyone else is wondering how to achieve this in the undirected setting (to which an "edge" is supposed to refer, as opposed to an "arc" in the directed setting) , the corresponding methods to source and target are u and v. A snippet for listing the endpoints of all edges of an undirected graph G would look something like this:

for(ListGraph::EdgeIt edge(G); edge != INVALID; ++edge) 
    std::cout << G.id(G.u(edge)) << " -- " << G.id(G.v(edge)) << endl;

See the relevant part of LEMON's documentation.

Anthony Labarre
  • 2,745
  • 1
  • 28
  • 39