Пример #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;
    }
  }
Пример #2
0
 public MaxView(IntVar a, IntVar b, Solver solver) {
   super(a, b, solver);
   int lb = Math.max(A.getLB(), B.getLB());
   int ub = Math.max(A.getUB(), B.getUB());
   LB.set(lb);
   UB.set(ub);
   SIZE.set(ub - lb + 1);
 }
Пример #3
0
 @Override
 public void backPropagate(int mask) throws ContradictionException {
   // one of the variable as changed externally, this involves a complete update of this
   if (!EventType.isRemove(mask)) {
     int elb = A.getLB() + B.getLB();
     int eub = A.getUB() + B.getUB();
     int ilb = LB.get();
     int iub = UB.get();
     int old_size = iub - ilb; // is == 0, then the view is already instantiated
     boolean up = false, down = false;
     EventType e = EventType.VOID;
     if (elb > ilb) {
       if (elb > iub) {
         this.contradiction(this, MSG_LOW);
       }
       VALUES.clear(ilb - OFFSET, elb - OFFSET);
       ilb = VALUES.nextSetBit(ilb - OFFSET) + OFFSET;
       LB.set(ilb);
       e = EventType.INCLOW;
       down = true;
     }
     if (eub < iub) {
       if (eub < ilb) {
         this.contradiction(this, MSG_LOW);
       }
       VALUES.clear(eub - OFFSET + 1, iub - OFFSET + 1);
       iub = VALUES.prevSetBit(iub - OFFSET + 1) + OFFSET;
       UB.set(iub);
       if (e != EventType.VOID) {
         e = EventType.BOUND;
       } else {
         e = EventType.DECUPP;
       }
       up = true;
     }
     int size = VALUES.cardinality();
     SIZE.set(size);
     if (ilb > iub) {
       this.contradiction(this, MSG_EMPTY);
     }
     if (down || size == 1) {
       filterOnGeq(this, ilb);
     }
     if (up || size == 1) { // size == 1 means instantiation, then force filtering algo
       filterOnLeq(this, iub);
     }
     if (ilb == iub) { // size == 1 means instantiation, then force filtering algo
       if (old_size > 0) {
         notifyPropagators(EventType.INSTANTIATE, this);
       }
     } else {
       notifyPropagators(e, this);
     }
   }
 }
Пример #4
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);
        }
      }
    }
  }
Пример #5
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;
 }
Пример #6
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;
  }
Пример #7
0
  public BitsetXYSumView(IntVar a, IntVar b, Solver solver) {
    super(a, b, solver);
    int lbA = A.getLB();
    int ubA = A.getUB();
    int lbB = B.getLB();
    int ubB = B.getUB();
    OFFSET = lbA + lbB;
    VALUES = solver.getEnvironment().makeBitSet((ubA + ubB) - (lbA + lbB) + 1);

    DisposableRangeIterator itA = A.getRangeIterator(true);
    DisposableRangeIterator itB = B.getRangeIterator(true);
    while (itA.hasNext()) {
      itB.bottomUpInit();
      while (itB.hasNext()) {
        VALUES.set(itA.min() + itB.min() - OFFSET, itA.max() + itB.max() - OFFSET + 1);
        itB.next();
      }
      itB.dispose();
      itA.next();
    }
    itA.dispose();
    SIZE.set(VALUES.cardinality());
  }
Пример #8
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;
  }
Пример #9
0
 @Override
 public boolean contains(int value) {
   return A.contains(value) || B.contains(value);
 }