コード例 #1
0
ファイル: RegularTest.java プロジェクト: HilmiHB/choco3
  @Test(groups = "1s")
  public void testSimpleAuto() {
    Solver solver = new Solver();

    int n = 10;
    IntVar[] vars = new IntVar[n];
    for (int i = 0; i < n; i++) {
      vars[i] = VariableFactory.enumerated("x_" + i, 0, 2, solver);
    }

    FiniteAutomaton auto = new FiniteAutomaton();
    int start = auto.addState();
    int end = auto.addState();
    auto.setInitialState(start);
    auto.setFinal(start);
    auto.setFinal(end);

    auto.addTransition(start, start, 0, 1);
    auto.addTransition(start, end, 2);

    auto.addTransition(end, start, 2);
    auto.addTransition(end, start, 0, 1);

    solver.post(IntConstraintFactory.regular(vars, auto));
    solver.set(IntStrategyFactory.lexico_LB(vars));

    solver.findAllSolutions();
    Assert.assertEquals(solver.getMeasures().getSolutionCount(), 59049);
  }
コード例 #2
0
ファイル: IntLinCombTest.java プロジェクト: sfurlow/choco3
 protected Solver intlincomb(int[][] domains, int[] coeffs, int b, int op) {
   Solver solver = new Solver();
   IntVar[] bins = new IntVar[domains.length];
   for (int i = 0; i < domains.length; i++) {
     bins[i] =
         VariableFactory.bounded(
             "v_" + i, domains[i][0], domains[i][domains[i].length - 1], solver);
   }
   String opname = "=";
   if (op != 0) {
     if (op > 0) {
       opname = ">=";
     } else {
       opname = "<=";
     }
   }
   IntVar sum = VariableFactory.bounded("scal", -99999999, 99999999, solver);
   Constraint[] cstrs =
       new Constraint[] {
         IntConstraintFactory.scalar(bins, coeffs, sum),
         IntConstraintFactory.arithm(sum, opname, b)
       };
   solver.post(cstrs);
   solver.set(IntStrategyFactory.lexico_LB(bins));
   return solver;
 }
コード例 #3
0
ファイル: RegularTest.java プロジェクト: HilmiHB/choco3
  @Test(groups = "10s")
  public void compareVersionSpeedNew() {
    int n = 14;
    FiniteAutomaton auto = new FiniteAutomaton("(0|1|2)*(0|1)(0|1)(0|1)(0|1|2)*");

    Solver solver = new Solver();
    IntVar[] vars = new IntVar[n];
    for (int i = 0; i < n; i++) {
      vars[i] = VariableFactory.enumerated("x_" + i, 0, 2, solver);
    }
    solver.post(IntConstraintFactory.regular(vars, auto));
    solver.set(IntStrategyFactory.lexico_LB(vars));

    solver.findAllSolutions();
    Assert.assertEquals(solver.getMeasures().getSolutionCount(), 4371696);
  }
コード例 #4
0
ファイル: RegularTest.java プロジェクト: HilmiHB/choco3
  @Test(groups = "1s")
  public void compareVersionSpeedNew2() {
    int n = 5;
    FiniteAutomaton auto = new FiniteAutomaton("(0|<10>|<20>)*(0|<10>)");

    Solver solver = new Solver();
    IntVar[] vars = new IntVar[n];
    for (int i = 0; i < n; i++) {
      vars[i] = VariableFactory.enumerated("x_" + i, new int[] {0, 10, 20}, solver);
    }
    solver.post(IntConstraintFactory.regular(vars, auto));
    solver.set(IntStrategyFactory.lexico_LB(vars));

    Chatterbox.showSolutions(solver);
    solver.findAllSolutions();
    Assert.assertEquals(solver.getMeasures().getSolutionCount(), 162);
  }
コード例 #5
0
ファイル: RegularTest.java プロジェクト: HilmiHB/choco3
  @Test(groups = "1s")
  public void ccostregular2() {
    Solver solver = new Solver();

    int n = 12;
    IntVar[] vars = new IntVar[n];
    for (int i = 0; i < n; i++) {
      vars[i] = VariableFactory.enumerated("x_" + i, 0, 2, solver);
    }

    // different rules are formulated as patterns that must NOT be matched by x
    List<String> forbiddenRegExps = new ArrayList<>();
    // do not end with '00' if start with '11'
    forbiddenRegExps.add("11(0|1|2)*00");
    // at most three consecutive 0
    forbiddenRegExps.add("(0|1|2)*0000(0|1|2)*");
    // no pattern '112' at position 5
    forbiddenRegExps.add("(0|1|2){4}112(0|1|2)*");
    // pattern '12' after a 0 or a sequence of 0
    forbiddenRegExps.add("(0|1|2)*02(0|1|2)*");
    forbiddenRegExps.add("(0|1|2)*01(0|1)(0|1|2)*");
    // at most three 2 on consecutive even positions
    forbiddenRegExps.add("(0|1|2)((0|1|2)(0|1|2))*2(0|1|2)2(0|1|2)2(0|1|2)*");

    // a unique automaton is built as the complement language composed of all the forbidden patterns
    FiniteAutomaton auto = new FiniteAutomaton();
    for (String reg : forbiddenRegExps) {
      FiniteAutomaton a = new FiniteAutomaton(reg);
      auto = auto.union(a);
      auto.minimize();
    }
    auto = auto.complement();
    auto.minimize();
    Assert.assertEquals(auto.getNbStates(), 54);

    solver.post(IntConstraintFactory.regular(vars, auto));
    solver.set(IntStrategyFactory.lexico_LB(vars));

    solver.findAllSolutions();
    Assert.assertEquals(solver.getMeasures().getSolutionCount(), 25980);
  }
コード例 #6
0
ファイル: IntLinCombTest.java プロジェクト: sfurlow/choco3
  public static void testOp(int n, int min, int max, int cMax, int seed, Operator operator) {
    Random random = new Random(seed);
    Solver s = new Solver();
    IntVar[] vars = new IntVar[n];
    int[] coeffs = new int[n];
    for (int i = 0; i < vars.length; i++) {
      vars[i] = VariableFactory.enumerated("v_" + i, min, max, s);
      coeffs[i] = random.nextInt(cMax);
    }
    int constant = -random.nextInt(cMax);

    IntVar sum = VariableFactory.bounded("scal", -99999999, 99999999, s);

    Constraint[] cstrs =
        new Constraint[] {
          IntConstraintFactory.scalar(vars, coeffs, sum),
          IntConstraintFactory.arithm(sum, operatorToString(operator), constant)
        };

    s.post(cstrs);
    s.set(IntStrategyFactory.lexico_LB(vars));

    s.findAllSolutions();
  }