Skip to content
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

PR for issue 32136: Add parameter 'induced' to connected_subgraphs_iterator #35131

Merged
merged 12 commits into from
Mar 26, 2023

Conversation

dcoudert
Copy link
Contributor

@dcoudert dcoudert commented Feb 14, 2023

Fixes #32136

@dcoudert
Copy link
Contributor Author

This is my first PR on GitHub. Not obvious for dummies...
So far I don't understand how to add labels, but this branch is ready for review.

@codecov-commenter
Copy link

codecov-commenter commented Feb 14, 2023

Codecov Report

Patch coverage: 97.95% and no project coverage change

Comparison is base (52a81cb) 88.57% compared to head (9d177a5) 88.58%.

Additional details and impacted files
@@            Coverage Diff            @@
##           develop   #35131    +/-   ##
=========================================
  Coverage    88.57%   88.58%            
=========================================
  Files         2140     2140            
  Lines       397273   397415   +142     
=========================================
+ Hits        351891   352052   +161     
+ Misses       45382    45363    -19     
Impacted Files Coverage Δ
src/sage/schemes/elliptic_curves/ell_generic.py 93.11% <66.66%> (-0.12%) ⬇️
src/sage/interfaces/tachyon.py 87.93% <90.00%> (+0.43%) ⬆️
src/sage/schemes/elliptic_curves/gal_reps.py 82.23% <90.00%> (+0.04%) ⬆️
src/sage/quadratic_forms/quadratic_form.py 90.26% <95.65%> (+0.16%) ⬆️
src/sage/modular/quasimodform/element.py 99.20% <100.00%> (+0.06%) ⬆️
src/sage/rings/qqbar.py 95.30% <100.00%> (+<0.01%) ⬆️
src/sage/schemes/affine/affine_morphism.py 90.33% <100.00%> (ø)
src/sage/schemes/elliptic_curves/BSD.py 43.75% <100.00%> (+0.21%) ⬆️
src/sage/schemes/elliptic_curves/cardinality.py 87.54% <100.00%> (+0.93%) ⬆️
src/sage/schemes/elliptic_curves/cm.py 89.52% <100.00%> (+0.39%) ⬆️
... and 70 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@mkoeppe
Copy link
Contributor

mkoeppe commented Feb 14, 2023

So far I don't understand how to add labels

I've sent you an invite for the team that has the permissions for that

Copy link
Contributor

@videlec videlec left a comment

Choose a reason for hiding this comment

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

I do not quite understand why you use here the dense datastructure rather than the sparse one. Since you need to iterate as fast as possible over the list of vertices the latter naively seems more appropriate to me.

# If vertex u has k active neighbors, we have 2^k possibilities. We
# use the binary representation of n_cpt[i] to indicate which of the
# k neighbors are selected. We omit the empty neighborhood which is
# considered else where.
Copy link
Contributor

Choose a reason for hiding this comment

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

"else where" -> "elsewhere"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, this iterator was already using dense data structure, so I added the functionality in it. We can of course try to do the same with another data structure and compare performances, but this should be done in a separate issue/PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see.

Copy link
Contributor

@videlec videlec left a comment

Choose a reason for hiding this comment

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

Isn't the following naive algorithm (theoretically) optimal

  • pick an edge e
  • put e in H, merge its two ends in G and make a recursive call
  • remove e from G, if the resulting graph is connected make a recursive call

Here by optimal, I mean that it explores no more edges than what is needed. Though, it does not seem delicate to make many efficient calls to connectedness + design an appropriate datastructure with efficient merge/removal.

src/sage/graphs/base/static_dense_graph.pyx Show resolved Hide resolved
src/sage/graphs/base/static_dense_graph.pyx Show resolved Hide resolved
@github-actions
Copy link

github-actions bot commented Mar 4, 2023

Documentation preview for this PR is ready! 🎉
Built with commit: 9d177a5

@dcoudert
Copy link
Contributor Author

dcoudert commented Mar 4, 2023

@videlec, I'm not sure what you want to compute with the algorithm you propose. With edge contraction, you may force the selection of some edges. For instance, if you have the triangle [1, 2, 3], after contracting edge (1, 2), you can either take both edges (1, 3) and (2, 3), or none of them. So I think you may miss some non-induced connected subgraphs.

@videlec
Copy link
Contributor

videlec commented Mar 5, 2023

@videlec, I'm not sure what you want to compute with the algorithm you propose. With edge contraction, you may force the selection of some edges. For instance, if you have the triangle [1, 2, 3], after contracting edge (1, 2), you can either take both edges (1, 3) and (2, 3), or none of them. So I think you may miss some non-induced connected subgraphs.

You indeed need to keep track edge multiplicities in the contracted graph. Once you contracted e = (1, 2), taking either (1, 3), (2, 3) or both makes no difference in G / e. "Choosing an edge e" should be replaced by "choose a non-empty subset of edges in the multiedge e".

@dcoudert
Copy link
Contributor Author

dcoudert commented Mar 5, 2023

Does not seems easy to implement. This can be the object of a future PR.

@videlec
Copy link
Contributor

videlec commented Mar 5, 2023

Does not seems easy to implement.

Sure. I would be delighted to know if there is a generation algorithm with O(1) delay!

This can be the object of a future PR.

I definitely agree :-)

@dcoudert
Copy link
Contributor Author

dcoudert commented Mar 5, 2023

I don't think that O(1) delay is possible as you need to check connectivity after each edge deletion.

@videlec
Copy link
Contributor

videlec commented Mar 5, 2023

I don't think that O(1) delay is possible as you need to check connectivity after each edge deletion.

Maybe an adaptation of : https://dl.acm.org/doi/10.1145/322234.322235?

@vbraun vbraun merged commit e6bc06f into sagemath:develop Mar 26, 2023
@mkoeppe mkoeppe added this to the sage-10.0 milestone Mar 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add parameter 'induced' to connected_subgraphs_iterator
6 participants