shortest-path

Find the shortest Path between two nodes (vertices)

北战南征 提交于 2019-12-24 02:16:28
问题 I have a list of interconnected edges ( E ), how can I find the shortest path connecting from one vertex to another? I am thinking about using lowest common ancestors, but the edges don't have a clearly defined root, so I don't think the solution works. Shortest path is defined by the minimum number of vertexes traversed. Note: There could be a multi-path connecting two vertices, so obviously breadth first search won't work 回答1: I'm not sure if you need a path between every pair of nodes or

Python: how to compute the number of shortest paths passing through one node?

放肆的年华 提交于 2019-12-24 01:49:11
问题 Say that I have a regular network of NxN nodes. The shortest path between two nodes is the minimum number of hops required to reach one target node from a source node. Now, each shortest path passes through a number of nodes along the way. My goal: for each node in the network, I want to count the number of shortest paths that pass through a specific node, and save that number in a dict . In this little example, node B has 4 shortest paths passing through it: A -> B , A -> C , C -> B , C -> A

Using Dijkstra to detect multiple shortest paths

本秂侑毒 提交于 2019-12-24 00:36:48
问题 Given a weighted directed graph, how can the Dijkstra algorithm be modified to test for the presence of multiple lowest-cost paths between a given pair of nodes? My current algorithm is as follows: (credit to Weiss) /** * Single-source weighted shortest-path algorithm. (Dijkstra) * using priority queues based on the binary heap */ public void dijkstra( String startName ) { PriorityQueue<Path> pq = new PriorityQueue<Path>( ); Vertex start = vertexMap.get( startName ); if( start == null ) throw

Single-source shortest path with distance and weight for each edge

旧巷老猫 提交于 2019-12-23 19:15:46
问题 Suppose there's an undirected graph and each edge that connects any two nodes has two weights (i.e. distance and cost). I want to get the shortest path, but also make sure I do not go beyond a certain cost. I've tried implementing Djikstra's and simply backtracking (for lack of a better term) if I exceed the cost, until I traverse the entire graph. However, I'm looking for a faster solution than this. I've also attempted to use a function that creates a weight given the distance and cost of

how to calculate short path geodesic distance of adjacency matrix csv [python]?

ぐ巨炮叔叔 提交于 2019-12-23 04:17:34
问题 i have an adjacency matrix of graph graph n 1 2 3 4 5 6 7 8 9 1 0 1 1 1 0 0 0 0 0 2 1 0 1 0 0 0 0 0 0 3 1 1 0 1 0 0 0 0 0 4 1 0 1 0 1 1 0 0 0 5 0 0 0 1 0 1 1 1 0 6 0 0 0 1 1 0 1 1 0 7 0 0 0 0 1 1 0 1 1 8 0 0 0 0 1 1 1 0 0 9 0 0 0 0 0 0 1 0 0 how to convert it to geodesic discance matrix using python? my goal is to make it like this : n 1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 2 3 3 4 2 1 0 1 2 3 3 4 4 5 3 1 1 0 1 2 2 3 3 4 4 1 2 1 0 1 1 2 2 3 5 2 3 2 1 0 1 1 1 2 6 2 3 2 1 1 0 1 1 2 7 3 4 3 2 1 1 0 1 1 8

How would I clear a linked list?

℡╲_俬逩灬. 提交于 2019-12-23 03:05:02
问题 I have been trying to write a shortest path algorithm, dijkstras algorithm, finding the shortest path for the first two vertices works just fine. I run into the problem while trying to clear a linked list and a priority queue. class llNode { public: int id; int source; int weight; llNode* next; llNode(int key, int distance, int from) { id=key; weight=distance; source=from; next = NULL; } }; class lList { private: llNode* root; llNode* end; void clearAll(llNode* toClear); public: lList() {

Limiting depth of shortest path query using Gremlin on JanusGraph

谁说胖子不能爱 提交于 2019-12-23 00:25:18
问题 I have a fairly large graph (currently 3806702 vertices and 7774654 edges, all edges with the same label) in JanusGraph. I am interested in shortest path searches in it. Gremlin recipes mention this query: g.V(startId).until(hasId(targetId)).repeat(out().simplePath()).path().limit(1) This returns path that I know to be a correct one immediately but then hangs the console ( top shows janusgraph and scylla to be processing stuff furiously though, so I guess it's working in the background, but

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

Modification of shortest path algorithm (route from a node to itself)

☆樱花仙子☆ 提交于 2019-12-22 08:35:36
问题 I am applying the all-pairs shortest path algorithm (Floyd-Warshall) to this directed graph: The graph is represented by its adjacency matrix. The simple code looks like this: public class ShortestPath { public static void main(String[] args) { int x = Integer.MAX_VALUE; int [][] adj= { {0, 6, x, 6, 7}, {x, 0, 5, x, x}, {x, x, 0, 9, 3}, {x, x, 9, 0, 7}, {x, 4, x, x, 0}}; int [][] D = adj; for (int k=0; k<5; k++){ for (int i=0; i<5; i++){ for (int j=0; j<5; j++){ if(D[i][k] != x && D[k][j] !=

Cluster growing of blobs

你说的曾经没有我的故事 提交于 2019-12-21 20:43:30
问题 Consider the following image which is from Mathworks: I have labelled the blobs with [L, num]= bwlabel(I); How do I connect all the blobs iteratively,i.e.start with one blob and find the nearest one to it.Consider the left-most two blobs, there can be many lines that can be drawn from many points of a blob to connect to the other blob, but the shortest one would be obtained by finding the pixel of a blob that is nearest to the other blob, find a similar pixel in the other blob and connect