I have pseudo boolean problems and I need to solve it with sat4j.
Can someone help me?
Here's my problem:
I have a list of variables named: a,b,c,d,e,f
And I have a list of values represented by: #1, #2, #3.....
h(a,#1) means assign #1 to a
I have some example constraints:
h(a,#1)=1
h(a,#1)+h(b,#1)+h(c,#1)=1
h(a,#1)+h(a,#5)>=1
h(b,#2)+h(b,#3)+h(b,#4)>=1
So many constraints like examples above. Finally, I want a result of assign which values to which value.
How can I solve it with sat4J? How should I represent the constraints?
If I understand your problem correctly as a pseudo-boolean satisfaction problem, you can directly encode it as an OPB file:
where I have arbitrarily encoded
h(a,#1)asx1,h(b,#1)asx2,h(c,#1)asx3,h(a,#5)asx4,h(b,#2)asx5,h(b,#3)asx6, andh(b,#4)asx7. (You may wish to add constraints likestating that each variable has at most one value, or
=for exactly one value.)Then run
which outputs (ignoring many comment lines beginning with
c):meaning
x1andx5are true whilex2,x3,x4,x6, andx7are false.(I’m sure there’s a way to do the same thing using the
org.sat4j.pbJava API, but perhaps this command-line recipe gives you a starting point to help you figure that out.)