graph-theory

Use list of lists to save every path in a graph

安稳与你 提交于 2020-01-06 06:39:28
问题 I have to implement dfs algorithm to save all paths from a starting node. So for example i have the following graph: i have a list path = [] to save all the paths starting from node 1. So my list will have only the starting node 1: 1, then i will check for neighbors of 1 which is the node 2 and the list will be: [1,2] . Now i check the neighbors of 2 which are 3 and 4. The list now i think that it will be like [[1,2,3], [1,2,4]] and in the end the final list will be [[1,2,3], [1,2,4,5], [1,2

bipartite graph matching to match two sets

匆匆过客 提交于 2020-01-05 09:02:12
问题 I'm a newbie to igraph package in R. I have two sets A and B , each with N vertices (A1, A2, ..., AN) and (B1, B2, ..., BN) . There is an edge between every element of A to every element of B , and I have a function fWgt(Ai, Bj) that returns the weights of the edge between Ai and Bj . I have been trying to use the igraph package in R to do a weighted maximum bipartite matching, but I haven't been able to formulate the problem as per the igraph package. For instance, in the example given for

bipartite graph matching to match two sets

老子叫甜甜 提交于 2020-01-05 09:01:29
问题 I'm a newbie to igraph package in R. I have two sets A and B , each with N vertices (A1, A2, ..., AN) and (B1, B2, ..., BN) . There is an edge between every element of A to every element of B , and I have a function fWgt(Ai, Bj) that returns the weights of the edge between Ai and Bj . I have been trying to use the igraph package in R to do a weighted maximum bipartite matching, but I haven't been able to formulate the problem as per the igraph package. For instance, in the example given for

What does a matrix array look like for a Johnson graph?

强颜欢笑 提交于 2020-01-05 05:10:01
问题 I can't seem to find any examples (or much information at all) of what a matrix array looks like for a Johnson graph. Can anyone send me an example of what their arrays look like? 回答1: This directly uses the definition of a Johnson Graph given here Wiki Johnson Graph johnsonmatrix[n_, k_] := Module[{s=Select[Subsets[Range[n]], Length[#]==k&]}, {s, MatrixForm[Table[If[Length[Intersection[s[[i]], s[[j]]]]==k-1, 1, 0], {i, Length[s]}, {j, Length[s]}]]}] and generates the list of subsets which

Sorting Geographical non-contiguous line segments along an implied curve

时光毁灭记忆、已成空白 提交于 2020-01-02 08:03:22
问题 Given: A Set (for the sake of discussion we will call it S ), which is an unordered collection of line segments. Each line segment is defined as two Longitude-Latitude end-points. While all of the line segments follow an implied curve, there are "gaps" between each of the segments, of various sizes. We refer to this curve as "implied" because it is not explicitly defined anywhere. The only information that we have available are the line segments contained within S . Desired Result: A sequence

Sorting Geographical non-contiguous line segments along an implied curve

南笙酒味 提交于 2020-01-02 08:02:23
问题 Given: A Set (for the sake of discussion we will call it S ), which is an unordered collection of line segments. Each line segment is defined as two Longitude-Latitude end-points. While all of the line segments follow an implied curve, there are "gaps" between each of the segments, of various sizes. We refer to this curve as "implied" because it is not explicitly defined anywhere. The only information that we have available are the line segments contained within S . Desired Result: A sequence

Find end nodes (leaf nodes) in radial (tree) networkx graph

痴心易碎 提交于 2020-01-02 01:56:09
问题 Given the following graph, is there a convenient way to get only the end nodes? By end nodes I mean those to-nodes with one connecting edge. I think these are sometimes referred to as leaf nodes. G=nx.DiGraph() fromnodes=[0,1,1,1,1,1,2,3,4,5,5,5,7,8,9,10] tonodes=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16] for x,y in zip(fromnodes,tonodes): G.add_edge(x,y) G.add_node(17) # isolated node nx.draw_shell(G) In this example, it would be [6,11,12,13,14,15,16] 回答1: To make sure the definition is clear:

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

☆樱花仙子☆ 提交于 2020-01-01 10:23:53
问题 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.

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.

Postgres CTE : type character varying(255)[] in non-recursive term but type character varying[] overall

折月煮酒 提交于 2020-01-01 08:43:17
问题 I am new to SO and postgres so please excuse my ignorance. Attempting to get the cluster for a graph in postgres using a solution similar to the one in this post Find cluster given node in PostgreSQL the only difference is my id is a UUID and I am using varchar(255) to store this id when i try to run the query I get the following error (but not sure how to cast): ERROR: recursive query "search_graph" column 1 has type character varying(255)[] in non-recursive term but type character varying[]