Ejemplo n.º 1
0
  @Test(groups = "1m")
  public void testSumvsIntLinCombTest() {
    Random rand = new Random();
    for (int seed = 0; seed < 400; seed++) {
      rand.setSeed(seed);
      int n = 1 + rand.nextInt(6);
      int min = -10 + rand.nextInt(20);
      int max = min + rand.nextInt(20);
      int[][] domains = DomainBuilder.buildFullDomains(n, min, max, rand, 1.0, false);
      int[] coeffs = new int[n];
      for (int i = 0; i < n; i++) {
        coeffs[i] = -25 + rand.nextInt(50);
      }
      int lb = -50 + rand.nextInt(100);
      int op = -1 + rand.nextInt(3);

      Solver sum = sum(domains, coeffs, lb, op);
      Solver intlincomb = intlincomb(domains, coeffs, lb, op);

      sum.findAllSolutions();
      intlincomb.findAllSolutions();
      Assert.assertEquals(
          sum.getMeasures().getSolutionCount(), intlincomb.getMeasures().getSolutionCount());
      Assert.assertEquals(
          sum.getMeasures().getNodeCount(), intlincomb.getMeasures().getNodeCount());
      LoggerFactory.getLogger("test")
          .info(
              "({}) {}ms vs {}ms",
              op,
              sum.getMeasures().getTimeCount(),
              intlincomb.getMeasures().getTimeCount());
    }
  }
Ejemplo n.º 2
0
 @Test(groups = "10s")
 public void testMax2() {
   Random random = new Random();
   for (int seed = 169; seed < 9999; seed++) {
     random.setSeed(seed);
     int[][] domains =
         DomainBuilder.buildFullDomains(
             3, 1, 15, random, random.nextDouble(), random.nextBoolean());
     Solver ref = new Solver();
     {
       IntVar[] xs = new IntVar[3];
       xs[0] = VariableFactory.enumerated("x", domains[0], ref);
       xs[1] = VariableFactory.enumerated("y", domains[1], ref);
       xs[2] = VariableFactory.enumerated("z", domains[2], ref);
       maxref(ref, xs[0], xs[1], xs[2]);
       //                SearchMonitorFactory.log(ref, true, true);
       ref.set(IntStrategyFactory.random_value(xs, seed));
     }
     Solver solver = new Solver();
     {
       IntVar[] xs = new IntVar[3];
       xs[0] = VariableFactory.enumerated("x", domains[0], solver);
       xs[1] = VariableFactory.enumerated("y", domains[1], solver);
       xs[2] = VariableFactory.enumerated("z", domains[2], solver);
       max(solver, xs[0], xs[1], xs[2]);
       //                SearchMonitorFactory.log(solver, true, true);
       solver.set(IntStrategyFactory.random_value(xs, seed));
     }
     ref.findAllSolutions();
     solver.findAllSolutions();
     Assert.assertEquals(
         solver.getMeasures().getSolutionCount(),
         ref.getMeasures().getSolutionCount(),
         "SOLUTIONS (" + seed + ")");
     // BEWARE: MAX does not ensure AC, unlike reformulation; so nb of nodes can be different...
     //            Assert.assertTrue(solver.getMeasures().getNodeCount() <=
     // ref.getMeasures().getNodeCount(), "NODES (" + seed + "): "
     //                    + solver.getMeasures().getNodeCount() + " vs. " +
     // ref.getMeasures().getNodeCount());
   }
 }
Ejemplo n.º 3
0
 @Test(groups = "10s")
 public void testMax1() {
   Random random = new Random();
   for (int seed = 1; seed < 9999; seed++) {
     random.setSeed(seed);
     int[][] domains = DomainBuilder.buildFullDomains(3, 1, 15);
     Solver ref = new Solver();
     {
       IntVar[] xs = new IntVar[3];
       xs[0] = VariableFactory.bounded("x", domains[0][0], domains[0][1], ref);
       xs[1] = VariableFactory.bounded("y", domains[1][0], domains[1][1], ref);
       xs[2] = VariableFactory.bounded("z", domains[2][0], domains[2][1], ref);
       maxref(ref, xs[0], xs[1], xs[2]);
       //                SearchMonitorFactory.log(ref, true, true);
       ref.set(IntStrategyFactory.random_bound(xs, seed));
     }
     Solver solver = new Solver();
     {
       IntVar[] xs = new IntVar[3];
       xs[0] = VariableFactory.bounded("x", domains[0][0], domains[0][1], solver);
       xs[1] = VariableFactory.bounded("y", domains[1][0], domains[1][1], solver);
       xs[2] = VariableFactory.bounded("z", domains[1][0], domains[2][1], solver);
       max(solver, xs[0], xs[1], xs[2]);
       //                SearchMonitorFactory.log(solver, true, true);
       solver.set(IntStrategyFactory.random_bound(xs, seed));
     }
     ref.findAllSolutions();
     solver.findAllSolutions();
     Assert.assertEquals(
         solver.getMeasures().getSolutionCount(),
         ref.getMeasures().getSolutionCount(),
         "SOLUTIONS (" + seed + ")");
     Assert.assertTrue(
         solver.getMeasures().getNodeCount() <= ref.getMeasures().getNodeCount(),
         "NODES (" + seed + ")");
   }
 }