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

Performance improvement idea for cardinality constraint encoders #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

drasive
Copy link

@drasive drasive commented Jan 16, 2023

Improves encode_at_most_k_constraint_binomial execution speed while keeping the output the same:

  • itertools.combinations is faster than the custom implementation.
  • Negating the input of subsets_of_size_k is faster than negating the output, as the input is smaller.

encode_at_most_k_constraint_binomial(...) is now a generator. Some callers expect the return value to be a list, the call needs to be wrapped in list(encode_at_most_k_constraint_binomial(...)) there. I did not integrate these changes with other parts of the code, I expect there are additional places where this needs to happen, so this PR can not be merged without some adjustments but may be useful to some.

Negating the input of subsets_of_size_k is faster than negating the output, as the input is smaller.
encode_at_most_k_constraint_binomial is now a generator, so we need to wrap it in list() where needed.
@drasive drasive changed the title Performance improvements cardinality constraint encoders Performance improvements for cardinality constraint encoders Jan 16, 2023
@drasive drasive changed the title Performance improvements for cardinality constraint encoders Performance improvements idea for cardinality constraint encoders Jan 20, 2023
@drasive drasive changed the title Performance improvements idea for cardinality constraint encoders Performance improvement idea for cardinality constraint encoders Jan 20, 2023
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.

1 participant