Search in sources :

Example 76 with IntVar

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

Example 77 with IntVar

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

the class CSplit method fullfillOthers.

private static void fullfillOthers(ReconfigurationProblem rp, TIntArrayList[] otherPositions, List<IntVar>[] otherEnds, List<List<VM>> vmGroups) {
    Mapping map = rp.getSourceModel().getMapping();
    // Fulfill the others stuff.
    for (int i = 0; i < vmGroups.size(); i++) {
        List<VM> grp = vmGroups.get(i);
        for (VM vm : grp) {
            if (map.isRunning(vm)) {
                int myPos = rp.getNode(map.getVMLocation(vm));
                IntVar myEnd = rp.getVMAction(vm).getCSlice().getEnd();
                for (int j = 0; j < vmGroups.size(); j++) {
                    if (i != j) {
                        otherPositions[j].add(myPos);
                        otherEnds[j].add(myEnd);
                    }
                }
            }
        }
    }
}
Also used : VM(org.btrplace.model.VM) Mapping(org.btrplace.model.Mapping) IntVar(org.chocosolver.solver.variables.IntVar)

Example 78 with IntVar

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

the class CSplitAmong method inject.

@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
    if (cstr.isContinuous() && !cstr.isSatisfied(rp.getSourceModel())) {
        rp.getLogger().error("The constraint '{}' must be already satisfied to provide a continuous restriction", cstr);
        return false;
    }
    Collection<Collection<VM>> vGroups = cstr.getGroupsOfVMs();
    Collection<Collection<Node>> pGroups = cstr.getGroupsOfNodes();
    Model csp = rp.getModel();
    IntVar[] grpVars = new IntVar[vGroups.size()];
    // VM is assigned on a node <-> group variable associated to the VM
    // is assigned to the group of nodes it belong too.
    int i = 0;
    for (Collection<VM> vms : vGroups) {
        Among a = new Among(vms, pGroups);
        // If the constraint is continuous, there is no way a group of VMs already bound to a group of
        // nodes can move to another group. It also means the group of VMs will never overlap
        a.setContinuous(cstr.isContinuous());
        CAmong ca = new CAmong(a);
        if (!ca.inject(ps, rp)) {
            return false;
        }
        grpVars[i++] = ca.getGroupVariable();
    }
    // forces all the vGroups to use different group of nodes
    csp.post(csp.allDifferent(grpVars, "DEFAULT"));
    return true;
}
Also used : VM(org.btrplace.model.VM) Model(org.chocosolver.solver.Model) Collection(java.util.Collection) Among(org.btrplace.model.constraint.Among) SplitAmong(org.btrplace.model.constraint.SplitAmong) 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