Search in sources :

Example 1 with RelocatableVM

use of org.btrplace.scheduler.choco.transition.RelocatableVM 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;
}
Also used : StayAwayVM(org.btrplace.scheduler.choco.transition.StayAwayVM) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) VM(org.btrplace.model.VM) StayAwayVM(org.btrplace.scheduler.choco.transition.StayAwayVM) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) ArrayList(java.util.ArrayList) Model(org.chocosolver.solver.Model) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM)

Example 2 with RelocatableVM

use of org.btrplace.scheduler.choco.transition.RelocatableVM 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) ArrayList(java.util.ArrayList) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) IntVar(org.chocosolver.solver.variables.IntVar)

Example 3 with RelocatableVM

use of org.btrplace.scheduler.choco.transition.RelocatableVM 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));
*/
    }
}
Also used : ArrayList(java.util.ArrayList) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) IntVar(org.chocosolver.solver.variables.IntVar)

Example 4 with RelocatableVM

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

the class CMinMigrations method injectPlacementHeuristic.

private void injectPlacementHeuristic(ReconfigurationProblem p, Parameters ps, IntVar cost) {
    List<CShareableResource> rcs = rp.getSourceModel().getViews().stream().filter(v -> v instanceof ShareableResource).map(v -> (CShareableResource) rp.getRequiredView(v.getIdentifier())).collect(Collectors.toList());
    useResources = !rcs.isEmpty();
    Model mo = p.getSourceModel();
    Mapping map = mo.getMapping();
    OnStableNodeFirst schedHeuristic = new OnStableNodeFirst(p);
    // Get the VMs to place
    Set<VM> onBadNodes = new HashSet<>(p.getManageableVMs());
    // Get the VMs that runs and have a pretty low chances to move
    Set<VM> onGoodNodes = map.getRunningVMs(map.getOnlineNodes());
    onGoodNodes.removeAll(onBadNodes);
    List<VMTransition> goodActions = p.getVMActions(onGoodNodes);
    List<VMTransition> badActions = p.getVMActions(onBadNodes);
    Solver s = p.getSolver();
    // Get the VMs to move for exclusion issue
    Set<VM> vmsToExclude = new HashSet<>(p.getManageableVMs());
    for (Iterator<VM> ite = vmsToExclude.iterator(); ite.hasNext(); ) {
        VM vm = ite.next();
        if (!(map.isRunning(vm) && p.getFutureRunningVMs().contains(vm))) {
            ite.remove();
        }
    }
    List<AbstractStrategy<?>> strategies = new ArrayList<>();
    Map<IntVar, VM> pla = VMPlacementUtils.makePlacementMap(p);
    if (!vmsToExclude.isEmpty()) {
        List<VMTransition> actions = new LinkedList<>();
        // Get all the involved slices
        for (VM vm : vmsToExclude) {
            if (p.getFutureRunningVMs().contains(vm)) {
                actions.add(p.getVMAction(vm));
            }
        }
        placeVMs(ps, strategies, actions, schedHeuristic, pla);
    }
    TObjectIntMap<VM> costs = CShareableResource.getWeights(rp, rcs);
    badActions.sort((v2, v1) -> costs.get(v1.getVM()) - costs.get(v2.getVM()));
    goodActions.sort((v2, v1) -> costs.get(v1.getVM()) - costs.get(v2.getVM()));
    placeVMs(ps, strategies, badActions, schedHeuristic, pla);
    placeVMs(ps, strategies, goodActions, schedHeuristic, pla);
    // Reinstantations. Try to reinstantiate first
    List<IntVar> migs = new ArrayList<>();
    for (VMTransition t : rp.getVMActions()) {
        if (t instanceof RelocatableVM) {
            migs.add(((RelocatableVM) t).getRelocationMethod());
        }
    }
    strategies.add(Search.intVarSearch(new FirstFail(rp.getModel()), new IntDomainMax(), migs.toArray(new IntVar[migs.size()])));
    if (!p.getNodeActions().isEmpty()) {
        // Boot some nodes if needed
        IntVar[] starts = p.getNodeActions().stream().map(Transition::getStart).toArray(IntVar[]::new);
        strategies.add(new IntStrategy(starts, new FirstFail(rp.getModel()), new IntDomainMin()));
        // Fix the duration. The side effect will be that states will be fixed as well
        // with the objective to not do un-necessary actions
        IntVar[] durations = p.getNodeActions().stream().map(Transition::getDuration).toArray(IntVar[]::new);
        strategies.add(new IntStrategy(durations, new FirstFail(rp.getModel()), new IntDomainMin()));
    }
    postCostConstraints();
    // /SCHEDULING PROBLEM
    MovementGraph gr = new MovementGraph(rp);
    IntVar[] starts = dSlices(rp.getVMActions()).map(Slice::getStart).filter(v -> !v.isInstantiated()).toArray(IntVar[]::new);
    strategies.add(new IntStrategy(starts, new StartOnLeafNodes(rp, gr), new IntDomainMin()));
    strategies.add(new IntStrategy(schedHeuristic.getScope(), schedHeuristic, new IntDomainMin()));
    IntVar[] ends = rp.getVMActions().stream().map(Transition::getEnd).filter(v -> !v.isInstantiated()).toArray(IntVar[]::new);
    strategies.add(Search.intVarSearch(new MyInputOrder<>(s), new IntDomainMin(), ends));
    // At this stage only it matters to plug the cost constraints
    strategies.add(new IntStrategy(new IntVar[] { p.getEnd(), cost }, new MyInputOrder<>(s, this), new IntDomainMin()));
    s.setSearch(new StrategiesSequencer(s.getEnvironment(), strategies.toArray(new AbstractStrategy[strategies.size()])));
}
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) 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) 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) Solver(org.chocosolver.solver.Solver) ArrayList(java.util.ArrayList) Mapping(org.btrplace.model.Mapping) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) AbstractStrategy(org.chocosolver.solver.search.strategy.strategy.AbstractStrategy) CShareableResource(org.btrplace.scheduler.choco.view.CShareableResource) ShareableResource(org.btrplace.model.view.ShareableResource) IntVar(org.chocosolver.solver.variables.IntVar) MyInputOrder(org.btrplace.scheduler.choco.constraint.mttr.MyInputOrder) IntStrategy(org.chocosolver.solver.search.strategy.strategy.IntStrategy) IntDomainMin(org.chocosolver.solver.search.strategy.selectors.values.IntDomainMin) FirstFail(org.chocosolver.solver.search.strategy.selectors.variables.FirstFail) StartOnLeafNodes(org.btrplace.scheduler.choco.constraint.mttr.StartOnLeafNodes) CShareableResource(org.btrplace.scheduler.choco.view.CShareableResource) HashSet(java.util.HashSet) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) StrategiesSequencer(org.chocosolver.solver.search.strategy.strategy.StrategiesSequencer) LinkedList(java.util.LinkedList) MovementGraph(org.btrplace.scheduler.choco.constraint.mttr.MovementGraph) Slice(org.btrplace.scheduler.choco.Slice) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) Transition(org.btrplace.scheduler.choco.transition.Transition) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) OnStableNodeFirst(org.btrplace.scheduler.choco.constraint.mttr.OnStableNodeFirst) IntDomainMax(org.chocosolver.solver.search.strategy.selectors.values.IntDomainMax)

