Пример #1
0
  @Override
  public void backPropagate(int mask) throws ContradictionException {
    // one of the variable as changed externally, this involves a complete update of this
    // one of the variable as changed externally, this involves a complete update of this
    if (!EventType.isRemove(mask)) {
      int lA = A.getLB(), uA = A.getUB();
      int lB = B.getLB(), uB = B.getUB();

      int elb = Math.max(lA, lB);
      int eub = Math.max(uA, uB);

      int ilb = LB.get();
      int iub = UB.get();
      boolean change = false;
      EventType e = EventType.VOID;
      if (elb > ilb) {
        if (elb > iub) {
          this.contradiction(this, MSG_LOW);
        }
        SIZE.add(elb - ilb);
        ilb = elb;
        LB.set(ilb);
        e = EventType.INCLOW;
        change = true;
      }
      if (eub < iub) {
        if (eub < ilb) {
          this.contradiction(this, MSG_LOW);
        }
        SIZE.add(eub - iub);
        iub = eub;
        UB.set(iub);
        if (e != EventType.VOID) {
          e = EventType.BOUND;
        } else {
          e = EventType.DECUPP;
        }
        change |= true;
      }
      if (ilb > iub) {
        this.contradiction(this, MSG_EMPTY);
      }
      if (change) {
        if (ilb == iub) {
          notifyPropagators(EventType.INSTANTIATE, this);
        } else {
          notifyPropagators(e, this);
        }
      }
    }
  }
Пример #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;
  }
Пример #3
0
  @Override
  public boolean removeValue(int value, ICause cause, boolean informCause)
      throws ContradictionException {
    ICause antipromo = cause;
    if (informCause) {
      cause = Cause.Null;
    }
    boolean change = false;
    int inf = getLB();
    int sup = getUB();
    if (value == inf && value == sup) {
      this.contradiction(cause, MSG_REMOVE);
    } else {
      if (inf <= value && value <= sup) {
        EventType e = EventType.REMOVE;

        int aValue = value - OFFSET;
        change = VALUES.get(aValue);
        this.VALUES.clear(aValue);
        if (change) {
          SIZE.add(-1);
          // todo delta
        }

        if (value == inf) {
          inf = VALUES.nextSetBit(aValue) + OFFSET;
          LB.set(inf);
          e = EventType.INCLOW;
          filterOnGeq(cause, inf);
          if (cause.reactOnPromotion()) {
            cause = Cause.Null;
          }
        } else if (value == sup) {
          sup = VALUES.prevSetBit(aValue) + OFFSET;
          UB.set(sup);
          e = EventType.DECUPP;
          filterOnLeq(cause, sup);
          if (cause.reactOnPromotion()) {
            cause = Cause.Null;
          }
        }
        if (change && !VALUES.isEmpty()) {
          if (this.instantiated()) {
            e = EventType.INSTANTIATE;
            if (cause.reactOnPromotion()) {
              cause = Cause.Null;
            }
          }
          this.notifyPropagators(e, cause);
        } else {
          if (VALUES.isEmpty()) {
            this.contradiction(cause, MSG_EMPTY);
          }
        }
      }
    }
    return change;
  }
Пример #4
0
  @Override
  public boolean updateLowerBound(int aValue, ICause cause, boolean informCause)
      throws ContradictionException {
    ICause antipromo = cause;
    if (informCause) {
      cause = Cause.Null;
    }
    int old = this.getLB();
    if (old < aValue) {
      if (this.getUB() < aValue) {
        this.contradiction(cause, MSG_LOW);
      } else {
        EventType e = EventType.INCLOW;
        // todo delta
        SIZE.add(old - aValue);
        LB.set(aValue);

        if (A.getLB() > B.getUB()) {
          A.updateLowerBound(aValue, this, false);
        }
        if (B.getLB() > A.getUB()) {
          B.updateLowerBound(aValue, this, false);
        }

        if (instantiated()) {
          e = EventType.INSTANTIATE;
          if (cause.reactOnPromotion()) {
            cause = Cause.Null;
          }
        }
        this.notifyPropagators(e, cause);
        return true;
      }
    }
    return false;
  }