I have a strange pathfinding problem. In the diagram below, there are two kinds of edges - red and blue. Red edges are reliable, while blue edges are not - they provide shortcuts, but may disappear or be unavailable in some circumstances - you can think of them as mountain passes that get snowed in in winter, or ferry crossings that don't operate on weekends, or train lines that only operate during commuter hours.
I want my pathfinder to produce a selection of possible paths. The user must know the fastest unreliable way to get to their destination, and possible alternatives if that path is not available. The pathfinder should produce the shortest route (in the diagram, 3 hops using blue edge 'b'), and the shortest reliable route - (5 hops, using only red edges) and also all other possible routes that are shorter than the reliable route and make use of the unreliable blue edges.
For the diagram, these are the possible permutations:
My first attempt for this algorithm was as follows:
However, this algorithm is not complete, as it can miss some possible paths. In the example above, the path using only edge 'a' would be missed (all other paths would be included.)
My next thought was to run a search for every possible combination of blue edges: [a], [b], [c], [d], [a,b], [a,c], ..., [a,b,c,d]
. Naturally, this is very inefficient and is probably not viable for large numbers of blue edges.
Can you think of any solutions that could help me out here? I need one of:
The former is the best solution, but the later I could run for, say, 10 seconds, and then return at least a good selection of short paths to the destination.
Incidentally, I have a pretty good idea of the size of my graph: There are around 7000 vertexes, 30,000 red edges and 200 blue edges.
I'm sure this kind of problem has been considered before, but I can't find anything written about it. Can you point me in the right direction?
As I can see it, you can split your problem into two parts:
k
. Bigger k
is - more expansive it is going to be to generate the paths.Note that finding ALL possible paths is extremely inefficient, since there is factorial number of those, and that number tends to be impossible to calculate in all but the smallest graphs (definetly out of reach for 7,000 nodes)