Search in sources :

Example 1 with Slice

use of org.btrplace.scheduler.choco.Slice in project scheduler by btrplace.

the class AbstractCumulatives method inject.

@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
    cUsages = new ArrayList<>();
    dUsages = new ArrayList<>();
    List<Slice> dS = new ArrayList<>();
    List<Slice> cS = new ArrayList<>();
    non = new IntObjectMap<>(null, rp.getVMActions().size());
    int dIdx = 0;
    int cIdx = 0;
    for (VMTransition a : rp.getVMActions()) {
        Slice c = a.getCSlice();
        Slice d = a.getDSlice();
        if (d != null && c != null) {
            non.put(a.getVM().id(), new int[] { dIdx, cIdx });
        }
        if (d != null) {
            dS.add(dIdx, d);
            dIdx++;
        }
        if (c != null) {
            cS.add(cIdx, c);
            cIdx++;
        }
    }
    int i = 0;
    cHosts = new IntVar[cS.size()];
    cEnds = new IntVar[cS.size()];
    for (Slice s : cS) {
        cHosts[i] = s.getHoster();
        cEnds[i] = s.getEnd();
        i++;
    }
    i = 0;
    dStarts = new IntVar[dS.size()];
    dHosts = new IntVar[dS.size()];
    for (Slice s : dS) {
        dHosts[i] = s.getHoster();
        dStarts[i] = s.getStart();
        i++;
    }
    associations = makeAssociations();
    return true;
}
Also used : Slice(org.btrplace.scheduler.choco.Slice) ArrayList(java.util.ArrayList) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition)

Example 2 with Slice

use of org.btrplace.scheduler.choco.Slice 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)

Example 3 with Slice

use of org.btrplace.scheduler.choco.Slice in project scheduler by btrplace.

the class CMinMTTR method placeVMs.

/*
     * Try to place the VMs associated on the actions in a random node while trying first to stay on the current node
     */
private void placeVMs(Parameters ps, List<AbstractStrategy<?>> strategies, List<VMTransition> actions, OnStableNodeFirst schedHeuristic, Map<IntVar, VM> map) {
    IntValueSelector rnd = new WorstFit(map, rp, new BiggestDimension());
    if (!useResources) {
        rnd = new RandomVMPlacement(rp, map, true, ps.getRandomSeed());
    }
    IntVar[] hosts = dSlices(actions).map(Slice::getHoster).filter(v -> !v.isInstantiated()).toArray(IntVar[]::new);
    if (hosts.length > 0) {
        strategies.add(new IntStrategy(hosts, new HostingVariableSelector(rp.getModel(), schedHeuristic), rnd));
    }
}
Also used : Slice(org.btrplace.scheduler.choco.Slice) SchedulerException(org.btrplace.scheduler.SchedulerException) Transition(org.btrplace.scheduler.choco.transition.Transition) StrategiesSequencer(org.chocosolver.solver.search.strategy.strategy.StrategiesSequencer) Solver(org.chocosolver.solver.Solver) Search(org.chocosolver.solver.search.strategy.Search) TObjectIntMap(gnu.trove.map.TObjectIntMap) CObjective(org.btrplace.scheduler.choco.constraint.CObjective) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) IntDomainMin(org.chocosolver.solver.search.strategy.selectors.values.IntDomainMin) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) VM(org.btrplace.model.VM) FirstFail(org.chocosolver.solver.search.strategy.selectors.variables.FirstFail) Mapping(org.btrplace.model.Mapping) Map(java.util.Map) ReconfigurationProblem(org.btrplace.scheduler.choco.ReconfigurationProblem) CShareableResource(org.btrplace.scheduler.choco.view.CShareableResource) LinkedList(java.util.LinkedList) Model(org.btrplace.model.Model) BiggestDimension(org.btrplace.scheduler.choco.constraint.mttr.load.BiggestDimension) Iterator(java.util.Iterator) Set(java.util.Set) Parameters(org.btrplace.scheduler.choco.Parameters) Collectors(java.util.stream.Collectors) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) Objects(java.util.Objects) IntVar(org.chocosolver.solver.variables.IntVar) MinMTTR(org.btrplace.model.constraint.MinMTTR) List(java.util.List) Stream(java.util.stream.Stream) IntStrategy(org.chocosolver.solver.search.strategy.strategy.IntStrategy) ShareableResource(org.btrplace.model.view.ShareableResource) IntValueSelector(org.chocosolver.solver.search.strategy.selectors.values.IntValueSelector) Instance(org.btrplace.model.Instance) AbstractStrategy(org.chocosolver.solver.search.strategy.strategy.AbstractStrategy) IntDomainMax(org.chocosolver.solver.search.strategy.selectors.values.IntDomainMax) Collections(java.util.Collections) BiggestDimension(org.btrplace.scheduler.choco.constraint.mttr.load.BiggestDimension) IntStrategy(org.chocosolver.solver.search.strategy.strategy.IntStrategy) Slice(org.btrplace.scheduler.choco.Slice) IntVar(org.chocosolver.solver.variables.IntVar) IntValueSelector(org.chocosolver.solver.search.strategy.selectors.values.IntValueSelector)

