Search in sources :

Example 1 with ChocoView

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

the class DefaultReconfigurationProblem method addContinuousResourceCapacities.

private void addContinuousResourceCapacities() {
    TIntArrayList cUse = new TIntArrayList();
    List<IntVar> iUse = new ArrayList<>();
    for (int j = 0; j < getVMs().size(); j++) {
        VMTransition a = vmActions.get(j);
        if (a.getDSlice() != null) {
            iUse.add(csp.intVar(1));
        }
        if (a.getCSlice() != null) {
            cUse.add(1);
        }
    }
    ChocoView v = getView(Cumulatives.VIEW_ID);
    if (v == null) {
        throw SchedulerModelingException.missingView(model, Cumulatives.VIEW_ID);
    }
    ((Cumulatives) v).addDim(getNbRunningVMs(), cUse.toArray(), iUse.toArray(new IntVar[iUse.size()]));
}
Also used : ChocoView(org.btrplace.scheduler.choco.view.ChocoView) AliasedCumulatives(org.btrplace.scheduler.choco.view.AliasedCumulatives) Cumulatives(org.btrplace.scheduler.choco.view.Cumulatives) TIntArrayList(gnu.trove.list.array.TIntArrayList) IntVar(org.chocosolver.solver.variables.IntVar) TIntArrayList(gnu.trove.list.array.TIntArrayList)

Example 2 with ChocoView

use of org.btrplace.scheduler.choco.view.ChocoView 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 3 with ChocoView

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

the class DefaultReconfigurationProblem method linkCardinalityWithSlices.

private void linkCardinalityWithSlices() {
    Stream<Slice> s = vmActions.stream().map(VMTransition::getDSlice).filter(Objects::nonNull);
    IntVar[] ds = s.map(Slice::getHoster).toArray(IntVar[]::new);
    int[] usages = new int[ds.length];
    Arrays.fill(usages, 1);
    ChocoView v = getView(Packing.VIEW_ID);
    if (v == null) {
        throw SchedulerModelingException.missingView(model, Packing.VIEW_ID);
    }
    ((Packing) v).addDim("vmsOnNodes", vmsCountOnNodes, usages, ds);
}
Also used : ChocoView(org.btrplace.scheduler.choco.view.ChocoView) Packing(org.btrplace.scheduler.choco.view.Packing) IntVar(org.chocosolver.solver.variables.IntVar)

Example 4 with ChocoView

use of org.btrplace.scheduler.choco.view.ChocoView 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().debug("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.getFutureVMAllocation(rp.getVM(vmId));
            dUse.add(rp.fixed(m, "vmAllocation('", rcm.getResourceIdentifier(), "', '", vmId, "'"));
        }
    }
    ChocoView v = rp.getRequiredView(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) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) IntVar(org.chocosolver.solver.variables.IntVar) TIntArrayList(gnu.trove.list.array.TIntArrayList)

Example 5 with ChocoView

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

the class InstanceSolverRunner method makeViews.

private List<ChocoView> makeViews() throws SchedulerException {
    List<ChocoView> l = new ArrayList<>();
    ChocoMapper mapper = params.getMapper();
    origin.getViews().stream().filter(v -> mapper.viewHasMapping(v.getClass())).forEach(v -> l.add(mapper.get(v)));
    return l;
}
Also used : ChocoView(org.btrplace.scheduler.choco.view.ChocoView) LifeCycleViolationException(org.btrplace.scheduler.choco.LifeCycleViolationException) ChocoView(org.btrplace.scheduler.choco.view.ChocoView) MeasuresRecorder(org.chocosolver.solver.search.measure.MeasuresRecorder) java.util(java.util) SchedulerException(org.btrplace.scheduler.SchedulerException) Node(org.btrplace.model.Node) ContradictionException(org.chocosolver.solver.exception.ContradictionException) Callable(java.util.concurrent.Callable) SolvingStatistics(org.btrplace.scheduler.choco.runner.SolvingStatistics) CObjective(org.btrplace.scheduler.choco.constraint.CObjective) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) DefaultReconfigurationProblemBuilder(org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder) VM(org.btrplace.model.VM) SchedulerModelingException(org.btrplace.scheduler.SchedulerModelingException) Measures(org.chocosolver.solver.search.measure.Measures) ReconfigurationProblem(org.btrplace.scheduler.choco.ReconfigurationProblem) IMonitorSolution(org.chocosolver.solver.search.loop.monitors.IMonitorSolution) SearchState(org.chocosolver.solver.search.SearchState) org.btrplace.model.constraint(org.btrplace.model.constraint) ChocoMapper(org.btrplace.scheduler.choco.constraint.ChocoMapper) Model(org.btrplace.model.Model) SolutionStatistics(org.btrplace.scheduler.choco.runner.SolutionStatistics) ChocoConstraint(org.btrplace.scheduler.choco.constraint.ChocoConstraint) Cause(org.chocosolver.solver.Cause) Parameters(org.btrplace.scheduler.choco.Parameters) IntVar(org.chocosolver.solver.variables.IntVar) Metrics(org.btrplace.scheduler.choco.runner.Metrics) ChocoViews(org.btrplace.scheduler.choco.view.ChocoViews) Solution(org.chocosolver.solver.Solution) Instance(org.btrplace.model.Instance) ChocoMapper(org.btrplace.scheduler.choco.constraint.ChocoMapper)

Aggregations

ChocoView (org.btrplace.scheduler.choco.view.ChocoView)5 IntVar (org.chocosolver.solver.variables.IntVar)5 Node (org.btrplace.model.Node)3 AliasedCumulatives (org.btrplace.scheduler.choco.view.AliasedCumulatives)3 TIntArrayList (gnu.trove.list.array.TIntArrayList)2 VM (org.btrplace.model.VM)2 java.util (java.util)1 Callable (java.util.concurrent.Callable)1 Instance (org.btrplace.model.Instance)1 Model (org.btrplace.model.Model)1 org.btrplace.model.constraint (org.btrplace.model.constraint)1 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)1 SchedulerException (org.btrplace.scheduler.SchedulerException)1 SchedulerModelingException (org.btrplace.scheduler.SchedulerModelingException)1 DefaultReconfigurationProblemBuilder (org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder)1 LifeCycleViolationException (org.btrplace.scheduler.choco.LifeCycleViolationException)1 Parameters (org.btrplace.scheduler.choco.Parameters)1 ReconfigurationProblem (org.btrplace.scheduler.choco.ReconfigurationProblem)1 Slice (org.btrplace.scheduler.choco.Slice)1 CObjective (org.btrplace.scheduler.choco.constraint.CObjective)1