Graphs.jl icon indicating copy to clipboard operation
Graphs.jl copied to clipboard

Rename algorithms by what they return instead of their creator

Open gdalle opened this issue 2 years ago • 3 comments

Currently, many algorithms are not discoverable unless you know who created them. We should instead export more explicit function names, and add a type-based mechanism for dispatch with a reasonable default choice. For instance,

function dijkstra(g, v)
    ...
end

function a_star(g, v)
    ...
end

might become

struct Dijkstra end
struct Astar end

function shortest_path(::Type{Dijkstra}, g, v)
    ...
end

function shortest_path(::Type{Astar}, g, v)
    ...
end

shortest_path(g, v) = shortest_path(Dijkstra(), g, v)

gdalle avatar Jun 28 '23 10:06 gdalle

👍 for a problem bases approach instead of a solution based one.

In some cases it might also make sense to use some kind of heuristic in such a function to select the optimal algorithm.

simonschoelly avatar Jun 28 '23 19:06 simonschoelly

Although maybe shortest path with A* is not the best example, as in that case we need more parameters than for dijkstra.

simonschoelly avatar Jun 28 '23 19:06 simonschoelly

In some cases it might also make sense to use some kind of heuristic in such a function to select the optimal algorithm.

Yeah here I did a dummy example but there are some cases where preliminary checks would make sense. For instance choosing between Dijkstra and Bellman-Ford based on the presence of negative edges

gdalle avatar Jun 28 '23 20:06 gdalle