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()); }
@Override public DisposableRangeIterator getRangeIterator(boolean bottomUp) { if (_riterator == null || !_riterator.isReusable()) { _riterator = new DisposableRangeIterator() { int from; int to; @Override public void bottomUpInit() { super.bottomUpInit(); this.from = VALUES.nextSetBit(0); this.to = VALUES.nextClearBit(from + 1) - 1; } @Override public void topDownInit() { super.topDownInit(); this.to = VALUES.prevSetBit(VALUES.size() - 1); this.from = VALUES.prevClearBit(to) + 1; } public boolean hasNext() { return this.from != -1; } @Override public boolean hasPrevious() { return this.to != -1; } public void next() { this.from = VALUES.nextSetBit(this.to + 1); this.to = VALUES.nextClearBit(this.from) - 1; } @Override public void previous() { this.to = VALUES.prevSetBit(this.from - 1); this.from = VALUES.prevClearBit(this.to) + 1; } @Override public int min() { return from + OFFSET; } @Override public int max() { return to + OFFSET; } }; } if (bottomUp) { _riterator.bottomUpInit(); } else { _riterator.topDownInit(); } return _riterator; }
@Override public DisposableRangeIterator getRangeIterator(boolean bottomUp) { if (_riterator == null || !_riterator.isReusable()) { _riterator = new DisposableRangeIterator() { DisposableRangeIterator vir; @Override public void bottomUpInit() { super.bottomUpInit(); vir = var.getRangeIterator(true); } @Override public void topDownInit() { super.topDownInit(); vir = var.getRangeIterator(false); } @Override public boolean hasNext() { return vir.hasNext(); } @Override public boolean hasPrevious() { return vir.hasPrevious(); } @Override public void next() { vir.next(); } @Override public void previous() { vir.previous(); } @Override public int min() { return vir.min() + cste; } @Override public int max() { return vir.max() + cste; } @Override public void dispose() { super.dispose(); vir.dispose(); } }; } if (bottomUp) { _riterator.bottomUpInit(); } else { _riterator.topDownInit(); } return _riterator; }