Search in sources :

Example 16 with Slice

use of org.btrplace.scheduler.choco.Slice in project scheduler by btrplace.

the class DefaultCumulatives method symmetryBreakingForStayingVMs.

/**
 * Symmetry breaking for VMs that stay running, on the same node.
 *
 * @return {@code true} iff the symmetry breaking does not lead to a problem without solutions
 */
private boolean symmetryBreakingForStayingVMs(ReconfigurationProblem rp) {
    for (VM vm : rp.getFutureRunningVMs()) {
        VMTransition a = rp.getVMAction(vm);
        Slice dSlice = a.getDSlice();
        Slice cSlice = a.getCSlice();
        if (dSlice != null && cSlice != null) {
            BoolVar stay = ((KeepRunningVM) a).isStaying();
            Boolean ret = strictlyDecreasingOrUnchanged(vm);
            if (Boolean.TRUE.equals(ret) && !zeroDuration(rp, stay, cSlice)) {
                return false;
            // Else, the resource usage is decreasing, so
            // we set the cSlice duration to 0 to directly reduces the resource allocation
            } else if (Boolean.FALSE.equals(ret) && !zeroDuration(rp, stay, dSlice)) {
                // (the allocation will be performed at the end of the reconfiguration process)
                return false;
            }
        }
    }
    return true;
}
Also used : Slice(org.btrplace.scheduler.choco.Slice) KeepRunningVM(org.btrplace.scheduler.choco.transition.KeepRunningVM) VM(org.btrplace.model.VM) KeepRunningVM(org.btrplace.scheduler.choco.transition.KeepRunningVM) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) BoolVar(org.chocosolver.solver.variables.BoolVar)

Example 17 with Slice

use of org.btrplace.scheduler.choco.Slice in project scheduler by btrplace.

the class CBan method inject.

@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) {
    if (ban.isContinuous()) {
        for (VM vm : ban.getInvolvedVMs()) {
            if (ban.getInvolvedNodes().contains(rp.getSourceModel().getMapping().getVMLocation(vm))) {
                rp.getLogger().error("Constraint {} is not satisfied initially", ban);
                return false;
            }
        }
    }
    Collection<Node> nodes = ban.getInvolvedNodes();
    int[] nodesIdx = new int[nodes.size()];
    int i = 0;
    for (Node n : ban.getInvolvedNodes()) {
        nodesIdx[i++] = rp.getNode(n);
    }
    VM vm = ban.getInvolvedVMs().iterator().next();
    Slice t = rp.getVMAction(vm).getDSlice();
    if (t != null) {
        for (int x : nodesIdx) {
            try {
                t.getHoster().removeValue(x, Cause.Null);
            } catch (ContradictionException e) {
                rp.getLogger().error("Unable to disallow " + vm + " to be running on " + rp.getNode(x), e);
                return false;
            }
        }
    }
    return true;
}
Also used : Slice(org.btrplace.scheduler.choco.Slice) ContradictionException(org.chocosolver.solver.exception.ContradictionException) VM(org.btrplace.model.VM) Node(org.btrplace.model.Node)

Example 18 with Slice

use of org.btrplace.scheduler.choco.Slice in project scheduler by btrplace.

the class CFence method inject.

@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) {
    if (cstr.isContinuous()) {
        for (VM vm : cstr.getInvolvedVMs()) {
            Node location = rp.getSourceModel().getMapping().getVMLocation(vm);
            if (location != null && !cstr.getInvolvedNodes().contains(location)) {
                rp.getLogger().error("Constraint {} is not satisfied initially", cstr);
                return false;
            }
        }
    }
    VM vm = cstr.getInvolvedVMs().iterator().next();
    Collection<Node> nodes = cstr.getInvolvedNodes();
    Slice t = rp.getVMAction(vm).getDSlice();
    if (!rp.getFutureRunningVMs().contains(vm)) {
        return true;
    }
    if (nodes.size() == 1) {
        return force(rp, t.getHoster(), vm, nodes.iterator().next());
    }
    return allBut(rp, t.getHoster(), vm, nodes);
}
Also used : Slice(org.btrplace.scheduler.choco.Slice) VM(org.btrplace.model.VM) Node(org.btrplace.model.Node)

Example 19 with Slice

use of org.btrplace.scheduler.choco.Slice 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 20 with Slice

use of org.btrplace.scheduler.choco.Slice 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

Slice (org.btrplace.scheduler.choco.Slice)22 VMTransition (org.btrplace.scheduler.choco.transition.VMTransition)17 VM (org.btrplace.model.VM)16 ArrayList (java.util.ArrayList)12 IntVar (org.chocosolver.solver.variables.IntVar)11 Node (org.btrplace.model.Node)8 List (java.util.List)6 TIntArrayList (gnu.trove.list.array.TIntArrayList)5 TObjectIntMap (gnu.trove.map.TObjectIntMap)5 Collections (java.util.Collections)5 HashSet (java.util.HashSet)5 Map (java.util.Map)5 Objects (java.util.Objects)5 Set (java.util.Set)5 Instance (org.btrplace.model.Instance)5 Mapping (org.btrplace.model.Mapping)5 Model (org.btrplace.model.Model)5 ShareableResource (org.btrplace.model.view.ShareableResource)5 SchedulerException (org.btrplace.scheduler.SchedulerException)5 Parameters (org.btrplace.scheduler.choco.Parameters)5