Search in sources :

Example 36 with Model

use of org.chocosolver.solver.Model in project scheduler by btrplace.

the class CRunningCapacity method injectContinuous.

private boolean injectContinuous(ReconfigurationProblem rp) throws SchedulerException {
    Model csp = rp.getModel();
    // The constraint must be already satisfied
    if (!cstr.isSatisfied(rp.getSourceModel())) {
        rp.getLogger().error("The constraint '{}' must be already satisfied to provide a continuous restriction", cstr);
        return false;
    }
    int[] alias = new int[cstr.getInvolvedNodes().size()];
    int i = 0;
    for (Node n : cstr.getInvolvedNodes()) {
        alias[i++] = rp.getNode(n);
    }
    int nbRunning = 0;
    for (Node n : rp.getSourceModel().getMapping().getOnlineNodes()) {
        nbRunning += rp.getSourceModel().getMapping().getRunningVMs(n).size();
    }
    int[] cUse = new int[nbRunning];
    IntVar[] dUse = new IntVar[rp.getFutureRunningVMs().size()];
    Arrays.fill(cUse, 1);
    Arrays.fill(dUse, csp.intVar(1));
    ChocoView v = rp.getView(AliasedCumulatives.VIEW_ID);
    if (v == null) {
        throw SchedulerModelingException.missingView(rp.getSourceModel(), Cumulatives.VIEW_ID);
    }
    ((AliasedCumulatives) v).addDim(cstr.getAmount(), cUse, dUse, alias);
    return true;
}
Also used : ChocoView(org.btrplace.scheduler.choco.view.ChocoView) Node(org.btrplace.model.Node) AliasedCumulatives(org.btrplace.scheduler.choco.view.AliasedCumulatives) Model(org.chocosolver.solver.Model) IntVar(org.chocosolver.solver.variables.IntVar)

Example 37 with Model

use of org.chocosolver.solver.Model in project scheduler by btrplace.

the class CSplit method inject.

@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
    List<List<IntVar>> groups = new ArrayList<>();
    List<List<VM>> vmGroups = new ArrayList<>();
    for (Collection<VM> grp : cstr.getSets()) {
        List<IntVar> l = new ArrayList<>();
        List<VM> vl = new ArrayList<>();
        for (VM vm : grp) {
            if (rp.getFutureRunningVMs().contains(vm)) {
                Slice s = rp.getVMAction(vm).getDSlice();
                l.add(s.getHoster());
                vl.add(vm);
            }
        }
        if (!l.isEmpty()) {
            groups.add(l);
            vmGroups.add(vl);
        }
    }
    Model csp = rp.getModel();
    int nbNodes = rp.getNodes().size();
    IntVar[][] vars = new IntVar[groups.size()][];
    for (int i = 0; i < groups.size(); i++) {
        vars[i] = groups.get(i).toArray(new IntVar[groups.get(i).size()]);
    }
    csp.post(new DisjointMultiple(vars, nbNodes));
    return !(cstr.isContinuous() && !injectContinuous(rp, vmGroups));
}
Also used : TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) IntVar(org.chocosolver.solver.variables.IntVar) Slice(org.btrplace.scheduler.choco.Slice) VM(org.btrplace.model.VM) Model(org.chocosolver.solver.Model) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) List(java.util.List) DisjointMultiple(org.btrplace.scheduler.choco.extensions.DisjointMultiple)

Example 38 with Model

use of org.chocosolver.solver.Model 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

Model (org.chocosolver.solver.Model)38 IntVar (org.chocosolver.solver.variables.IntVar)32 Test (org.testng.annotations.Test)20 BoolVar (org.chocosolver.solver.variables.BoolVar)17 Node (org.btrplace.model.Node)7 VM (org.btrplace.model.VM)7 ArrayList (java.util.ArrayList)6 VMTransition (org.btrplace.scheduler.choco.transition.VMTransition)4 TIntArrayList (gnu.trove.list.array.TIntArrayList)3 RelocatableVM (org.btrplace.scheduler.choco.transition.RelocatableVM)3 HashSet (java.util.HashSet)2 SchedulerModelingException (org.btrplace.scheduler.SchedulerModelingException)2 Task (org.chocosolver.solver.variables.Task)2 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Objects (java.util.Objects)1 Among (org.btrplace.model.constraint.Among)1 SplitAmong (org.btrplace.model.constraint.SplitAmong)1 Parameters (org.btrplace.scheduler.choco.Parameters)1