Propagate a knapsack on a given dimension and bin.
If the usage of an item exceeds the bin free capacity, it is filtered out.
@param bin the bin
@param d the dimension
@throws ContradictionException
962070
private void knapsack(int bin, int d) throws ContradictionException {
        final int maxLoad = prop.loads[d][bin].getUB();
        final int free = maxLoad - prop.assignedLoad[d][bin].get();

        if (free >= dynBiggest[d][bin].get()) {
            // fail fast. The remaining space > the biggest item.
            return;
        }

        if (free > 0) {
            // The bin is not full and some items exceeds the remaining space. We
            // get rid of them
            // In parallel, we set the new biggest candidate item for that
            // (bin,dimension)
            int newMax = -1;
            for (int i = candidate.get(bin).nextSetBit(0); i >= 0;
                 i = candidate.get(bin).nextSetBit(i + 1)) {
                if (prop.iSizes[d][i] > free) {
                    if (prop.bins[i].removeValue(bin, prop)) {
                        prop.removeItem(i, bin);
                        if (prop.bins[i].isInstantiated()) {
                            prop.assignItem(i, prop.bins[i].getValue());
                        }
                    }
                } else {
                    // The item is still a candidate, we just update the biggest value.
                    newMax = Math.max(newMax, prop.iSizes[d][i]);
                }
            }
            dynBiggest[d][bin].set(newMax);
        }
    }
1346428
public static int d(int x, int y) {
        int dist = 0;
        int val = x ^ y;

        // Count the number of set bits (Knuth's algorithm)
        while (val != 0) {
            ++dist;
            val &= val - 1;
        }

        return dist;
    }
1115864
@Override
	public void propagate(int evtmask) throws ContradictionException {

		// trivial case
		k.updateBounds(0, g.getPotentialNodes().size(), this);
		if (k.getUB() == 0) {
			for (int i : g.getPotentialNodes()) g.removeNode(i, this);
			return;
		}

		// bound computation
		int min = minCC();
		int max = maxCC();
		k.updateLowerBound(min, this);
		k.updateUpperBound(max, this);

		// The number of CC cannot increase :
		// - remove unreachable nodes
		// - force articulation points and bridges
		if(min != max) {
			if (k.getUB() == min) {

				// 1 --- remove unreachable nodes
				int n = g.getNbMaxNodes();
				for (int o = visitedMin.nextClearBit(0); o < n; o = visitedMin.nextClearBit(o + 1)) {
					g.removeNode(o, this);
				}

				ISet mNodes = g.getMandatoryNodes();
				if (mNodes.size() >= 2) {

					helper.findMandatoryArticulationPointsAndBridges();

					// 2 --- enforce articulation points that link two mandatory nodes
					for (int ap : helper.getArticulationPoints()) {
						g.enforceNode(ap, this);
					}

					// 3 --- enforce isthma that link two mandatory nodes (current version is bugged)
					TIntArrayList brI = helper.getBridgeFrom();
					TIntArrayList brJ = helper.getBridgeTo();
					for (int k = 0; k < brI.size(); k++) {
						int i = brI.get(k);
						int j = brJ.get(k);
						if (mNodes.contains(i) && mNodes.contains(j)) {
							g.enforceArc(i, j, this);
						}
					}
				}
			}
			// a maximal number of CC is required : remaining nodes will be singleton
			else if(k.getLB() == max){
				// --- transform every potential node into a mandatory isolated node
				ISet mNodes = g.getMandatoryNodes();
				for(int i:g.getPotentialNodes()){
					if(!mNodes.contains(i)){
						for(int j:g.getPotNeighOf(i)){
							g.removeArc(i,j,this);
						}
						g.enforceNode(i,this);
					}
				}
				// --- remove edges between mandatory nodes that would merge 2 CC
				// note that it can happen that 2 mandatory node already belong to the same CC
				// if so the edge should not be filtered
				for(int i:g.getPotentialNodes()){
					for(int j:g.getPotNeighOf(i)){
						if(ccOf[i] != ccOf[j]) {
							g.removeArc(i,j,this);
						}
					}
				}
			}
		}
	}
662315
public boolean pushWithLimit(E d, int maxSize) {
        StackNode<E> oldTop, newTop;

        newTop = new StackNode<E>(d);

        while (true) {
            oldTop = top.get();

            newTop.next = oldTop;
            if (oldTop != null) {
                newTop.index = oldTop.index + 1;
                if (newTop.index >= maxSize)
                    return false;
            } else {
                if (maxSize == 0)
                    return false;
                newTop.index = 0;
            }

            if (top.compareAndSet(oldTop, newTop))
                return true;
        }
    }
1289664
void d2xy(int n, int d, int[] xy) {
        int rx, ry, s, t = d;
        xy[0] = 0;
        xy[1] = 0;
        for (s = 1; s != n; s <<= 1) {
            rx = 1 & (t >> 1);
            ry = 1 & (t ^ rx);
            rot(s, xy, rx, ry);
            // if s was bits then shift
            xy[0] += s * rx;
            xy[1] += s * ry;
            t /= 4;
        }
    }
