Ejemplo n.º 1
0
 @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");
 }
Ejemplo n.º 2
0
 @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))");
 }
Ejemplo n.º 3
0
  @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)");
  }
Ejemplo n.º 4
0
 /**
  * create a logical connection between ``b`` and ``tree``.
  *
  * @param b operand
  * @param tree operand
  * @return a logical operator
  */
 public static LogOp reified(BoolVar b, ILogical tree) {
   try {
     BoolVar nb = b.not();
     ILogical ntree = negate(tree);
     return or(and(b, tree), and(nb, ntree));
   } catch (CloneNotSupportedException e) {
     e.printStackTrace();
   }
   return null;
 }
Ejemplo n.º 5
0
  @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));
  }
Ejemplo n.º 6
0
  @Test(groups = "1s", timeOut = 60000)
  public void test9() {
    Model model = new Model();

    BoolVar a = model.boolVar("a");
    BoolVar na = a.not();
    BoolVar b = model.boolVar("b");
    BoolVar c = model.boolVar("c");
    BoolVar d = model.boolVar("d");

    LogOp root = LogOp.and(a, b, na, c, d);

    ILogical l = LogicTreeToolBox.toCNF(root, model);

    Assert.assertEquals(l.toString(), "cste -- 0 = 0");
  }