graph-theory

Are there any R Packages for Graphs (shortest path, etc.)?

痞子三分冷 提交于 2019-12-05 10:59:49
I know that R is statistical pkg, but probably there is library to work with graphs and find shortest path btw 2 nodes. PS actually, I've found igraph and e1071, which one is better? Thank you Sure, there's a Task View that gathers a fair number of the graph-related Packages. (The page linked to is a CRAN portal, which uses iframes, so i can't directly link to the Graph Task View. So from the page linked to here, click on Task Views near the top of the LHS column, then click on the Task View gR , near the bottom of the list. Among the Packages there, igraph , for instance, has graph-theoretic

Dijkstras Algorithm doesn't appear to work, my understanding must be flawed

岁酱吖の 提交于 2019-12-05 10:50:14
Here's my interpretation of how Dijkstra's algorithm as described by wikipedia would deal with the below graph. First it marks the shortest distance to all neighbouring nodes, so A gets 1 and C gets 7. Then it picks the neighbour with the current shortest path. This is A. The origin is marked as visited and will not be considered again. The shortest (and only) path from the origin to B through A is now 12. A is marked as visited. The shortest path from the origin to the Destination through B is 13. B is marked as visited. The shortest path from the Origin to C through the destination is 14,

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

徘徊边缘 提交于 2019-12-05 10:47:53
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] To make sure the definition is clear: I am assuming you are looking for all nodes which have out-degree 0 and in-degree 1. This is what my

Redis: Implement Weighted Directed Graph

时光毁灭记忆、已成空白 提交于 2019-12-05 08:16:27
What's the best way to implement weighted graph using Redis? We will mostly search for shortest paths over the graph (probably using the Dijkstra algorithm) Currently we considered adding the edges to Redis For each node, we will have the nodeId as the key and a sortedset of keys of referenced nodes the score of each nodeId in the sortedSet is the weight of the edge. What do you think? Correct me if I am wrong but the only bummer here is that for each query for the next node in a sortedset we pay O(logn) instead of O(1)... http://redis.io/commands/zrange Getting the next item in a sorted set

Connect an even number of nodes without intersection

与世无争的帅哥 提交于 2019-12-05 08:04:45
I have two sets of n nodes. Now I want to connect each node from one set with another node from the other set. The resulting graph should have no intersections. I know of several sweep line algorithms ( Bentley-Ottmann-Algorithm to check where intersections occur, but I couldn't find an algorithm to solve those intersections, except for a brute-force approach. Each node from one set can be connected to any other node within the other set. Any pointers to (an efficient) algorithm that solves this problem? No implementation needed. EDIT1 : Here is one solution to the problem for n=7 : The black

How to do directed graph drawing in PHP?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-05 06:52:36
I'm looking for a way to draw directed graphs in PHP. (as in http://upload.wikimedia.org/wikipedia/commons/0/08/Directed_acyclic_graph.png ). I want it to create an image of the graph just like GD can output an image. I've googled a lot on this, but I only can find a lot of libraries for drawing graphs in general (with bars etc), not directed graphs. P.S. I've tried using dot (the linux program) via system(), but unfortunately I have no permission to do that on the server. Also, I have no rights to install PHP extensions and stuff like that on the server, so it should work with normal PHP

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

醉酒当歌 提交于 2019-12-05 04:41:36
Given a graph G, why is following greedy algorithm not guaranteed to find maximum independent set of G: 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 I am wondering can someone show me a simple example of a graph where this algorithm fails? I'm not sure this is the simplest example, but here is one that fails: http://imgur.com/QK3DC For the first step, you can choose B, C, D, or F since they all have degree 2. Suppose we remove B and its neighbors. That leaves F and D with degree 1 and E with degree

How to compute “shortest distance” between two words?

丶灬走出姿态 提交于 2019-12-05 02:54:36
问题 Recently I had an interview and I was asked to write a algorithm to find the minimum number of 1 letter changes to get from a particular of word to a given word , i.e. Cat->Cot->Cog->Dog I dont want the solution of the problem just guide me through How I can use BFS in this algorithm ? 回答1: according to this scrabble list, the shortest path between cat and dog is: ['CAT', 'COT', 'COG', 'DOG'] from urllib import urlopen def get_words(): try: html = open('three_letter_words.txt').read() except

Algorithm for distributing beads puzzle (2)?

只谈情不闲聊 提交于 2019-12-05 01:43:27
问题 Let's say you have a circle (shown below) with N slots. Your goal is to end up with a specified number of beads in each slot, and you have an array of size N containing the amount of beads you need in each slot. For example, if the array was {1, 5, 3}, then you would need to end up with 1 bead in slot 1, 5 beads in slot 2, and 3 beads in slot 3. You have an infinite amount of beads. You can "unlock" X slots. Once you unlock a slot, you can start putting beads in that slot. You can move beads

Minimal addition to strongly connected graph

这一生的挚爱 提交于 2019-12-05 01:22:03
I have a set of nodes and set of directed edges between them. The edges have no weight. How can I found minimal number of edges which has to be added to make the graph strongly connected (ie. there should be a path from every node to all others)? Does this problem have a name? It's a really classical graph problem. Run algorithm like Tarjan-SCC algorithm to find all SCCs. Consider each SCC as a new vertice, link a edge between these new vertices according to the origin graph, we can get a new graph. Obviously, the new graph is a Directed Acyclic Graph(DAG). In the DAG, find all vertices whose