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;
}
Aggregations