use of org.chocosolver.solver.exception.ContradictionException in project scheduler by btrplace.
the class CShareableResource method capHosting.
/**
* Reduce the cardinality wrt. the worst case scenario.
*
* @param nIdx the node index
* @param min the min (but > 0 ) consumption for a VM
* @param nbZeroes the number of VMs consuming 0
* @return {@code false} if the problem no longer has a solution
*/
private boolean capHosting(int nIdx, int min, int nbZeroes) {
Node n = rp.getNode(nIdx);
double capa = getSourceResource().getCapacity(n) * getOverbookRatio(nIdx);
int card = (int) (capa / min) + nbZeroes + 1;
if (card < source.getMapping().getRunningVMs(n).size()) {
// TODO: revise the notion of continuous constraint for the cardinality issue.
return true;
}
try {
// Restrict the hosting capacity.
rp.getNbRunningVMs().get(nIdx).updateUpperBound(card, Cause.Null);
} catch (ContradictionException ex) {
rp.getLogger().error("Unable to cap the hosting capacity of '" + n + " ' to " + card, ex);
return false;
}
return true;
}
use of org.chocosolver.solver.exception.ContradictionException in project scheduler by btrplace.
the class COffline method inject.
@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
if (cstr.isContinuous() && !cstr.getChecker().startsWith(rp.getSourceModel())) {
rp.getLogger().error("Constraint {} is not satisfied initially", cstr);
return false;
}
Node nId = cstr.getInvolvedNodes().iterator().next();
int id = rp.getNode(nId);
NodeTransition m = rp.getNodeAction(nId);
try {
m.getState().instantiateTo(0, Cause.Null);
if (rp.getSourceModel().getMapping().isOffline(nId)) {
m.getStart().instantiateTo(0, Cause.Null);
}
} catch (ContradictionException ex) {
rp.getLogger().error("Unable to force node '" + nId + "' at being offline", ex);
return false;
}
for (VMTransition am : rp.getVMActions()) {
Slice s = am.getDSlice();
if (s != null) {
try {
s.getHoster().removeValue(id, Cause.Null);
} catch (ContradictionException e) {
rp.getLogger().error("Unable to remove " + am.getVM() + " of node " + nId, e);
}
}
}
return true;
}
use of org.chocosolver.solver.exception.ContradictionException in project scheduler by btrplace.
the class CResourceCapacity method injectWithSingleNode.
private boolean injectWithSingleNode(CShareableResource rcm, ReconfigurationProblem rp) {
int amount = cstr.getAmount();
Model csp = rp.getModel();
Node n = cstr.getInvolvedNodes().iterator().next();
int nIdx = rp.getNode(n);
IntVar v = rcm.getVirtualUsage().get(nIdx);
csp.post(csp.arithm(v, "<=", amount));
// Continuous in practice ?
if (cstr.isContinuous()) {
if (cstr.isSatisfied(rp.getSourceModel())) {
try {
v.updateUpperBound(cstr.getAmount(), Cause.Null);
} catch (ContradictionException e) {
rp.getLogger().error("Unable to restrict to up to " + cstr.getAmount() + ", the maximum '" + rcm.getResourceIdentifier() + "' usage on " + n, e);
return false;
}
} else {
rp.getLogger().error("The constraint '{}' must be already satisfied to provide a continuous restriction", cstr);
return false;
}
}
return true;
}
use of org.chocosolver.solver.exception.ContradictionException in project scheduler by btrplace.
the class CRoot method inject.
@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
VM vm = cstr.getInvolvedVMs().iterator().next();
VMTransition m = rp.getVMAction(vm);
Slice cSlice = m.getCSlice();
Slice dSlice = m.getDSlice();
if (cSlice != null && dSlice != null) {
try {
dSlice.getHoster().instantiateTo(cSlice.getHoster().getValue(), Cause.Null);
} catch (ContradictionException ex) {
Node n = rp.getSourceModel().getMapping().getVMLocation(vm);
rp.getLogger().error("Unable to force '" + vm + "' to be running on node '" + n + "'", ex);
return false;
}
}
return true;
}
use of org.chocosolver.solver.exception.ContradictionException in project scheduler by btrplace.
the class InstanceSolverRunner method buildRP.
private ReconfigurationProblem buildRP() throws SchedulerException {
// Build the RP. As VM state management is not possible
// We extract VM-state related constraints first.
// For other constraint, we just create the right choco constraint
Set<VM> toRun = new HashSet<>();
Set<VM> toForge = new HashSet<>();
Set<VM> toKill = new HashSet<>();
Set<VM> toSleep = new HashSet<>();
cConstraints = new ArrayList<>();
for (SatConstraint cstr : cstrs) {
checkNodesExistence(origin, cstr.getInvolvedNodes());
// (when they will be forged)
if (!(cstrs instanceof Ready)) {
checkUnknownVMsInMapping(origin, cstr.getInvolvedVMs());
}
if (cstr instanceof Running) {
toRun.addAll(cstr.getInvolvedVMs());
} else if (cstr instanceof Sleeping) {
toSleep.addAll(cstr.getInvolvedVMs());
} else if (cstr instanceof Ready) {
checkUnknownVMsInMapping(origin, cstr.getInvolvedVMs());
toForge.addAll(cstr.getInvolvedVMs());
} else if (cstr instanceof Killed) {
checkUnknownVMsInMapping(origin, cstr.getInvolvedVMs());
toKill.addAll(cstr.getInvolvedVMs());
}
cConstraints.add(build(cstr));
}
cConstraints.add(build(obj));
views = makeViews();
DefaultReconfigurationProblemBuilder rpb = new DefaultReconfigurationProblemBuilder(origin).setNextVMsStates(toForge, toRun, toSleep, toKill).setParams(params);
if (params.doRepair()) {
Set<VM> toManage = new HashSet<>();
cConstraints.forEach(c -> toManage.addAll(c.getMisPlacedVMs(instance)));
views.forEach(v -> toManage.addAll(v.getMisPlacedVMs(instance)));
rpb.setManageableVMs(toManage);
}
// The core views have been instantiated and available through rp.getViews()
// Set the maximum duration
ReconfigurationProblem p = rpb.build();
try {
p.getEnd().updateUpperBound(params.getMaxEnd(), Cause.Null);
} catch (ContradictionException e) {
p.getLogger().error("Unable to restrict the maximum plan duration to " + params.getMaxEnd(), e);
return null;
}
return p;
}
Aggregations