use of org.btrplace.scheduler.choco.transition.ShutdownableNode in project scheduler by btrplace.
the class CMinMTTRMig method injectSchedulingHeuristic.
/**
* Inject a specific scheduling heuristic to the solver.
*
* @param cost the global cost variable.
*/
private void injectSchedulingHeuristic(IntVar cost) {
// Init a list of strategies
List<AbstractStrategy<?>> strategies = new ArrayList<>();
// Init a list of vars
List<IntVar> endVars = new ArrayList<>();
// Boot nodes
for (Node n : rp.getNodes()) {
if (rp.getNodeAction(n) instanceof BootableNode) {
endVars.add(rp.getNodeAction(n).getEnd());
}
}
if (!endVars.isEmpty()) {
strategies.add(Search.intVarSearch(new FirstFail(rp.getModel()), new IntDomainMin(), // Split from max
DecisionOperatorFactory.makeIntSplit(), endVars.toArray(new IntVar[endVars.size()])));
}
endVars.clear();
// Migrate VMs
MovementGraph gr = new MovementGraph(rp);
OnStableNodeFirst schedHeuristic = new OnStableNodeFirst(rp);
Stream<Slice> s = rp.getVMActions().stream().map(VMTransition::getDSlice).filter(Objects::nonNull);
IntVar[] starts = s.map(Slice::getStart).toArray(IntVar[]::new);
strategies.add(new IntStrategy(starts, new StartOnLeafNodes(rp, gr), new IntDomainMin()));
strategies.add(new IntStrategy(schedHeuristic.getScope(), schedHeuristic, new IntDomainMin()));
// Add remaining VMs actions
for (VMTransition a : rp.getVMActions()) {
endVars.add(a.getEnd());
}
if (!endVars.isEmpty()) {
strategies.add(Search.intVarSearch(new FirstFail(rp.getModel()), new IntDomainMin(), // Split from max
DecisionOperatorFactory.makeIntSplit(), endVars.toArray(new IntVar[endVars.size()])));
}
endVars.clear();
// Shutdown nodes
for (Node n : rp.getNodes()) {
if (rp.getNodeAction(n) instanceof ShutdownableNode) {
endVars.add(rp.getNodeAction(n).getEnd());
}
}
if (!endVars.isEmpty()) {
strategies.add(Search.intVarSearch(new FirstFail(rp.getModel()), new IntDomainMin(), DecisionOperatorFactory.makeIntSplit(), endVars.toArray(new IntVar[endVars.size()])));
}
// Set the strategies in the correct order (as added before)
strategies.add(new IntStrategy(new IntVar[] { rp.getEnd(), cost }, new MyInputOrder<>(rp.getSolver(), this), new IntDomainMin()));
// Add all defined strategies
rp.getSolver().setSearch(new StrategiesSequencer(rp.getModel().getEnvironment(), strategies.toArray(new AbstractStrategy[strategies.size()])));
}
use of org.btrplace.scheduler.choco.transition.ShutdownableNode in project scheduler by btrplace.
the class CPowerView method inject.
@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
powerStarts = new TIntObjectHashMap<>(rp.getNodes().size());
powerEnds = new TIntObjectHashMap<>(rp.getNodes().size());
for (Node n : rp.getNodes()) {
NodeTransition na = rp.getNodeAction(n);
if (na instanceof ShutdownableNode) {
powerStarts.put(rp.getNode(n), rp.getStart());
IntVar powerEnd = rp.makeUnboundedDuration("NodeActionType(", n, ").Pe");
TaskMonitor.build(na.getHostingEnd(), na.getDuration(), powerEnd);
powerEnds.put(rp.getNode(n), powerEnd);
rp.getModel().post(rp.getModel().arithm(powerEnd, "<=", rp.getEnd()));
} else if (na instanceof BootableNode) {
powerStarts.put(rp.getNode(n), na.getStart());
powerEnds.put(rp.getNode(n), rp.getEnd());
}
}
return true;
}
Aggregations