Search in sources :

Example 1 with VMTransition

use of org.btrplace.scheduler.choco.transition.VMTransition in project scheduler by btrplace.

the class CSpread method inject.

@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) {
    if (cstr.isContinuous()) {
        Set<Node> usedNodes = new HashSet<>();
        for (VM vm : cstr.getInvolvedVMs()) {
            Node node = rp.getSourceModel().getMapping().getVMLocation(vm);
            if (node != null && !usedNodes.add(node)) {
                rp.getLogger().error("Constraint {} is not satisfied initially", cstr);
                // System.out.println(rp.getSourceModel().getMapping());
                return false;
            }
        }
    }
    List<IntVar> running = placementVariables(rp);
    Model csp = rp.getModel();
    if (running.isEmpty()) {
        return true;
    }
    // The lazy spread implementation for the placement
    csp.post(csp.allDifferent(running.toArray(new IntVar[running.size()]), "AC"));
    if (cstr.isContinuous()) {
        List<VM> vms = new ArrayList<>(cstr.getInvolvedVMs());
        for (int i = 0; i < vms.size(); i++) {
            VM vm = vms.get(i);
            VMTransition aI = rp.getVMAction(vm);
            for (int j = 0; j < i; j++) {
                VM vmJ = vms.get(j);
                VMTransition aJ = rp.getVMAction(vmJ);
                disallowOverlap(rp, aI, aJ);
            }
        }
    }
    return true;
}
Also used : Node(org.btrplace.model.Node) VM(org.btrplace.model.VM) Model(org.chocosolver.solver.Model) ArrayList(java.util.ArrayList) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) IntVar(org.chocosolver.solver.variables.IntVar) HashSet(java.util.HashSet)

Example 2 with VMTransition

use of org.btrplace.scheduler.choco.transition.VMTransition in project scheduler by btrplace.

the class CSpread method placementVariables.

private List<IntVar> placementVariables(ReconfigurationProblem rp) {
    List<IntVar> running = new ArrayList<>();
    for (VM vmId : cstr.getInvolvedVMs()) {
        if (rp.getFutureRunningVMs().contains(vmId)) {
            VMTransition a = rp.getVMAction(vmId);
            Slice d = a.getDSlice();
            if (d != null) {
                running.add(d.getHoster());
            }
        }
    }
    return running;
}
Also used : Slice(org.btrplace.scheduler.choco.Slice) VM(org.btrplace.model.VM) ArrayList(java.util.ArrayList) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) IntVar(org.chocosolver.solver.variables.IntVar)

Example 3 with VMTransition

use of org.btrplace.scheduler.choco.transition.VMTransition 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 4 with VMTransition

use of org.btrplace.scheduler.choco.transition.VMTransition in project scheduler by btrplace.

