Calculate alternative paths in road network - algorithm

I'm working on an alternative paths finding problem recently and trying to enhance route result's diversity. But there seems to have little material on the internet (or maybe I miss something), what I get is algorithms like remove or add penalty cost for segments on an path already found, which require re-routing multiple times.
Currently we are using bidirectional A* algorithm to construct forward and backward shortest path tree, and each meet points of these two trees will produce an alternative path.
However, since there only exist one optimal path from the root to each meet point, the diversity of alternative paths is still limited. I'm trying to add second parent(may be sub-optimal parent) for each node in road network to tackle this problem, but I have no idea whether this method can solve the problem.
Does anybody have any idea about algorithms to find alternative paths used in industrial map productions, like google map or baidu map. Any suggestion or reference link will be appreciated.

You have multiple ways to implement this.
You can:
Artificially increase the cost of the optimal path so that if an another path is only slightly slower it will appear first, thus you have an alternative route.
You can "disable" the best path (or part of it) then compute the optimal path again to force an alternative road to be taken.
Use advanced techniques such as these presented in this paper. These thechnique are more adapted for industrial usage.

Related

How to compute single source shortest paths with OSRM?

I've been playing around with the OSRM routing library recently. It seems to be highly efficient at solving the shortest path problem. However, I didn't see how to compute single source shortest paths with it. More precisely, given a fixed starting point, compute the shortest distances to all locations that can be reached within a given distance limit (e.g., reachable within 30 minutes).
OSRM uses contraction hierarchies internally. From my understanding, this technique is way superior to Dijkstra's algorithm when it comes to computing the distance between two locations in real world data. However, for my problem, Dijkstra's algorithm seems to fit better, doesn't it?
Does OSRM provide an API to compute single source shortest path problems (with a limit on the distance)? Are there other free routing libraries that are better suited for this type of problem? Preferably one with good support for OpenStreetMap data.
OSRM is using contraction hierarchies (CH) to be that fast for "one to one routing". To make CH working you need an adapted bidirectional algorithm (A*, Dijkstra, ...) so the single source case is more difficult. BUT a one to many algorithm is relative simple if you know up front which destinations you want.
Also have a look into the paper "Fast Detour Computation for Ride Sharing" or here if you want a solution for a "non goal-directed, bidirectional search" which uses lookup tables.
other free routing libraries?
I would suggest my Java GraphHopper project ;)
but there are of course more: http://wiki.openstreetmap.org/wiki/Routing

How to find the quickest path between many locations which have time restrictions

I am trying to start on a personal research project that I have been brainstorming for a couple of years now. I am aware of graphs and algorithms for finding the best order in which to visit locations for the quickest time. However I am stuck on the next step of my research, are there research papers / algorithms that can solve this problem? Given a starting point and an end point with a number of "waypoints" that have to be visited. And some waypoints have time restrictions such as waypoint three has to be reached by 4:00 pm. So the algorithm will have to first sort the locations based on the time restrictions of them (if there are any) and then find the best order to visit each of the waypoints.
I have looked into many different algorithms/heuristics and I have searched for research papers on this topic but I cannot find anything definitive.
Thank you for the help in advance.
Never done anything like that but... elaborating on what has already told you BlueRaja, I have to say that most likely you already found your Grail (and, maybe, you are just not realizing it).
The time-related problem you are trying to solve looks like just another way to re-state the same space-related path-finding problem you already had to solve for travelling across your graph.
In other words, it looks like you have two graphs to traverse. The first one is the spatial one, represented by the net of waypoints you have to visit. The second one is the temporal (aka "time-related") graph of "time windows" you have to meet in order to not miss any bus/train/ship/airplane/whatever.
As long as I can see, you could use a regular path-finding/graph-crossing algorithm (Dijkstra, A*, contraction hierarchies, etc.) to traverse the spatial graph and re-use the same algorithm (or a very similar one) to traverse the time-related graph as well.
After all, both graphs are just a mathematical representation of a net of "constrains" (the points to be traversed, being them in space or in time) and can traversed using the same algorithm. Most likely, if you look at the code you are using to sort out your "time windows", you will see that it is already quite similar to a very simple space-related graph-traversing algorithm.
The main problem seems to be finding a good representation of the temporal graph (the net of "time windows" you have to respect). Most likely, it will have to be a graph of time-constrained spatial waypoints (spatial points, or "doors", with a "time window" attached to each of them).
In any case, there is no way to solve two problems with one single operation. First, you will have to find the "shortest path" that connects all of your time windows (in the required order) in the temporal graph (that is: you have to sort them out, as you are already doing). Second, you will have to find the shortest paths between any pair of time windows in the spatial graph (and check if the shortest/fastest path is fast enough to meet the next time window).

How to find shortest path in dynamic situation

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 are too many heuristic ideas for this problem.
Assume input is graph G(V,E), m agents which are in: S1, S2,...,Sm nodes of graph in startup and they should go to nodes D1,...Dm at the end. Also may be there is conflict in nodes Si or Di,... but these conflicts are not important they shouldn't have conflict when they are in their internal nodes of their path.
If their path shouldn't have same internal node, It will be kind of k-disjoint paths problem which is NPC, but in this case paths can have same nodes, but agent shouldn't be in same node in same time. I don't know I can tell the exact problem statement or not. If is confusing tell me in comments to edit it.
Is there any optimal and fast algorithm (by optimal I mean sum of length of all paths be as smallest as possible, and by fast I mean good polynomial time algorithm).
A Google search reveals two links that might be helpful:
Cooperative path planning for multi-robot systems in dynamic domains
Optimizing schedules for prioritized path planning of multi-robot systems
Edit: From the book chapter (first link):
There are various approaches to path planning in multi-robot system [sic], however, finding the
optimal solution is NP-hard. Hopcraft et al. (1984) simplify the planning problem to the
problem of moving rectangles in a rectangular container. They proved the NP-hardness of
finding a plan from a given configuration to a goal configuration with the least amount of
steps. Hence, all feasible approaches to path planning are a compromise between efficiency
and accuracy of the result.
I can't find the original paper by Hopcroft online, but given that quote, I suspect the problem they reduced the navigation task to is similar to Rush Hour, which is PSPACE-complete.
If it's just a matter of getting from point a to point b for each robot, you could just use a search algorithm like A* (A Star) or Best-First.
Give it a simple heuristic like the sum of distances from goal.

