Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any implementation of bidirectional search for Dijkstra algorithm? [closed]

I am looking for an implementation of bidirectional search (a.k.a. "meet in the middle" algorithm) for Dijkstra (or any other source-to-destination shortest path algorithm) in Java.

As bidirectional search processing is trickier than it looks like (Graph Algorithms, p.26), I want to consider an existing implementation before reinventing the wheel!

P.S.: I am talking about bidirectional search, not to be confused with a bidirectional graph)

Here is an example of a tricky graph:

enter image description here

like image 983
Fabien Avatar asked May 28 '12 11:05

Fabien


People also ask

Is Dijkstra bidirectional?

On the other hand, if we run two searches, one starting at s and the other at t, stopping when they meet in the middle, we would only relax 2mn/2 edges. This method is called bidirectional Dijkstra. The subtlety in bidirectional Dijkstra is the stopping condition.

What is bidirectional search Dijkstra?

Bidirectional search is a graph search algorithm that finds a shortest path from an initial vertex to a goal vertex in a directed graph. It runs two simultaneous searches: one forward from the initial state, and one backward from the goal, stopping when the two meet.

Will bidirectional search always find shortest path?

Heuristic refers to the concept of finding the shortest path from the current node in the graph to the goal node. The search always takes the shortest path to the goal node.

For which condition bidirectional search is perfect suitable?

Completeness : Bidirectional search is complete if BFS is used in both searches. Optimality : It is optimal if BFS is used for search and paths have uniform cost. Time and Space Complexity : Time and space complexity is O(bd/2).


1 Answers

Yes, there is at least in Java: https://github.com/coderodde/GraphSearchPal/blob/master/src/main/java/net/coderodde/gsp/model/support/BidirectionalDijkstraPathFinder.java

In a bidirectional Dijkstra's algorithm, you maintain actually two "Dijkstra's algorithms": the forward search and the backward search. Now, the forward search resembles a lot the unidirectional Dijkstra's algorithm. The backward search, however, proceeds in "reversed" fashion. If there is a directed edge (colloquially called an arc) (u, v), the forward search would traverse it from u to v, whereas the backward search would do the same in opposite direction.

Because the two search processes meet (usually) somewhere in between the source node and the target node, we need another termination condition, which in bidirectional Dijkstra's algorithm is

g(top(OPEN_forward)) + g(top(OPEN_backward)) > l

where l is the length of the shortest known so far path between the source and target nodes.

Additional code you might see only in bidirectional version is checking the possibility of shortening a shortest path candidate every time you improve the g value of any node. (The g value of a node u is the shortest (known so far) distance from the node from which the search started to u.)

like image 96
coderodde Avatar answered Oct 28 '22 13:10

coderodde