shortest-path

Shortest sequence of nodes though an unweighted graph

会有一股神秘感。 提交于 2019-12-05 16:41:54
I would like to know if there is an algorithm for finding the shortest sequence of nodes though a graph from its a head node to the tail node. The graph branches out from the head node and is arbitrarily complex and converges at the tail node. All connections between nodes are unweighted. I'm considering tackling this problem taking exploratory steps from the head and tail nodes and until the nodes from either end of the graph touch etc, but I'd like to know if a "better wheel" exists before I (re)invent one. Use breadth first search , which runs in O(E+V). It's the fastest you'll get on an

Fastest Path with Acceleration at Points

感情迁移 提交于 2019-12-05 14:24:12
问题 This is just something I came up with on my own, but it seems like a fun problem and it has me stumped. You have a set of points in two-dimensional space, with one point designated "Start" and one "End". Each point has coordinates (in meters from the origin), but also an "acceleration number" (in meters/second of delta-V). Upon reaching a point (including the start), you may accelerate by up to that point's acceleration number in any direction. Edge cost is dependent on your current speed,

Updating Shortest path distances matrix if one edge weight is decreased

会有一股神秘感。 提交于 2019-12-05 13:17:49
We are given a weighed graph G and its Shortest path distance's matrix delta. So that delta(i,j) denotes the weight of shortest path from i to j (i and j are two vertexes of the graph). delta is initially given containing the value of the shortest paths. Suddenly weight of edge E is decreased from W to W'. How to update delta(i,j) in O(n^2)? (n=number of vertexes of graph) The problem is NOT computing all-pair shortest paths again which has the best O(n^3) complexity. the problem is UPDATING delta, so that we won't need to re-compute all-pair shortest paths. More clarified : All we have is a

Modification of shortest path algorithm (route from a node to itself)

这一生的挚爱 提交于 2019-12-05 13:06:24
I am applying the all-pairs shortest path algorithm ( Floyd-Warshall ) to this directed graph: The graph is represented by its adjacency matrix. The simple code looks like this: public class ShortestPath { public static void main(String[] args) { int x = Integer.MAX_VALUE; int [][] adj= { {0, 6, x, 6, 7}, {x, 0, 5, x, x}, {x, x, 0, 9, 3}, {x, x, 9, 0, 7}, {x, 4, x, x, 0}}; int [][] D = adj; for (int k=0; k<5; k++){ for (int i=0; i<5; i++){ for (int j=0; j<5; j++){ if(D[i][k] != x && D[k][j] != x && D[i][k]+D[k][j] < D[i][j]){ D[i][j] = D[i][k]+D[k][j]; } } } } //Print out the paths for (int r

Are there any R Packages for Graphs (shortest path, etc.)?

痞子三分冷 提交于 2019-12-05 10:59:49
I know that R is statistical pkg, but probably there is library to work with graphs and find shortest path btw 2 nodes. PS actually, I've found igraph and e1071, which one is better? Thank you Sure, there's a Task View that gathers a fair number of the graph-related Packages. (The page linked to is a CRAN portal, which uses iframes, so i can't directly link to the Graph Task View. So from the page linked to here, click on Task Views near the top of the LHS column, then click on the Task View gR , near the bottom of the list. Among the Packages there, igraph , for instance, has graph-theoretic

Get shortest path to a cell in a 2d array python

送分小仙女□ 提交于 2019-12-05 07:21:35
问题 I have a 2d array arr where each cell in it has a value 1, 2 or 3 for example arr[0][0] = 3, arr[2][1] = 2 and arr[0][4] = 1 . I want to know the shortest path from a given certain cell eg arr[5][5] to the closest cell which has value 2 where the path shouldn't contain any cells that have the value 1. Any advice? Below is a the script for the BFS but I don't know how I can make it accept a 2d array as graph and starting point as a certain cell location in the array and then go to the nearest

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

前提是你 提交于 2019-12-05 06:24:28
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 connecting any two nodes. Limits are 1 <= N <= 40 000 / 1 <= X <= 15 / 1 <= E <= 50 000 Here's an example : The

Dijkstra's Algorithm for Negative Weights

不想你离开。 提交于 2019-12-05 05:30:05
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 work. I though of multiplying all the weights by -1 but then the shortest path becomes the longest path.

Shortest path that traverses a list of required edges

旧巷老猫 提交于 2019-12-05 05:19:52
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 require such edge traversals? Let R be the set of required edges and F = | R |. Let G be the input graph

How to set target vertex in QuickGraph Dijkstra or A*

二次信任 提交于 2019-12-05 03:33:28
问题 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. 回答1: 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>