Example #1
0
 @Test(groups = "1s")
 public void testregExp6() {
   Solver solver = new Solver();
   IntVar[] CS = VF.enumeratedArray("CS", 4, 0, 3, solver);
   solver.post(ICF.regular(CS, new FiniteAutomaton("0{2,3}1*")));
   Chatterbox.showSolutions(solver);
   Chatterbox.showDecisions(solver);
   solver.findAllSolutions();
   Assert.assertEquals(solver.getMeasures().getSolutionCount(), 2);
 }
  public void solveProblem() {
    Solver solver = new Solver();

    // Decision selection
    BoolVar Root = (BoolVar) VariableFactory.fixed(1, solver);
    BoolVar A = (BoolVar) VariableFactory.fixed(1, solver);
    BoolVar B = (BoolVar) VariableFactory.fixed(1, solver);
    BoolVar C = (BoolVar) VariableFactory.fixed(1, solver);
    BoolVar D = VariableFactory.bool("D", solver);
    BoolVar E = VariableFactory.bool("E", solver);
    BoolVar A1 = VariableFactory.bool("A1", solver);
    BoolVar A2 = VariableFactory.bool("A2", solver);
    BoolVar C1 = VariableFactory.bool("C1", solver);
    BoolVar C2 = VariableFactory.bool("C2", solver);
    BoolVar C3 = VariableFactory.bool("C3", solver);
    BoolVar E1 = VariableFactory.bool("E1", solver);
    BoolVar E2 = VariableFactory.bool("E2", solver);
    BoolVar e1 = VariableFactory.bool("e1", solver);
    BoolVar e2 = VariableFactory.bool("e2", solver);
    BoolVar e3 = VariableFactory.bool("e3", solver);

    // Decision cost
    IntVar A1Cost = VariableFactory.bounded("A1Cost", 0, 500, solver);
    IntVar A2Cost = VariableFactory.bounded("A2Cost", 0, 200, solver);
    IntVar C1Cost = VariableFactory.bounded("C1Cost", 0, 600, solver);
    IntVar C2Cost = VariableFactory.bounded("C2Cost", 0, 400, solver);
    IntVar C3Cost = VariableFactory.bounded("C3Cost", 0, 300, solver);
    IntVar E1Cost = VariableFactory.bounded("E1Cost", 0, 450, solver);
    IntVar e1Cost = VariableFactory.bounded("e1Cost", 0, 350, solver);
    IntVar e2Cost = VariableFactory.bounded("e2Cost", 0, 350, solver);
    IntVar e3Cost = VariableFactory.bounded("e3Cost", 0, 500, solver);

    IntVar[] Vars = new IntVar[9];
    Vars[0] = A1Cost;
    Vars[1] = A2Cost;
    Vars[2] = C1Cost;
    Vars[3] = C2Cost;
    Vars[4] = C3Cost;
    Vars[5] = E1Cost;
    Vars[6] = e1Cost;
    Vars[7] = e2Cost;
    Vars[8] = e3Cost;

    int maxValue = 3650;
    IntVar TotalCost = VariableFactory.bounded("TotalCost", 0, maxValue, solver);

    solver.post(IntConstraintFactory.sum(Vars, TotalCost));

    Chatterbox.showSolutions(solver);
    solver.findOptimalSolution(ResolutionPolicy.MAXIMIZE, TotalCost);
    Chatterbox.printStatistics(solver);
  }
Example #3
0
 @Test(groups = "1s")
 public void testIss237_1() {
   Solver solver = new Solver();
   BoolVar[] bs = VF.boolArray("b", 3, solver);
   solver.post(ICF.scalar(bs, new int[] {1, 2, 3}, "=", VF.fixed(2, solver)));
   Chatterbox.showSolutions(solver);
   solver.findAllSolutions();
 }
Example #4
0
  @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);
  }
Example #5
0
  @Test(groups = "1s", expectedExceptions = SolverException.class)
  public void testNeg() {
    Solver solver = new Solver();
    IntVar[] CS = VF.enumeratedArray("CS", 4, -10, 10, solver);
    solver.post(ICF.regular(CS, new FiniteAutomaton("<-9>1*")));
    Chatterbox.showSolutions(solver);
    solver.findAllSolutions();

    final List<Solution> solutions = solver.getSolutionRecorder().getSolutions();

    System.out.println(solutions);

    Assert.assertEquals(1, solutions.size());
    Assert.assertEquals(-9, (int) solutions.get(0).getIntVal(CS[0]));
    Assert.assertEquals(1, (int) solutions.get(0).getIntVal(CS[1]));
    Assert.assertEquals(1, (int) solutions.get(0).getIntVal(CS[2]));
    Assert.assertEquals(-5, (int) solutions.get(0).getIntVal(CS[3]));
  }
Example #6
0
 @Test(groups = "1s")
 public void testregExp7() {
   Solver solver = new Solver();
   IntVar[] CS = VF.enumeratedArray("CS", 10, 0, 2, solver);
   solver.post(ICF.regular(CS, new FiniteAutomaton("0*(1{2,4}0{0,2}0)*0*")));
   Chatterbox.showSolutions(
       solver,
       () -> {
         for (int i = 0; i < 10; i++) {
           System.out.printf("%d", CS[i].getValue());
         }
         //            System.out.printf("\n");
         return "";
       });
   solver.set(ISF.lexico_LB(CS));
   //        Chatterbox.showDecisions(solver);
   solver.findAllSolutions();
   Assert.assertEquals(solver.getMeasures().getSolutionCount(), 84);
 }