Add Left-Right Planarity Test Algorithm to NetworKit#1276
Add Left-Right Planarity Test Algorithm to NetworKit#1276fabratu merged 45 commits intonetworkit:masterfrom
Conversation
…e default constructor of Edge class constepxr.
angriman
left a comment
There was a problem hiding this comment.
Thank you for your contribution! I left some comments, most of them are just minor style changes to be consistent with the rest of the codebase.
|
Hi @angriman, Thank you for your feedback! I’d like to provide some context and arguments for the choice of graph sizes in the tests and the use of many test cases:
Given these reasons, I’d appreciate it if we could retain the current test cases in the file What do you think? |
There are positives and negatives about having random generated graphs for testing. In the past it helped us discover some quite subtle bugs. However, sometimes these can come from the generators itself, leading to the case that a test implicitly checks the functionalities of different code units. Also you can not predict when these errors turn up. Overall there are better systems to generate these tests, but these would need a complete pipeline overhaul. We had more bugs in algorithms / core functionalities which only use a pre-defined set of graphs, since these are often too narrow to cover all corner-cases and are tailored around the original use-cases of the algorithm. Therefore I would not drop the strategy of testing random graphs. It is true though that this one algorithm does incorporate a lot of generated graphs. While fast for now, running times can explode when new features are encoded or data structures change. I would therefore suggest to drop some redundancy / cases. As a rule of thumb, most algorithms don't test for more than 10 different graphs. |
Hi @farbratu, Thank you for your detailed feedback! I have to admit that I might not have fully grasped all the concerns raised by @angriman. Thank you for providing additional context and suggestions.
Before I proceed, is the above proposal acceptable for you guys? |
I agree that testing on random graphs is very helpful for finding bugs in the algorithm you are developing (I've used them a lot in the past). However, I think that, when possible, they should not be part of unit tests because of the following reasons (more about testing best practices can be found in [1]):
My recommendation is to test on a fixed and representative set of instances to evaluate that the algorithm behaves as intended. I understand that sometimes this is easier said than done because the algorithm may be complex. If that's the case, we can keep tests on random graphs. Regarding large graphs: it's ok to have individual tests on larger instances (you can also use those in the input/ directory in NetworKit). What I'm against is writing a unit test with 50+ lines used for graph edges, which makes it impossible for a future reader to understand what's going on. Why do you need do define such a large graph? What kind of behavior are you trying to test that cannot be tested with a smaller instance? If you just need to test your algorithm on a larger graph, then my recommendation is to replace the custom graphs with 50+ nodes ( Let me know if you have further questions! |
Thank you for the detailed explanation of your concerns. I considered the large graphs of the input folder before but shied away from the effort to independently determine if they are planar or not. I will go ahead and try while removing the "random graphs" from the unit tests. For the "typed graphs" I will reduce the number of generated graphs as proposed above and reorganize the tests to focus on specific behaviors. Thank your for the link to the article. It was a great read and a helpful reminder of best practices. |
…esults checked with independent tools.
angriman
left a comment
There was a problem hiding this comment.
Thank you for addressing the comments, I left a few minor ones, the rest LGTM.
|
A side-comment: The error in the pipeline for the aarch64 wheel build is fixed in PR #1283 and can be ignored concerning the finish state of this PR. |
|
There are still unresolved comments (e.g., |
Sorry. They should all be marked as Outdated. I will go through and resolve them. |
Overview
This PR introduces an implementation of the Left-Right Planarity Test algorithm, which is used to determine whether a given graph is planar. The implementation was guided by the paper "The Left-Right Planarity Test" as well as the corresponding implementation in NetworkX.
Unit Tests
To ensure correctness and robustness, I have included 18 unit tests for the algorithm. However, given the complexity of the problem, I would be happy to add more test cases with known outcomes if provided or suggested.
Graph API Extension
I added a new method,
sortNeighbors, to theGraphclass. This method sorts the neighbors of a graph node based on a binary predicate, and I have included a corresponding unit test for this functionality. However, it’s possible that this could be achieved with existing APIs, and I would appreciate guidance if such an alternative already exists.Notes
This PR represents my first feature contribution to NetworKit. There is likely room for optimization, and I welcome any feedback or suggestions for improvement.
I look forward to your review and guidance to help refine this contribution.