Example 4 with Slice

use of org.btrplace.scheduler.choco.Slice in project scheduler by btrplace.

the class MovementGraph method make.

public void make() {
    incoming.clear();
    outgoings.clear();
    for (VMTransition a : rp.getVMActions()) {
        Slice cSlice = a.getCSlice();
        Slice dSlice = a.getDSlice();
        if (cSlice != null) {
            addOutgoing(cSlice);
        }
        if (dSlice != null) {
            addIncoming(dSlice);
        }
    }
}
Also used : Slice(org.btrplace.scheduler.choco.Slice) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition)

Example 5 with Slice

use of org.btrplace.scheduler.choco.Slice in project scheduler by btrplace.

the class CSpread method disallowOverlap.

private static void disallowOverlap(ReconfigurationProblem rp, VMTransition t1, VMTransition t2) {
    Slice dI = t1.getDSlice();
    Slice cI = t1.getCSlice();
    Slice dJ = t2.getDSlice();
    Slice cJ = t2.getCSlice();
    if (dI != null && cJ != null) {
        precedenceIfOverlap(rp, dI, cJ);
    }
    // The inverse relation
    if (dJ != null && cI != null) {
        precedenceIfOverlap(rp, dJ, cI);
    }
}
Also used : Slice(org.btrplace.scheduler.choco.Slice)

Aggregations

Slice (org.btrplace.scheduler.choco.Slice)22 VMTransition (org.btrplace.scheduler.choco.transition.VMTransition)17 VM (org.btrplace.model.VM)13 IntVar (org.chocosolver.solver.variables.IntVar)11 ArrayList (java.util.ArrayList)6 Node (org.btrplace.model.Node)6 TIntArrayList (gnu.trove.list.array.TIntArrayList)5 TObjectIntMap (gnu.trove.map.TObjectIntMap)5 Objects (java.util.Objects)5 ShareableResource (org.btrplace.model.view.ShareableResource)5 SchedulerException (org.btrplace.scheduler.SchedulerException)5 Parameters (org.btrplace.scheduler.choco.Parameters)5 ReconfigurationProblem (org.btrplace.scheduler.choco.ReconfigurationProblem)5 RelocatableVM (org.btrplace.scheduler.choco.transition.RelocatableVM)5 ContradictionException (org.chocosolver.solver.exception.ContradictionException)5 IntDomainMin (org.chocosolver.solver.search.strategy.selectors.values.IntDomainMin)5 FirstFail (org.chocosolver.solver.search.strategy.selectors.variables.FirstFail)5 AbstractStrategy (org.chocosolver.solver.search.strategy.strategy.AbstractStrategy)5 Collections (java.util.Collections)4 HashSet (java.util.HashSet)4