You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For this graph we 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
The code to accomplish this is:
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)
```;
However only 2 paths are found, not finding the one that has edge B:
- 0 -> 2
- 0 -edge A-> 1 -> 2
Would we add a parallel edge between nodes 1 and 2, then indeed 3 paths are found.
The text was updated successfully, but these errors were encountered:
Considering the following graph
For this graph we 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:
The code to accomplish this is:
The text was updated successfully, but these errors were encountered: