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

Pysat wsum #114

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

Pysat wsum #114

wants to merge 83 commits into from

Conversation

sourdough-bread
Copy link
Collaborator

Weighted sum

  • Added case where a boolean variable-based expression is of the form a * x - b * y where a and b: sum should transform to weighted sum.
    • Moved implementation into the flattening to stay true to the user's model.
  • Added support with PySAT:
    • weighted sum interpreted as pseudo boolean constraint
    • sum encoded as a cardinality constraint

@sourdough-bread sourdough-bread requested a review from tias April 1, 2022 15:41
@tias tias self-assigned this Apr 21, 2022
Copy link
Collaborator

@tias tias left a comment

Choose a reason for hiding this comment

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

feedback

@sourdough-bread
Copy link
Collaborator Author

New version can be reviewed.

@tias
Copy link
Collaborator

tias commented Jun 8, 2022

I wanted to include it in the release I am about to make, so I made some quick cleanups (space changes, solver_vars instead of list of solver_var, a few one-line docs).

But then I noticed:

  1. there are two test failing, including in test_flatten, which need to be fixed
  2. current master is not merge into it yet, so there might be more (or less) tests failing after that.

If you could fix that, then it can be merged for the next release, it looks ready otherwise (but so there might be some subtle cases still in the new flatten code)

@hbierlee
Copy link
Contributor

hbierlee commented Feb 5, 2025

After offline discussion, the question remains whether outputting a Boolean value from linearize is still optimal (since it's not a linear; if we go this route we should update linearize's spec). An alternative solution is to return actual linears [] = 0 and [] = 1 for true/false which does (technically) adhere to the spec.

@hbierlee hbierlee marked this pull request as ready for review February 5, 2025 15:07
@hbierlee hbierlee requested review from IgnaceBleukx and tias February 5, 2025 15:07
Copy link
Collaborator

@IgnaceBleukx IgnaceBleukx left a comment

Choose a reason for hiding this comment

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

Nice! Seems like this acient PR is getting there : )
I fully agree with putting pysat directly after linearize, with the has_subexpr optimization that was merged recently, the overhead should be ok (maybe we do have to test that tho... see #512 ).

I'm not sure we need to full transformation stack however, see the comments in the files themselves.
You can also remove the old code instead of commenting it, that makes the review process (imho) a little easier

The inferrance of the p-line was not complete, so I just removed it. In
general, it is better in terms of debugging and performance to enforce
that DIMACS files are well-formed with contiguous literals and
a matching number of variables/clauses.
- Removing unneeded transformations
- Remove outdated (e.g. `mul`) and commented code
- Improve testing
- Refactor calls to PySAT's card/pb functions
- Merge duplicated behaviour in linearize/only_positive_bv
@hbierlee
Copy link
Contributor

@IgnaceBleukx I believe it's mergeable; tests seem stable and I think the code/docs are decent.

@hbierlee
Copy link
Contributor

hbierlee commented Feb 13, 2025

Working out the last unit test.

This removes the possibility of Boolean literals from the output of
linearize, which is good b/c they are not linear constraints.
@hbierlee
Copy link
Contributor

Approximately one minute later..

Now I'm a lot happier with the changes to linearize, because it is simplified by never returning Boolean literals (instead turning them into trivial constraint, linear or clausal, depending on the solver). An even better approach would be to simply fix them to their value (so they might propagate further), but I believe this is not usually done so should be left for another issue.

Copy link
Collaborator

@IgnaceBleukx IgnaceBleukx left a comment

Choose a reason for hiding this comment

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

Nice, I think the testing-infrastructure is getting pretty robust, but left some comments on the changed to linearize and the solver-interface itself

@hbierlee
Copy link
Contributor

hbierlee commented Feb 21, 2025

[nevermind]

@@ -1292,7 +1292,7 @@ def test_among(self):
iv = cp.intvar(0,10, shape=3, name="x")

for name, cls in cp.SolverLookup.base_solvers():

if name in ("pysat",): continue
Copy link
Contributor

Choose a reason for hiding this comment

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

add comment why

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.

4 participants