Reduce the cardinality wrt. the worst case scenario.

@param nIdx the node index
@param min  the min (but > 0 ) consumption for a VM
@param nbZeroes the number of VMs consuming 0
@return {@code false} if the problem no longer has a solution
540302
private boolean capHosting(int nIdx, int min, int nbZeroes) {
        Node n = rp.getNode(nIdx);
        double capa = getSourceResource().getCapacity(n) * getOverbookRatio(nIdx)/*.getLB()*/;
      int card = (int) (capa / min) + nbZeroes + 1;
      if (card < source.getMapping().getRunningVMs(n).size()) {
        // This shortcut is required to prevent a filtering issue in the scheduling phase:
        // At time 0, LocalTaskScheduler will complain and start to backtrack.
        // TODO: revise the notion of continuous constraint for the cardinality issue.
        return true;
      }
        try {
            //Restrict the hosting capacity.
            rp.getNbRunningVMs().get(nIdx).updateUpperBound(card, Cause.Null);
        } catch (ContradictionException ex) {
            rp.getLogger().error("Unable to cap the hosting capacity of '" + n + " ' to " + card, ex);
            return false;
        }
        return true;
    }
406861
@Override
    @SuppressWarnings("squid:S3346")
    public boolean beforeSolve(ReconfigurationProblem rp) {
        super.beforeSolve(rp);
        if (rp.getSourceModel().getMapping().getNbNodes() == 0 || capacities.isEmpty()) {
            return true;
        }

        int nbDims = capacities.size();
        int nbRes = capacities.get(0).size();

        //We get the UB of the node capacity and the LB for the VM usage.
        int[][] capas = new int[nbRes][nbDims];
        int d = 0;
        for (List<IntVar> capaDim : capacities) {
            assert capaDim.size() == nbRes;
            for (int j = 0; j < capaDim.size(); j++) {
                capas[j][d] = capaDim.get(j).getUB();
            }
            d++;
        }
        assert cUsages.size() == nbDims;
        int nbCHosts = cUsages.get(0).length;
        int[][] cUses = new int[nbCHosts][nbDims];
        d = 0;
        for (int[] cUseDim : cUsages) {
            assert cUseDim.length == nbCHosts;
            for (int i = 0; i < nbCHosts; i++) {
                cUses[i][d] = cUseDim[i];
            }
            d++;
        }


        assert dUsages.size() == nbDims;
        int nbDHosts = dUsages.get(0).length;
        int[][] dUses = new int[nbDHosts][nbDims];
        d = 0;
        for (IntVar[] dUseDim : dUsages) {
            assert dUseDim.length == nbDHosts;
            for (int j = 0; j < nbDHosts; j++) {
                dUses[j][d] = dUseDim[j].getLB();
            }
            d++;
        }
        symmetryBreakingForStayingVMs(rp);
        IntVar[] earlyStarts = rp.getNodeActions().stream().map(NodeTransition::getHostingStart).toArray(IntVar[]::new);
        IntVar[] lastEnd = rp.getNodeActions().stream().map(NodeTransition::getHostingEnd).toArray(IntVar[]::new);
        rp.getModel().post(
                new TaskScheduler(earlyStarts,
                        lastEnd,
                        capas,
                        cHosts, cUses, cEnds,
                        dHosts, dUses, dStarts,
                        associations)
        );
        return true;
    }
1130741
private boolean isLatticeBrokenAfter(int endIndex, ViterbiLattice lattice) {
        ViterbiNode[][] nodeStartIndices = lattice.getStartIndexArr();

        return nodeStartIndices[endIndex] == null;
    }
976778
private RedBlackTreeNode<Key, Value> min(RedBlackTreeNode<Key, Value> x) {
	// assert x != null;
	if (x.getLeft() == null)
	    return x;
	else
	    return min(x.getLeft());
    }
666911
public static void deleteNode(DbConn cnx, int id)
    {
        int countRunning = cnx.runSelectSingle("ji_select_count_by_node", Integer.class, id);
        if (countRunning > 0)
        {
            cnx.setRollbackOnly();
            throw new JqmAdminApiUserException(
                    "cannot delete a node with running instances. Disable it, wait for the end of all running instances, then retry.");
        }

        try
        {
            Node n = Node.select_single(cnx, "node_select_by_id", id);
            Calendar limit = Calendar.getInstance();
            limit.add(Calendar.MINUTE, -10);
            if (n.getLastSeenAlive() != null && n.getLastSeenAlive().after(limit))
            {
                cnx.setRollbackOnly();
                throw new JqmAdminApiUserException(
                        "Can only remove a node either properly shut down or that has crashed more than 10 minutes ago.");
            }
        }
        catch (NoResultException e)
        {
            throw new JqmAdminApiUserException("no item with ID " + id);
        }

        cnx.runUpdate("dp_delete_for_node", id);
        QueryResult qr = cnx.runUpdate("node_delete_by_id", id);
        if (qr.nbUpdated != 1)
        {
            cnx.setRollbackOnly();
            throw new JqmAdminApiUserException("no item with ID " + id);
        }
    }
1364239
@Pure
	public static int min(int... values) {
		if (values == null || values.length == 0) {
			return 0;
		}
		int min = values[0];
		for (final int v : values) {
			if (v < min) {
				min = v;
			}
		}
		return min;
	}
