Exemplo n.º 1
0
  @Override
  public boolean instantiateTo(int value, ICause cause, boolean informCause)
      throws ContradictionException {
    if (informCause) {
      cause = Cause.Null;
    }
    if (this.instantiated()) {
      if (value != this.getValue()) {
        this.contradiction(cause, MSG_INST);
      }
      return false;
    } else if (contains(value)) {
      // todo: delta
      this.LB.set(value);
      this.UB.set(value);
      this.SIZE.set(1);

      A.updateUpperBound(value, this, false);
      B.updateUpperBound(value, this, false);
      if (!A.contains(value)) {
        B.instantiateTo(value, this, false);
      }
      if (!B.contains(value)) {
        A.instantiateTo(value, this, false);
      }

      this.notifyPropagators(EventType.INSTANTIATE, cause);
      return true;
    } else {
      this.contradiction(cause, MSG_UNKNOWN);
      return false;
    }
  }
Exemplo n.º 2
0
  @Override
  public boolean updateUpperBound(int aValue, ICause cause, boolean informCause)
      throws ContradictionException {
    ICause antipromo = cause;
    if (informCause) {
      cause = Cause.Null;
    }
    int old = this.getUB();
    if (old > aValue) {
      if (this.getLB() > aValue) {
        this.contradiction(cause, MSG_UPP);
      } else {
        EventType e = EventType.DECUPP;
        // todo delta
        SIZE.add(aValue - old);
        UB.set(aValue);

        A.updateUpperBound(aValue, this, false);
        B.updateUpperBound(aValue, this, false);

        if (instantiated()) {
          e = EventType.INSTANTIATE;
          if (cause.reactOnPromotion()) {
            cause = Cause.Null;
          }
        }
        this.notifyPropagators(e, cause);
        return true;
      }
    }
    return false;
  }
Exemplo n.º 3
0
 @Override
 public boolean removeValue(int value, ICause cause, boolean informCause)
     throws ContradictionException {
   ICause antipromo = cause;
   if (informCause) {
     cause = Cause.Null;
   }
   int inf = getLB();
   int sup = getUB();
   if (value == inf && value == sup) {
     this.contradiction(cause, AbstractVariable.MSG_REMOVE);
   } else if (inf == value || value == sup) {
     EventType e;
     if (value == inf) {
       // todo: delta...
       LB.set(value + 1);
       e = EventType.INCLOW;
       if (cause.reactOnPromotion()) {
         cause = Cause.Null;
       }
       if (A.getLB() > B.getUB()) {
         A.updateLowerBound(value + 1, this, false);
       }
       if (B.getLB() > A.getUB()) {
         B.updateLowerBound(value + 1, this, false);
       }
     } else {
       // todo: delta...
       UB.set(value - 1);
       e = EventType.DECUPP;
       if (cause.reactOnPromotion()) {
         cause = Cause.Null;
       }
       A.updateUpperBound(value - 1, this, false);
       B.updateUpperBound(value - 1, this, false);
     }
     if (SIZE.get() > 0) {
       if (this.instantiated()) {
         e = EventType.INSTANTIATE;
         if (cause.reactOnPromotion()) {
           cause = Cause.Null;
         }
       }
       this.notifyPropagators(e, cause);
     } else if (SIZE.get() == 0) {
       this.contradiction(cause, MSG_EMPTY);
     }
     return true;
   }
   return false;
 }