dijkstra

using Dijkstra algorithm to find shortest path in an adjacency matrix

依然范特西╮ 提交于 2019-12-11 02:57:11
问题 I have a homework assignment where I'm supposed to find the cheapest airfares between two cities, taking into account layovers. We are required to use an adjacency matrix along with Dijkstra's algorithm. I'm looking at the algorithm in my book, as well as wikipedia (among other sites). I'm confused because in the parameter for the algorithm it has: DijkstraAlgorithm(weighted simple digraph, vertex first) What I'm having a hard time understanding- especially when looking at the entire

Find the shortest path between a given source and a set of destinations

a 夏天 提交于 2019-12-11 02:20:39
问题 You are given a weighted connected graph (20 nodes) with all edges having positive weight. We have a robot that starts at point A and it must pass at points B, D and E for example. The idea is to find the shortest path that connects all these 4 points. The robot also has a limited battery, but it can be recharged in some points. After researching on the internet I have two algorithms in mind: Dijkstra's and TSP . Dijkstra's will find the shortest path between a node and every other node and

Is there better way than a Dijkstra algorithm for finding fastest path that do not exceed specified cost

佐手、 提交于 2019-12-11 00:53:48
问题 I'm having a problem with finding fastest path that do not exceed specified cost. There's similar question to this one, however there's a big difference between them. Here, the only records that can appear in the data are the ones, that lead from a lower point to a higher point (eg. 1 -> 3 might appear but 3 -> 1 might not) (see below). Without knowing that, I'd use Dijkstra. That additional information, might let it do in a time faster than Dijkstras algorithm. What do you think about it?

Does Dijkstra's algorithm give shortest path always?

旧街凉风 提交于 2019-12-10 19:48:27
问题 I am learning Dijkstra's algorithm and had a basic query. I have a graph that looks as follows..(non-negative nodes): A---2-----B------16------D-----3-------F * * * * 3 4 * * C----------2---------------------------E Not clear from above graph display, but AC has a distance of 3 and EF has a distance of 4. I am interested in finding shortest path between A and F. Consider destination node F. When we consider its nearest node, we get D (DF has weight 3 and EF 4). However, when we follow that

Shortest path in a grid between two points. With a catch

痞子三分冷 提交于 2019-12-10 17:04:03
问题 I have this problem where I have to find the shortest path in an NxM grid from point A (always top left) to point B (always bottom right) by only moving right or down. Sounds easy, eh? Well here's the catch: I can only move the number shown on the tile I'm sitting on at the moment. Let me illustrate: 2 5 1 2 9 2 5 3 3 3 1 1 4 8 2 7 In this 4x4 grid the shortest path would take 3 steps, walking from top left 2 nodes down to 3, and from there 3 nodes right to 1, and then 1 node down to the goal

Dijkstra Shortest-Paths fast recalculation if only an edge got removed

谁说胖子不能爱 提交于 2019-12-10 16:09:13
问题 I'm trying to calculate the shortest paths. This does work with the below pasted implementation of Dijkstra. However I want to speed the things up. I use this implementation to decide to which field I want to go next. The graph represents an two dimensional array where all fields are connected to each neighbours. But over time the following happens: I need to remove some edges (there are obstacles). The start node is my current position which does also change over time. This means: I do never

Build a list using specific keys in a dict (python)?

て烟熏妆下的殇ゞ 提交于 2019-12-10 15:13:38
问题 I'm implementing the Dijkstra search algorithm in Python. At the end of the search, I reconstruct the shortest path using a predecessor map, starting with the destination node's predecessor. For example: path = [] path.append(destination) previous = predecessor_map[destination] while previous != origin: path.append(previous) previous = predecessor_map[previous] Is there any way to do this with less lines of code (e.g. list comprehension)? 回答1: The only suggestion that I have is to get rid of

Shortest Path distance between points given as X-Y coordinates

我与影子孤独终老i 提交于 2019-12-10 13:51:29
问题 I am currently working on a project that has a vector containing X and Y coordinates for approximately 800 points. These points represent an electric network of lines. My goal is to compute the shortest distance Path between a Point A and Point B that can be or can not be located along the path given by the vectors containing the X-Y coordinates of the electric lines. I have read about the Dijkstra Algorithm but since i am not that much familiar with it, I am not sure if I should go in that

Bellman–Ford, Dijkstra's, Prim's algorithm, Kruskal's, directed acyclic graph [closed]

无人久伴 提交于 2019-12-10 12:27:18
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 6 years ago . What are some real life examples where each one of these are used? 回答1: Dijkstra's algorithm, on every other question tagged algorithm on stackoverflow 回答2: Bellman-Ford + Djikstra: Shortest paths, navigational systems. Prim's + Kruskal: Minimum spanning trees, used for example in

Dijkstra's algorithm on directed acyclic graph with negative edges

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-10 09:11:56
问题 Will Dijkstra's algorithm work on a graph with negative edges if it is acyclic (DAG)? I think it would because since there are no cycles there cannot be a negative loop. Is there any other reason why this algorithm would fail? Thanks [midterm tomorrow] 回答1: Consider the graph (directed 1 -> 2, 2-> 4, 4 -> 3, 1 -> 3, 3 -> 5 ): 1---(2)---3--(2)--5 | | (3) (2) | | 2--(-10)--4 The minimum path is 1 - 2 - 4 - 3 - 5 , with cost -3 . However, Dijkstra will set d[3] = 2, d[2] = 3 in the first step,