Fastest path to walk over all given nodes

I'm coding a simple game and currently doing the AI part. NPC gets a list of his 'interest points' which he needs to visit. Each point has a coordinate on the map. I need to find a fastest path for the character to visit all of the given points.
As far as I understand it, the task could be described as 'finding fastest traverse path in a strongly connected weighted undirected graph'.
I'd like to get either the name of some algorithm to calculate that or if there is no name - some keypoints on programming it myself.
Thanks in advance.
This is very similar to the Travelling Salesman problem, although I'm not going to try to prove equivalency offhand. The TSP is NP-complete, which means that solving the problem exactly may be impractical, depending on the number of interest points. There are approximation algorithms that you may find more useful.
See previous post regarding tree traversals:
Tree traversal algorithm for directory structures with a lot of files
I would use algorithm like: ant algorithm.
Not directly on point but what I did in an MMO emulator was to store waypoint indices along with the rest of the pathing data. If your requirement is to demonstrate solutions to TSP then ignore this. If not, it's worth consideration IMO.
In my case it was the best solution as otherwise the server could have potentially hundreds of mobs (re)spawning and along with all the other AI logic, would have to burn cycles computing route logic.

Algorithm Optimization - Shortest Route Between Multiple Points

Problem: I have a large collection of points. Each of these points has a list with references to other points with the distance between them already calculated and stored. I need to determine the shortest route that begins from an origin and passes through a specific number of points to any destination.
Ex: I'm on vacation and I'm staying in a specific city. I'm making a ONE WAY trip to see ANY four cities and I want to travel the least distance possible. I cannot visit the same city more than once.
Current solution: Right now I'm just iterating through every possibility manually and storing the shortest path. This works but feels inefficient. Also, this problem will eventually be expanded to include searching from multiple origin points to multiple destination points, so I think that might explode the search space.
What is the better way to search for the shortest route?
Answering to the updated post, your solution of checking every possibility is optimal (at least, noone has discovered better algorithms so far). Yes, that's a travelling salesman, whose essense is not touching every city, but touching every city once. If you don't want to search for best solution possible, you may find it useful to use heuristics that work faster, but allow for limited discrepancy from ideal solution.
For future answerers: Floyd-Warshall algorithm and all Floyd-like variations are inapplicable here.
In generally you should to strict bad variants...
I think you should use some variations of Branch_and_bound method
http://en.wikipedia.org/wiki/Branch_and_bound
Either bredth first search as norheim.se said or Dijkstra's algorithm would be my suggestion as well.
This sounds Travelling Salesman-esque? One solution is to use an optimisation technique such as an evolutionary algorithm. Currently you are doing an exhaustive search, which will get very slow very quickly. But I think this is pretty much a travelling salesman problem and it has been tackled for several decades if not centuries, and such there are several possible ways of attack. Google is your friend.
Perhaps this is what the original poster means by "iterating through each possibility manually and storing the shortest path", but I thought I'd like to make explicit what appears to be a baseline solution.
Assume you already have a two-point shortest path algorithm--this has classical solutions for various kinds of graphs. Assume all distances are nonnegative and d(A->B->C) = d(A->B) + d(B->C).
The essentials are that the path starts at S goes through one of intermediate cities "abcd" and ends with E:
e.g. SabcdE, SacbdE, etc...
With only 4 intermediate cities, you enumerate all 24 permutations. For each permutation use your shortest two-point algorithm to compute the path from head to tail, and its total distance.
Then given the start and ending point, there are 12 possibilities attaching to one of abcd and for each two possibilities for the interior. You've computed these distances already, so you add on the distance from S to the head and the tail to E. Choose minimum. So once you've precomputed the intermediate distances for a fixed set of interior cities you need to do 12 two point shortest path problems for any pair of start and end points.
This obviously scales poorly with increasing number of intermediate cities. It's not clear to me that it could do better unless you impose greater restrictions on the graph structure (is this in a physical Euclidenan space? Triangle inequality?).
My thought example: suppose all intermediate distances between cities are O(1). With no restriction on the graph, then the distance from S to any intermediate city might be 1000 except for one being 1. Same for the tail. So you can force the first city to be visited to be anything. Now, go one layer down, take the first city as the "start point". Apply the same argument: you can make the best path go to any of the following cities by manipulating the distances in the graph.
So it seems that the complexity can't be helped without additional assumptions.
This is the very common and real time situation any one can fall in.Google map user interface gives you the path in the same order, you add in the destination list. it doesn't give you the optimal path though their own Google maps API provide the solution.
Google maps API provides the solution for this. In the request to find out the path you have to provide the flag 'optimizeWaypoints: true,'. The request will seem like this.
var request = {
origin: start,
destination: end,
waypoints: waypts,
optimizeWaypoints: true,
travelMode: google.maps.TravelMode.DRIVING
};
and you can see whole code of the utility in the view source as complete utility is developed in javascript and HTML.
I hope it will help.
It appears that the edges of your graph are bidirectional. In this case, the algorithm you're looking for is Dijkstra's algorithm.

Resources