1

I have a directed multi graph where multiple edges can exist between two nodes. For this graph I would like to know all possible paths between two nodes. So for the example below the resulting paths between nodes 0 and 2 would be:

  • 0 -> 2
  • 0 -edge A-> 1 -> 2
  • 0 -edge B-> 1 -> 2

enter image description here

I'm trying to accomplish this using the following QuickGraph implementation:

var startNode = "0";
var endNode = "2";

var graph = new AdjacencyGraph<string, TaggedEdge<string, string>>(allowParallelEdges: true);

var edges = new List<TaggedEdge<string, string>>{
    new TaggedEdge<string, string>("0", "1", "edge A"),
    new TaggedEdge<string, string>("0", "1", "edge B"),
    new TaggedEdge<string, string>("1", "2", string.Empty),
    new TaggedEdge<string, string>("0", "2", string.Empty),
    new TaggedEdge<string, string>("0", "3", string.Empty),
    new TaggedEdge<string, string>("1", "3", string.Empty), };
edges.ForEach(x => graph.AddVerticesAndEdge(x));

var algo = new EdgeDepthFirstSearchAlgorithm<string, TaggedEdge<string, string>>(graph);
var observer = new EdgePredecessorRecorderObserver<string, TaggedEdge<string, string>>();

using (observer.Attach(algo))
{
    algo.Compute(startNode);
}

var allPaths = observer.AllPaths().Where(x => x.Last().Target == endNode);

This implementation however returns only 2 paths:

  • 0 -> 2
  • 0 -> 1 -> 2

So it seems that the parallel edge does not result in a separate path. Is there any way in QuickGraph that this can be accomplished. And, does anyone know what the 'allowParallelEdges' parameter does in the Graph constructor?

Boxed
  • 71
  • 1
  • 3

0 Answers0