Search in sources :

Example 1 with IIntDeltaMonitor

use of org.chocosolver.solver.variables.delta.IIntDeltaMonitor in project scheduler by btrplace.

the class VectorPackingPropagator method initialize.

// ***********************************************************************************************************************//
// HELPER
// ***********************************************************************************************************************//
/**
 * initialize the internal data: sumItemSize, assignedLoad, potentialLoad, sumLoadInf, sumLoadSup, maxSlackBinHeap
 * shrink the item-to-bins assignment variables: 0 <= bins[i] < nbBins
 * shrink the bin load variables: assignedLoad <= binLoad <= potentialLoad
 */
@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();
    }
}
Also used : IIntDeltaMonitor(org.chocosolver.solver.variables.delta.IIntDeltaMonitor) DisposableValueIterator(org.chocosolver.util.iterators.DisposableValueIterator)

Aggregations

IIntDeltaMonitor (org.chocosolver.solver.variables.delta.IIntDeltaMonitor)1 DisposableValueIterator (org.chocosolver.util.iterators.DisposableValueIterator)1