directed-graph

A fast way to find connected component in a 1-NN graph?

[亡魂溺海] 提交于 2020-01-01 10:23:22
问题 First of all, I got a N*N distance matrix, for each point, I calculated its nearest neighbor, so we had a N*2 matrix, It seems like this : 0 -> 1 1 -> 2 2 -> 3 3 -> 2 4 -> 2 5 -> 6 6 -> 7 7 -> 6 8 -> 6 9 -> 8 the second column was the nearest neighbor's index. So this was a special kind of directed graph, with each vertex had and only had one out-degree. Of course, we could first transform the N*2 matrix to a standard graph representation, and perform BFS/DFS to get the connected components.

Python networkx and persistence (perhaps in neo4j)

半世苍凉 提交于 2020-01-01 06:34:28
问题 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

Find all possible paths from one vertex in a directed cyclic graph in Erlang

匆匆过客 提交于 2020-01-01 03:21:05
问题 I would like to implement a function which finds all possible paths to all possible vertices from a source vertex V in a directed cyclic graph G. The performance doesn't matter now, I just would like to understand the algorithm. I have read the definition of the Depth-first search algorithm, but I don't have full comprehension of what to do. I don't have any completed piece of code to provide here, because I am not sure how to: store the results (along with A->B->C-> we should also store A->B

Best Way to Store/Access a Directed Graph

佐手、 提交于 2019-12-31 09:05:55
问题 I have around 3500 flood control facilities that I would like to represent as a network to determine flow paths (essentially a directed graph). I'm currently using SqlServer and a CTE to recursively examine all the nodes and their upstream components and this works as long as the upstream path doesn't fork alot. However, some queries take exponentially longer than others even when they are not much farther physically down the path (i.e. two or three segments "downstream") because of the added

Best Way to Store/Access a Directed Graph

試著忘記壹切 提交于 2019-12-31 09:04:09
问题 I have around 3500 flood control facilities that I would like to represent as a network to determine flow paths (essentially a directed graph). I'm currently using SqlServer and a CTE to recursively examine all the nodes and their upstream components and this works as long as the upstream path doesn't fork alot. However, some queries take exponentially longer than others even when they are not much farther physically down the path (i.e. two or three segments "downstream") because of the added

Ruby on Rails - Modelling a Directed Graph

余生长醉 提交于 2019-12-25 02:24:42
问题 I'm trying to model a directed graph for my ruby on rails application I have two Models, Tag and Connection class Connection < ActiveRecord::Base attr_accessible :cost, :from_id, :to_id belongs_to :from_tag, :foreign_key => "from_id", :class_name => "Tag" belongs_to :to_tag, :foreign_key => "to_id", :class_name => "Tag" end class Tag < ActiveRecord::Base attr_accessible :location_info, :reference has_many :to_connections, :foreign_key => 'from_id', :class_name => 'Connection' has_many :to

Determine whether a directed graph has a unique topological ordering?

扶醉桌前 提交于 2019-12-24 11:30:15
问题 I'm trying to create pseudo-code for an algorithm that will be able to determine whether a directed graph has a unique topological ordering. I've already come up with the following pseudo-code for a topological sort, but what would I have to add or edit in order to determine whether a digraph has a unique topological ordering? Input: A graph G Output: A list L that contain the sorted vertices define an empty list L; create a stack Stack; push all vertices with no incoming edges into Stack;

Most efficient way to get all connected nodes in neo4j

99封情书 提交于 2019-12-24 03:37:18
问题 The answer to this question shows how to get a list of all nodes connected to a particular node via a path of known relationship types. As a follow up to that question, I'm trying to determine if traversing the graph like this is the most efficient way to get all nodes connected to a particular node via any path. My scenario: I have a tree of groups (group can have any number of children). This I model with IS_PARENT_OF relationships. Groups can also relate to any other groups via a special

Does a path exist through all vertices of a directed graph?

眉间皱痕 提交于 2019-12-24 01:19:18
问题 Given G, a directed graph, is there a path (not necessarily a simple path) that goes through all the vertices in G? I first need to examine what happens in an acyclic graph and in a strongly-connected graph, and then to find a solution for a general graph, using the graph of the strongly connected components. So far I have figured out that for a strongly connected graph there is always a path. For an acyclic graph, if there is more than one source a path will never exist. Also, if there is a

Find all paths in directed cyclic graph as regular expression

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-24 00:45:03
问题 Let G = (V,E,r) a rooted directed graph, defined by a set of vertices V and a set of edges E with a designated root node r. The graph may contain cycles. The task: Given two vertices x and y from V, find all paths from x to y. Since cycles are allowed, the set of paths may obviously be infinite. Therefore, I want to find the set of paths in the form of a regular expression (Kleene Algebra). Here are a few examples: Examples graphs. Multiplication means sequence, so a path abc means first a,