[BGL] Common children for vertices in DAG
Is there a fast way, with or without preprocessing of the graph, for checking if two non-adjacent vertices in a DAG have one or more common children? Any pointers to components of the BGL that implement, or can be used to implement, this task would be much appreciated. Thanks, Erik
Hi Erik, On Mon, 5 Aug 2002, Erik Arner wrote: yg-boo> yg-boo> Is there a fast way, with or without preprocessing of the graph, for yg-boo> checking if two non-adjacent vertices in a DAG have one or more common yg-boo> children? Any pointers to components of the BGL that implement, or can yg-boo> be used to implement, this task would be much appreciated. If you use a bidirectional graph (with both in and out edges), then you can do the following in average O(V*E) time. for each vertex c for each in-edge e1 of c for each in-edge e2 of c { p1 = source(e1); p2 = source(e2); if (!(is_adjacent(p1, p2) || is_adjacent(p2, p1))) parents_with_common_children.push_back(make_pair(p1,p2)); } Cheers, Jeremy ---------------------------------------------------------------------- Jeremy Siek http://php.indiana.edu/~jsiek/ Ph.D. Student, Indiana Univ. B'ton email: jsiek@osl.iu.edu C++ Booster (http://www.boost.org) office phone: (812) 855-3608 ----------------------------------------------------------------------
Jeremy Siek wrote:
Hi Erik,
On Mon, 5 Aug 2002, Erik Arner wrote: yg-boo> yg-boo> Is there a fast way, with or without preprocessing of the graph, for yg-boo> checking if two non-adjacent vertices in a DAG have one or more common yg-boo> children? Any pointers to components of the BGL that implement, or can yg-boo> be used to implement, this task would be much appreciated.
If you use a bidirectional graph (with both in and out edges), then you can do the following in average O(V*E) time.
for each vertex c for each in-edge e1 of c for each in-edge e2 of c { p1 = source(e1); p2 = source(e2); if (!(is_adjacent(p1, p2) || is_adjacent(p2, p1))) parents_with_common_children.push_back(make_pair(p1,p2)); }
OK thanks, I now realize I formulated the question wrongly. What I really was looking for is a fast method for determining whether two vertices have common *descendants*, not necessarily children... I might have to perform this task many times during the run of the program, so it really needs to be fast. Any thoughts? Maybe this is really stupid, but consider the following: if the graph was undirected, I could preprocess (potentially time consuming, I admit) by performing johnson_all_pairs_shortest_paths and store the result. Then I would have constant time lookup of whether two vertices are connected in some way just by checking for a non-infinity value of the shortest path between them. But my graph is, alas, directed so this doesn't seem feasible unless there is some way to (temporarily) regard the graph as undirected. Any ideas would be much appreciated. Please excuse my uneducated ramblings on this subject - I am a newbie at graph theory, and I ordered the BGL book but it hasn't arrived yet and my deadline is in a week... :-\ Thanks Erik
On Tue, 6 Aug 2002, Erik Arner wrote: yg-boo> yg-boo> OK thanks, I now realize I formulated the question wrongly. What I yg-boo> really was looking for is a fast method for determining whether two yg-boo> vertices have common *descendants*, not necessarily children... I might yg-boo> have to perform this task many times during the run of the program, so yg-boo> it really needs to be fast. Any thoughts? Yeah, what you want is the transitive closure of the reverse graph. This adds edges such that all descendants become children. Cheers, Jeremy ---------------------------------------------------------------------- Jeremy Siek http://php.indiana.edu/~jsiek/ Ph.D. Student, Indiana Univ. B'ton email: jsiek@osl.iu.edu C++ Booster (http://www.boost.org) office phone: (812) 855-3608 ----------------------------------------------------------------------
participants (2)
-
Erik Arner
-
Jeremy Siek