shortest-path

Bellman-Ford: all shortest paths

拜拜、爱过 提交于 2019-12-06 05:09:13
问题 I've successfully implemented Bellman-Ford to find the distance of the shortest path when edges have negative weights/distances. I've not been able to get it to return all shortest paths (when there are ties for shortest). I managed to get all shortest paths (between a given pair of nodes) with Dijkstra. Is this possible with Bellman-Ford? (just want to know if I'm wasting my time trying) 回答1: If you alter the second step of the Bellman-Ford algorithm a little bit you can achieve something

Compute the shortest path with exactly `n` nodes between two points on a meshgrid

佐手、 提交于 2019-12-06 04:23:41
问题 I have defined the following 3D surface on a grid: %pylab inline def muller_potential(x, y, use_numpy=False): """Muller potential Parameters ---------- x : {float, np.ndarray, or theano symbolic variable} X coordinate. If you supply an array, x and y need to be the same shape, and the potential will be calculated at each (x,y pair) y : {float, np.ndarray, or theano symbolic variable} Y coordinate. If you supply an array, x and y need to be the same shape, and the potential will be calculated

Shortest path between raw geo coordinates and a node of a graph

喜夏-厌秋 提交于 2019-12-06 03:11:02
问题 I have implemented a simple Dijkstra's algorithm for finding the shortest path on an .osm map with Java. The pathfinding in a graph which is created from an .osm file works pretty well. But in case the user's current location and/or destination is not a node of this graph (just raw coordinates) how do we 'link' those coordinates to the graph to make pathfinding work? The simple straightforward solution "find the nearest to the current location node and draw a straight line" doesn't seem to be

Go, Dijkstra : print out the path, not just calculate the shortest distance

可紊 提交于 2019-12-06 02:40:38
问题 Go, Dijkstra : print out the path, not just calculate the shortest distance. http://play.golang.org/p/A2jnzKcbWD I was able to find the shortest distance using Dijkstra algorithm, maybe not. The code can be found here. But it would be useless if I can't print out the path. With a lot of pointers going on, I can't figure out how to print out the final path that takes the least amount of weights. In short, how do I not only find the shortest distance, but also print out the shortest path on

Dynamically updating shortest paths

旧时模样 提交于 2019-12-06 02:01:13
问题 I have a graph on which I frequently need to know all shortest paths (or rather their lengths). Because I do not want to recalculate them I store them in a simple array and just retrieve them from there. However since the graph might also change over time I will have to recalculate them at given times. For now the following changes might happen: Adding a node and an edge to it to the graph Changing the length of an edge Adding a new edge of the graph Deleting an edge or deleting a node In all

Modified Dijkstra to find most optimized shortest path given extra properties

人盡茶涼 提交于 2019-12-06 01:24:07
This is a follow-up question for a question I asked at here . The problem is mapped to a graph with say non-negative weights on edges (no preference if it can be directed or not). However, along with a weight which is actually distance, we also have another property which is data coverage of the edge which can be important factor which route to select given how severe I need internet on my phone (for real-time gaming for example I need good bandwidth). So overall, we want to somehow find a trade-off between the length of the path and network bandwidth to solve the problem of finding most

Faster way to calculate the number of shortest paths a vertex belongs to using Networkx

久未见 提交于 2019-12-05 20:26:57
I am considering that the Stress of a vertex i is the number of shortest paths between all pairs of vertices that i belongs to. I am trying to calculate it using Networkx, I've made in three ways so far. The readable , dirty , and dirtiest but none of them is fast. Actually, I would like it to be faster than the betweenness ( source ) present on Networkx. Is there a better way to calculate that? Thanks in advance for any suggestion, answer or comment. Following see what I did so far: Ps.: Here is a pastie with the code ready to go if you want give it a try, thanks again. Here is the common

k-shortest (alternative) path algorithm, java implementations

别说谁变了你拦得住时间么 提交于 2019-12-05 20:09:40
问题 Could you recommend any java library which implements k-shortest algorithm -> searching for alternative ways, not the only shortest one in directed multigraph ? I found only JGraphT but there is actually bug (which i submitted) but it will take a lot of time to fix it i guess, are there any other available implementations ? Except JGraphT i found only small one-man projects :/ OR would be hard to modify Disjktra shortest path alg to show alternative paths ? Thanks 回答1: 2 Possible Options:

NetworkX vs Scipy all shortest path algorithms

試著忘記壹切 提交于 2019-12-05 19:16:06
What are the differences between the NetworkX all shortest paths algorithm and the scipy floyd warshall algorithm? Are there any reasons to prefer one over another? Which is fastest? Joel (for those who aren't aware the numpy floyd-warshall algorithm is available in networkx) The networkx description of floyd_warshall_numpy states: Floyd’s algorithm is appropriate for finding shortest paths in dense graphs or graphs with negative weights when Dijkstra’s algorithm fails. This algorithm can still fail if there are negative cycles. It has running time O(n^3) with running space of O(n^2). The

@Query shortestPath return type in Spring Data Neo4j

不羁岁月 提交于 2019-12-05 18:54:15
What's the return Type of the following query and how do I use it? I tried several things like Path , Iterable<Path> , and others but I always hit some sort of exceptions. It seems to be a LinkedHashMap but are there any other handier object types that I can use? @Query( "START u1=node:User(key= {0}), u2=node:User(key = {1}) " + "MATCH p = shortestPath(u1-[*]-u2) " + "RETURN p") public ??? findShortestPath(String u1, String u2); Am I missing any dependencies? This is the only one that I'm using: <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-neo4j-rest<