In QuickGraph - is there algorithm for find all parents (up to root vertex's) of a set of vertex's. In other words all vertex's which have somewhere under them (on the way to the leaf nodes) one or more of the vertexs input. So if the vertexs were Nodes, and the edges were a depends on relationship, find all nodes that would be impacted by a given set of nodes.
If not how hard is it to write one's own algorithms?
I used Doug's answer and found out that if there are more than one parent for a vertex, his solution only provides one of the parents. I am not sure why.
So, I created my own version which is as follows:
Here's what I've used to accomplish a predecessor search on a given vertex:
Note that if you know your root beforehand, you can specify it in the
dfs.Compute()
method (i.e.dfs.Compute(0)
).-Doug
You either need to maintain a reversed graph, or create a wrapper over the graph that reverses every edge. QuickGraph has the ReversedBidirectionalGraph class that is a wrapper intended just for that, but it does not seem to work with the algorithm classes because of generic type incompatibility. I had to create my own wrapper class:
Then run DFS or BFS on this wrapper:
Doug's answer is not correct, because DFS will only visit the downstream subgraph. The predecessor observer does not help.