0

I am using QuickGraph in C# and have a graph that I can traverse by calling Compute on a node and traverse down the graph. However, there are times when I want to select a child node and it traverse in the reverse direction of all the edges.

The documentation is really poor so I was wondering if anyone knows how to do this.

Here is an example

        BidirectionalGraph<string, Edge<string>> graph = new BidirectionalGraph<string, Edge<string>>();

        graph.AddVertex("node1");
        graph.AddVertex("node2");
        graph.AddVertex("node3");
        graph.AddVertex("node4");

        graph.AddEdge(new Edge<string>("node1", "node2"));
        graph.AddEdge(new Edge<string>("node2", "node3"));
        graph.AddEdge(new Edge<string>("node2", "node4"));

        var dfs = new DepthFirstSearchAlgorithm<string, Edge<string>>(graph);
        var observer = new VertexPredecessorRecorderObserver<string, Edge<string>>();
        observer.Attach(dfs);

        dfs.Compute("node1");

        foreach(var obj in observer.VertexPredecessors) {
            System.Console.WriteLine(obj.Key);
        }

If I compute "node1", I get node2,node3,node4.

What I also want to do is compute "node4" and get node2,node1

0 Answers0