@Test(groups = "1s", timeOut = 60000) public void test2() { Model model = new Model(); BoolVar a = model.boolVar("a").not(); BoolVar b = model.boolVar("b"); BoolVar c = model.boolVar("c"); BoolVar d = model.boolVar("d"); LogOp root = LogOp.or(LogOp.or(LogOp.or(a, b), c), d); LogicTreeToolBox.merge(LogOp.Operator.OR, root); Assert.assertEquals(root.toString(), "(d or c or not(a) or b)"); }
@Test(groups = "1s", timeOut = 60000) public void test8() { Model model = new Model(); BoolVar a = model.boolVar("a"); BoolVar na = a.not(); BoolVar b = model.boolVar("b"); BoolVar nb = b.not(); BoolVar c = model.boolVar("c"); BoolVar d = model.boolVar("d"); LogOp root = LogOp.and(LogOp.or(a, b, na), LogOp.or(c, d), LogOp.or(b, nb)); ILogical l = LogicTreeToolBox.toCNF(root, model); Assert.assertEquals(l.toString(), "(c or d)"); }
@Test(groups = "1s", timeOut = 60000) public void test14() { Model model = new Model(); BoolVar a = model.boolVar("a"); BoolVar b = model.boolVar("b"); LogOp l = LogOp.or(a, b, a.not(), a.not()); ILogical ll = LogicTreeToolBox.toCNF(l, model); Assert.assertEquals(ll.toString(), "cste -- 1 = 1"); }
@Test(groups = "1s", timeOut = 60000) public void test11() { Model model = new Model(); BoolVar a = model.boolVar("a"); BoolVar b = model.boolVar("b"); LogOp l = LogOp.or(LogOp.and(a, b.not()), LogOp.and(a.not(), b), LogOp.and(a.not(), b.not())); ILogical ll = LogicTreeToolBox.toCNF(l, model); Assert.assertEquals(ll.toString(), "(not(b) or not(a))"); }
public void maxref(Solver solver, IntVar x, IntVar y, IntVar z) { BoolVar[] bs = VariableFactory.boolArray("b", 3, solver); LogicalConstraintFactory.ifThenElse( bs[0], IntConstraintFactory.arithm(z, "=", x), IntConstraintFactory.arithm(z, "!=", x)); LogicalConstraintFactory.ifThenElse( bs[1], IntConstraintFactory.arithm(z, "=", y), IntConstraintFactory.arithm(z, "!=", y)); LogicalConstraintFactory.ifThenElse( bs[2], IntConstraintFactory.arithm(x, ">=", y), IntConstraintFactory.arithm(x, "<", y)); SatFactory.addClauses(LogOp.or(LogOp.and(bs[0], bs[2]), LogOp.and(bs[1], bs[2].not())), solver); }
@Test(groups = "1s", timeOut = 60000) public void test3() { Model model = new Model(); BoolVar a = model.boolVar("a"); BoolVar b = model.boolVar("b"); BoolVar c = model.boolVar("c"); LogOp root = LogOp.or(LogOp.and(a, b), c); root = LogicTreeToolBox.developOr(root); Assert.assertEquals(root.toString(), "((a or c) and (b or c))"); }
@Test(groups = "1s", timeOut = 60000) public void test4() { Model model = new Model(); BoolVar a = model.boolVar("a").not(); BoolVar b = model.boolVar("b"); BoolVar c = model.boolVar("c"); BoolVar d = model.boolVar("d"); LogOp root = LogOp.nor(LogOp.or(LogOp.nand(a, b), c), d); LogicTreeToolBox.expandNot(root); Assert.assertEquals(root.toString(), "(((not(a) and b) and not(c)) and not(d))"); }
@Test(groups = "1s", timeOut = 60000) public void test1() { Model model = new Model(); BoolVar a = model.boolVar("a"); BoolVar b = model.boolVar("b"); BoolVar c = model.boolVar("c"); BoolVar d = model.boolVar("d"); LogOp root = LogOp.nand(LogOp.nor(a, b), LogOp.or(c, d)); ILogical l = LogicTreeToolBox.toCNF(root, model); Assert.assertEquals(l.toString(), "((a or b or not(c)) and (a or b or not(d)))"); }
@Test(groups = "1s", timeOut = 60000) public void test16() { Model model = new Model(); IntVar a = model.intVar("a", -1, 1, false); BoolVar b1 = model.boolVar("b1"); BoolVar b2 = model.boolVar("b2"); model.arithm(a, "=", 0).reifyWith(b1); model.arithm(a, ">", 0).reifyWith(b2); LogOp l = LogOp.or(b1.not(), b2.not()); model.addClauses(l); model.getMinisat().getPropSat().initialize(); try { model.getSolver().propagate(); b1.instantiateTo(1, Cause.Null); model.getSolver().propagate(); } catch (ContradictionException ex) { Assert.fail(); } Assert.assertTrue(b1.isInstantiatedTo(1)); Assert.assertTrue(b2.isInstantiatedTo(0)); Assert.assertTrue(a.isInstantiatedTo(0)); }