Search in sources :

Example 6 with CShareableResource

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

Aggregations

CShareableResource (org.btrplace.scheduler.choco.view.CShareableResource)6 VM (org.btrplace.model.VM)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 Mapping (org.btrplace.model.Mapping)3 Node (org.btrplace.model.Node)3 ShareableResource (org.btrplace.model.view.ShareableResource)3 SchedulerModelingException (org.btrplace.scheduler.SchedulerModelingException)3 IntVar (org.chocosolver.solver.variables.IntVar)3 TObjectIntMap (gnu.trove.map.TObjectIntMap)2 Collections (java.util.Collections)2 Iterator (java.util.Iterator)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Map (java.util.Map)2 Objects (java.util.Objects)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2 Instance (org.btrplace.model.Instance)2