Exemple #1
0
 private void backPropRemPoss() throws ContradictionException {
   ISetIterator iter = poss.iterator();
   while (iter.hasNext()) {
     int i = iter.nextInt();
     IntVar v = vars[i];
     if (v.hasEnumeratedDomain()) {
       for (int value : values) {
         v.removeValue(value, this);
       }
       poss.remove(i);
     } else {
       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 (newLB > values[values.length - 1] || newUB < values[0]) {
         poss.remove(i);
       }
     }
   }
 }
 @Override
 public void propagate(int evtmask) throws ContradictionException {
   if (!antecedent.isInstantiated()) {
     if (!PropUtil.isKerSubsetEnv(result, consequent)
         || !PropUtil.isKerSubsetEnv(consequent, result)) {
       antecedent.instantiateTo(0, this);
     } else if (!PropUtil.isKerSubsetEnv(result, alternative)
         || !PropUtil.isKerSubsetEnv(alternative, result)) {
       antecedent.instantiateTo(1, this);
     } else {
       ISetIterator iter = result.getUB().iterator();
       while (iter.hasNext()) {
         int i = iter.nextInt();
         if (!consequent.getUB().contains(i) && !alternative.getUB().contains(i)) {
           result.remove(i, this);
         } else if (consequent.getLB().contains(i) && alternative.getLB().contains(i)) {
           result.force(i, this);
         }
       }
     }
   }
   if (antecedent.isInstantiated()) {
     if (antecedent.getValue() == 1) {
       PropUtil.envSubsetEnv(result, consequent, this);
       PropUtil.envSubsetEnv(consequent, result, this);
       PropUtil.kerSubsetKer(result, consequent, this);
       PropUtil.kerSubsetKer(consequent, result, this);
     } else {
       PropUtil.envSubsetEnv(result, alternative, this);
       PropUtil.envSubsetEnv(alternative, result, this);
       PropUtil.kerSubsetKer(result, alternative, this);
       PropUtil.kerSubsetKer(alternative, result, this);
     }
   }
 }
Exemple #3
0
  @Override
  public ESat isEntailed() {
    if (!PropUtil.isKerSubsetEnv(s1, s2) || !PropUtil.isKerSubsetEnv(s2, s1)) {
      return ESat.FALSE;
    }
    if (s1.isInstantiated() && s2.isInstantiated()) {
      return ESat.TRUE;
    }
    int setIntersection = 0;
    ISetIterator iter = s1.getUB().iterator();
    while (iter.hasNext()) {
      int i = iter.nextInt();
      if (s2.getUB().contains(i)) {
        setIntersection++;
      }
    }
    if (setIntersection < s1.getCard().getLB() || setIntersection < s2.getCard().getLB()) {
      return ESat.FALSE;
    }

    return ESat.UNDEFINED;
  }
 private int augmentPath_BFS(int root) {
   in.clear();
   int indexFirst = 0, indexLast = 0;
   fifo[indexLast++] = root;
   int x;
   ISetIterator succs;
   while (indexFirst != indexLast) {
     x = fifo[indexFirst++];
     succs = digraph.getSuccOf(x).iterator();
     while (succs.hasNext()) {
       int y = succs.nextInt();
       if (!in.get(y)) {
         father[y] = x;
         fifo[indexLast++] = y;
         in.set(y);
         if (free.get(y)) {
           return y;
         }
       }
     }
   }
   return -1;
 }