-
Notifications
You must be signed in to change notification settings - Fork 157
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 Left-Right Planarity test. #475
Conversation
This commit implements a new function `is_planar` that checks if an undirected graph can be drawn in a plane without any edge intersections. The planarity check algorithm is based on the Left-Right Planarity Test. Reference: http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.217.9208
Marking this on hold since it depends on #456. |
Pull Request Test Coverage Report for Build 2064399819
💛 - Coveralls |
After #497, you can use the new generator to make some test cases. Table 2 of https://www.sciencedirect.com/science/article/pii/S0166218X08000371 has the crossing numbers of the Petersen graphs, zeros in the table are planar and the rest aren't |
@georgios-ts is there any update on this? It would be good to get this rebased as @enavarro51 is starting to look at adding a |
@mtreinish This should be ready for review now. |
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.
@georgios-ts. It was suggested by @mtreinish that I review this PR more as a process of learning. To start with some high-level questions
is_planar
is inretworkx-core
. Is there a reason it's there instead ofretworkx
? It seems this would be a function accessed externally the same asplanar_layout
might be.- The
networkx
approach creates the embedding at the same time the planarity test is being done. Is there a reason you only did the planarity test? As in, do you think the creation of the embedding should be separate from the planarity test, or incorporated within it? - My current plan is to create a
PlanarEmbedding
struct and associated methods mirroring what is done innetworkx
and then when your PR is merged, to add the hooks to create the embedding withinlr_planar.rs
code. This would be followed by writing thecombinatorial_embedding_to_pos
function. Does this seem like a reasonable approach? - Thanks.
@enavarro51 Thanks for taking the time to look into this.
If you have any other questions feel free to reach out. |
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.
Thanks, @georgios-ts (and good QAs with @enavarro51, the previous comments helped my review a lot.) This PR looks good to me. I mainly reviewed it from an algorithmic point of view especially comparing with the networkx implementation. It implements a planarity check algorithm using the visitor pattern in two depth-first searches nicely. I think that is making the code quite readable and also useful for another PRs such as #645. I've left a few minor comments inline but I think none of them would prevent from merging this after resolving conflicts.
retworkx-core/tests/planar.rs
Outdated
use retworkx_core::petgraph::graph::UnGraph; | ||
use retworkx_core::planar::is_planar; | ||
|
||
#[test] |
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.
Those tests look well-isolated to the module so we could put them in #[cfg(test)]
block in /src/planar/lr_planar.rs
as suggested in #587 (comment)
Pull Request Test Coverage Report for Build 3148280248
💛 - 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.
LGTM, I think having readable code for a long algorithm implementation like this one is a huge plus.
I am also confident on the implementation because of the tests. I think we cover a good amount of them, and further in #645 we have planar layout tests building on top of this so I believe this is good to merge
This commit implements a new function
is_planar
thatchecks if an undirected graph can be drawn in a plane without any edge
intersections. The planarity check algorithm is based on the
Left-Right Planarity Test.
Reference: http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.217.9208