コード例 #1
0
ファイル: DistanceTest.java プロジェクト: Schmirgel/choco2
  @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
ファイル: DistanceTest.java プロジェクト: Schmirgel/choco2
 @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);
   }
 }
コード例 #3
0
ファイル: DistanceTest.java プロジェクト: Schmirgel/choco2
 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();
 }
コード例 #4
0
ファイル: DistanceTest.java プロジェクト: Schmirgel/choco2
 @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);
   }
 }
コード例 #5
0
ファイル: DistanceTest.java プロジェクト: Schmirgel/choco2
  @Test
  public void testDXYZProp1bis() {

    IntegerVariable v0 = makeIntVar("v0", 1, 4);
    IntegerVariable v1 = makeIntVar("v1", 5, 7);
    IntegerVariable v2 = makeIntVar("v2", -100, 100);
    m.addVariables(Options.V_BOUND, v0, v1, v2);
    m.addConstraint(distanceEQ(v0, v1, v2, 2));
    s.read(m);
    try {
      s.propagate();
    } catch (ContradictionException e) {
      LOGGER.info(e.getMessage());
      assertTrue(false);
    }
    assertEquals(-1, s.getVar(v2).getInf());
    assertEquals(4, s.getVar(v2).getSup());
  }