Esempio n. 1
0
  @Test(groups = "1s", timeOut = 60000)
  public void test10() {

    Model model = new Model();
    BoolVar[] rows = model.boolVarArray("b", 3);

    model.ifThen(rows[0], model.arithm(rows[1], "+", rows[2], "=", 2));
    model.ifThen(rows[0].not(), model.arithm(rows[1], "+", rows[2], "<=", 1));
    // SearchMonitorFactory.log(solver, true, true);
    while (model.getSolver().solve()) ;
    long nbSol = model.getSolver().getSolutionCount();

    for (int seed = 0; seed < 2000; seed++) {
      Model sCNF = new Model();
      BoolVar[] rCNF = sCNF.boolVarArray("b", 3);
      LogOp tree = ifOnlyIf(rCNF[0], and(rCNF[1], rCNF[2]));
      sCNF.addClauses(tree);
      sCNF.getSolver().setSearch(randomSearch(rCNF, seed));

      //            SearchMonitorFactory.log(sCNF, true, true);
      while (sCNF.getSolver().solve()) ;
      assertEquals(sCNF.getSolver().getSolutionCount(), nbSol);
    }
  }
Esempio n. 2
0
  @Test(groups = "1s", timeOut = 60000)
  public void test17() {
    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);

    model.addClauses(new BoolVar[0], new BoolVar[] {b1, b2});
    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));
  }