shortest-path

Shortest path to visit all nodes

拟墨画扇 提交于 2019-12-01 16:02:29
问题 I'm looking for an algorithm that seems very typical to me, but it seems that the common solutions are all just a little bit different. In an undirected graph, I want the shortest path that visits every node. Nodes can be revisited and I do not have to return to the start node. The Travelling Salesman Problem seems to add the restriction that each node can only be visited once and that the path has to return to where it started. Minimal Spanning Trees may be part of a solution, but such

Shortest path in “two-graph” with limited number of changes

对着背影说爱祢 提交于 2019-12-01 11:05:52
问题 Let's say we have two directed and positive-weighted graphs on one set of vertices (first graph represents for example rail-roads and the second one - bus lanes; vertices are bus stops or rail-road stations or both). We need to find the shortest path from A to B, but we can't change the type of transport more than N times. I was trying to modify the Dijkstra's algorithm, but it's working only on a few "not-so-mean-and-complicated" graphs and I think I need to try something different. How to

Bellman ford queue based approach from Sedgewick and Wayne - Algorithms, 4th edition

寵の児 提交于 2019-12-01 03:50:02
问题 I was studying queue-based approach for Bellman-Ford algorithm for single source shortest path from Robert Sedgewick and Kevin Wayne - Algorithms, 4th edition source code for algorithm from book is present at this link http://algs4.cs.princeton.edu/44sp/BellmanFordSP.java. I have two points one is a doubt and other is code improvement suggestion. In above approach following is code for relax method for relaxing distance to vertices. for (DirectedEdge e : G.adj(v)) { int w = e.to(); if (distTo

Non-cycle path to all nodes

感情迁移 提交于 2019-12-01 02:45:19
问题 Is there an algorithm or set of algorithms that would let you find the shortest walking distance from an arbitrary start node so that every node gets visited in a weight, undirected graph? It's not quite Traveling Salesman, because I don't care if a node is visited more than once. (It doesn't even matter if you make it back to the start -- the walker can end up in some far-off node as long as it was the last one needed to visit all nodes.) It's not quite minimum spanning tree, because it may

How do I get the vertices on the shortest path using igraph?

浪子不回头ぞ 提交于 2019-12-01 01:10:18
问题 I'm using igraph to generate a matrix of shortest path distances between pairs of vertices but I can't figure out how to return the vertices. So far I have: path_length_matrix = ig_graph.shortest_paths_dijkstra(None,None,"distance", "ALL") I'm looking for a function which returns a matrix of paths like the matrix of distances but I can't see anything in the igraph documentation which shows how to get the paths. 回答1: The function you need is get_shortest_paths I believe. See http://packages

Suggestions for KSPA on undirected graph

依然范特西╮ 提交于 2019-11-30 22:15:03
There is a custom implementation of KSPA which needs to be re-written. The current implementation uses a modified Dijkstra's algorithm whose pseudocode is roughly explained below. It is commonly known as KSPA using edge-deletion strategy i think so. (i am a novice in graph-theory). Step:-1. Calculate the shortest path between any given pair of nodes using the Dijkstra algorithm. k = 0 here. Step:-2. Set k = 1 Step:-3. Extract all the edges from all the ‘k-1’ shortest path trees. Add the same to a linked list Edge_List. Step:-4. Create a combination of ‘k’ edges from Edge_List to be deleted at

What are some good methods to finding a heuristic for the A* algorithm?

可紊 提交于 2019-11-30 21:49:54
You have a map of square tiles where you can move in any of the 8 directions. Given that you have function called cost(tile1, tile2) which tells you the cost of moving from one adjacent tile to another, how do you find a heuristic function h(y, goal) that is both admissible and consistent? Can a method for finding the heuristic be generalized given this setting, or would it be vary differently depending on the cost function? Amit's tutorial is one of the best I've seen on A* (Amit's page) . You should find some very useful hint about heuristics on this page . Here is the quote about your

Dijkstra algorithm with min-priority queue

蹲街弑〆低调 提交于 2019-11-30 18:10:02
I'm trying to implement the dijkstra algorithm with priority queue, but I can't understand how it works. I read many guide on the web but I can't understand this algorithm at all. My question are: what is the priority for each node? I think that it is the weight of the incoming edge with minimun value, but I'm not sure. Is this true? Second question, when I extract the root of the queue, how works if this node is not adjacency with no one of the visited nodes? You should use priority queue where the vertex with the shortest distance from the starting vertex will get the highest priority.

Algorithm: shortest path between all points

删除回忆录丶 提交于 2019-11-30 17:39:59
Suppose I have 10 points. I know the distance between each point. I need to find the shortest possible route passing through all points. I have tried a couple of algorithms (Dijkstra, Floyd Warshall,...) and they all give me the shortest path between start and end, but they don't make a route with all points on it. Permutations work fine, but they are too resource-expensive. What algorithms can you advise me to look into for this problem? Or is there a documented way to do this with the above-mentioned algorithms? Have a look at travelling salesman problem . You may want to look into some of

A Shortest Path Algorithm With Minimum Number Of Nodes Traversed

我是研究僧i 提交于 2019-11-30 17:04:33
I am looking for a Dijkstra's algorithm implementation, that also takes into consideration the number of nodes traversed. What I mean is, a typical Dijkstra's algorithm, takes into consideration the weight of the edges connecting the nodes, while calculating the shortest route from node A to node B. I want to insert another parameter into this. I want the algorithm to give some weightage to the number of nodes traversed, as well. So that the shortest route computed from A to B, under certain values, may not necessarily be the Shortest Route, but the route with the least number of nodes