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

OR-tools gives UNSAT while SAT #211

Closed
IgnaceBleukx opened this issue Jan 18, 2023 · 3 comments · Fixed by #275
Closed

OR-tools gives UNSAT while SAT #211

IgnaceBleukx opened this issue Jan 18, 2023 · 3 comments · Fixed by #275

Comments

@IgnaceBleukx
Copy link
Collaborator

Given in the zip file is a model for which OR-tools returns UNSAT.

However, there does exist a model, which I have filled in by fixing vars, then OR-tools does return SAT as it should be.

Either this is an issue in our _post_constraint but it looks like an OR-tools issue...
models.zip

@IgnaceBleukx
Copy link
Collaborator Author

Did some more digging, it looks like an OR-tools issue indeed. Will post on their github page.
I ran all constraints trough the transformations and created a new model with some more friendly names. Result below:

from ortools.sat.python import cp_model as ort

model = ort.CpModel()

a = model.NewIntVar(0,3,"a")
b = model.NewIntVar(0,3,"b")
c = model.NewIntVar(0,3,"c")
d = model.NewIntVar(0,3,"d")

p = model.NewIntVar(0,3,"p")
q = model.NewIntVar(0,3,"q")
r = model.NewIntVar(0,3,"r")
s = model.NewIntVar(0,3,"s")

bv1 = model.NewBoolVar("bv1")
bv2 = model.NewBoolVar("bv2")
bv3 = model.NewBoolVar("bv3")


model.Add(b != 1)
model.Add(b != 2)

model.Add(c != 0)
model.Add(c != 3)

model.Add(d != 0)

model.Add(p != 2)
model.Add(p != 3)

model.Add(q != 1)

model.Add(r != 1)

model.Add(s != 2)

model.AddAllDifferent([a,b,c,d])
model.AddAllDifferent([p,q,r,s])

model.Add(a == 0).OnlyEnforceIf(bv1)
model.Add(r == 0).OnlyEnforceIf(bv2)
model.AddBoolOr([bv2,bv3])
model.Add(a == 2).OnlyEnforceIf(bv3)
model.Add(p == 0).OnlyEnforceIf(bv1.Not())

# add solution
# model.AddBoolOr(bv1)
# model.AddBoolOr(bv2)
# model.AddBoolOr(bv3.Not())

status = ort.CpSolver().Solve(model)

if status == ort.INFEASIBLE:
    print("Model is UNSAT")
else:
    print("Model is not UNSAT")

Commenting in the # add solution bit result in the model becoming SAT!

@IgnaceBleukx
Copy link
Collaborator Author

OR-tools issue for the ones interested in following up:
google/or-tools#3643

@IgnaceBleukx
Copy link
Collaborator Author

Fixed in OR-tools main branch, not yet in pip version of library. Will be in version 9.6, closing issue when new OR-tools version is released in pip.

@IgnaceBleukx IgnaceBleukx linked a pull request Apr 12, 2023 that will close this issue
@tias tias closed this as completed in #275 Apr 14, 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 a pull request may close this issue.

1 participant