c# - QuickGraph - is there algorithm for find all parents (up to root vertex's) of a set of vertex's -


in quickgraph - there algorithm find parents (up root vertex's) of set of vertex's. in other words vertex's have somewhere under them (on way leaf nodes) 1 or more of vertexs input. if vertexs nodes, , edges depends on relationship, find nodes impacted given set of nodes.

if not how hard write one's own algorithms?

here's i've used accomplish predecessor search on given vertex:

ibidirectionalgraph<int, iedge<int>> creategraph(int vertexcount) {     bidirectionalgraph<int, iedge<int>> graph = new bidirectionalgraph<int, iedge<int>>(true);     (int = 0; < vertexcount; i++)         graph.addvertex(i);      (int = 1; < vertexcount; i++)         graph.addedge(new edge<int>(i - 1, i));      return graph; }  static public void main() {     ibidirectionalgraph<int, iedge<int>> graph = creategraph(5);      var dfs = new depthfirstsearchalgorithm<int, iedge<int>>(graph);                 var observer = new vertexpredecessorrecorderobserver<int, iedge<int>>();      using (observer.attach(dfs)) // attach, detach dfs events         dfs.compute();      int vertextofind = 3;     ienumerable<iedge<int>> edges;     if (observer.trygetpath(vertextofind, out edges))     {         console.writeline("to vertex '" + vertextofind + "', take following edges:");         foreach (iedge<int> edge in edges)             console.writeline(edge.source + " -> " + edge.target);     } } 

note if know root beforehand, can specify in dfs.compute() method (i.e. dfs.compute(0)).

-doug


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -