コード例 #1
0
 static void postTeamConstraints(IntSetVar E, int n, int[] nbMembers, IntSetVarArray memberSets)
     throws Failure {
   C.postConstraint(E.cardinality().eq(n));
   for (int i = 0; i < nbMembers.length; i++) {
     C.postConstraint(E.intersectionWith(memberSets.get(i)).cardinality().ge(nbMembers[i]));
   }
 }
コード例 #2
0
 public void testExecute() {
   IntVar a = C.addIntVar(0, 10, "a", IntVar.DOMAIN_PLAIN);
   IntVar b = C.addIntVar(0, 10, "b", IntVar.DOMAIN_PLAIN);
   try {
     C.postConstraint(a.add(b).gt(4));
     C.postConstraint(a.add(b).lt(6));
     C.postConstraint(a.le(b));
     C.postConstraint(a.mul(b).eq(6));
     Goal gen = new GoalAnd(new GoalInstantiate(a), new GoalInstantiate(b));
     boolean flag = C.execute(gen);
     assertTrue("Can't generate any solution", flag);
     assertEquals("a = " + a.value(), a.value(), 2);
     assertEquals("b = " + b.value(), b.value(), 3);
   } catch (Failure f) {
     f.printStackTrace();
   } catch (Throwable ex) {
     fail("Unexpected exception has been thrown");
   }
 }
コード例 #3
0
  public void testIntersection() {
    int[] array1 = {1, 2, 3, 4, 5, 6, 7};
    int[] array2 = {1, 2, 7, 9, 4};

    Constrainer C = new Constrainer("test");
    IntSetVar var2 = C.addIntSetVar(array1);
    IntSetVar var1 = C.addIntSetVar(array2);

    IntSetVar var3 = var2.intersectionWith(var1);
    try {
      C.postConstraint(var3.cardinality().eq(2));
      IntSetVarArray array = new IntSetVarArray(C, 2);
      array.set(var1, 0);
      array.set(var2, 1);

      assertTrue(C.execute(new GoalIntSetGenerate(array)));
      assertTrue(intersectionCardinality(var2.requiredSet(), var1.requiredSet()) == 2);
    } catch (Failure f) {
      fail("test failed: " + f);
    }

    var1 = C.addIntSetVar(new int[] {1, 2, 3, 4, 5});
    var2 = C.addIntSetVar(new int[] {4, 5, 6, 7, 8});
    var3 = var2.intersectionWith(var1);

    try {
      IntSetVarArray array = new IntSetVarArray(C, 2);
      array.set(var1, 0);
      array.set(var2, 1);
      assertTrue(
          C.execute(new GoalFastMinimize(new GoalIntSetGenerate(array), var3.cardinality().neg())));
      assertTrue(var1.value().contains(new Integer(4)));
      assertTrue(var1.value().contains(new Integer(5)));
      assertTrue(var2.value().contains(new Integer(4)));
      assertTrue(var2.value().contains(new Integer(5)));
    } catch (Failure f) {
      fail("test failed: " + f);
    }
  }