graph-theory

Create simple graph object in Julia using Graphs.jl

回眸只為那壹抹淺笑 提交于 2019-12-23 10:14:06
问题 I am starting to study graph theory (I plan to use it in machine learning and/or bayesian inference). I want to code in Julia, and found the package Graphs. But how can I use this package to create simple graphs? For example, this one: It would be very useful if I undertood how to create an Julia object that represents this graph using Graphs . Its documentation lacks examples so I can't get started. 回答1: Julia's Graphs package has simple_graph interface for creating such small graphs. To

Algorithm for counting connected components of a graph in Python

岁酱吖の 提交于 2019-12-23 04:14:54
问题 I try to write a script that counts connected components of a graph and I can't get the right solution. I have a simple graph with 6 nodes (vertexes), nodes 1 and 2 are connected, and nodes 3 and 4 are connected (6 vertexes; 1-2,3-4,5,6). So the graph contains 4 connected components. I use following script to count connected components, but I get wrong result (2). nodes = [[1, [2], False], [2, [1], False], [3, [4], False], [4, [3], False], [5, [], False], [6, [], False]] # 6 nodes, every node

Minimum path between two vertices passing through a given set

半腔热情 提交于 2019-12-23 03:57:08
问题 Suppose I have a source node S , destination node D and a set A of intermediate nodes P1,P2, P3,… in an edge-weighted undirected graph. I want to find the vertex Pi ∈ A that minimizes dist(S,Pi)+dist(D,Pi) ? In addition, the overall path from S to D should contain only one node from the set A . What is an efficient algorithm for this? I don't want to go with brute-force approach. 回答1: What do you mean by brute force? Without assumption If you remove the assumption about "only one node from

Gremlin- how to find paths from A to Z that went through G only

人走茶凉 提交于 2019-12-23 02:47:11
问题 Need some help with Gremlin: If I know the start vertex and the end vertex and there are multiple paths between start and end BUT I have a couple of vertexes along the way. How can I find the correct path based on the data I have? For instance here I what I have to find the paths from 'college' to 'finch' g.V().has('station','college'). repeat(out().simplePath()) .until(has('station','finch')) .path().by('station') Results ==>[college, wellesley, bloor-yonge, rosedale, summerhill, st. clair,

how to generate all 3 regular graphs given number of vertices in python

早过忘川 提交于 2019-12-23 02:27:06
问题 I want to generate all 3-regular graphs with given number of vertices to check if some property applies to all of them or not. checking the property is easy but first I have to generate the graphs efficiently. Can somebody please help me Generate these graphs (as adjacency matrix) or give me a file containing such graphs. Number of vertices are less than 24. Thank you 回答1: It is possible to read scd file into python as binary and convert data in same way it is done in readscd.c file. Here is

How to find the distance between the two most widely separated nodes

风格不统一 提交于 2019-12-22 10:54:21
问题 I'm working through previous years ACM Programming Competition problems trying to get better at solving Graph problems. The one I'm working on now is I'm given an arbitrary number of undirected graph nodes, their neighbors and the distances for the edges connecting the nodes. What I NEED is the distance between the two farthest nodes from eachother (the weight distance, not by # of nodes away). Now, I do have Dijkstra's algorithm in the form of: // Dijkstra's Single-Source Algorithm private

Shortest sequence of nodes though an unweighted graph

北城余情 提交于 2019-12-22 09:15:48
问题 I would like to know if there is an algorithm for finding the shortest sequence of nodes though a graph from its a head node to the tail node. The graph branches out from the head node and is arbitrarily complex and converges at the tail node. All connections between nodes are unweighted. I'm considering tackling this problem taking exploratory steps from the head and tail nodes and until the nodes from either end of the graph touch etc, but I'd like to know if a "better wheel" exists before

Redis: Implement Weighted Directed Graph

笑着哭i 提交于 2019-12-22 05:41:12
问题 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

Redis: Implement Weighted Directed Graph

可紊 提交于 2019-12-22 05:41:10
问题 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

Cycle of maximum weight in a graph

跟風遠走 提交于 2019-12-22 04:47:20
问题 Given a weighted graph (directed or undirected) I need to find the cycle of the graph with the maximum weight. The weight of a cycle being the sum of the weight of the edges of the graph. It can be any cycle, not just base cycle for which we can find all base cycle (see Algorithms to Identify All the Cycle Bases in a UnDirected Graph ) compute the weight of each base cycle and find the maximum I could try to enumerate all cycles of the graph and then compute the maximum but the total number