根据Choco 4.0.1
在线手册,它应该是这样的:
SatFactory.addClauses(LogOp.ifOnlyIf(x, LogOp.and(a, LogOp.nor(b))), model);
// with static import of LogOp
SatFactory.addClauses(ifOnlyIf(x, and(a, nor(b))), model);
但是,该手册似乎已过时。就像评论中建议的那样,我到达了:
import static org.chocosolver.solver.constraints.nary.cnf.LogOp.and;
import static org.chocosolver.solver.constraints.nary.cnf.LogOp.ifOnlyIf;
import static org.chocosolver.solver.constraints.nary.cnf.LogOp.nor;
import org.chocosolver.solver.Model;
import org.chocosolver.solver.variables.BoolVar;
public class AkChocoSatDemo {
public static void main(String[] args) {
// 1. Create a Model
Model model = new Model("my first problem");
// 2. Create variables
BoolVar x = model.boolVar("X");
BoolVar a = model.boolVar("A");
BoolVar b = model.boolVar("B");
// 3. Post constraints
// LogOp omitted due to import static ...LogOp.*
model.addClauses(ifOnlyIf(x, and(a, nor(b))));
// 4. Solve the problem
model.getSolver().solve();
// 5. Print the solution
System.out.println(x); // X = 1
System.out.println(a); // A = 1
System.out.println(b); // B = 0
}
}
我使用nor()
单个参数not()
来否定输入。