the class CMinMigrations 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) OnStableNodeFirst(org.btrplace.scheduler.choco.constraint.mttr.OnStableNodeFirst) 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) CObjective(org.btrplace.scheduler.choco.constraint.CObjective) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) IntDomainMin(org.chocosolver.solver.search.strategy.selectors.values.IntDomainMin) TObjectIntMap(gnu.trove.map.TObjectIntMap) 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) WorstFit(org.btrplace.scheduler.choco.constraint.mttr.WorstFit) Map(java.util.Map) ReconfigurationProblem(org.btrplace.scheduler.choco.ReconfigurationProblem) StartOnLeafNodes(org.btrplace.scheduler.choco.constraint.mttr.StartOnLeafNodes) CShareableResource(org.btrplace.scheduler.choco.view.CShareableResource) MinMigrations(org.btrplace.model.constraint.MinMigrations) LinkedList(java.util.LinkedList) RandomVMPlacement(org.btrplace.scheduler.choco.constraint.mttr.RandomVMPlacement) Model(org.btrplace.model.Model) BiggestDimension(org.btrplace.scheduler.choco.constraint.mttr.load.BiggestDimension) Iterator(java.util.Iterator) MovementGraph(org.btrplace.scheduler.choco.constraint.mttr.MovementGraph) HostingVariableSelector(org.btrplace.scheduler.choco.constraint.mttr.HostingVariableSelector) Set(java.util.Set) MyInputOrder(org.btrplace.scheduler.choco.constraint.mttr.MyInputOrder) Parameters(org.btrplace.scheduler.choco.Parameters) Collectors(java.util.stream.Collectors) VMPlacementUtils(org.btrplace.scheduler.choco.constraint.mttr.VMPlacementUtils) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) Objects(java.util.Objects) IntVar(org.chocosolver.solver.variables.IntVar) 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) HostingVariableSelector(org.btrplace.scheduler.choco.constraint.mttr.HostingVariableSelector) Slice(org.btrplace.scheduler.choco.Slice) WorstFit(org.btrplace.scheduler.choco.constraint.mttr.WorstFit) RandomVMPlacement(org.btrplace.scheduler.choco.constraint.mttr.RandomVMPlacement) IntVar(org.chocosolver.solver.variables.IntVar) IntValueSelector(org.chocosolver.solver.search.strategy.selectors.values.IntValueSelector)

Example 5 with VMTransition

use of org.btrplace.scheduler.choco.transition.VMTransition in project scheduler by btrplace.

the class CSerialize method inject.

@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
    // Get the solver
    Model csp = rp.getModel();
    // Not enough VMs
    if (ser.getInvolvedVMs().size() < 2) {
        return true;
    }
    // Get all migrations involved
    for (VM vm : ser.getInvolvedVMs()) {
        VMTransition vt = rp.getVMAction(vm);
        if (vt instanceof RelocatableVM) {
            migrationList.add((RelocatableVM) vt);
        }
    }
    // Not enough migrations
    if (migrationList.size() < 2) {
        return true;
    }
    // Using a cumulative
    List<Task> tasks = new ArrayList<>();
    for (RelocatableVM mig : migrationList) {
        tasks.add(new Task(mig.getStart(), mig.getDuration(), mig.getEnd()));
    }
    IntVar[] heights = new IntVar[tasks.size()];
    Arrays.fill(heights, csp.intVar(1));
    csp.post(csp.cumulative(tasks.toArray(new Task[tasks.size()]), heights, csp.intVar(1), true));
    return true;
}
Also used : Task(org.chocosolver.solver.variables.Task) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) VM(org.btrplace.model.VM) Model(org.chocosolver.solver.Model) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) IntVar(org.chocosolver.solver.variables.IntVar)

Aggregations

VMTransition (org.btrplace.scheduler.choco.transition.VMTransition)41 VM (org.btrplace.model.VM)34 RelocatableVM (org.btrplace.scheduler.choco.transition.RelocatableVM)23 Node (org.btrplace.model.Node)22 IntVar (org.chocosolver.solver.variables.IntVar)22 ArrayList (java.util.ArrayList)18 Model (org.btrplace.model.Model)17 HashSet (java.util.HashSet)16 Mapping (org.btrplace.model.Mapping)16 Slice (org.btrplace.scheduler.choco.Slice)16 DefaultModel (org.btrplace.model.DefaultModel)12 BootableNode (org.btrplace.scheduler.choco.transition.BootableNode)12 ShutdownableNode (org.btrplace.scheduler.choco.transition.ShutdownableNode)12 StayAwayVM (org.btrplace.scheduler.choco.transition.StayAwayVM)12 Test (org.testng.annotations.Test)12 BootVM (org.btrplace.scheduler.choco.transition.BootVM)11 ForgeVM (org.btrplace.scheduler.choco.transition.ForgeVM)11 KillVM (org.btrplace.scheduler.choco.transition.KillVM)11 ResumeVM (org.btrplace.scheduler.choco.transition.ResumeVM)11 ShutdownVM (org.btrplace.scheduler.choco.transition.ShutdownVM)11