Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename algorithms by what they return instead of their creator #264

Open
gdalle opened this issue Jun 28, 2023 · 3 comments
Open

Rename algorithms by what they return instead of their creator #264

gdalle opened this issue Jun 28, 2023 · 3 comments
Labels
enhancement New feature or request
Milestone

Comments

@gdalle
Copy link
Member

gdalle commented Jun 28, 2023

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)
@simonschoelly
Copy link
Contributor

👍 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
Copy link
Contributor

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

@gdalle
Copy link
Member Author

gdalle commented Jun 28, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants