-
Notifications
You must be signed in to change notification settings - Fork 35
Xor decomp simpl #908
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
base: master
Are you sure you want to change the base?
Xor decomp simpl #908
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -859,12 +859,12 @@ def test_div(self): | |
| assert all_sols == decomp_sols# same on decision vars | ||
| assert count == decomp_count# same on all vars | ||
|
|
||
| def test_xor(self): | ||
| def test_xor(self, solver): | ||
| bv = cp.boolvar(5) | ||
| assert cp.Model(cp.Xor(bv)).solve() | ||
| assert cp.Model(cp.Xor(bv)).solve(solver=solver) | ||
| assert cp.Xor(bv).value() | ||
|
|
||
| def test_xor_with_constants(self): | ||
| def test_xor_with_constants(self, solver): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought you had to use the pytest fixture for this to work?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agent says that tests/conftest.py defines it for all tests... @ThomSerg can you confirm that just adding 'solver' here (without the fixture being mentioned on the function nor the class) will work because the conftest does it at project level? |
||
|
|
||
| bvs = cp.boolvar(shape=3) | ||
|
|
||
|
|
@@ -879,17 +879,18 @@ def test_xor_with_constants(self): | |
| expr = cp.Xor(args) | ||
| model = cp.Model(expr) | ||
|
|
||
| assert model.solve() | ||
| assert model.solve(solver=solver) | ||
| assert expr.value() | ||
|
|
||
| # also check with decomposition | ||
| model = cp.Model(expr.decompose()) | ||
| assert model.solve() | ||
| assert model.solve(solver=solver) | ||
| assert expr.value() | ||
|
|
||
| # edge case with False constants | ||
| assert not cp.Model(cp.Xor([False, False])).solve() | ||
| assert not cp.Model(cp.Xor([False, False, False])).solve() | ||
| assert not cp.Model(cp.Xor([False, False])).solve(solver=solver) | ||
| assert not cp.Model(cp.Xor([False, False, False])).solve(solver=solver) | ||
| assert cp.Model(cp.Xor([False, True, False])).solve(solver=solver) | ||
|
|
||
| def test_ite_with_constants(self): | ||
| x,y,z = cp.boolvar(shape=3) | ||
|
|
||
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.
What happens if
new_args[-1]is an expression? Then it will introduce a complex negation, right?Ideally, we want to negate a variable here (see the
.negate()of xor).If there is no variable in any of the args, we can indeed negate this one, but we'll have to run
push_down_negationagain once we move that transformation before decompose (which I currently have in a local branch)