Skip to content

Implement giant component and percolation#2746

Closed
Zepeacedust wants to merge 27 commits intoigraph:masterfrom
Zepeacedust:master
Closed

Implement giant component and percolation#2746
Zepeacedust wants to merge 27 commits intoigraph:masterfrom
Zepeacedust:master

Conversation

@Zepeacedust
Copy link
Copy Markdown
Contributor

@Zepeacedust Zepeacedust commented Apr 7, 2025

  • By submitting this pull request, I assign the copyright of my contribution to The igraph development team.

Closes #2736

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 7, 2025

Codecov Report

Attention: Patch coverage is 0% with 24 lines in your changes missing coverage. Please review.

Project coverage is 75.37%. Comparing base (fc6860b) to head (6db2bab).
Report is 17 commits behind head on master.

Files with missing lines Patch % Lines
src/misc/percolation.c 0.00% 24 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2746      +/-   ##
==========================================
- Coverage   75.38%   75.37%   -0.02%     
==========================================
  Files         379      380       +1     
  Lines       55128    55179      +51     
  Branches    12320    12330      +10     
==========================================
+ Hits        41559    41589      +30     
- Misses      10017    10040      +23     
+ Partials     3552     3550       -2     
Files with missing lines Coverage Δ
src/misc/percolation.c 0.00% <0.00%> (ø)

... and 9 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fc6860b...6db2bab. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment on lines +65 to +66
IGRAPH_EXPORT igraph_error_t igraph_bond_percolation(const igraph_t *graph, igraph_vector_t * output);
IGRAPH_EXPORT igraph_error_t igraph_site_percolation(const igraph_t *graph, igraph_vector_t * output);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move these to igraph_components.h

Comment on lines +22 to +23
IGRAPH_EXPORT igraph_error_t igraph_bond_percolation(const igraph_t *graph, igraph_vector_t * output);
IGRAPH_EXPORT igraph_error_t igraph_site_percolation(const igraph_t *graph, igraph_vector_t * output);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First step is to discuss the prototype. It's best if we do this in the issue. I'll post there.

Comment on lines +44 to +56
IGRAPH_CHECK(igraph_vector_int_init(&sizes, vert_count));
igraph_vector_int_t links;
IGRAPH_CHECK(igraph_vector_int_init(&links, vert_count));

int edge_count = igraph_vector_int_size(edges) / 2;
IGRAPH_CHECK(igraph_vector_int_resize(output, edge_count));

for (int i = 0; i < edge_count; i++) {
igraph_i_percolate_edge(&links, &sizes, &biggest, VECTOR(*edges)[2*i], VECTOR(*edges)[2*i+1]);
VECTOR(*output)[i] = biggest;
}
igraph_vector_int_destroy(&sizes);
igraph_vector_int_destroy(&links);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
IGRAPH_CHECK(igraph_vector_int_init(&sizes, vert_count));
igraph_vector_int_t links;
IGRAPH_CHECK(igraph_vector_int_init(&links, vert_count));
int edge_count = igraph_vector_int_size(edges) / 2;
IGRAPH_CHECK(igraph_vector_int_resize(output, edge_count));
for (int i = 0; i < edge_count; i++) {
igraph_i_percolate_edge(&links, &sizes, &biggest, VECTOR(*edges)[2*i], VECTOR(*edges)[2*i+1]);
VECTOR(*output)[i] = biggest;
}
igraph_vector_int_destroy(&sizes);
igraph_vector_int_destroy(&links);
IGRAPH_CHECK(igraph_vector_int_init(&sizes, vert_count));
IGRAPH_FINALLY(igraph_vector_int_destroy, &sizes);
igraph_vector_int_t links;
IGRAPH_CHECK(igraph_vector_int_init(&links, vert_count));
IGRAPH_FINALLY(igraph_vector_int_destroy, &links);
int edge_count = igraph_vector_int_size(edges) / 2;
IGRAPH_CHECK(igraph_vector_int_resize(output, edge_count));
for (int i = 0; i < edge_count; i++) {
igraph_i_percolate_edge(&links, &sizes, &biggest, VECTOR(*edges)[2*i], VECTOR(*edges)[2*i+1]);
VECTOR(*output)[i] = biggest;
}
igraph_vector_int_destroy(&sizes);
igraph_vector_int_destroy(&links);
IGRAPH_FINALLY_CLEAN(2);

IGRAPH_FINALLY places an object and a destructor on a stack which we call the "finally" stack.

If an error occurs, all destructors currently on the stack are called. This way allocated resources are freed even if the function returns early because of an error.

IGRAPH_FINALLY_CLEAN(2) removes the elements from this stack. This always comes after you manually called destructors, in this case two destructors.

There's a shorthand for the following pattern:

    IGRAPH_CHECK(igraph_vector_int_init(&sizes, vert_count));
    IGRAPH_FINALLY(igraph_vector_int_destroy, &sizes);

We usually just write

   IGRAPH_VECTOR_INT_INIT_FINALLY(&sizes, vert_count);

This is what you should use here, as well as with vector types, but such a macro is not available for all data structures, so I wanted to show you the separated init + FINALLY pattern as well.

Zepeacedust and others added 22 commits April 11, 2025 19:12
This reverts commit 6ce30a6.
@Zepeacedust Zepeacedust mentioned this pull request Jun 24, 2025
9 tasks
@szhorvat
Copy link
Copy Markdown
Member

Continued in #2778

@szhorvat szhorvat closed this Jun 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wishlist: Giant component and percolation

2 participants