Beispiel #1
0
 private int nbNodeFromRegulatModel(int seed) {
   m = new CPModel();
   s = new CPSolver();
   int k = 2;
   IntegerVariable v0 = makeIntVar("v0", 0, 10);
   IntegerVariable v1 = makeIntVar("v1", 0, 10);
   List<int[]> ltuple = new LinkedList<int[]>();
   for (int i = 0; i <= 10; i++) {
     for (int j = 0; j <= 10; j++) {
       if (Math.abs(i - j) < k) ltuple.add(new int[] {i, j});
     }
   }
   m.addConstraint(regular(new IntegerVariable[] {v0, v1}, ltuple));
   s.read(m);
   s.setVarIntSelector(new RandomIntVarSelector(s, seed + 32));
   s.setValIntSelector(new RandomIntValSelector(seed));
   try {
     s.propagate();
   } catch (ContradictionException e) {
     LOGGER.info(e.getMessage()); // To change body of catch statement use File | Settings | File
     // Templates.
   }
   s.solveAll();
   // LOGGER.info("solutions regular : " + s.getNbSolutions());
   return s.getNodeCount();
 }
Beispiel #2
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);
  }
Beispiel #3
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);
  }