shortest-path

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

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

Finding the shortest path in a graph between 2 nodes that goes through a subset of nodes

亡梦爱人 提交于 2019-12-10 11:28:57
问题 I'm trying to find out an efficient way of finding the shortest path between 2 nodes in a graph with positive edge costs that goes trough a subset of nodes. More formally: Given a graph G = (U, V) where U is the set of all nodes in the graph and V is the set of all edges in the graph, a subset of U called U' and a cost function say: f : UxU -> R+ f(x, y) = cost to travel from node x to node y if there exists an edge between node x and node y or 0 otherwise, I have to find the shortest path

Dijkstra's Algorithm for Negative Weights

≯℡__Kan透↙ 提交于 2019-12-10 04:17:20
问题 Okay, first of all I know Dijkstra does not work for negative weights and we can use Bellman-ford instead of it. But in a problem I was given it states that all the edges have weights from 0 to 1 (0 and 1 are not included). And the cost of the path is actually the product. So what I was thinking is just take the log. Now all the edges are negative. Now I know Dijkstra won't work for negative weights but in this case all the edges are negative so can't we do something so that Dijkstra would

Shortest path that traverses a list of required edges

霸气de小男生 提交于 2019-12-10 04:01:40
问题 I have a directed graph, that looks like this: I want to find the cheapest path from Start to End where the orange dotted lines are all required for the path to be valid. The natural shortest path would be: Start -> A -> B -> End with the resultant cost = 5, but we have not met all required edge visits. The path I want to find (via a general solution) is Start -> A -> B -> C -> D -> B -> End where the cost = 7 and we have met all required edge visits. Does anyone have any thoughts on how to

Finding shortest circuit in a graph that visits X nodes at least once

老子叫甜甜 提交于 2019-12-10 03:38:36
问题 Even though I'm still a beginner, I love solving graph related problems (shortest path, searches, etc). Recently I faced a problem like this : Given a non-directed, weighted (no negative values) graph with N nodes and E edges (a maximum of 1 edge between two nodes, an edge can only be placed between two different nodes) and a list of X nodes that you must visit, find the shortest path that starts from node 0, visits all X nodes and returns to node 0. There's always at least one path

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

旧时模样 提交于 2019-12-09 12:46:25
问题 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? 回答1: 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

Does java have an indexed minimum priority queue?

你离开我真会死。 提交于 2019-12-09 10:05:09
问题 I need it for an implementation of Dijkstra's algorithm, and I do have my own implementation but documenting my code would be easier with java's own classes. 回答1: No, Java standard library has no such data structure. I think most people use this: http://algs4.cs.princeton.edu/24pq/IndexMinPQ.java.html 回答2: What do you mean 'indexed'? Priority queue doesn't support indexing, unless it won't be queue any more. Java supports standard Priority Queue like C++ STL. It can be found in java.util

How to find shortest path in dynamic situation

Deadly 提交于 2019-12-09 09:46:18
问题 Some days ago, Someone ask me, If we have some agents in our environment, and they want go from their sources to their destinations, how we can find the total shortest path for all of them such that they shouldn't have conflict during their walk. The point of problem is all agents simultaneously walking in environment (which can be modeled by undirected weighted graph), and we shouldn't have any collision. I thought about this but I couldn't find optimum path for all of them. But sure there