Search in sources :

Example 6 with Constraint

use of org.chocosolver.solver.constraints.Constraint in project scheduler by btrplace.

the class VectorPackingTest method modelPack.

public void modelPack(int[][] capa, int[][] height) {
    int nRes = capa.length;
    assert nRes == height.length;
    int nBins = capa[0].length;
    int nItems = height[0].length;
    s = new Model();
    loads = new IntVar[nRes][nBins];
    bins = new IntVar[nItems];
    String[] name = new String[nRes];
    for (int d = 0; d < nRes; d++) {
        name[d] = "d" + d;
        for (int i = 0; i < nBins; i++) {
            loads[d][i] = s.intVar("l" + d + "." + i, 0, capa[d][i], true);
        }
    }
    sizes = height;
    bins = s.intVarArray("b", nItems, 0, nBins, false);
    Constraint cPack = new VectorPacking(name, loads, sizes, bins);
    s.post(cPack);
}
Also used : VectorPacking(org.btrplace.scheduler.choco.extensions.pack.VectorPacking) Constraint(org.chocosolver.solver.constraints.Constraint) Model(org.chocosolver.solver.Model) Constraint(org.chocosolver.solver.constraints.Constraint)

Example 7 with Constraint

use of org.chocosolver.solver.constraints.Constraint in project scheduler by btrplace.

the class CAmong method restrictGroup.

private boolean restrictGroup(Parameters ps, ReconfigurationProblem rp, Set<VM> running, List<Collection<Node>> groups, int selected) {
    if (selected == -1) {
        // Now, we create a variable to indicate on which group of nodes the VMs will be
        vmGrpId = rp.getModel().intVar(rp.makeVarLabel(GROUP_LABEL), 0, groups.size() - 1, false);
        // grp: A table to indicate the group each node belong to, -1 for no group
        int[] grp = new int[rp.getNodes().size()];
        for (int i = 0; i < grp.length; i++) {
            Node n = rp.getNode(i);
            int idx = getGroup(n, groups);
            if (idx >= 0) {
                grp[i] = idx;
            } else {
                grp[i] = -1;
            }
        }
        // We link the VM placement variable with the group variable
        for (VM vm : running) {
            IntVar assign = rp.getVMAction(vm).getDSlice().getHoster();
            Constraint c = rp.getModel().element(vmGrpId, grp, assign, 0);
            rp.getModel().post(c);
        }
    } else {
        // As the group is already known, it's now just a fence constraint
        vmGrpId = rp.fixed(selected, GROUP_LABEL);
        if (!fence(ps, rp, running, groups.get(selected))) {
            return false;
        }
    }
    return true;
}
Also used : Constraint(org.chocosolver.solver.constraints.Constraint) Node(org.btrplace.model.Node) VM(org.btrplace.model.VM) IntVar(org.chocosolver.solver.variables.IntVar) Constraint(org.chocosolver.solver.constraints.Constraint)

Example 8 with Constraint

use of org.chocosolver.solver.constraints.Constraint in project scheduler by btrplace.

the class CNoDelay method inject.

@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) {
    VM v = noDelay.getInvolvedVMs().iterator().next();
    // For each vm involved in the constraint
    VMTransition vt = rp.getVMAction(v);
    // Get the VMTransition start time
    // Add the constraint "start = 0" to the solver
    Slice d = vt.getDSlice();
    if (d == null) {
        return true;
    }
    if (!(vt instanceof RelocatableVM)) {
        try {
            d.getStart().instantiateTo(0, Cause.Null);
        } catch (ContradictionException ex) {
            rp.getLogger().error("Unable to prevent any delay on '" + v + "'", ex);
            return false;
        }
    } else {
        Constraint c = rp.getModel().arithm(d.getStart(), "=", 0);
        BoolVar move = ((RelocatableVM) vt).isStaying().not();
        ChocoUtils.postImplies(rp, move, c);
    }
    return true;
}
Also used : Constraint(org.chocosolver.solver.constraints.Constraint) Slice(org.btrplace.scheduler.choco.Slice) ContradictionException(org.chocosolver.solver.exception.ContradictionException) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) VM(org.btrplace.model.VM) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) BoolVar(org.chocosolver.solver.variables.BoolVar)

Aggregations

Constraint (org.chocosolver.solver.constraints.Constraint)8 IntVar (org.chocosolver.solver.variables.IntVar)6 VM (org.btrplace.model.VM)5 Node (org.btrplace.model.Node)4 BoolVar (org.chocosolver.solver.variables.BoolVar)4 Mapping (org.btrplace.model.Mapping)3 DefaultModel (org.btrplace.model.DefaultModel)2 Model (org.btrplace.model.Model)2 OptConstraint (org.btrplace.model.constraint.OptConstraint)2 SatConstraint (org.btrplace.model.constraint.SatConstraint)2 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)2 Test (org.testng.annotations.Test)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 ShareableResource (org.btrplace.model.view.ShareableResource)1 Slice (org.btrplace.scheduler.choco.Slice)1 CMinMTTR (org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR)1 VectorPacking (org.btrplace.scheduler.choco.extensions.pack.VectorPacking)1 RelocatableVM (org.btrplace.scheduler.choco.transition.RelocatableVM)1