graph-theory

Pruning large graphs of stray nodes

时光怂恿深爱的人放手 提交于 2019-12-12 08:13:03
问题 I have a graph consisting of about 35,000 nodes represented in plain text: node1 -> node35000 node29420 -> node35000 node2334 -> node4116 ... I'd like to trim it down by removing nodes that are not part of a chain at least three long. So if I had only 1 -> 2; 2 -> 3; 3 -> 4; 0 -> 4; I'd like to keep 1, 2, 3, and 4 (since 1 -> 2 -> 3 -> 4 is four nodes long) but discard 0, that is, remove 0 -> 4 . Any idea of a good way to do this? I tried a combination of Perl and shell functions but I think

Computing minimum path lengths in an SQL table

允我心安 提交于 2019-12-12 06:18:49
问题 I'm having a problem with this exercise: Table Friend : Friend1 Friend2 Table Relationship : Friend1 Friend2 GradeOfFriendship I need to create a trigger in which I must obtain symmetric tuple, for example: Luc Mark Mark Luc in both tables. If there is a direct contact between two people then their GradeOfFriendship = 1 If there is no contact between a pair of people then GradeOfFriendship = 0 . In other cases the GradeOfFriendship must be calculated as the minimum distance over all possible

Coloring specific edges in NetworkX

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 05:14:55
问题 I'm running a Dikjstra's shortest path algorithm on a NetworkX Watts-Strogatz randomly generated graph and I want to color the edges of the path I've found differently from the rest of the edges before I draw the graph. My Dijkstra's algorithm returns a list of the nodes in the path as follows: dijkstra(graph, '5', '67') ['67', '62', '59', '56', '3', '99', '5'] How would I go about changing the color of the edges between these nodes to say blue instead of red? Note that the graph is randomly

Tile Trial NP-hard complexity

核能气质少年 提交于 2019-12-12 02:48:54
问题 In the game Final Fantasy XIII-3, the player is presented with a couple puzzles. The first puzzle introduced is called Tile Trial , which presents the player with a grid of tiles, some of which have crystals on them. The goal is to retrieve all of the crystals and reach the exit, while stepping on each tile no more than once. The author of http://arxiv.org/pdf/1203.1633v1.pdf stated that this problem is NP-Hard because a specific case can be reduced to Hamiltonian-cycle. I find that this is a

segmentation fault for deep recursion upon going from python 2.6 to 2.7

混江龙づ霸主 提交于 2019-12-11 18:37:19
问题 I have simple recursive program to find connected subgraphs. The code works by traversing, from each unvisited vertex in the graph, all the edges (recursively) and marking those which have been visited with 'ingraph=False' in the process. (the graphs are always undirected unweighted graphs). The problem I have is that for large graphs (with a subgraph of ~100,000 vertices) python(-2.7) returns a segmentation fault. But this worked just fine in python-2.6 (and still does). Can someone explain

How to write a recursive function in Python?

时光总嘲笑我的痴心妄想 提交于 2019-12-11 17:59:23
问题 I have an undirected graph, and I want to iteratively remove each serial edge and replace it with a new edge. The weight of the new edge represents the number of spanning trees, and should be computed as follows: T_new = (1/a+b) * T_old , where a and b are the weights of the removed edges, T_new is the number of spanning trees in current iteration and T_old is the number of spanning trees in the previous iteration. This equation changes iteratively, as the graph changes, so if we have 4

Shortest Path Dijkstra Java

这一生的挚爱 提交于 2019-12-11 11:54:56
问题 I am trying to print the shortest path for a specific adjacency matrix using dijktra's algorithm. My dijkstra algorithm works fine, I am getting the correct distances. However when printing out the path I am getting an incorrect path. Here is my code for printing the path: My first class is my driver that takes in an adjacency matrix. The matrix contains the size at the top of the file, the actual matrix in the middle, and the source vertex at the end of the file. That all works fine for

Graph theory algorithm to find vertex with out-degree 0 and in-degree (n-1)

六月ゝ 毕业季﹏ 提交于 2019-12-11 11:29:42
问题 I'm wondering how to determine whether a directed graph has a get-stuck vertex, which is defined as a vertex with in-degree n-1 and out-degree 0. I guess the dumb way would be to print the in-degree and out-degree of every vertex in the graph, but that's O(m+n). I'm interested in an O(n) algorithm. Any ideas? Thanks!! 回答1: (I assume that n is vertices and m is edges.) Note that there is at most one get-stuck vertex in a graph. Suppose we have an O(n) algorithm. If m is large, we must reach a

how to check if there exists a unique shortest path between two vertices in igraph

时光毁灭记忆、已成空白 提交于 2019-12-11 07:47:38
问题 I'd like to identify if there exist a unique shortest path or multiple shortest paths between two vertices with igraph. If I use length(all_shortest_paths(g, i,j) , that actually helps me, but I feel like there are so many redundant operations. I rather prefer first to get one shortest path with get.shortest.paths(g, i,j) , and then see if there is another. However, I could not figure out how to do this. Can someone help me how to identify whether there is another shortest path different than

How to find the shortest path between two vertices in a BGL graph?

半腔热情 提交于 2019-12-11 07:37:40
问题 So I'm currently working on a project of a word ladder problem and I have already built the graph for storing all dictionary words in it and added the edges in it, I did this using boost graph library. But what is confusing me is that breadth_first_search() function, seems like the parameters only take the starting vertex but no ending vertex. I checked the documentations and noticed that I can define the BFS visitor for that search function, but since I'm a newbie to the boost library I