-
Notifications
You must be signed in to change notification settings - Fork 22
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
base: master
Are you sure you want to change the base?
Pysat wsum #114
Conversation
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.
feedback
New version can be reviewed. |
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:
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) |
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.
see open comments
also, we merged the transform()
refactor so pysat interface changed a bit, which needs conflict/merging.
but importantly, I want the changes to 'flatten_model.py' as a separate pull request. These are optimisations that improve the flattening, but imho can be treated independently of pysat. I think it also means that the pysat_wsum tests should become generic flatten tests?
If yes, we can merge this branch before checking the optimisations in more detail. (the preferred option)
If no, we should first get the optimisations on that separate branch right, and then merge this
@IgnaceBleukx you probably best do the resolve of test_constraints yourself |
# Conflicts: # cpmpy/solvers/pysat.py # tests/test_constraints.py
refactor to directly call the transformations split out cardinality encoding in a function so that it can also be used for implied constraints fixes #296
@IgnaceBleukx the tests indeed test bvar*bvar, which pysat does not support (and throwns an exception on now); so I had to remove 'mul' from the tests to not trigger this test. However, it also tests that for z3, which does not support it either. Note that this code is rebased on the unmerged #316, you can wait with a further code review till that one is merged. |
OK, so first, we need to check for 'out of bounds' bounds in both card/pb, as the encoding libraries simply refuse to encode a trivially true/false constraint. I might also accidentally have removed the bv < 1 support case (or it used to be in simplify_bool and now it aint no more?)... Then, all pb/cardinality expressions are expected to be of the following normalized form: From a CPMpy design that is fine: a solver interface only implements the constraint formulations it 'natively' supports. So then the question is, do we have a transformation that rewrites e.g. wsum <= var or wsum >= wsum into such 'normalized' linear constraints? But this interface is more sensitive to the creation of auxliary integer variables (e.g. for bv[0] > bv[1]+bv[2]). So how far do we want to go with this? |
Yes, we absolutely have such normalization! I think it would be best if we indeed put PySAT after linearize, but we have to adapt the transformation so it leaves simple clauses and I would simply add the case of The only potential downside of putting PySAT after linearize is the potential overhead of the transformation... Linearize is quite a beast to get through for each expression... Regarding the bounds checking for encoding, I am ok for doing it ourselves now, but I think we can also just open an issue with PySAT themselves to fix this. |
Weighted sum