Search code examples
c++path-findingdirected-graphlemon-graph-library

Lemon Graph Library C++ - Directed Graph


I am looking at Lemon to handle my pathfinding, since it has search and shortest paths algorithms, among other things.

The thing is, I am already stuck right at the start in understanding how Lemon works, and they have a tutorial but no forum to ask.

My understanding of a directed graph is that you have a node, and it can link or not link to another node and then you have a weight on it.

Example:

     A    B    C
A    0    1    0
B    1    0    5
C    0    0    0

In this, A is connected to B with a weight of 1, C is connected to nothing (so once you get to C you are stuck), and B connects to A with a value of 1 and B connects to C with a value of 5.

The tutorial says to do something like this:

ListDigraph g;
ListDigraph::Node A = g.addNode();
ListDigraph::Node B = g.addNode();
ListDigraph::Node C = g.addNode();

So now I have a graph g with the three nodes. Now what? Where / how do I add the connectivity information as well as the weight values?


Solution

  • From the Lemon tutorial

      ListDigraph g;
    
      ListDigraph::Node x = g.addNode();
      ListDigraph::Node y = g.addNode();
      ListDigraph::Node z = g.addNode();
    
      g.addArc(x,y);
      g.addArc(y,z);
      g.addArc(z,x);
    

    Never used this library mind, I'm just quoting what I've read.