shortest-path

A Shortest Path Algorithm With Minimum Number Of Nodes Traversed

痞子三分冷 提交于 2019-12-18 18:37:57
问题 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

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

Neo4j query for shortest path stuck (Do not work) if I have 2way relationship in graph nodes and nodes are interrelated

旧城冷巷雨未停 提交于 2019-12-18 07:05:10
问题 I made relation graph two relationship, like if A knows B then B knows A, Every node has unique Id and Name along with other properties.. So my graph looks like if I trigger a simple query MATCH (p1:SearchableNode {name: "Ishaan"}), (p2:SearchableNode {name: "Garima"}),path = (p1)-[:NAVIGATE_TO*]-(p2) RETURN path it did not give any response and consumes 100% CPU and RAM of the machine. UPDATED As I read though posts and from comments on this post I simplified the model and relationship. Now

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

Shortest path in 2d arrays

时光毁灭记忆、已成空白 提交于 2019-12-18 06:54:42
问题 *...*..D .G..*..... **...**. .S....*. ........ ...G**.. ........ .G..*... Here is 2d array where S- Source D-Destination G-Point must be visited ." . "Free paths "*"Block Paths Can you help me which would be the efficient algorithm to find the length of shortest pathi in java Only Horizontal and Vertical movements are possiable 回答1: To find the shortest distance from start point to all other points in the map, you can use a BFS. Sample code: public void visit(String []map , Point start){ int

How do I find the shortest path that covers all nodes in a directed cyclic graph?

核能气质少年 提交于 2019-12-18 05:01:42
问题 I need an example of the shortest path of a directed cyclic graph from one node (it should reach to all nodes of the graph from a node that will be the input). Please if there is an example, I need it in C++, or the algorithm. 回答1: EDIT: Oops, misread the question. Thanks @jfclavette for picking this up. Old answer is at the end. The problem you're trying to solve is called the Travelling salesman problem. There are many potential solutions, but it's NP-complete so you won't be able to solve

Knight's Shortest Path on Chessboard

我们两清 提交于 2019-12-17 15:18:28
问题 I've been practicing for an upcoming programming competition and I have stumbled across a question that I am just completely bewildered at. However, I feel as though it's a concept I should learn now rather than cross my fingers that it never comes up. Basically, it deals with a knight piece on a chess board. You are given two inputs: starting location and ending location. The goal is to then calculate and print the shortest path that the knight can take to get to the target location. I've

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

How does a Breadth-First Search work when looking for Shortest Path?

社会主义新天地 提交于 2019-12-17 08:01:31
问题 I've done some research, and I seem to be missing one small part of this algorithm. I understand how a Breadth-First Search works, but I don't understand how exactly it will get me to a specific path, as opposed to just telling me where each individual node can go. I guess the easiest way to explain my confusion is to provide an example: So for instance, let's say I have a graph like this: And my goal is to get from A to E (all edges are unweighted). I start at A, because that's my origin. I

Why doesn't Dijkstra's algorithm work for negative weight edges?

雨燕双飞 提交于 2019-12-17 02:40:57
问题 Can somebody tell me why Dijkstra's algorithm for single source shortest path assumes that the edges must be non-negative. I am talking about only edges not the negative weight cycles. 回答1: Recall that in Dijkstra's algorithm, once a vertex is marked as "closed" (and out of the open set) - the algorithm found the shortest path to it , and will never have to develop this node again - it assumes the path developed to this path is the shortest. But with negative weights - it might not be true.