Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can find the relevant docs here :)</p> <p><a href="http://networkx.github.io/documentation/latest/reference/generated/networkx.algorithms.simple_paths.all_simple_paths.html#networkx.algorithms.simple_paths.all_simple_paths" rel="nofollow">Simple Paths in NetworkX</a></p> <p>essentially it's just a tree search of some sort</p> <p>you can use the <a href="http://networkx.github.io/documentation/latest/reference/generated/networkx.classes.function.nodes.html#networkx.classes.function.nodes" rel="nofollow">list of nodes</a> and do this</p> <pre><code>list_of_nodes = nodes(my_graph) for mysource in list_of_nodes: for mytarget in list_of_nodes: if source != target: print all_simple_paths(my_graph,source=mysource,target=mytarget, cutoff=4) </code></pre> <p>If you want all the shortest paths of length 4 you can use <a href="http://networkx.github.io/documentation/latest/reference/generated/networkx.algorithms.shortest_paths.unweighted.all_pairs_shortest_path.html#networkx.algorithms.shortest_paths.unweighted.all_pairs_shortest_path" rel="nofollow">``all_pairs_shortest_path_```</a></p> <pre><code>paths = all_pairs_shortest_path(my_graph,cutoff=4) for k,v in paths: if len(paths[k][v]) == 4: print paths[k][v] </code></pre> <p>There is no real command built in to generate all the simple paths of a certain length as the only way to find that is to generate a tree from every node, e.g. doing a modified version of my for loop above since that uses a modified depth-first search.</p> <hr> <blockquote> <p>"A path with no repeated vertices is called a simple path" - <a href="http://en.wikipedia.org/wiki/Path_%28graph_theory%29" rel="nofollow">Wikipedia</a></p> </blockquote> <p>If you would like a <a href="http://ieeexplore.ieee.org/xpls/abs_all.jsp?arnumber=1084515" rel="nofollow">paper citation</a>. The only way to check for simple paths is to check from each node. If you have a graph with 90000 elements; there is no other way to check if two connect :/. The 'target' is really not consequential as it's just another cutoff, though if you have a large number of nodes it can make a difference so you're right there :).</p> <pre><code> " def _all_simple_paths_graph(G, source, target, cutoff=None): if cutoff &lt; 1: return visited = [source] stack = [iter(G[source])] while stack: children = stack[-1] child = next(children, None) if child is None: stack.pop() visited.pop() elif len(visited) &lt; cutoff: if child == target: yield visited + [target] elif child not in visited: visited.append(child) stack.append(iter(G[child])) else: #len(visited) == cutoff: if child == target or target in children: yield visited + [target] stack.pop() visited.pop()" </code></pre> <p>code above from <a href="http://networkx.github.io/documentation/latest/reference/algorithms.html" rel="nofollow">networkx docs</a></p> <p>to modify it in order to generate the DFS without the 'target' cutoff you can use:</p> <pre><code> def _all_simple_paths_graph(G, source, target, cutoff=None): if cutoff &lt; 1: return visited = [source] stack = [iter(G[source])] while stack: children = stack[-1] child = next(children, None) if child is None: stack.pop() visited.pop() elif len(visited) &lt; cutoff: #if child == target: # yield visited + [target] #elif child not in visited: if child not in visited: visited.append(child) stack.append(iter(G[child])) #else: #len(visited) == cutoff: #if child == target or target in children: # yield visited + [target] #stack.pop() #visited.pop() </code></pre> <hr> <p>Hope that works for you :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload