Search in sources :

Example 1 with BootableNode

use of org.btrplace.scheduler.choco.transition.BootableNode 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;
}
Also used : ShutdownableNode(org.btrplace.scheduler.choco.transition.ShutdownableNode) BootableNode(org.btrplace.scheduler.choco.transition.BootableNode) Node(org.btrplace.model.Node) NodeTransition(org.btrplace.scheduler.choco.transition.NodeTransition) ShutdownableNode(org.btrplace.scheduler.choco.transition.ShutdownableNode) BootableNode(org.btrplace.scheduler.choco.transition.BootableNode) IntVar(org.chocosolver.solver.variables.IntVar)

Example 2 with BootableNode

use of org.btrplace.scheduler.choco.transition.BootableNode 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()])));
}
Also used : ShutdownableNode(org.btrplace.scheduler.choco.transition.ShutdownableNode) Node(org.btrplace.model.Node) BootableNode(org.btrplace.scheduler.choco.transition.BootableNode) ArrayList(java.util.ArrayList) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) BootableNode(org.btrplace.scheduler.choco.transition.BootableNode) ShutdownableNode(org.btrplace.scheduler.choco.transition.ShutdownableNode) AbstractStrategy(org.chocosolver.solver.search.strategy.strategy.AbstractStrategy) StrategiesSequencer(org.chocosolver.solver.search.strategy.strategy.StrategiesSequencer) IntVar(org.chocosolver.solver.variables.IntVar) MyInputOrder(org.btrplace.scheduler.choco.constraint.mttr.MyInputOrder) IntDomainMin(org.chocosolver.solver.search.strategy.selectors.values.IntDomainMin) IntStrategy(org.chocosolver.solver.search.strategy.strategy.IntStrategy) MovementGraph(org.btrplace.scheduler.choco.constraint.mttr.MovementGraph) Slice(org.btrplace.scheduler.choco.Slice) FirstFail(org.chocosolver.solver.search.strategy.selectors.variables.FirstFail) Objects(java.util.Objects) StartOnLeafNodes(org.btrplace.scheduler.choco.constraint.mttr.StartOnLeafNodes) OnStableNodeFirst(org.btrplace.scheduler.choco.constraint.mttr.OnStableNodeFirst)

Aggregations

Node (org.btrplace.model.Node)2 BootableNode (org.btrplace.scheduler.choco.transition.BootableNode)2 ShutdownableNode (org.btrplace.scheduler.choco.transition.ShutdownableNode)2 IntVar (org.chocosolver.solver.variables.IntVar)2 ArrayList (java.util.ArrayList)1 Objects (java.util.Objects)1 Slice (org.btrplace.scheduler.choco.Slice)1 MovementGraph (org.btrplace.scheduler.choco.constraint.mttr.MovementGraph)1 MyInputOrder (org.btrplace.scheduler.choco.constraint.mttr.MyInputOrder)1 OnStableNodeFirst (org.btrplace.scheduler.choco.constraint.mttr.OnStableNodeFirst)1 StartOnLeafNodes (org.btrplace.scheduler.choco.constraint.mttr.StartOnLeafNodes)1 NodeTransition (org.btrplace.scheduler.choco.transition.NodeTransition)1 VMTransition (org.btrplace.scheduler.choco.transition.VMTransition)1 IntDomainMin (org.chocosolver.solver.search.strategy.selectors.values.IntDomainMin)1 FirstFail (org.chocosolver.solver.search.strategy.selectors.variables.FirstFail)1 AbstractStrategy (org.chocosolver.solver.search.strategy.strategy.AbstractStrategy)1 IntStrategy (org.chocosolver.solver.search.strategy.strategy.IntStrategy)1 StrategiesSequencer (org.chocosolver.solver.search.strategy.strategy.StrategiesSequencer)1