示例#1
0
 /** In case of a EQ, due to the instantion to one variable to val */
 public void filterOnInst(IntVar v, int val) throws ContradictionException {
   if (!v.contains(val + cste)) {
     v.instantiateTo(val - cste, this);
   } else if (!v.contains(val - cste)) {
     v.instantiateTo(val + cste, this);
   } else {
     if (v.hasEnumeratedDomain()) {
       DisposableRangeIterator rit = v.getRangeIterator(true);
       try {
         while (rit.hasNext()) {
           int from = rit.min();
           int to = rit.max();
           for (int value = from; value <= to; value++) {
             if (value != (val - cste) && value != (val + cste)) {
               v.removeValue(value, this);
             }
           }
           rit.next();
         }
       } finally {
         rit.dispose();
       }
     } else {
       v.updateBounds(val - cste, val + cste, this);
     }
   }
 }
示例#2
0
 /**
  * Initial propagation in case of EQ and enumerated domains
  *
  * @throws ContradictionException
  */
 public void filterFromVarToVar(IntVar var1, IntVar var2) throws ContradictionException {
   DisposableRangeIterator it = var1.getRangeIterator(true);
   try {
     while (it.hasNext()) {
       int from = it.min();
       int to = it.max();
       for (int value = from; value <= to; value++)
         if (!var2.contains(value - cste) && !var2.contains(value + cste)) {
           var1.removeValue(value, this);
         }
       it.next();
     }
   } finally {
     it.dispose();
   }
 }