use of org.btrplace.scheduler.choco.transition.VMTransition 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.btrplace.scheduler.choco.transition.VMTransition 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.btrplace.scheduler.choco.transition.VMTransition in project scheduler by btrplace.
the class CSequentialVMTransitions method inject.
@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
List<VM> seq = cstr.getInvolvedVMs();
List<VMTransition> ams = new ArrayList<>();
for (VM vmId : seq) {
VMTransition am = rp.getVMAction(vmId);
// Avoid VMs with no action model or Transition that do not denotes a state transition
if (am == null || am instanceof StayAwayVM || am instanceof RelocatableVM) {
continue;
}
ams.add(am);
}
if (ams.size() > 1) {
Iterator<VMTransition> ite = ams.iterator();
VMTransition prev = ite.next();
Model csp = rp.getModel();
while (ite.hasNext()) {
VMTransition cur = ite.next();
csp.post(csp.arithm(prev.getEnd(), "<=", cur.getStart()));
prev = cur;
}
}
return true;
}
use of org.btrplace.scheduler.choco.transition.VMTransition in project scheduler by btrplace.
the class CMinMTTRMig method inject.
@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
this.rp = rp;
List<IntVar> endVars = new ArrayList<>();
// Define the cost constraint: sum of all actions' end time
for (VMTransition m : rp.getVMActions()) {
endVars.add(m.getEnd());
}
for (NodeTransition m : rp.getNodeActions()) {
endVars.add(m.getEnd());
}
IntVar[] costs = endVars.toArray(new IntVar[endVars.size()]);
IntVar cost = rp.getModel().intVar(rp.makeVarLabel("costEndVars"), 0, Integer.MAX_VALUE / 100, true);
costConstraints.add(rp.getModel().sum(costs, "=", cost));
// Set the objective, minimize the cost
rp.setObjective(true, cost);
// Inject the scheduling heuristic
injectSchedulingHeuristic(cost);
// Post the cost constraint
postCostConstraints();
return true;
}
use of org.btrplace.scheduler.choco.transition.VMTransition in project scheduler by btrplace.
the class CMinMigrations method postCostConstraints.
@Override
public void postCostConstraints() {
if (!costActivated) {
costActivated = true;
rp.getLogger().debug("Post the cost-oriented constraints");
List<IntVar> stays = new ArrayList<>();
for (VMTransition t : rp.getVMActions()) {
if (t instanceof RelocatableVM && rp.getManageableVMs().contains(t.getVM())) {
stays.add(t.getDuration());
}
}
// With choco 4.0.1, we cannot post a simple sum() constraint due to hardcore
// simplification it made. So we bypass the optimisation phase and post the propagator
rp.getModel().post(rp.getModel().sum(stays.toArray(new IntVar[0]), "=", cost));
/*stays.add(cost);
Propagator<IntVar> p =
new PropSum(stays.toArray(new IntVar[0]), stays.size() - 1, Operator.EQ, 0);
rp.getModel().post(new org.chocosolver.solver.constraints.Constraint("sumCost", p));
*/
}
}
Aggregations