382447
@SuppressWarnings("squid:S3346")
    private void initialize() throws ContradictionException {

        sumISizes = new long[nbDims];
        computeSumItemSizes();

        int[][] rLoads = new int[nbDims][nbBins];
        int[][] cLoads = new int[nbDims][nbBins];

        for (int i = 0; i < bins.length; i++) {
            bins[i].updateLowerBound(0, this);
            bins[i].updateUpperBound(nbBins - 1, this);
            if (bins[i].isInstantiated()) {
                for (int d = 0; d < nbDims; d++) {
                    rLoads[d][bins[i].getValue()] += iSizes[d][i];
                }
            } else {
                DisposableValueIterator it = bins[i].getValueIterator(true);
                try {
                    while (it.hasNext()) {
                        int b = it.next();
                        for (int d = 0; d < nbDims; d++) {
                            cLoads[d][b] += iSizes[d][i];
                        }
                    }
                } finally {
                    it.dispose();
                }
            }
        }

        int[] slb = new int[nbDims];
        int[] slu = new int[nbDims];
        for (int b = 0; b < nbBins; b++) {
            for (int d = 0; d < nbDims; d++) {
                assignedLoad[d][b].set(rLoads[d][b]);
                potentialLoad[d][b].set(rLoads[d][b] + cLoads[d][b]);
                loads[d][b].updateLowerBound(rLoads[d][b], this);
                loads[d][b].updateUpperBound(rLoads[d][b] + cLoads[d][b], this);
                slb[d] += loads[d][b].getLB();
                slu[d] += loads[d][b].getUB();
            }
        }

        for (int d = 0; d < nbDims; d++) {
            sumLoadInf[d].set(slb[d]);
            sumLoadSup[d].set(slu[d]);
        }

        loadsHaveChanged = getModel().getEnvironment().makeBool(false);

        if (decoKPSimple != null) {
            decoKPSimple.postInitialize();
        }

        assert checkLoadConsistency();

        for (IIntDeltaMonitor delta : deltaMonitor) {
            delta.unfreeze();
        }
    }
1281761
public void performPruning(double UB) throws ContradictionException {
		double delta = UB - treeCost;
		assert delta >= 0;
		fromInterest = 0;
		if (selectAndCompress(delta)) {
			lca.preprocess(cctRoot, ccTree);
			pruning(fromInterest, delta);
		}
	}
906216
@Override
	public void propagate(int evtmask) throws ContradictionException {
		ISet act = g.getPotentialNodes();
		for (int node : act) {
			checkAtLeast(node);
		}
		gdm.unfreeze();
	}
1310522
@Override
	public void propagate(int evtmask) throws ContradictionException {
		int max = -1;
		for (int i : g.getPotentialNodes()) {
			if (g.getMandatoryNodes().contains(i)) {
				diameter.updateLowerBound(depthBFS(i, true), this);
			}
			max = Math.max(max, depthBFS(i, false));
		}
		diameter.updateUpperBound(max, this);
	}
1071252
private void computeSumItemSizes() {
        for (int d = 0; d < nbDims; d++) {
            long sum = 0;
            for (int i = 0; i < iSizes[d].length; i++) {
                sum += iSizes[d][i];
            }
            this.sumISizes[d] = sum;
        }

    }
17717
void push_slot( int d, int n ) {
    assert d==0;                // Should use a fcn's closure for d>1
    int idx = _display[_tod-d]+n;
    push(1);
    _ary[_sp-1] = addRef(_ary[idx]);
    _d  [_sp-1] =        _d  [idx];
    _fcn[_sp-1] = addRef(_fcn[idx]);
    _str[_sp-1] =        _str[idx];
    assert _ary[0]==null || check_refcnt(_ary[0].anyVec());
  }
429648
public static double logChoose(int n, int k) {
        if (n < 0 || k < 0 || k > n) {
            throw new IllegalArgumentException(String.format("Invalid n = %d, k = %d", n, k));
        }

        return Math.logFactorial(n) - Math.logFactorial(k) - Math.logFactorial(n - k);
    }
747895
public static int d(BitSet x, BitSet y) {
        if (x.size() != y.size())
            throw new IllegalArgumentException(String.format("BitSets have different length: x[%d], y[%d]", x.size(), y.size()));

        int dist = 0;
        for (int i = 0; i < x.size(); i++) {
            if (x.get(i) != y.get(i))
                dist++;
        }

        return dist;
    }
484098
@Override
    public void addDim(List<IntVar> c, int[] cUse, IntVar[] dUse) {
        capacities.add(c);
        cUsages.add(cUse);
        dUsages.add(dUse);
    }
285116
private boolean checkDimensions(CLIQUEUnit other, int e) {
    for(int i = 0, j = 0; i < e; i++, j += 2) {
      if(dims[i] != other.dims[i] || bounds[j] != other.bounds[j] || bounds[j + 1] != bounds[j + 1]) {
        return false;
      }
    }
    return true;
  }
425722
@Override
	public void propagate(int evtmask) throws ContradictionException {
		if (PropagatorEventType.isFullPropagation(evtmask)) {
			for (int i = 0; i < n; i++) {
				e1[i].set(i);
				e2[i].set(i);
				size[i].set(1);
				g.removeArc(i,i,this);
			}
			ISet nei;
			for (int i = 0; i < n; i++) {
				nei = g.getMandNeighOf(i);
				for (int j : nei) {
					if (i < j) {
						enforce(i, j);
					}
				}
			}
		}
		gdm.unfreeze();
	}
1242755
@Override
	public void propagate(int evtmask) throws ContradictionException {
		for (int i = 0; i < n; i++) {
			color[i].set(i);
			size[i].set(1);
			mate[i] = -1;
		}
		ISet nei;
		for (int i = 0; i < n; i++) {
			nei = g.getMandNeighOf(i);
			for (int j : nei) {
				if (i < j) {
					enforce(i, j);
				}
			}
		}
		gdm.unfreeze();
	}