예제 #1
0
  @Test
  public void test1() {
    CPSolver s = new CPSolver();
    RealVar alpha = s.createRealVal("alpha", -Math.PI, Math.PI);

    RealExp exp = new RealMinus(s, new RealCos(s, alpha), new RealSin(s, alpha));
    SConstraint c = s.makeEquation(exp, s.cst(0.0));
    LOGGER.info("c = " + c.pretty());
    s.post(s.makeEquation(exp, s.cst(0.0)));

    boolean first = false;
    s.setFirstSolution(first);
    s.generateSearchStrategy();
    s.addGoal(new AssignInterval(new CyclicRealVarSelector(s), new RealIncreasingDomain()));
    s.launch();

    assertTrue("Nb sols", s.getNbSolutions() >= 2);
    assertTrue("Precision", Math.abs(Math.cos(alpha.getInf()) - Math.sin(alpha.getInf())) < 1e-8);
  }
예제 #2
0
  @Test
  public void test1bis() {
    CPModel m = new CPModel();

    RealVariable alpha = makeRealVar("alpha", -Math.PI, Math.PI);
    Constraint exp = eq(cos(alpha), sin(alpha));
    m.addConstraint(exp);

    CPSolver s = new CPSolver();
    s.read(m);
    LOGGER.info("eq = " + s.getCstr(exp).pretty());

    boolean first = false;
    s.setFirstSolution(first);
    s.generateSearchStrategy();
    s.addGoal(new AssignInterval(new CyclicRealVarSelector(s), new RealIncreasingDomain()));
    s.launch();

    assertTrue(s.getNbSolutions() >= 2);
    assertTrue(
        Math.abs(Math.cos(s.getVar(alpha).getInf()) - Math.sin(s.getVar(alpha).getInf())) < 1e-8);
  }