shortest-path

Find the shortest path with the least number of edges

点点圈 提交于 2019-12-04 03:15:44
问题 I need to modify Dijkstra's algorithm so that if there are several shortest paths I need to find the one with minimum number of edges on the path. I've been stuck on how to use Dijkstra's method to find multiple shortest paths, how do you do that? doesn't it always output only 1 shortest path? pseudo code or any general direction would be very helpful. 回答1: Instead of assigning every node with the distance from source you can assign the number of edges traversed so far also. So each node will

What is the purpose of the visited set in Dijkstra?

别等时光非礼了梦想. 提交于 2019-12-04 02:55:31
On the Wikipedia page for Dijkstra's algorithm, they mark visited nodes so they wouldn't be added to the queue again. However, if a node is visited then there can be no distance to that node that is shorter, so doesn't the check alt < dist[v] already account for visited nodes? Am I misunderstanding something about the visited set? for each neighbor v of u: alt := dist[u] + dist_between(u, v); // accumulate shortest dist from source if alt < dist[v] && !visited[v]: dist[v] := alt; // keep the shortest dist from src to v previous[v] := u; insert v into Q; // Add unvisited v into the Q to be

k-shortest (alternative) path algorithm, java implementations

╄→гoц情女王★ 提交于 2019-12-04 02:39:37
Could you recommend any java library which implements k-shortest algorithm -> searching for alternative ways, not the only shortest one in directed multigraph ? I found only JGraphT but there is actually bug (which i submitted) but it will take a lot of time to fix it i guess, are there any other available implementations ? Except JGraphT i found only small one-man projects :/ OR would be hard to modify Disjktra shortest path alg to show alternative paths ? Thanks Ram Narasimhan 2 Possible Options: Option 1. The class KshortestPath from the MascOpt Package is a good option for a Java

AStar - explanation of name

て烟熏妆下的殇ゞ 提交于 2019-12-04 01:53:28
I am looking for an explanation why the AStar / A* algorithm is called AStar. All similar (shortest path problem) algorithms are often named like its developer(s), so what is AStar standing for? There were algorithms called A1 and A2. Later, it was proved that A2 was optimal and in fact also the best algorithm possible, so he gave it the name A* which symbolically includes all possible version numbers. Source: In 1964 Nils Nilsson invented a heuristic based approach to increase the speed of Dijkstra's algorithm. This algorithm was called A1. In 1967 Bertram Raphael made dramatic improvements

Dijkstra shortest path algorithm with edge cost

纵然是瞬间 提交于 2019-12-03 17:47:17
问题 I have a directed, positive weighted graph. Each edge have a cost of use. I have only A money, i want to calculate shortest paths with dijkstra algorithm, but sum of edges costs on route must be less or equal to A. I want to do this with most smallest Dijstra modification (if I can do it with small modification of Dijkstra). I must do this in O(n*log(n)) if I can, but i think i can. Anyone can help me with this? 回答1: https://www.spoj.pl/problems/ROADS/ The problem was given at CEOI '98 and

Will a minimum spanning tree and shortest path tree always share at least one edge?

自作多情 提交于 2019-12-03 17:41:44
问题 I'm studying graph theory and I have a question about the connection between minimum spanning trees and shortest path trees. Let G be an undirected, connected graph where all edges are weighted with different costs . Let T be an MST of G and let T s be a shortest-path tree for some node s . Are T and T s guaranteed to share at least one edge? I believe this is not always true, but I can't find a counterexample. Does anyone have a suggestion on how to find a counterexample? 回答1: I think that

shortest path with one edge turn to zero

廉价感情. 提交于 2019-12-03 17:16:29
given an undirected weighted graph G , and two vertices: start vertex and end vertex what's the most efficient algorithm that finds the shortest path from start to end with ability to turn weight of exactly one edge to zero? EDIT: i know dijkstra algorithm , but as i said , situation is different in this problem: we're allowed to turn one edge to zero, i wanna know how solve this problem efficiently, actually , one way is turn edges weights to zero iteratively! and apply dijkstra algorithmin each step, but , i'm looking for more efficient way thanks You can solve this by using Djikstra's

How to set target vertex in QuickGraph Dijkstra or A*

丶灬走出姿态 提交于 2019-12-03 17:16:24
I am using QuickGraph version 3.6 and I found function SetRootVertex, but no SetTagretVertex. I need this because I am searching short paths in huge graph and this would speed up program a lot. Clases in question are DijkstraShortestPathAlgorithm and AStarShortestPathAlgorithm. I don't think there is a way to this without using events. You could wrap the necessary code in one extension method, making things clear, e.g.: public static class Extensions { class AStarWrapper<TVertex, TEdge> where TEdge : IEdge<TVertex> { private TVertex target; private AStarShortestPathAlgorithm<TVertex, TEdge>

Shortest Path For A Dag

佐手、 提交于 2019-12-03 16:50:07
I have a graph with an s and t vertex that I need to find the shortest path between. The graph has a lot of special properties that I would like to capitalize on: The graph is a DAG (directed acyclic graph). I can create a topological sort in O(|V|) time, faster than the traditional O(|V + E|). Within the topological sort, s is the first item in the list and t is the last. I was told that once I have a topological sort of the vertices I could find the shortest path faster than my current standard of Dijkstra's Uniform Cost, but I cannot seem to find the algorithm for it. Pseudo code would be

How to find all vertex-disjoint paths in a graph?

只愿长相守 提交于 2019-12-03 14:34:02
Suppose there are 3 target nodes in a graph. A vertex-disjoint path means there is not any same node except the end nodes during the path. For any one single node, say node i, how to find all vertex-disjoint paths from node i to the three target nodes? You can solve this problem by reducing it to a max-flow problem in an appropriately-constructed graph. The idea is as follows: Split each node v in the graph into to nodes: v in and v out . For each node v, add an edge of capacity one from v in to v out . Replace each other edge (u, v) in the graph with an edge from u out to v in of capacity 1.