directed-graph

How to determine Strahler number on a directed graph for a stream network

南笙酒味 提交于 2019-12-23 19:18:57
问题 Question / example / expected values I need to determine a Strahler number or Strahler stream order for a directed graph representing a stream network. I can derive information forwards and backwards using WITH RECURSIVE queries, but it seems I need to do something different to determine the Strahler number. For example, here is a 19 segment stream network with 10 tributaries and one outlet. The upstream portion of each segment is represented by a node ID. And the same data in a table

couting back edges to get the number of cylces in a directed graph

断了今生、忘了曾经 提交于 2019-12-23 18:13:46
问题 I have been writing code to get all the possible cycles in a directed graph. Here is an implementation that keeps track of back edges and whenever one back edge is found, it return true that one cycle is detected. I extended this to the following: calculate all the possible back edges in a tree, the number of back edges should give the number of cycles. Not sure if this correct. using this, I implemented the following: The count variable below is not useful. Initially I had it to give the

Enumerating All Minimal Directed Cycles Of A Directed Graph

限于喜欢 提交于 2019-12-21 20:32:02
问题 I have a directed graph and my problem is to enumerate all the minimal (cycles that cannot be constructed as the union of other cycles) directed cycles of this graph. This is different from what the Tarjan algorithm outputs. For instance, for the directed graph at this wikipedia page, I would like to get c <-> d and d <-> h as two separated directed cycles. I don't if this problem is polynomial or not. I ran over a paper "Enumerating Minimal Dicuts and Strongly Connected Subgraphs" that seems

Finding all paths in directed graph with specific cost

感情迁移 提交于 2019-12-21 20:22:37
问题 Suppose we have the directed, weighted graph. Our task is to find all paths beetween two vertices (source and destination) which cost is less or equal =< N. We visit every vertex only once. In later version I'd like to add a condition that the source can be the destination (we just make a loop). I think it can be done with modified Dijkstra's algorithm, but I have no idea how implement such thing. Thanks for any help. 回答1: You could use recursive backtracking to solve this problem. Terminate

Getting the root (head) of a DiGraph in networkx (Python)

落花浮王杯 提交于 2019-12-20 10:34:41
问题 I'm trying to use networkx to do some graph representation in a project, and I'm not sure how to do a few things that should be simple. I created a directed graph with a bunch of nodes and edges, such that there is only one root element in this graph. Now, what I'd like to do is start at the root, and then iterate through the children of each element and extract some information from them. How do I get the root element of this DiGraph? So it would be something like this: #This is NOT real

How can one create cyclic (and immutable) data structures in Clojure without extra indirection?

人盡茶涼 提交于 2019-12-20 10:28:18
问题 I need to represent directed graphs in Clojure. I'd like to represent each node in the graph as an object (probably a record) that includes a field called :edges that is a collection of the nodes that are directly reachable from the current node. Hopefully it goes without saying, but I would like these graphs to be immutable. I can construct directed acyclic graphs with this approach as long as I do a topological sort and build each graph "from the leaves up". This approach doesn't work for

Graphviz Dot Algorithm

主宰稳场 提交于 2019-12-17 23:08:23
问题 Is there any documentation (full pseudo code?) on the algorithm from dot within the Graphviz Library? I only found some partial pseudo code documentation. 回答1: Here are a few references for you. The most complete (short of the Graphviz source code itself) is probably #2, the paper "A Technique for Drawing Directed Graphs" which is written by several of the Graphviz contributors themselves. (1) "Drawing graphs with dot" In Drawing graphs with dot, dot's layout algorithm is described like this:

How do I check if a directed graph is acyclic?

流过昼夜 提交于 2019-12-17 08:04:33
问题 How do I check if a directed graph is acyclic? And how is the algorithm called? I would appreciate a reference. 回答1: I would try to sort the graph topologically, and if you can't, then it has cycles. 回答2: Doing a simple depth-first-search is not good enough to find a cycle. It is possible to visit a node multiple times in a DFS without a cycle existing. Depending on where you start, you also might not visit the entire graph. You can check for cycles in a connected component of a graph as

TSP Where Vertices Can be Visited Multiple Times

烂漫一生 提交于 2019-12-14 02:14:49
问题 I am looking to solve a problem where I have a weighted directed graph and I must start at the origin, visit all vertices at least once and return to the origin in the shortest path possible. Essentially this would be a classic example of TSP, except I DO NOT have the constraint that each vertex can only be visited once. In my case any vertex excluding the origin can be visited any number of times along the path, if this makes the path shorter. So for example in a graph containing the

code for cycle detection is not finding returning the right number of cycles in directed graph in Java?

不羁的心 提交于 2019-12-13 21:24:23
问题 I have code written for calculating the no of cycles in a directed graph using DFS . The method to check if a cycle exists or not works fine. I now iterate through all the vertices (which I have in a HashMap) and check if a vertex is unvisited, then check if a cycle exists, if so increment the counter by 1. Now the code breaks, it does not give the right number of cycles eg: for the graph with following edges: (A B),(B C),(C E),(E A),(B E) Here is my code; public int getTotalCyclesinDir(){