Search in sources :

Example 66 with IntVar

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

the class DefaultReconfigurationProblem method linkCardinalityWithSlices.

private void linkCardinalityWithSlices() {
    Stream<Slice> s = vmActions.stream().map(VMTransition::getDSlice).filter(Objects::nonNull);
    IntVar[] ds = s.map(Slice::getHoster).toArray(IntVar[]::new);
    int[] usages = new int[ds.length];
    Arrays.fill(usages, 1);
    ChocoView v = getView(Packing.VIEW_ID);
    if (v == null) {
        throw SchedulerModelingException.missingView(model, Packing.VIEW_ID);
    }
    ((Packing) v).addDim("vmsOnNodes", vmsCountOnNodes, usages, ds);
}
Also used : ChocoView(org.btrplace.scheduler.choco.view.ChocoView) Packing(org.btrplace.scheduler.choco.view.Packing) Objects(java.util.Objects) IntVar(org.chocosolver.solver.variables.IntVar)

Example 67 with IntVar

use of org.chocosolver.solver.variables.IntVar 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 68 with IntVar

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

the class CGather method forceDiscreteCollocation.

private static boolean forceDiscreteCollocation(ReconfigurationProblem rp, List<Slice> dSlices) {
    for (int i = 0; i < dSlices.size(); i++) {
        for (int j = 0; j < i; j++) {
            Slice s1 = dSlices.get(i);
            Slice s2 = dSlices.get(j);
            IntVar i1 = s1.getHoster();
            IntVar i2 = s2.getHoster();
            if (i1.isInstantiated() && !instantiateTo(rp, i2, i1.getLB(), s1, s2)) {
                return false;
            } else if (i2.isInstantiated() && !instantiateTo(rp, i1, i2.getLB(), s1, s2)) {
                return false;
            }
            rp.getModel().post(rp.getModel().arithm(i1, "=", i2));
        }
    }
    return true;
}
Also used : Slice(org.btrplace.scheduler.choco.Slice) IntVar(org.chocosolver.solver.variables.IntVar)

Example 69 with IntVar

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

the class CLonely method inject.

@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) {
    // Remove non future-running VMs
    List<IntVar> myHosts = new ArrayList<>();
    List<IntVar> otherHosts = new ArrayList<>();
    Collection<VM> vms = new HashSet<>();
    Set<VM> otherVMs = new HashSet<>();
    for (VM vm : rp.getFutureRunningVMs()) {
        IntVar host = rp.getVMAction(vm).getDSlice().getHoster();
        if (cstr.getInvolvedVMs().contains(vm)) {
            myHosts.add(host);
            vms.add(vm);
        } else {
            otherHosts.add(host);
            otherVMs.add(vm);
        }
    }
    // Link the assignment variables with the set
    Model s = rp.getModel();
    s.post(new Disjoint(myHosts.toArray(new IntVar[myHosts.size()]), otherHosts.toArray(new IntVar[otherHosts.size()]), rp.getNodes().size()));
    if (cstr.isContinuous()) {
        continuousRestriction(rp, vms, otherVMs);
    }
    return true;
}
Also used : VM(org.btrplace.model.VM) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) Model(org.chocosolver.solver.Model) Disjoint(org.btrplace.scheduler.choco.extensions.Disjoint) IntVar(org.chocosolver.solver.variables.IntVar) HashSet(java.util.HashSet)

Example 70 with IntVar

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

the class CQuarantine method inject.

@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
    // It is just a composition of a root constraint on the VMs on the given nodes (the zone)
    // plus a ban on the other VMs to prevent them for being hosted in the zone
    Mapping map = rp.getSourceModel().getMapping();
    Node n = cstr.getInvolvedNodes().iterator().next();
    int nIdx = rp.getNode(n);
    for (VM vm : rp.getFutureRunningVMs()) {
        if (n.equals(map.getVMLocation(vm))) {
            IntVar d = rp.getVMAction(vm).getDSlice().getHoster();
            try {
                d.instantiateTo(nIdx, Cause.Null);
            } catch (ContradictionException e) {
                rp.getLogger().error("Unable to root " + vm + " on " + n, e);
                return false;
            }
        } else {
            IntVar d = rp.getVMAction(vm).getDSlice().getHoster();
            try {
                d.removeValue(nIdx, Cause.Null);
            } catch (ContradictionException e) {
                rp.getLogger().error("Unable to disallow " + vm + " to be hosted on " + n, e);
                return false;
            }
        }
    }
    return true;
}
Also used : ContradictionException(org.chocosolver.solver.exception.ContradictionException) Node(org.btrplace.model.Node) VM(org.btrplace.model.VM) Mapping(org.btrplace.model.Mapping) IntVar(org.chocosolver.solver.variables.IntVar)

Aggregations

IntVar (org.chocosolver.solver.variables.IntVar)78 VM (org.btrplace.model.VM)35 Model (org.chocosolver.solver.Model)32 Test (org.testng.annotations.Test)30 Node (org.btrplace.model.Node)29 ArrayList (java.util.ArrayList)23 VMTransition (org.btrplace.scheduler.choco.transition.VMTransition)22 BoolVar (org.chocosolver.solver.variables.BoolVar)17 Mapping (org.btrplace.model.Mapping)16 Model (org.btrplace.model.Model)15 RelocatableVM (org.btrplace.scheduler.choco.transition.RelocatableVM)13 HashSet (java.util.HashSet)11 Slice (org.btrplace.scheduler.choco.Slice)10 DefaultModel (org.btrplace.model.DefaultModel)9 TIntArrayList (gnu.trove.list.array.TIntArrayList)8 ShareableResource (org.btrplace.model.view.ShareableResource)8 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)8 Constraint (org.chocosolver.solver.constraints.Constraint)8 List (java.util.List)7 Set (java.util.Set)7