Generation of All Path in a Directed Acyclic Graph - MathOverflow most recent 30 from http://mathoverflow.net2013-05-23T12:59:11Zhttp://mathoverflow.net/feeds/question/105330http://www.creativecommons.org/licenses/by-nc/2.5/rdfhttp://mathoverflow.net/questions/105330/generation-of-all-path-in-a-directed-acyclic-graphGeneration of All Path in a Directed Acyclic GraphHJosef2012-08-23T15:43:26Z2012-10-25T17:37:32Z
<p>I am working on a very large dataset of a single <a href="http://en.wikipedia.org/wiki/Directed_acyclic_graph" rel="nofollow">DAG</a> whose vertices have a low branching factor. I need to generate all possible (simple) paths starting from the source and write them to a file.</p>
<p>My question is: what is <a href="http://en.wikipedia.org/wiki/Computational_complexity_theory" rel="nofollow">computational complexity</a> class of this problem?</p>
<p>If this problem is <a href="http://en.wikipedia.org/wiki/NP-hard" rel="nofollow">NP-Hard</a>, is there any relatively space-efficient algorithm that can generate this exponential number of paths iteratively?</p>
<p><em>Any references are extremely appreciated.</em></p>
<p>Thanks in advance.</p>
http://mathoverflow.net/questions/105330/generation-of-all-path-in-a-directed-acyclic-graph/105340#105340Answer by joro for Generation of All Path in a Directed Acyclic Graphjoro2012-08-23T17:00:40Z2012-08-23T17:00:40Z<p>The worst case is exponential in the number of nodes. Consider an <a href="https://en.wikipedia.org/wiki/Binary_decision_diagram" rel="nofollow">Ordered Binary Decision Diagram</a> (OBDD) which is a DAG with outdegrees 2. Let it be on $n$ boolean variables and on $m$ nodes. Each assignment of the variables corresponds to a path to either True or False, so there are at least $2^n$ (simple) paths. Even if outputting a path is $O(1)$, you will have to do it $2^n$ times (not counting the inner paths).</p>
<p>To check if you are lucky, you can efficiently count the number of paths via powers of the <a href="https://en.wikipedia.org/wiki/Adjacency_matrix" rel="nofollow">adjacency matrix</a>.</p>
<p>The open source software <a href="http://sagemath.org" rel="nofollow">sage</a> (available online at <a href="http://sagenb.org/" rel="nofollow">http://sagenb.org/</a>)
has a method "all_simple_paths()" that does exactly what you want.</p>
http://mathoverflow.net/questions/105330/generation-of-all-path-in-a-directed-acyclic-graph/110495#110495Answer by Rosh for Generation of All Path in a Directed Acyclic GraphRosh2012-10-24T00:59:37Z2012-10-25T17:37:32Z<p>My just published book , " A New Algorithm for Studying Routes in a Connected Graph', Kindle Edition, by Amazon. Com may be helpful in your problem. My new algorithm does not employ search, recursion or AI. It is based on combinatorial Analysis/Block Design. My algorithm produces all routes of length (PL) between the starting node, s and all other nodes. The number of such routes is simply Avg(Nc)^PL where Avg(Nc) is average degree of nodal connectivity. My software package (EcoNets) also selects routes (simple or cyclic) between any two nodes s and t. It can also select any routes with any set of route-attributes such as distance, link costs or reliabilities. A sample network (10n, 20s) took about 1 minute of my laptop and about 1 Gigabytes of RAM for all routes with PL <=10.</p>