Search in sources :

Example 71 with IntVar

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

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

the class CResourceCapacity method inject.

@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
    Model csp = rp.getModel();
    CShareableResource rcm = (CShareableResource) rp.getView(ShareableResource.VIEW_ID_BASE + cstr.getResource());
    if (rcm == null) {
        throw new SchedulerModelingException(rp.getSourceModel(), "No resource associated to identifier '" + cstr.getResource() + "'");
    }
    if (cstr.getInvolvedNodes().size() == 1) {
        return injectWithSingleNode(rcm, rp);
    }
    if (cstr.isContinuous() && !injectContinuous(rp, rcm)) {
        return false;
    }
    List<IntVar> vs = new ArrayList<>();
    for (Node u : cstr.getInvolvedNodes()) {
        vs.add(rcm.getVirtualUsage().get(rp.getNode(u)));
    }
    IntVar mySum = csp.intVar(rp.makeVarLabel("usage(", rcm.getIdentifier(), ")"), 0, Integer.MAX_VALUE / 100, true);
    csp.post(csp.sum(vs.toArray(new IntVar[vs.size()]), "=", mySum));
    csp.post(csp.arithm(mySum, "<=", cstr.getAmount()));
    return true;
}
Also used : Node(org.btrplace.model.Node) Model(org.chocosolver.solver.Model) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) CShareableResource(org.btrplace.scheduler.choco.view.CShareableResource) IntVar(org.chocosolver.solver.variables.IntVar) SchedulerModelingException(org.btrplace.scheduler.SchedulerModelingException)

Example 73 with IntVar

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

the class CRunningCapacity method inject.

@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
    Model csp = rp.getModel();
    if (cstr.getInvolvedNodes().size() == 1) {
        return filterWithSingleNode(rp);
    }
    if (cstr.isContinuous() && !injectContinuous(rp)) {
        return false;
    }
    List<IntVar> vs = new ArrayList<>();
    for (Node u : cstr.getInvolvedNodes()) {
        vs.add(rp.getNbRunningVMs().get(rp.getNode(u)));
    }
    // Try to get a lower bound
    // basically, we count 1 per VM necessarily in the set of nodes
    // if involved nodes == all the nodes, then sum == nb of running VMs
    IntVar mySum = csp.intVar(rp.makeVarLabel("nbRunning"), 0, rp.getFutureRunningVMs().size(), true);
    csp.post(csp.sum(vs.toArray(new IntVar[vs.size()]), "=", mySum));
    csp.post(csp.arithm(mySum, "<=", cstr.getAmount()));
    if (cstr.getInvolvedNodes().equals(rp.getSourceModel().getMapping().getAllNodes())) {
        csp.post(csp.arithm(mySum, "=", rp.getFutureRunningVMs().size()));
    }
    return true;
}
Also used : Node(org.btrplace.model.Node) Model(org.chocosolver.solver.Model) ArrayList(java.util.ArrayList) IntVar(org.chocosolver.solver.variables.IntVar)

Example 74 with IntVar

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

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

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