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

Floyd-Warshall algorithm #98

Merged
merged 47 commits into from
Sep 27, 2023
Merged

Floyd-Warshall algorithm #98

merged 47 commits into from
Sep 27, 2023

Conversation

Hromz
Copy link
Contributor

@Hromz Hromz commented Sep 24, 2023

Added Floyd-Warshall alogorithm, tests and docs.

@codecov
Copy link

codecov bot commented Sep 24, 2023

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Files Coverage Δ
test/graaflib/algorithm/floyd_warshall_test.cpp 100.00% <100.00%> (ø)
...raaflib/algorithm/shortest_path/floyd_warshall.tpp 95.83% <95.83%> (ø)

... and 2 files with indirect coverage changes

📢 Thoughts on this report? Let us know!.

@Hromz Hromz mentioned this pull request Sep 24, 2023
6 tasks
@bobluppes bobluppes self-requested a review September 24, 2023 20:08
@bobluppes bobluppes added the enhancement New feature label Sep 24, 2023
Copy link
Owner

@bobluppes bobluppes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very good already!
I will take a closer look tomorrow but wanted to provide some early feedback :)

Comment on lines 33 to 39
template <typename V, typename E, graph_type T, typename WEIGHT_T>
std::vector<std::vector<WEIGHT_T>> floyd_warshall_shortest_paths(
const graph<V, E, T>& graph) {
WEIGHT_T ZERO{};
std::size_t n = graph.vertex_count();
auto INF = std::numeric_limits<WEIGHT_T>::max();
auto NO_PATH = std::numeric_limits<WEIGHT_T>::min();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding using std::numeric_limits<WEIGHT_T>::min() for vertex pairs between which we cannot find a path (i.e. vertices in negative weight cycles), consider the case where the WEIGHT_T is an unsigned type.

In that case, the caller cannot distinguish between a NO_PATH and a true distance of 0. However, I do not see an elegant way of handling this. What do you think about removing the negative cycle detection, as it is also documented on the interface that the algorithm does not work in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I didn't see this one. My bad. I'll fix it right away. Agreed, we could move it to a different PR as Floyd-Warshall negative cycle detection so results will be less confusing. And in this case, NO_PATH will no longer be needed.

I look forward to your next comments about PR. :)

Copy link
Owner

@bobluppes bobluppes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this, LGTM 🚀

@bobluppes bobluppes merged commit 6e38b83 into bobluppes:main Sep 27, 2023
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants