use of org.chocosolver.solver.variables.IntVar 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);
}
use of org.chocosolver.solver.variables.IntVar in project scheduler by btrplace.
the class CAmong method restrictGroup.
private boolean restrictGroup(Parameters ps, ReconfigurationProblem rp, Set<VM> running, List<Collection<Node>> groups, int selected) {
if (selected == -1) {
// Now, we create a variable to indicate on which group of nodes the VMs will be
vmGrpId = rp.getModel().intVar(rp.makeVarLabel(GROUP_LABEL), 0, groups.size() - 1, false);
// grp: A table to indicate the group each node belong to, -1 for no group
int[] grp = new int[rp.getNodes().size()];
for (int i = 0; i < grp.length; i++) {
Node n = rp.getNode(i);
int idx = getGroup(n, groups);
if (idx >= 0) {
grp[i] = idx;
} else {
grp[i] = -1;
}
}
// We link the VM placement variable with the group variable
for (VM vm : running) {
IntVar assign = rp.getVMAction(vm).getDSlice().getHoster();
Constraint c = rp.getModel().element(vmGrpId, grp, assign, 0);
rp.getModel().post(c);
}
} else {
// As the group is already known, it's now just a fence constraint
vmGrpId = rp.fixed(selected, GROUP_LABEL);
if (!fence(ps, rp, running, groups.get(selected))) {
return false;
}
}
return true;
}
use of org.chocosolver.solver.variables.IntVar in project scheduler by btrplace.
the class CGather method forceDiscreteCollocation.
private static boolean forceDiscreteCollocation(ReconfigurationProblem rp, List<Slice> dSlices) {
for (int i = 0; i < dSlices.size(); i++) {
for (int j = 0; j < i; j++) {
Slice s1 = dSlices.get(i);
Slice s2 = dSlices.get(j);
IntVar i1 = s1.getHoster();
IntVar i2 = s2.getHoster();
if (i1.isInstantiated() && !instantiateTo(rp, i2, i1.getLB(), s1, s2)) {
return false;
} else if (i2.isInstantiated() && !instantiateTo(rp, i1, i2.getLB(), s1, s2)) {
return false;
}
rp.getModel().post(rp.getModel().arithm(i1, "=", i2));
}
}
return true;
}
use of org.chocosolver.solver.variables.IntVar in project scheduler by btrplace.
the class CLonely method inject.
@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) {
// Remove non future-running VMs
List<IntVar> myHosts = new ArrayList<>();
List<IntVar> otherHosts = new ArrayList<>();
Collection<VM> vms = new HashSet<>();
Set<VM> otherVMs = new HashSet<>();
for (VM vm : rp.getFutureRunningVMs()) {
IntVar host = rp.getVMAction(vm).getDSlice().getHoster();
if (cstr.getInvolvedVMs().contains(vm)) {
myHosts.add(host);
vms.add(vm);
} else {
otherHosts.add(host);
otherVMs.add(vm);
}
}
// Link the assignment variables with the set
Model s = rp.getModel();
s.post(new Disjoint(myHosts.toArray(new IntVar[myHosts.size()]), otherHosts.toArray(new IntVar[otherHosts.size()]), rp.getNodes().size()));
if (cstr.isContinuous()) {
continuousRestriction(rp, vms, otherVMs);
}
return true;
}
use of org.chocosolver.solver.variables.IntVar in project scheduler by btrplace.
the class CQuarantine method inject.
@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
// It is just a composition of a root constraint on the VMs on the given nodes (the zone)
// plus a ban on the other VMs to prevent them for being hosted in the zone
Mapping map = rp.getSourceModel().getMapping();
Node n = cstr.getInvolvedNodes().iterator().next();
int nIdx = rp.getNode(n);
for (VM vm : rp.getFutureRunningVMs()) {
if (n.equals(map.getVMLocation(vm))) {
IntVar d = rp.getVMAction(vm).getDSlice().getHoster();
try {
d.instantiateTo(nIdx, Cause.Null);
} catch (ContradictionException e) {
rp.getLogger().error("Unable to root " + vm + " on " + n, e);
return false;
}
} else {
IntVar d = rp.getVMAction(vm).getDSlice().getHoster();
try {
d.removeValue(nIdx, Cause.Null);
} catch (ContradictionException e) {
rp.getLogger().error("Unable to disallow " + vm + " to be hosted on " + n, e);
return false;
}
}
}
return true;
}
Aggregations