graph-theory

Python: how to convert elements of a list of lists into an undirected graph?

江枫思渺然 提交于 2019-12-14 03:56:33
问题 I have a program which retrieves a list of PubMed publications and wish to build a graph of co-authorship, meaning that for each article I want to add each author (if not already present) as a vertex and add an undirected edge (or increase its weight) between every coauthor. I managed to write the first of the program which retrieves the list of authors for each publication and understand I could use the NetworkX library to build the graph (and then export it to GraphML for Gephi) but cannot

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

maximum_spanning_tree networkx has no attribute

℡╲_俬逩灬. 提交于 2019-12-13 15:47:11
问题 I am trying to find maximum spanning tree of a network using networkx python module. According to documentation specified[link below], nx.maximum_spanning_tree(G) should do this work. But i am getting error File "air_traffic_network_base.py", line 65, in <module> max_spanning_tree = nx.maximum_spanning_tree(net) AttributeError: 'module' object has no attribute 'maximum_spanning_tree' Here is the code snippet: net = nx.read_weighted_edgelist(graph_file) min_spanning_tree = nx.minimum_spanning

Fastest algorithm to detect if there is negative cycle in a graph

∥☆過路亽.° 提交于 2019-12-13 15:19:08
问题 I use a matrix d to present a graph. d.(i).(j) means the distance between i and j ; v denotes the number of nodes in the graph. It is possible that there is negative cycle in this graph. I would like to check if a negative cycle exists. I have written something as follows from a variation of Floyd-Warshall: let dr = Matrix.copy d in (* part 1 *) for i = 0 to v - 1 do dr.(i).(i) <- 0 done; (* part 2 *) try for k = 0 to v - 1 do for i = 0 to v - 1 do for j = 0 to v - 1 do let improvement = dr.

How to search a specific node in a graph structure in C?

被刻印的时光 ゝ 提交于 2019-12-13 03:06:45
问题 Not that I have time to discuss this properly to reach a conclusion and adapt my code because the phase one (of three) of a school project is in 24hrs, but at least I need to know if I did the correct decision. I'm using linked lists and here's my structures: typedef struct sCity { int cityID; char *cityName; struct sCityLink *links; struct sCity *next; } nCity, *City; typedef struct sCityLink { City cityLinkParent; City cityLinkTo; struct sCityLink *next; } nCityLink, *CityLink; Basically, I

Place nodes explicitly with visNetwork (or an Alternative)

為{幸葍}努か 提交于 2019-12-12 23:10:48
问题 How can I explicitly place nodes on a visNetwork graph? Or: How can I recreate that graphic in R using visNetwork or an alternative? Background: The ultimate goal is to represent Causal Loop Diagrams coming from Vensim files. Placing the nodes explicitly is just the first (crucial) step, because in Causal Loop Diagrams the visual mapping of nodes is part of the information (unlike in general graph theory). So if anybody has advice on the bigger picture aka. 'Bringing Causal Loop Diagram

Fast hiding of intersecting rectangles

老子叫甜甜 提交于 2019-12-12 22:16:43
问题 I'm working on an efficient algorithm to "hide" all the pairs of intersecting rectangles laid out in 2D in a set of N rectangles (axis aligned). All the rectangles have the same width and height. Suppose my starting set of rectangles laid out in 2D is R={r_1,r_2,...,r_n} where r_i are all the rectangles, r_i has the boolean attribute visible . I want to find the subset S of R such that for every r_i , r_j belonging to S r_i,_r_j don't intersect. A first trivial solution is the brute force

Javascript group linked key values into arrays

二次信任 提交于 2019-12-12 17:07:34
问题 Hi I have a very long list of key value pairs in json key:value, key:value and so on car <--> wheel wheel <--> tyre bed <--> sheets guitar <--> strings guitar <--> pickup tyre <--> rubber What I want is to group all relations into arrays no matter how distant like this [car, wheel, tyre, rubber] [guitar, strings, pickup] [bed, sheets] What is an efficient way to do this with Javascript? 回答1: First of all, I would store the relationships as arrays so that you can have duplicate "keys." Key

Why is greedy algorithm not finding maximum independent set of a bipartite graph?

限于喜欢 提交于 2019-12-12 10:43:04
问题 I was trying to solve the maximum independent set problem on bipartite graphs using the greedy method. So came across this post which does exactly what i was trying to do. But am concentrating only on the bipartite graphs. The counter case in the answer is not a bipartite graph. Are there any bipartite graphs that this one wont work? Greedy(G): S = {} While G is not empty: Let v be a node with minimum degree in G S = union(S, {v}) remove v and its neighbors from G return S Why is greedy

Find a monotonic shortest path in a graph in O(E logV)

半世苍凉 提交于 2019-12-12 08:53:55
问题 Problem 34 of creative problems from this page. Monotonic shortest path. Given an edge-weighted digraph, find a monotonic shortest path from s to every other vertex. A path is monotonic if the weight of every edge on the path is either strictly increasing or strictly decreasing. Partial solution : relax edges in ascending order and find a best path; then relax edges in descending order and find a best path. My question: Suppose we are relaxing edges in descending order and we have an option