graph-theory

Algorithm for finding t-friends of node

痞子三分冷 提交于 2019-12-11 06:20:37
问题 I have the following exercise where I have a social graph look below. From my understanding if t = 2 and we have p = H then the result would be equal O and B . Is this understanding correct? 回答1: Do a breadth-first search from the origin point. When you enqueue a point, also enqueue the distance from the origin. Limit the distance to t by not enqueueing point with a distance more than t . The set of visited nodes is the solution. You visit each vertex at most once, you visit each edge at most

Map edgelist with string node labels to integer labels

℡╲_俬逩灬. 提交于 2019-12-11 04:55:41
问题 I have a huge graph in edgelist format with strings as node labels. I wonder what is the "best" way to map strings to integers. Input file follows the example: Mike Andrew Mike Jane John Jane The output (i.e., a mapped file) should be: 1 2 1 3 4 3 Pasted below is a skeleton in C that reads the input file. Could somebody please advice me how to proceed. #include <stdio.h> int LoadFile(const char * filename) { FILE *fp = NULL; char node1[10]; char node2[10]; int idx = 0; fp = fopen(filename, "r

Finding ALL paths between 2 points on a square Matrix

廉价感情. 提交于 2019-12-11 04:29:33
问题 READ CAREFULLY BEFORE MARKING AS DUPLICATE! I have a matrix: 0 0 0 x 0 0 0 0 0 0 0 0 0 0 0 0 x 0 0 0 0 0 0 0 0 You CANNOT move diagonally in the matrix! I want to find ALL possible paths between the two 'x's. The only condition is, that the path cannot cross itself (so no cycles). Apparently the DSF algorithm would not find every single path (to understand why, see this paper: http://www.algolist.net/Algorithms/Graph/Undirected/Depth-first_search). So what algorithms should else be used? 回答1:

object appears in multiple graph cliques

回眸只為那壹抹淺笑 提交于 2019-12-11 04:26:19
问题 I have a piece of code that supposed to find cliques of nodes, while nodes are ids of django model objects: import networkx as nx final_groups = [] graph = nx.Graph() for img_test in Same_Img_Test.objects.filter(id__in=test_ids, is_same=1): graph.add_edge(img_test.product_1.id, img_test.product_2.id) for x in nx.find_cliques(graph): final_groups.append(x) print x I get this result: [1293856L, 909760L] [1293856L, 909730L] [1293856L, 909797L] [1293856L, 909767L] [1293856L, 909741L] my question

Collecting all paths of DAG with backward and forward links

可紊 提交于 2019-12-11 03:25:19
问题 I have a directed acyclic graph where each node is represent by a state public class State{ List<State> ForwardStates; List<State> backStates; string stateName; } where ForwardStates is a list of states via forward links from the current state. and backStates is a list of states via backward links from the current state. I have two special state State initialState (name=initial) State finalState (name=final) I wish to find all paths the start from initial state to final state, and populated

Calculate local clustering coefficient of a vertex (node) with R (by hand)

杀马特。学长 韩版系。学妹 提交于 2019-12-11 03:22:16
问题 I found an example showing how to calculate LCC by hand (see image). How can I replicate these steps in R? Focus is on finding the "Actual number of links among Neighbors" (middle step) I would preferably have to calculate it by hand *Does the igraph package provide this number? Example adjacency matrix: matrix(data = c(0,1,0,1,1,0,0,1,1,1,0,1,1,0,1,0), ncol = 4) 回答1: All of this can be done in igraph . It is nice that you gave an example, but since the graph is fully connected, all vertices

Shortest Path Algorithm : Uniform distances from one point to adjacent points

[亡魂溺海] 提交于 2019-12-11 01:44:58
问题 I am trying to develop an algorithm wherein I have a Location Class. In each class, I create a list of its adjacent Locations. I want to know, how can I get the shortest path from one Location to another. I am trying to look for different algorithms but it seems that they doesn't answer my problem. For example, I have a point A and I want to go to point B, A - - C - - H - - J | F- - K- -B My idea for this is if B is in the List of adjacent locations of A, then that is the shortest path. If

Traversing a graph breadth first, marking visited nodes in Haskell

不想你离开。 提交于 2019-12-11 00:46:04
问题 So the question is simple. Given a graph (I hope that the structure of the graph doesn't matter much in this problem), how do I go about doing a BFS on it? I've recently asked a question about generating a list where each element appends many elements to the end of it. The answer should hopefully let me make a queue I need to do the BFS. But there's another key component that a search needs and it's marking the nodes as visited so we don't go over them again. This also needs to have no

find shortest path in a graph that compulsorily visits certain Edges while others are not compulsory to visit

巧了我就是萌 提交于 2019-12-10 23:39:10
问题 I have an undirected graph with about 1000 nodes and 2000 edges, a start node and an end node. I have to traverse from the start node to the end node passing through all the compulsory edges(which are about 10) while its not necessary to traverse through all the vertices or nodes. Is there an easy solution to this like some minor changes in the existing graph traversing algorithms? How do I do it? Thanks for help.:) This question is different from Find the shortest path in a graph which

Maximum edge weight from one node A to node B

℡╲_俬逩灬. 提交于 2019-12-10 23:36:04
问题 Given a connected undirected graph having N nodes (1 <= N <= 2 * 10^5) and N-1 edges. Let's define a function F(a,b) , where F(a, b) is equal to the maximum edge weight in the path from a to b . How do we find the sum of the F(a, b) for all a , b such that 1 <= a , b <= N (mod 10^9 + 7) Example figure F(a, b) is equal to the maximum edge weight in the path from a to b. F(1, 2) = 2 F(1, 3) = 2 F(1, 4) = 4 F(1, 5) = 4 F(2, 3) = 1 F(2, 4) = 4 F(2, 5) = 4 F(3, 4) = 4 F(3, 5) = 4 F(4, 5) = 3 Sum