-
Notifications
You must be signed in to change notification settings - Fork 145
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
Add is_semi_connected()
to rustworkx
#1215
Conversation
~rustworkx.is_semi_connected()
~rustworkx.is_semi_connected()
~rustworkx.is_semi_connected()
is_semi_connected
to rustworkx
is_semi_connected
to rustworkx
is_semi_connected()
to rustworkx
Pull Request Test Coverage Report for Build 9452263211Details
💛 - Coveralls |
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.
Rust code is looking good BUT I think we can still take advantage of multi-threading to boost our speedup compared to sequential libraries. Let me know if you have more questions.
The tests are good but I think we should add some larger inputs. Our generators can help with that
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.
LGTM, just leaving one final comment about removing has_path_connecting
for something simpler
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.
I left a comment on a test case that is wrong, the condition is simpler, we check only one direction not both
Co-authored-by: Ivan Carvalho <8753214+IvanIsCoding@users.noreply.github.com>
Co-authored-by: Ivan Carvalho <8753214+IvanIsCoding@users.noreply.github.com>
Co-authored-by: Ivan Carvalho <8753214+IvanIsCoding@users.noreply.github.com>
I fixed clippy due to the Rust update to 1.79, sorry for the inconvenience. Let's hope CI passes now. |
Pull Request Test Coverage Report for Build 9558747991Details
💛 - Coveralls |
So some test cases were not correct, I pushed the test cases I believe are correct (you can double check with NetworkX, every path graph should be semi connected). So let's focus on finding the bug and making the test cases pass. |
|
The disconnected graph was my mistake, but graphs like We can use the |
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.
After thinking about the problem more thoroughly, I am jumping in to implement is_semi_connected
in a way that reuses almost 100% of our existing code.
I apologize for not thinking about it earlier, but the condition of u->v
for each vertex of the NetworkX implementation is simply checking that there is a path covering all vertices in the DAG. It turns out that longest_path
that we recently moved to be pure Rust code in #1192 does exactly that! So the NetworkX check is equivalent to seeing if there is a longest path with N-1
nodes in a DAG of N
nodes.
Thanks a lot of for writing the original code! I know it ended up not being the original idea but this process led us to implement the least amount of code possible, which will be simpler to maintain in the future.
match longest_path(&condensed, weight_fn) { | ||
Ok(path_len) => { | ||
if let Some(path_len) = path_len { | ||
Ok(path_len.1 == n - 1) | ||
} else { | ||
Ok(false) | ||
} | ||
} | ||
Err(_) => Err(PyValueError::new_err("Graph could not be condensed")), | ||
} |
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.
This is equivalent to checking the chain of u->v
from NetworkX
Pull Request Test Coverage Report for Build 9575905154Details
💛 - Coveralls |
Implemented the is_semi_connected function, I don't believe it's fully ready to go so I would appreciate feedback regarding my changes, and any more tests I can add, and etc. Followed implementation from definition: https://networkx.org/documentation/stable/reference/algorithms/generated/networkx.algorithms.components.is_semiconnected.html#networkx.algorithms.components.is_semiconnected
Fixes #446