Ejemplo n.º 1
0
 @Override
 public void propagate(int evtmask) throws ContradictionException {
   updateBounds();
   // ensure that, in case of enumerated domains, holes are also propagated
   if (bothEnumerated) {
     int ub = x.getUB();
     for (int val = x.getLB(); val <= ub; val = x.nextValue(val)) {
       if (!y.contains(val - cste)) {
         x.removeValue(val, aCause);
       }
     }
     ub = y.getUB();
     for (int val = y.getLB(); val <= ub; val = y.nextValue(val)) {
       if (!x.contains(val + cste)) {
         y.removeValue(val, aCause);
       }
     }
     idms[0].unfreeze();
     idms[1].unfreeze();
   }
   if (x.isInstantiated()) {
     assert (y.isInstantiated());
     setPassive();
   }
 }
Ejemplo n.º 2
0
 @Override
 public ESat isEntailed() {
   if ((x.getUB() < y.getLB() + cste)
       || (x.getLB() > y.getUB() + cste)
       || x.hasEnumeratedDomain() && y.hasEnumeratedDomain() && !match()) return ESat.FALSE;
   else if (x.isInstantiated() && y.isInstantiated() && (x.getValue() == y.getValue() + cste))
     return ESat.TRUE;
   else return ESat.UNDEFINED;
 }
Ejemplo n.º 3
0
 @Override
 public void propagate(int evtmask) throws ContradictionException {
   int min = 0;
   int max = 0;
   ISet nodes = g.getPotentialNodes();
   for (int i = nodes.getFirstElement(); i >= 0; i = nodes.getNextElement()) {
     if (g.getMandSuccOrNeighOf(i).contain(i)) {
       min++;
       max++;
     } else if (g.getPotSuccOrNeighOf(i).contain(i)) {
       max++;
     }
   }
   k.updateLowerBound(min, aCause);
   k.updateUpperBound(max, aCause);
   if (min == max) {
     setPassive();
   } else if (k.isInstantiated()) {
     if (k.getValue() == max) {
       for (int i = nodes.getFirstElement(); i >= 0; i = nodes.getNextElement()) {
         if (g.getPotSuccOrNeighOf(i).contain(i)) {
           g.enforceArc(i, i, aCause);
         }
       }
       setPassive();
     } else if (k.getValue() == min) {
       for (int i = nodes.getFirstElement(); i >= 0; i = nodes.getNextElement()) {
         if (!g.getMandSuccOrNeighOf(i).contain(i)) {
           g.removeArc(i, i, aCause);
         }
       }
       setPassive();
     }
   }
 }
Ejemplo n.º 4
0
 @Override
 public void propagate(int varIdx, int mask) throws ContradictionException {
   updateBounds();
   if (x.isInstantiated()) {
     assert (y.isInstantiated());
     setPassive();
   } else if (bothEnumerated) {
     if (varIdx == 0) {
       indexToFilter = 1;
       offSet = -cste;
     } else {
       indexToFilter = 0;
       offSet = cste;
     }
     idms[varIdx].freeze();
     idms[varIdx].forEachRemVal(rem_proc);
     idms[varIdx].unfreeze();
   }
 }
 @Override
 public ESat isEntailed() {
   assert intVars.length == realVars.length;
   boolean allInst = true;
   for (int i = 0; i < n; i++) {
     IntVar intVar = intVars[i];
     RealVar realVar = realVars[i];
     if ((realVar.getLB() < (double) intVar.getLB() - epsilon)
         || (realVar.getUB() > (double) intVar.getUB() + epsilon)) {
       return ESat.FALSE;
     }
     if (!(intVar.isInstantiated() && realVar.isInstantiated())) {
       allInst = false;
     }
   }
   return allInst ? ESat.TRUE : ESat.UNDEFINED;
 }
Ejemplo n.º 6
0
 private void backPropForcePoss() throws ContradictionException {
   ISetIterator iter = poss.iterator();
   while (iter.hasNext()) {
     int i = iter.nextInt();
     IntVar v = vars[i];
     if (v.hasEnumeratedDomain()) {
       for (int val = v.getLB(); val <= v.getUB(); val = v.nextValue(val)) {
         if (!setValues.contains(val)) {
           v.removeValue(val, this);
         }
       }
       poss.remove(i);
       nbSure.add(1);
     } else {
       v.updateBounds(values[0], values[values.length - 1], this);
       int newLB = v.getLB();
       int newUB = v.getUB();
       for (int val = v.getLB(); val <= newUB; val = v.nextValue(val)) {
         if (!setValues.contains(val)) {
           newLB = val + 1;
         } else {
           break;
         }
       }
       for (int val = newUB; val >= newLB; val = v.previousValue(val)) {
         if (!setValues.contains(val)) {
           newUB = val - 1;
         } else {
           break;
         }
       }
       v.updateBounds(newLB, newUB, this);
       if (v.isInstantiated()) {
         poss.remove(i);
         nbSure.add(1);
       }
     }
   }
 }
Ejemplo n.º 7
0
 @Override
 public ESat isEntailed() {
   BitSet values = new BitSet(n2);
   BitSet mandatoryValues = new BitSet(n2);
   IntVar v;
   int ub;
   for (int i = 0; i < n; i++) {
     v = vars[i];
     ub = v.getUB();
     if (v.isInstantiated()) {
       mandatoryValues.set(map.get(ub));
     }
     for (int j = v.getLB(); j <= ub; j++) {
       values.set(map.get(j));
     }
   }
   if (mandatoryValues.cardinality() >= vars[n].getUB()) {
     return ESat.TRUE;
   }
   if (values.cardinality() < vars[n].getLB()) {
     return ESat.FALSE;
   }
   return ESat.UNDEFINED;
 }
Ejemplo n.º 8
0
 @Override
 public ESat isEntailed() {
   int min = 0;
   int max = 0;
   int nbInst = vars[nb_vars].isInstantiated() ? 1 : 0;
   for (int i = 0; i < nb_vars; i++) {
     IntVar var = vars[i];
     if (var.isInstantiated()) {
       nbInst++;
       if (setValues.contains(var.getValue())) {
         min++;
         max++;
       }
     } else {
       int nb = 0;
       for (int j : values) {
         if (var.contains(j)) {
           nb++;
         }
       }
       if (nb == var.getDomainSize()) {
         min++;
         max++;
       } else if (nb > 0) {
         max++;
       }
     }
   }
   if (min > vars[nb_vars].getUB() || max < vars[nb_vars].getLB()) {
     return ESat.FALSE;
   }
   if (nbInst == nb_vars + 1) {
     return ESat.TRUE;
   }
   return ESat.UNDEFINED;
 }