Create subgraph of LEMON ListDigraph in c++

41 views Asked by At

I have a ListDigraph and related node and arc maps, namely,

ListDigraph::ArcMap<int>length;
ListDigraph::NodeMap<int> label;

I have a list of nodes, belonging to the graph. I would like to build a subgraph which has list of nodes mentioned before.

I'm using the LEMON library, but I cannot find a nice solution for it.

I used the reference here: http://lemon.cs.elte.hu/pub/tutorial/a00009.html but actually this does not help, for Digraphs it does not accept both arc and node maps in the copy of the graph.

Is there a simple solution that given a list of node I want to maintain, I can obtain the subgraph with only those nodes together with the arcs connected to them (unless the other end of the arc belonged to a now-erased node) ? Of course, also the edge map should be preserve: the label (length) on the arcs must remain.

1

There are 1 answers

4
ravenspoint On
  • Copy the input graph, call it g2
  • LOOP N over nodes in g2
    • If N NOT in nodes subset to be maintained
      • REMOVE from g2 all edges connected to N
      • REMOVE N from g2
  • RETURN g2