예제 #1
0
  @Test
  public void test1NeqSolve() {
    for (int seed = 0; seed < 10; seed++) {
      m = new CPModel();
      s = new CPSolver();
      int k = 9, k1 = 7, k2 = 6;
      IntegerVariable v0 = makeIntVar("v0", 0, 10);
      IntegerVariable v1 = makeIntVar("v1", 0, 10);
      IntegerVariable v2 = makeIntVar("v2", 0, 10);
      IntegerVariable v3 = makeIntVar("v3", 0, 10);

      m.addConstraint(distanceNEQ(v0, v1, k));
      m.addConstraint(distanceNEQ(v1, v2, k1));
      m.addConstraint(distanceNEQ(v2, v3, k2));
      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());
      }
      s.solveAll();
      int nbNode = s.getNodeCount();
      LOGGER.info("solutions : " + s.getNbSolutions() + " nbNode : " + nbNode);
      assertEquals(s.getNbSolutions(), 12147);
    }
  }
예제 #2
0
 @Test
 public void test3BoundsSolve() {
   for (int seed = 0; seed < 10; seed++) {
     m = new CPModel();
     s = new CPSolver();
     int k = 9, k1 = 7, k2 = 6;
     IntegerVariable v0 = makeIntVar("v0", 0, 10);
     IntegerVariable v1 = makeIntVar("v1", 0, 10);
     IntegerVariable v2 = makeIntVar("v2", 0, 10);
     IntegerVariable v3 = makeIntVar("v3", 0, 10);
     m.addVariables(Options.V_BOUND, v0, v1, v2, v3);
     m.addConstraint(distanceEQ(v0, v1, k));
     m.addConstraint(distanceEQ(v1, v2, k1));
     m.addConstraint(distanceEQ(v2, v3, k2));
     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();
     int nbNode = s.getNodeCount();
     LOGGER.info("solutions : " + s.getNbSolutions() + " nbNode : " + nbNode);
     assertEquals(s.getNbSolutions(), 4);
   }
 }
예제 #3
0
 @Test
 public void test3LTSolve() {
   for (int seed = 0; seed < 10; seed++) {
     m = new CPModel();
     s = new CPSolver();
     int k = 2;
     IntegerVariable v0 = makeIntVar("v0", 0, 10);
     IntegerVariable v1 = makeIntVar("v1", 0, 10);
     m.addConstraint(distanceLT(v0, v1, k));
     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();
     int nbNode = s.getNodeCount();
     LOGGER.info("solutions : " + s.getNbSolutions() + " nbNode : " + nbNode);
     assertEquals(s.getNbSolutions(), 31);
     assertEquals(nbNodeFromRegulatModel(seed), nbNode);
   }
 }
예제 #4
0
 private void checker() {
   s.solveAll(); // checkSolution enbaled by assertion
   //        s.solve();
   //        if(Boolean.TRUE.equals(s.isFeasible())){
   //            do{
   //                Assert.assertTrue(s.checkSolution());
   //            }while(s.nextSolution());
   //        }
   Assert.assertEquals("feasibility incoherence", pe.solver.isFeasible(), s.isFeasible());
   Assert.assertEquals("nb sol incoherence", pe.solver.getNbSolutions(), s.getNbSolutions());
 }
예제 #5
0
  @Test
  public void testDXYZSolve4() {
    for (int seed = 0; seed < 10; seed++) {
      m = new CPModel();
      s = new CPSolver();
      IntegerVariable v0 = makeIntVar("v0", 3, 6);
      IntegerVariable v1 = makeIntVar("v1", -3, 4);
      IntegerVariable v2 = makeIntVar("v2", 0, 5);
      IntegerVariable v3 = makeIntVar("v3", 2, 5);

      m.addConstraint(distanceGT(v0, v1, v2, 0));
      m.addConstraint(distanceGT(v0, v2, v3, 0));
      s.read(m);
      s.setVarIntSelector(new RandomIntVarSelector(s, seed + 32));
      s.setValIntSelector(new RandomIntValSelector(seed));

      s.solveAll();
      LOGGER.info("nbsol " + s.getNbSolutions());
      assertEquals(getNbSolByDecomp(2), s.getNbSolutions());
    }
  }
예제 #6
0
  @Test
  public void test2() {
    CPSolver s = new CPSolver();
    RealVar alpha = s.createRealVal("alpha", -5.5 * Math.PI, -1.5 * Math.PI);
    RealExp exp = new RealCos(s, alpha);
    s.post(s.makeEquation(exp, s.cst(1.0)));

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

    assertTrue(s.getNbSolutions() >= 2);
  }
예제 #7
0
  @Test
  public void testDXYZSolve1() {
    for (int seed = 0; seed < 10; seed++) {

      m = new CPModel();
      s = new CPSolver();
      IntegerVariable v0 = makeIntVar("v0", 0, 5);
      IntegerVariable v1 = makeIntVar("v1", 0, 5);
      IntegerVariable v2 = makeIntVar("v2", 0, 5);
      m.addConstraint(distanceEQ(v0, v1, v2, 0));
      s.read(m);
      s.setVarIntSelector(new RandomIntVarSelector(s, seed + 32));
      s.setValIntSelector(new RandomIntValSelector(seed));

      s.solveAll();
      assertEquals(36, s.getNbSolutions());
    }
  }
예제 #8
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);
  }
예제 #9
0
  @Test
  public void test2bis() {
    CPModel m = new CPModel();

    RealVariable alpha = makeRealVar("alpha", -5.5 * Math.PI, -1.5 * Math.PI);
    m.addVariable(alpha);
    m.addConstraint(eq(cos(alpha), 1));

    CPSolver s = new CPSolver();
    s.read(m);

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

    assertTrue(s.getNbSolutions() >= 2);
  }
예제 #10
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);
  }