directed-graph

Tarjan's strongly connected components algorithm in python not working

断了今生、忘了曾经 提交于 2019-12-04 09:12:56
问题 I implemented the Tarjan's strongly connected components algorithm, according to wikipedia, in Python, but it isn't working. The algorithm is quite short and I cannot find any difference, so I cannot tell why it isn't working. I tried to check the original paper, but could not find it. Here is the code. def strongConnect(v): global E, idx, CCs, c, S idx[v] = (c, c) #idx[v][0] for v.index # idx[v][1] for v.lowlink c += 1 S.append(v) for w in [u for (v2, u) in E if v == v2]: if idx[w][0] < 0:

Algorithm for topological sorting if cycles exist

允我心安 提交于 2019-12-04 07:54:44
问题 Some programming languages (like haskell) allow cyclic dependencies between modules. Since the compiler needs to know all definitions of all modules imported while compiling one module, it usually has to do some extra work if some modules import each other mutually or any other kind of cycle occurs. In that case, the compiler may not be able to optimize code as much as in modules that have no import cycles, since imported functions may have not yet been analyzed. Usually only one module of a

Cycle detection in a graph

你离开我真会死。 提交于 2019-12-04 05:54:48
We are given a graph with the following facts: edge(a,b) edge(a,c) edge(b,a) edge(c,d) edge(d,d) edge(d,e) edge(e,f) edge(f,g) edge(g,e) And we are asked to define a rule, cycle(X) , that determines if there is a cycle starting from the node X . I am really lost on how to do this, I tried attempting to traverse the nodes and checking if the next one would be the starting one again but I cannot seem to get it to work Karoly Horvath Archie's idea is a good starting point, but it will create an infinite loop if it finds another cycle while searching for the path. I also haven't used prolog for

Fast algorithm for counting the number of acyclic paths on a directed graph

喜夏-厌秋 提交于 2019-12-04 02:24:04
In short, I need a fast algorithm to count how many acyclic paths are there in a simple directed graph. By simple graph I mean one without self loops or multiple edges. A path can start from any node and must end on a node that has no outgoing edges. A path is acyclic if no edge occurs twice in it. My graphs (empirical datasets) have only between 20-160 nodes, however, some of them have many cycles in them, therefore there will be a very large number of paths, and my naive approach is simply not fast enough for some of the graph I have. What I'm doing currently is "descending" along all

Python networkx and persistence (perhaps in neo4j)

点点圈 提交于 2019-12-03 17:28:04
I have an application that creates many thousands of graphs in memory per second. I wish to find a way to persist these for subsequent querying. They aren't particularly large (perhaps max ~1k nodes). I need to be able to store the entire graph object including node attributes and edge attributes. I then need to be able to search for graphs within specific time windows based on a time attribute in a node. Is there a simple way to coerce this data into neo4j ? I've yet to find any examples of this. Though I have found several python libs including an embedded neo4j and a rest client. Is the

Solving dependency constraints

旧巷老猫 提交于 2019-12-03 16:32:26
问题 I have a classic dependency solving problem. I thought I was headed in the right direction, but now I've hit a roadblock and I am not sure how to proceed. Background In the known universe (the cache of all artifacts and their dependencies), each there is a 1->n relationship between artifacts and versions, and each version may contain a different set of dependencies. For example: A 1.0.0 B (>= 0.0.0) 1.0.1 B (~> 0.1) B 0.1.0 1.0.0 Given a set of "demand constraints", I'd like to find the best

Storing a directed graph in google appengine datastore

*爱你&永不变心* 提交于 2019-12-03 12:42:06
问题 I need to store a large and dynamic undirected graph in google appengine, what's the best way to do this? The graph representation must be able to support rapidly pulling out a set of vertices (for rendering on a page) and all the links from a specific vertex, and pathfinding across the graph (although the optimal path isn't really needed, just a fairly good one) My thoughts on the subject: The most obvious way is to have a vertex model, and an edge model which references two vertices,

How do I find all paths through a set of given nodes in a DAG?

回眸只為那壹抹淺笑 提交于 2019-12-03 11:07:24
I have a list of items (blue nodes below) which are categorized by the users of my application. The categories themselves can be grouped and categorized themselves. The resulting structure can be represented as a Directed Acyclic Graph (DAG) where the items are sinks at the bottom of the graph's topology and the top categories are sources. Note that while some of the categories might be well defined, a lot is going to be user defined and might be very messy. Example: (source: theuprightape.net ) On that structure, I want to perform the following operations: find all items (sinks) below a

Solving dependency constraints

一笑奈何 提交于 2019-12-03 05:47:31
I have a classic dependency solving problem. I thought I was headed in the right direction, but now I've hit a roadblock and I am not sure how to proceed. Background In the known universe (the cache of all artifacts and their dependencies), each there is a 1->n relationship between artifacts and versions, and each version may contain a different set of dependencies. For example: A 1.0.0 B (>= 0.0.0) 1.0.1 B (~> 0.1) B 0.1.0 1.0.0 Given a set of "demand constraints", I'd like to find the best possible solution (where "best" is the highest possible version that still satisfies all constraints).

What is the most efficient way to determine if a directed graph is singly connected?

佐手、 提交于 2019-12-03 05:46:56
I am working on an assignment where one of the problems asks to derive an algorithm to check if a directed graph G=(V,E) is singly connected (there is at most one simple path from u to v for all distinct vertices u,v of V. Of course you can brute force check it, which is what I'm doing right now, but I want to know if there's a more efficient way. Could anyone point me in the right direction? Have you tried DFS . Run DFS for every vertex in the graph as source If a visited vertex is encountered again, the graph is not singly connected repeat for every unvisited vertex. The graph is singly