Search in sources :

Example 1 with AliasedCumulatives

use of org.btrplace.scheduler.choco.view.AliasedCumulatives in project scheduler by btrplace.

the class CResourceCapacity method injectContinuous.

private boolean injectContinuous(ReconfigurationProblem rp, CShareableResource rcm) throws SchedulerException {
    // 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);
    }
    TIntArrayList cUse = new TIntArrayList();
    List<IntVar> dUse = new ArrayList<>();
    for (VM vmId : rp.getVMs()) {
        VMTransition a = rp.getVMAction(vmId);
        Slice c = a.getCSlice();
        Slice d = a.getDSlice();
        if (c != null) {
            cUse.add(rcm.getSourceResource().getConsumption(vmId));
        }
        if (d != null) {
            int m = rcm.getVMAllocation(rp.getVM(vmId));
            dUse.add(rp.fixed(m, "vmAllocation('", rcm.getResourceIdentifier(), "', '", vmId, "'"));
        }
    }
    ChocoView v = rp.getView(AliasedCumulatives.VIEW_ID);
    if (v == null) {
        throw SchedulerModelingException.missingView(rp.getSourceModel(), AliasedCumulatives.VIEW_ID);
    }
    ((AliasedCumulatives) v).addDim(cstr.getAmount(), cUse.toArray(), dUse.toArray(new IntVar[dUse.size()]), alias);
    return true;
}
Also used : ChocoView(org.btrplace.scheduler.choco.view.ChocoView) Slice(org.btrplace.scheduler.choco.Slice) Node(org.btrplace.model.Node) VM(org.btrplace.model.VM) AliasedCumulatives(org.btrplace.scheduler.choco.view.AliasedCumulatives) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) IntVar(org.chocosolver.solver.variables.IntVar) TIntArrayList(gnu.trove.list.array.TIntArrayList)

Example 2 with AliasedCumulatives

use of org.btrplace.scheduler.choco.view.AliasedCumulatives 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)

Aggregations

Node (org.btrplace.model.Node)2 AliasedCumulatives (org.btrplace.scheduler.choco.view.AliasedCumulatives)2 ChocoView (org.btrplace.scheduler.choco.view.ChocoView)2 IntVar (org.chocosolver.solver.variables.IntVar)2 TIntArrayList (gnu.trove.list.array.TIntArrayList)1 ArrayList (java.util.ArrayList)1 VM (org.btrplace.model.VM)1 Slice (org.btrplace.scheduler.choco.Slice)1 VMTransition (org.btrplace.scheduler.choco.transition.VMTransition)1 Model (org.chocosolver.solver.Model)1