862984
public RiakNode setMinConnections(int minConnections)
    {
        stateCheck(State.CREATED, State.RUNNING, State.HEALTH_CHECKING);
        if (minConnections <= getMaxConnections())
        {
            this.minConnections = minConnections;
        }
        else
        {
            throw new IllegalArgumentException("Min connections greater than max connections");
        }
        // TODO: Start / reap delta?
        return this;
    }
260283
public static /*@pure@*/ int minIndex(double[] doubles) {

    double minimum = 0;
    int minIndex = 0;

    for (int i = 0; i < doubles.length; i++) {
      if ((i == 0) || (doubles[i] < minimum)) {
	minIndex = i;
	minimum = doubles[i];
      }
    }

    return minIndex;
  }
833810
@SuppressWarnings("unchecked")
    private void decreaseKey(ReflectedHandle<K, V> n, K newKey) {
        if (n.inner == null && free != n) {
            throw new IllegalArgumentException("Invalid handle!");
        }

        int c;
        if (comparator == null) {
            c = ((Comparable<? super K>) newKey).compareTo(n.key);
        } else {
            c = comparator.compare(newKey, n.key);
        }
        if (c > 0) {
            throw new IllegalArgumentException("Keys can only be decreased!");
        }
        n.key = newKey;
        if (c == 0 || free == n) {
            return;
        }

        // actual decrease
        AddressableHeap.Handle<K, HandleMap<K, V>> nInner = n.inner;
        if (n.minNotMax) {
            // we are in the min heap, easy case
            n.inner.decreaseKey(newKey);
        } else {
            // we are in the max heap, remove
            nInner.delete();
            ReflectedHandle<K, V> nOuter = nInner.getValue().outer;
            nOuter.inner = null;
            nOuter.minNotMax = false;

            // remove min
            AddressableHeap.Handle<K, HandleMap<K, V>> minInner = nInner.getValue().otherInner;
            ReflectedHandle<K, V> minOuter = minInner.getValue().outer;
            minInner.delete();
            minOuter.inner = null;
            minOuter.minNotMax = false;

            // update key
            nOuter.key = newKey;

            // reinsert both
            insertPair(nOuter, minOuter);
        }
    }
298887
public void eachNonZero(MatrixProcedure procedure) {
        MatrixIterator it = nonZeroIterator();

        while (it.hasNext()) {
            double x = it.next();
            int i = it.rowIndex();
            int j = it.columnIndex();
            procedure.apply(i, j, x);
        }
    }
66842
public static double min(double[] x) {
        double m = Double.POSITIVE_INFINITY;

        for (double n : x) {
            if (n < m) {
                m = n;
            }
        }

        return m;
    }
793915
public static void descendingOrder(DMatrixRMaj U , boolean tranU ,
                                       DMatrixRMaj W ,
                                       DMatrixRMaj V , boolean tranV )
    {
        int numSingular = Math.min(W.numRows,W.numCols);

        checkSvdMatrixSize(U, tranU, W, V, tranV);

        for( int i = 0; i < numSingular; i++ ) {
            double bigValue=-1;
            int bigIndex=-1;

            // find the smallest singular value in the submatrix
            for( int j = i; j < numSingular; j++ ) {
                double v = W.get(j,j);

                if( v > bigValue ) {
                    bigValue = v;
                    bigIndex = j;
                }
            }

            // only swap if the current index is not the smallest
            if( bigIndex == i)
                continue;

            if( bigIndex == -1 ) {
                // there is at least one uncountable singular value.  just stop here
                break;
            }

            double tmp = W.get(i,i);
            W.set(i,i,bigValue);
            W.set(bigIndex,bigIndex,tmp);

            if( V != null ) {
                swapRowOrCol(V, tranV, i, bigIndex);
            }

            if( U != null ) {
                swapRowOrCol(U, tranU, i, bigIndex);
            }
        }
    }
382157
private void forceDecreaseKeyToMinimum(Node<K, V> n) {
        // if not root
        Node<K, V> y = n.parent;
        if (y != null) {
            cut(n, y);
            cascadingCut(y);
        }
        minRoot = n;
    }
512913
protected boolean initialLoad(int minimum)
        throws IOException
    {
        mInputPtr = 0;
        mInputEnd = 0;

        while (mInputEnd < minimum) {
            int count = mIn.read(mCharBuffer, mInputEnd,
                                 mCharBuffer.length - mInputEnd);
            if (count < 1) {
                return false;
            }
            mInputEnd += count;
        }
        return true;
    }
463190
@Override
	public void setMinX(double x) {
		double o = this.maxxProperty.doubleValue();
		if (o<x) {
			this.minxProperty.set(o);
			this.maxxProperty.set(x);
		}
		else {
			this.minxProperty.set(x);
		}
	}
185135
private static ByteBuffer min(ByteBuffer b1, ByteBuffer b2, AbstractType<?> comparator)
    {
        if (b1 == null)
            return b2;
        if (b2 == null)
            return b1;

        if (comparator.compare(b1, b2) >= 0)
            return b2;
        return b1;
    }
202855
public org.tensorflow.framework.CostGraphDef.NodeOrBuilder getNodeOrBuilder(
      int index) {
    return node_.get(index);
  }