dijkstra

Finding shortest values between the cities in a dataframe

纵然是瞬间 提交于 2019-12-18 09:48:14
问题 I have a dataframe with cities and distance between other cities from each city. My dataset looks like, df, From City City A City B City C City D City A 2166 577 175 City B 2166 1806 2092 City C 577 1806 653 City D 175 2092 653 im planning to visit all the cities, I am trying to find in which order by cities I can travel with the shortest distance. I want to end with a starting position. start point and end point should be same. Is there a way to find this shortest distance across all the

Shortest path with a twist

爷,独闯天下 提交于 2019-12-18 06:57:10
问题 I have n vertices and m undirected weighted edges between them (weights are representing minutes). Each vertex contains a number of minutes required to drink a coffee on that vertex. I want to determine the shortest amount of time (minutes) neccessary to get from vertex v to vertex w but with the additional constraint that I have to drink my coffee on exactly one of the vertices on my way from v to w ). Example : (number in the vertex is the amount of minutes required to drink a coffee, the

Weight map as function in Boost Graph Dijkstra algorithm

眉间皱痕 提交于 2019-12-18 06:53:58
问题 I'm using Boost Graph Libraries and need to use a weightmap which is not constant, but which is a function of a parameter K (i.e. the edge costs depend on K). In practice, given the following code: #include <boost/config.hpp> #include <iostream> #include <fstream> #include <boost/graph/graph_traits.hpp> #include <boost/graph/dijkstra_shortest_paths.hpp> #include <boost/graph/adjacency_list.hpp> struct Edge { Edge(float weight_) : weight(weight_) {} float weight; float getWeight(int K) {

Weight map as function in Boost Graph Dijkstra algorithm

旧时模样 提交于 2019-12-18 06:52:12
问题 I'm using Boost Graph Libraries and need to use a weightmap which is not constant, but which is a function of a parameter K (i.e. the edge costs depend on K). In practice, given the following code: #include <boost/config.hpp> #include <iostream> #include <fstream> #include <boost/graph/graph_traits.hpp> #include <boost/graph/dijkstra_shortest_paths.hpp> #include <boost/graph/adjacency_list.hpp> struct Edge { Edge(float weight_) : weight(weight_) {} float weight; float getWeight(int K) {

Are there faster algorithms than Dijkstra?

戏子无情 提交于 2019-12-18 01:03:15
问题 Given a directed, connected graph with only positive edge weights, are there faster algorithms for finding the shortest path between two vertices, than Dijkstra using a fibonacci heap? Wikipedia says, that Dijkstra is in O(|E| + |V| * log(|V|)) (using a fibonacci heap). I'm not looking for optimizations that, for example, half the execution time, but rather algorithms that are in a different time complexity (like going from O(n * log n) to O(n)). Further, I would like to know your opinion on

Difference between Prim's and Dijkstra's algorithms?

元气小坏坏 提交于 2019-12-17 21:38:02
问题 What is the exact difference between Dijkstra's and Prim's algorithms? I know Prim's will give a MST but the tree generated by Dijkstra will also be a MST. Then what is the exact difference? 回答1: Prim's algorithm constructs a minimum spanning tree for the graph, which is a tree that connects all nodes in the graph and has the least total cost among all trees that connect all the nodes. However, the length of a path between any two nodes in the MST might not be the shortest path between those

Complete graph with only two possible costs. What's the shortest path's cost from 0 to N - 1

自闭症网瘾萝莉.ら 提交于 2019-12-17 13:56:01
问题 You are given a complete undirected graph with N vertices. All but K edges have a cost of A. Those K edges have a cost of B and you know them (as a list of pairs). What's the minimum cost from node 0 to node N - 1. 2 <= N <= 500k 0 <= K <= 500k 1 <= A, B <= 500k The problem is, obviously, when those K edges cost more than the other ones and node 0 and node N - 1 are connected by a K-edge. Dijkstra doesn't work. I've even tried something very similar with a BFS. Step1: Let G(0) be the set of

Why use Dijkstra's Algorithm if Breadth First Search (BFS) can do the same thing faster?

旧城冷巷雨未停 提交于 2019-12-17 08:06:28
问题 Both can be used to find the shortest path from single source. BFS runs in O(E+V) , while Dijkstra's runs in O((V+E)*log(V)) . Also, I've seen Dijkstra used a lot like in routing protocols. Thus, why use Dijkstra's algorithm if BFS can do the same thing faster? 回答1: Dijkstra allows assigning distances other than 1 for each step. For example, in routing the distances (or weights) could be assigned by speed, cost, preference, etc. The algorithm then gives you the shortest path from your source

Why use Dijkstra's Algorithm if Breadth First Search (BFS) can do the same thing faster?

巧了我就是萌 提交于 2019-12-17 08:06:27
问题 Both can be used to find the shortest path from single source. BFS runs in O(E+V) , while Dijkstra's runs in O((V+E)*log(V)) . Also, I've seen Dijkstra used a lot like in routing protocols. Thus, why use Dijkstra's algorithm if BFS can do the same thing faster? 回答1: Dijkstra allows assigning distances other than 1 for each step. For example, in routing the distances (or weights) could be assigned by speed, cost, preference, etc. The algorithm then gives you the shortest path from your source

Dijkstra's algorithm with negative weights

谁说胖子不能爱 提交于 2019-12-17 07:17:20
问题 Can we use Dijkstra's algorithm with negative weights? STOP! Before you think "lol nub you can just endlessly hop between two points and get an infinitely cheap path", I'm more thinking of one-way paths. An application for this would be a mountainous terrain with points on it. Obviously going from high to low doesn't take energy, in fact, it generates energy (thus a negative path weight)! But going back again just wouldn't work that way, unless you are Chuck Norris. I was thinking of