In graph theory, the shortest path problem is the problem of finding a path between two vertices (or nodes) in a graph such that the sum of the weights of its constituent edges is minimized.
There are many algorithms available out there for solving this kind of problems, but all of them share a common propery: their high time complexity.
I tried to solve this problem using a different approach, a concurrent one.
-
Spawn a process in the
start
nodes -
Check if current node is a
goal
nodetrue
-> send the path found to theroot
false
-> spawn a process for every neighbour of the current node. The process keeps track of the path travelled
Processes are linked to a root process that collects the results, gets notified when a process dies and returns the result when the graph has been completely discovered (intensionally and consciusly, check todo list).
- Calculate
time complexity
. Hint: it is linear wrt the actual distance from start to end node - Prove that the algorithm is
sound and complete
- Check
space complecity
, see if it could be an issue with huge graphs - Add options that allow to call
get_path!
and return just the first path/ only shortest etc - Make it work with
weighted
graphs
The package can be installed by adding ex_graph
to your list of dependencies in mix.exs
:
def deps do
[{:ex_graph, github: "danielmorandini/ex_graph"}]
end
If cloned, run mix test
to run all tests