use of org.btrplace.scheduler.choco.Slice 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;
}
use of org.btrplace.scheduler.choco.Slice 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));
}
Aggregations