Search in sources :

Example 1 with Precedences

use of org.btrplace.scheduler.choco.extensions.Precedences in project scheduler by btrplace.

the class CLonely method continuousRestriction.

private static void continuousRestriction(ReconfigurationProblem rp, Collection<VM> vms, Set<VM> otherVMs) {
    // Get the position of all the others c-slices and their associated end moment
    TIntArrayList otherPos = new TIntArrayList();
    TIntArrayList minePos = new TIntArrayList();
    List<IntVar> otherEnds = new ArrayList<>();
    List<IntVar> mineEnds = new ArrayList<>();
    Mapping map = rp.getSourceModel().getMapping();
    for (Node n : map.getOnlineNodes()) {
        for (VM vm : map.getRunningVMs(n)) {
            if (!vms.contains(vm)) {
                otherPos.add(rp.getNode(map.getVMLocation(vm)));
                VMTransition a = rp.getVMAction(vm);
                otherEnds.add(a.getCSlice().getEnd());
            } else {
                minePos.add(rp.getNode(map.getVMLocation(vm)));
                VMTransition a = rp.getVMAction(vm);
                mineEnds.add(a.getCSlice().getEnd());
            }
        }
    }
    for (VM vm : vms) {
        VMTransition a = rp.getVMAction(vm);
        Precedences p = new Precedences(a.getDSlice().getHoster(), a.getDSlice().getStart(), otherPos.toArray(), otherEnds.toArray(new IntVar[otherEnds.size()]));
        rp.getModel().post(p);
    }
    // TODO: The following reveals a model problem. Too many constraints!!
    for (VM vm : otherVMs) {
        VMTransition a = rp.getVMAction(vm);
        Precedences p = new Precedences(a.getDSlice().getHoster(), a.getDSlice().getStart(), minePos.toArray(), mineEnds.toArray(new IntVar[mineEnds.size()]));
        rp.getModel().post(p);
    }
}
Also used : Precedences(org.btrplace.scheduler.choco.extensions.Precedences) Node(org.btrplace.model.Node) VM(org.btrplace.model.VM) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) Mapping(org.btrplace.model.Mapping) IntVar(org.chocosolver.solver.variables.IntVar) TIntArrayList(gnu.trove.list.array.TIntArrayList)

Example 2 with Precedences

use of org.btrplace.scheduler.choco.extensions.Precedences in project scheduler by btrplace.

the class CSplit method injectContinuous.

private boolean injectContinuous(ReconfigurationProblem rp, List<List<VM>> vmGroups) {
    if (!cstr.isSatisfied(rp.getSourceModel())) {
        rp.getLogger().error("The constraint '{}' must be already satisfied to provide a continuous restriction", cstr);
        return false;
    }
    // Each VM on a group, can not go to a node until all the VMs from the other groups have leaved
    // So, for each group of VM, we create a list containing the c^end and the c^host variable of all
    // the VMs in the other groups then we establish precedences constraints.
    TIntArrayList[] otherPositions = new TIntArrayList[vmGroups.size()];
    @SuppressWarnings("unchecked") List<IntVar>[] otherEnds = new List[vmGroups.size()];
    for (int i = 0; i < vmGroups.size(); i++) {
        otherPositions[i] = new TIntArrayList();
        otherEnds[i] = new ArrayList<>();
    }
    fullfillOthers(rp, otherPositions, otherEnds, vmGroups);
    // Now, we just have to put way too many precedences constraint, one per VM.
    for (int i = 0; i < vmGroups.size(); i++) {
        List<VM> grp = vmGroups.get(i);
        for (VM vm : grp) {
            if (rp.getFutureRunningVMs().contains(vm)) {
                VMTransition a = rp.getVMAction(vm);
                IntVar myPos = a.getDSlice().getHoster();
                IntVar myStart = a.getDSlice().getStart();
                rp.getModel().post(new Precedences(myPos, myStart, otherPositions[i].toArray(), otherEnds[i].toArray(new IntVar[otherEnds[i].size()])));
            }
        }
    }
    return true;
}
Also used : Precedences(org.btrplace.scheduler.choco.extensions.Precedences) VM(org.btrplace.model.VM) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IntVar(org.chocosolver.solver.variables.IntVar) TIntArrayList(gnu.trove.list.array.TIntArrayList)

Aggregations

TIntArrayList (gnu.trove.list.array.TIntArrayList)2 ArrayList (java.util.ArrayList)2 VM (org.btrplace.model.VM)2 Precedences (org.btrplace.scheduler.choco.extensions.Precedences)2 VMTransition (org.btrplace.scheduler.choco.transition.VMTransition)2 IntVar (org.chocosolver.solver.variables.IntVar)2 List (java.util.List)1 Mapping (org.btrplace.model.Mapping)1 Node (org.btrplace.model.Node)1