-
Notifications
You must be signed in to change notification settings - Fork 46
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
Refactor Floyd–Warshall C implementation #657
Merged
james-d-mitchell
merged 1 commit into
digraphs:main
from
mtorpey:refactor-c-floyd-warshall
Jun 19, 2024
Merged
Refactor Floyd–Warshall C implementation #657
james-d-mitchell
merged 1 commit into
digraphs:main
from
mtorpey:refactor-c-floyd-warshall
Jun 19, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I've run Valgrind on this, but I'm not exactly sure how to read the output. I can at least say that every line that starts Reveal full output
|
james-d-mitchell
approved these changes
Jun 19, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, thanks @mtorpey
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In digraphs.c we have a
FLOYD_WARSHALL
function that does a generalised version of the Floyd–Warshall algorithm with various options that customise the output. As noted in comments, some of this was rather hacky, with flags for special cases that return a totally different type of object early in the function and so on.This PR adds a
post
parameter to FLOYD_WARSHALL, which takes a post-processing function that inspects the state of the distance matrix and produces a final output. So far we have threepost
functions:FW_POST_DIAMETER
, used byDIGRAPH_DIAMETER
(returns the highest number in the matrix, or fail)FW_POST_HAS_CHANGED
used byIS_TRANSITIVE_DIGRAPH
(returns a bool saying whether the matrix was changed in the main loop)FW_POST_DISTANCES
, used by the other functions (returns the distance matrix as a GAP object)and more could be added. This replaces the
diameter
andcopy
parameters which previously hard-coded some of this into the function.There are also some readability improvements, basically changing variable names to describe what they do:
dist1
anddist2
are nownonEdgeDist
andedgeDist
shortest
is nowzeroEdgeDist
copy
is nowkeepCopy
, and is now used for nothing but creating a copy ofdist
.adj
is nowdistCopy
(it's just a copy ofdist
)out
was previously used for two things: out neighbours and function output. This is now split intoneighbours
andout
.This will be a useful first step towards making the function more configurable, which might be useful for edge-weighted algorithms later.