Example 5 with RelocatableVM

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

the class CSync method inject.

@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
    Model csp = rp.getModel();
    // Get all migrations involved
    for (VM vm : sec.getInvolvedVMs()) {
        VMTransition vt = rp.getVMAction(vm);
        if (vt instanceof RelocatableVM) {
            migrationList.add((RelocatableVM) vt);
        }
    }
    for (int i = 0; i < migrationList.size(); i++) {
        for (int j = i + 1; j < migrationList.size(); j++) {
            RelocatableVM vm1 = migrationList.get(i);
            RelocatableVM vm2 = migrationList.get(j);
            // Sync the start or end depending of the migration algorithm
            // TODO: support VMs that are not necessarily moving
            IntVar firstMigSync = vm1.usesPostCopy() ? vm1.getStart() : vm1.getEnd();
            IntVar secondMigSync = vm2.usesPostCopy() ? vm2.getStart() : vm2.getEnd();
            csp.post(csp.arithm(firstMigSync, "=", secondMigSync));
        }
    }
    return true;
}
Also used : 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) ChocoConstraint(org.btrplace.scheduler.choco.constraint.ChocoConstraint)

Aggregations

RelocatableVM (org.btrplace.scheduler.choco.transition.RelocatableVM)10 VMTransition (org.btrplace.scheduler.choco.transition.VMTransition)10 VM (org.btrplace.model.VM)9 IntVar (org.chocosolver.solver.variables.IntVar)8 ArrayList (java.util.ArrayList)7 Model (org.btrplace.model.Model)3 Node (org.btrplace.model.Node)3 Slice (org.btrplace.scheduler.choco.Slice)3 Task (org.chocosolver.solver.variables.Task)3 TObjectIntMap (gnu.trove.map.TObjectIntMap)2 Collections (java.util.Collections)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Map (java.util.Map)2 Objects (java.util.Objects)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2