use of org.btrplace.scheduler.choco.Slice in project scheduler by btrplace.
the class DefaultCumulatives method symmetryBreakingForStayingVMs.
/**
* Symmetry breaking for VMs that stay running, on the same node.
*
* @return {@code true} iff the symmetry breaking does not lead to a problem without solutions
*/
private boolean symmetryBreakingForStayingVMs(ReconfigurationProblem rp) {
for (VM vm : rp.getFutureRunningVMs()) {
VMTransition a = rp.getVMAction(vm);
Slice dSlice = a.getDSlice();
Slice cSlice = a.getCSlice();
if (dSlice != null && cSlice != null) {
BoolVar stay = ((KeepRunningVM) a).isStaying();
Boolean ret = strictlyDecreasingOrUnchanged(vm);
if (Boolean.TRUE.equals(ret) && !zeroDuration(rp, stay, cSlice)) {
return false;
// Else, the resource usage is decreasing, so
// we set the cSlice duration to 0 to directly reduces the resource allocation
} else if (Boolean.FALSE.equals(ret) && !zeroDuration(rp, stay, dSlice)) {
// (the allocation will be performed at the end of the reconfiguration process)
return false;
}
}
}
return true;
}
use of org.btrplace.scheduler.choco.Slice in project scheduler by btrplace.
the class CBan method inject.
@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) {
if (ban.isContinuous()) {
for (VM vm : ban.getInvolvedVMs()) {
if (ban.getInvolvedNodes().contains(rp.getSourceModel().getMapping().getVMLocation(vm))) {
rp.getLogger().error("Constraint {} is not satisfied initially", ban);
return false;
}
}
}
Collection<Node> nodes = ban.getInvolvedNodes();
int[] nodesIdx = new int[nodes.size()];
int i = 0;
for (Node n : ban.getInvolvedNodes()) {
nodesIdx[i++] = rp.getNode(n);
}
VM vm = ban.getInvolvedVMs().iterator().next();
Slice t = rp.getVMAction(vm).getDSlice();
if (t != null) {
for (int x : nodesIdx) {
try {
t.getHoster().removeValue(x, Cause.Null);
} catch (ContradictionException e) {
rp.getLogger().error("Unable to disallow " + vm + " to be running on " + rp.getNode(x), e);
return false;
}
}
}
return true;
}
use of org.btrplace.scheduler.choco.Slice in project scheduler by btrplace.
the class CFence method inject.
@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) {
if (cstr.isContinuous()) {
for (VM vm : cstr.getInvolvedVMs()) {
Node location = rp.getSourceModel().getMapping().getVMLocation(vm);
if (location != null && !cstr.getInvolvedNodes().contains(location)) {
rp.getLogger().error("Constraint {} is not satisfied initially", cstr);
return false;
}
}
}
VM vm = cstr.getInvolvedVMs().iterator().next();
Collection<Node> nodes = cstr.getInvolvedNodes();
Slice t = rp.getVMAction(vm).getDSlice();
if (!rp.getFutureRunningVMs().contains(vm)) {
return true;
}
if (nodes.size() == 1) {
return force(rp, t.getHoster(), vm, nodes.iterator().next());
}
return allBut(rp, t.getHoster(), vm, nodes);
}
use of org.btrplace.scheduler.choco.Slice 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.btrplace.scheduler.choco.Slice in project scheduler by btrplace.
the class CNoDelay method inject.
@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) {
VM v = noDelay.getInvolvedVMs().iterator().next();
// For each vm involved in the constraint
VMTransition vt = rp.getVMAction(v);
// Get the VMTransition start time
// Add the constraint "start = 0" to the solver
Slice d = vt.getDSlice();
if (d == null) {
return true;
}
if (!(vt instanceof RelocatableVM)) {
try {
d.getStart().instantiateTo(0, Cause.Null);
} catch (ContradictionException ex) {
rp.getLogger().error("Unable to prevent any delay on '" + v + "'", ex);
return false;
}
} else {
Constraint c = rp.getModel().arithm(d.getStart(), "=", 0);
BoolVar move = ((RelocatableVM) vt).isStaying().not();
ChocoUtils.postImplies(rp, move, c);
}
return true;
}
Aggregations