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
feat: igraph_is_complete #2510
feat: igraph_is_complete #2510
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2510 +/- ##
==========================================
- Coverage 84.37% 84.37% -0.01%
==========================================
Files 374 375 +1
Lines 61881 61608 -273
Branches 0 12055 +12055
==========================================
- Hits 52212 51980 -232
+ Misses 9669 9628 -41
... and 111 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
Let me know when this is ready for review. To fix the CodeQL CI failure, you can rebase on the latest |
f87c0f8
to
6fb6749
Compare
It can be reviewed now, or I can add the support for directed graphs, or even |
I had a look at the code (not the test though). Generally, it is very well written. Regarding the ordering of neighbour lists: it is indeed guaranteed that these are sorted. This is documented for We are missing support for directed graphs. Can you please add this? Regarding running Thus I agree with you that this is a good way to implement One more thing that is missing is an overflow check when computing the largest possible number of edges. What if Maybe instead of computing it, we can just assume that we're working with either standard 32-bit or 64-bit signed integers, and hard-code the limit for these two cases, similar to how it's done here: Lines 74 to 82 in 07d794d
|
So, in the undirected case, the max possible In the directed case, this will be A graph with a |
Finally, we still need to be smart about computing complete_ecount = vcount % 2 == 0 ? (vcount/2) * (vcount - 1) : vcount * ((vcount-1)/2) This won't overflow, assuming that the result is representable, which we will be checking earlier. |
I agree. It's unlikely that we'll ever want to support architectures that are not 32-bit or 64-bit anyway. |
6fb6749
to
fa1f36b
Compare
Thank you for the review.
I did not mean the neighbour list, but the list of all edges in the graph, iterated on according to edge ID. Those are not always sorted according to the "lowest adjacent vertex -- highest adjacent vertex" scheme I was mentioning, unless I'm mistaken. I asked because it would have allowed to count the edges directly on this list, rather than rely on
Done.
This was most useful, I am glad not to have had to do this myself. I've added a comment on how those numbers are produced.
This was very smart indeed, it is guaranteed to be very cheap. I think that the result of this function should be cached in a cache entry "is_complete". If you agree, I will add a placeholder comment to remind myself to add caching once you're finished refactoring it. |
1babfbc
to
83b87c5
Compare
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 added a few comments, but haven't had time to examine the test in detail yet.
Can you please include this function in the docs? I suggest adding it in docs/cliques.xxml
. Feel free to propose a different location if you find one.
I'll get back to this later, including answering your questions.
I thought about this a bit, and it seems to me that this property would not be needed very often. If the graph is simple, caching that already achieved O(1). So caching whether the graph is complete is relevant only for multigraphs. The original motivation for caching was to avoid running the most common checks multiple times. There are several functions which need to check if the graph is simple, or connected, before running their algorithm. Thus these checks were frequently run redundantly. Do you have a use case in mind where it is important to not repeat complete graph checks on a multigraph? |
1d512b3
to
836f278
Compare
836f278
to
a10f4fd
Compare
Done. I'm fine with adding it there, but then maybe I should change the header file in which it is declared ? I'll let you decide.
I refactored the unit test, added comments, and used the occasion to remove all the unneeded memory management and calls to
Agreed. But in that case, we should try and cache the simplicity of a graph wherever we can. For instance, a graph generated with
No. I do not use multigraphs. I agree with your decision to not cache the completeness. But then, see my other point about caching simplicity much more aggressively (I can help track the places where this can be done, if you want). |
@ntamas What do you think about adding an |
I'd be lying if I said I wasn't very tempted to do this, but experience has taught us that there is a rather high risk of introducing bugs. Caching bugs can have very bad consequences and could be very difficult to debug. Examples:
I do wonder if IMO keeping track of whether graphs are simple would be a huge benefit. Lots of checks become easier for simple graphs. EDIT: Opened an issue, #2522 |
Seems OK to me, we do this in many other places. But I th9nk we can merge the current PR as is and then we can add this later, right? |
Yes, it is marked as experimental. |
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.
Okay, this looks good to me then.
chore: update changelog feat: igraph_is_complete() checks if a graph is complete (igraph/igraph#2510) Merge pull request igraph/igraph#2525 from igraph/fix/linegraph-keep-loops do not generate full scanner tables with flex chore: improve readability of some code refactor: igraph_degree() now uses the cache when checking for self-loops refactor: minor readability cleanup for minimum_size_separators() chore: add note about empty minimal st separator fix tests: minor cleanup in regression tests chore: update changelog fix: correct `is_(minimal_)separator()` for disconnected graphs, fixes igraph/igraph#1480 tests: add more `is_separator()` tests tests: fix premature memory deallocation in is_separator example fix: igraph_all_minimal_st_separators() does not return empty separators any more, fixes igraph/igraph#2517 fix: GraphML reader does not accept duplicate attribute names any more, fixes igraph/igraph#2506 fuzzing: assertion readability in vertex separator fuzzer fuzzing: improve vertex separator fuzzers docs: doc improvements for ECC and Voronoi refactor: minor prettification in trie code fix: assert that keys in a trie are not NULL to make Coverity happy refactor: improved error messages from C attribute handler (igraph/igraph#2513) chore: updated changelog fix: prevent insertion of empty keys in a trie fix: prevent empty ID attributes for <key> tags in GraphML docs: change mentions to pointer vectors to vector lists where appropriate & other improvements fix: -CF causes buffer overflows with Flex, try -Cf instead fix: bug_2506 test case should not be run if igraph is compiled without GraphML support ci: run apt-get update in codeql-analysis pipeline fix: fix attribute value comparison in igraph_read_graph_graphml() fix: fix duplicate attribute detection in igraph_read_graph_graphml(), fixes igraph/igraph#2506 refactor: make use of IGRAPH_CHECK_OOM() in a few places style: fix wording for a few warnings refactor: more detailed error messages in C attribute handler refactor: experimental `-Cf` option for Flex for better performance at the cost of larger code size. Hopefully this avoids fuzzer timeouts. fix: `igraph_disjoint_union()` and `igraph_disjoint_union_many()` now check for overflow chore: Update CONTRIBUTING.md fuzzing: expand file format round-tripping fuzzers fix: disallow writing invalid graph attributes to GML files, fixes igraph/igraph#2505 fuzzing: write_all fuzzer fixes refactor: remove non-exposed igraph_maximum_matching() function whihc was already noted as removed in the 0.10 changelog fuzzing: activate write_all fuzzer fuzzing: add cohesive_blocks() Merge pull request igraph/igraph#2504 from igraph/fix/writing-invalid-lgl-ncol-files docs: document that `write_graph_graphml()` assumes that strings are UTF-8 encoded, fixes igraph/igraph#2503 docs: mention that the variation of information is in natural units
chore: update changelog feat: igraph_is_complete() checks if a graph is complete (igraph/igraph#2510) Merge pull request igraph/igraph#2525 from igraph/fix/linegraph-keep-loops do not generate full scanner tables with flex chore: improve readability of some code refactor: igraph_degree() now uses the cache when checking for self-loops refactor: minor readability cleanup for minimum_size_separators() chore: add note about empty minimal st separator fix tests: minor cleanup in regression tests chore: update changelog fix: correct `is_(minimal_)separator()` for disconnected graphs, fixes igraph/igraph#1480 tests: add more `is_separator()` tests tests: fix premature memory deallocation in is_separator example fix: igraph_all_minimal_st_separators() does not return empty separators any more, fixes igraph/igraph#2517 fix: GraphML reader does not accept duplicate attribute names any more, fixes igraph/igraph#2506 fuzzing: assertion readability in vertex separator fuzzer fuzzing: improve vertex separator fuzzers docs: doc improvements for ECC and Voronoi refactor: minor prettification in trie code fix: assert that keys in a trie are not NULL to make Coverity happy refactor: improved error messages from C attribute handler (igraph/igraph#2513) chore: updated changelog fix: prevent insertion of empty keys in a trie fix: prevent empty ID attributes for <key> tags in GraphML docs: change mentions to pointer vectors to vector lists where appropriate & other improvements fix: -CF causes buffer overflows with Flex, try -Cf instead fix: bug_2506 test case should not be run if igraph is compiled without GraphML support ci: run apt-get update in codeql-analysis pipeline fix: fix attribute value comparison in igraph_read_graph_graphml() fix: fix duplicate attribute detection in igraph_read_graph_graphml(), fixes igraph/igraph#2506 refactor: make use of IGRAPH_CHECK_OOM() in a few places style: fix wording for a few warnings refactor: more detailed error messages in C attribute handler refactor: experimental `-Cf` option for Flex for better performance at the cost of larger code size. Hopefully this avoids fuzzer timeouts. fix: `igraph_disjoint_union()` and `igraph_disjoint_union_many()` now check for overflow chore: Update CONTRIBUTING.md fuzzing: expand file format round-tripping fuzzers fix: disallow writing invalid graph attributes to GML files, fixes igraph/igraph#2505 fuzzing: write_all fuzzer fixes refactor: remove non-exposed igraph_maximum_matching() function whihc was already noted as removed in the 0.10 changelog fuzzing: activate write_all fuzzer fuzzing: add cohesive_blocks() Merge pull request igraph/igraph#2504 from igraph/fix/writing-invalid-lgl-ncol-files docs: document that `write_graph_graphml()` assumes that strings are UTF-8 encoded, fixes igraph/igraph#2503 docs: mention that the variation of information is in natural units
Follow-up of #2490.