Search in sources :

Example 6 with IntVar

use of org.chocosolver.solver.variables.IntVar 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) 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) 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 7 with IntVar

use of org.chocosolver.solver.variables.IntVar in project scheduler by btrplace.

the class OnStableNodeFirst method getVariable.

@Override
public IntVar getVariable(IntVar[] scope) {
    makeIncoming();
    IntVar v = getVMtoLeafNode();
    if (v == null) {
        last = null;
        return null;
    }
    v = getMovingVM();
    if (v != null) {
        return v;
    }
    IntVar early = getEarlyVar();
    last = (early != null) ? early : minInf();
    return last;
}
Also used : IntVar(org.chocosolver.solver.variables.IntVar)

Example 8 with IntVar

use of org.chocosolver.solver.variables.IntVar in project scheduler by btrplace.

the class InstanceSolverRunner method call.

@Override
// for the LifeCycleViolationException
@SuppressWarnings("squid:S1166")
public SolvingStatistics call() throws SchedulerException {
    stats = new SingleRunnerStatistics(params, instance, System.currentTimeMillis());
    rp = null;
    // Build the core problem
    long d = -System.currentTimeMillis();
    try {
        rp = buildRP();
    } catch (@SuppressWarnings("unused") LifeCycleViolationException ex) {
        // If there is a violation of the cycle it is not a bug that should be propagated
        // it it just indicating there is no solution
        stats.setCompleted(true);
        stats.setMetrics(new Metrics());
        return stats;
    } finally {
        d += System.currentTimeMillis();
        stats.setCoreBuildDuration(d);
    }
    stats.setNbManagedVMs(rp.getManageableVMs().size());
    // Customize the core problem
    d = -System.currentTimeMillis();
    if (!specialise()) {
        d += System.currentTimeMillis();
        stats.setSpecialisationDuration(d);
        stats.setCompleted(true);
        return getStatistics();
    }
    d += System.currentTimeMillis();
    stats.setSpecialisationDuration(d);
    // statistics
    stats.setMetrics(new Metrics(rp.getSolver().getMeasures()));
    rp.getLogger().debug(stats.toString());
    // The solution monitor to store the measures at each solution
    rp.getSolver().plugMonitor((IMonitorSolution) () -> {
        Solution solution = new Solution(rp.getModel());
        solution.record();
        ReconfigurationPlan plan = rp.buildReconfigurationPlan(solution, origin);
        views.forEach(v -> v.insertActions(rp, solution, plan));
        MeasuresRecorder m = rp.getSolver().getMeasures();
        SolutionStatistics st = new SolutionStatistics(new Metrics(m), plan);
        IntVar o = rp.getObjective();
        if (o != null) {
            st.setObjective(solution.getIntVal(o));
        }
        stats.addSolution(st);
        params.solutionListeners().forEach(c -> c.accept(rp, plan));
    });
    setVerbosity();
    // The actual solving process
    rp.solve(params.getTimeLimit(), params.doOptimize());
    return getStatistics();
}
Also used : LifeCycleViolationException(org.btrplace.scheduler.choco.LifeCycleViolationException) ChocoView(org.btrplace.scheduler.choco.view.ChocoView) Ready(org.btrplace.model.constraint.Ready) MeasuresRecorder(org.chocosolver.solver.search.measure.MeasuresRecorder) SchedulerException(org.btrplace.scheduler.SchedulerException) Node(org.btrplace.model.Node) OptConstraint(org.btrplace.model.constraint.OptConstraint) ContradictionException(org.chocosolver.solver.exception.ContradictionException) Callable(java.util.concurrent.Callable) SolvingStatistics(org.btrplace.scheduler.choco.runner.SolvingStatistics) CObjective(org.btrplace.scheduler.choco.constraint.CObjective) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) DefaultReconfigurationProblemBuilder(org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) VM(org.btrplace.model.VM) Running(org.btrplace.model.constraint.Running) SchedulerModelingException(org.btrplace.scheduler.SchedulerModelingException) Measures(org.chocosolver.solver.search.measure.Measures) ReconfigurationProblem(org.btrplace.scheduler.choco.ReconfigurationProblem) IMonitorSolution(org.chocosolver.solver.search.loop.monitors.IMonitorSolution) SearchState(org.chocosolver.solver.search.SearchState) ChocoMapper(org.btrplace.scheduler.choco.constraint.ChocoMapper) SatConstraint(org.btrplace.model.constraint.SatConstraint) Model(org.btrplace.model.Model) Sleeping(org.btrplace.model.constraint.Sleeping) Constraint(org.btrplace.model.constraint.Constraint) Collection(java.util.Collection) SolutionStatistics(org.btrplace.scheduler.choco.runner.SolutionStatistics) Set(java.util.Set) ChocoConstraint(org.btrplace.scheduler.choco.constraint.ChocoConstraint) Cause(org.chocosolver.solver.Cause) Parameters(org.btrplace.scheduler.choco.Parameters) IntVar(org.chocosolver.solver.variables.IntVar) List(java.util.List) Killed(org.btrplace.model.constraint.Killed) Metrics(org.btrplace.scheduler.choco.runner.Metrics) ChocoViews(org.btrplace.scheduler.choco.view.ChocoViews) Solution(org.chocosolver.solver.Solution) Optional(java.util.Optional) Instance(org.btrplace.model.Instance) Metrics(org.btrplace.scheduler.choco.runner.Metrics) LifeCycleViolationException(org.btrplace.scheduler.choco.LifeCycleViolationException) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) SolutionStatistics(org.btrplace.scheduler.choco.runner.SolutionStatistics) IntVar(org.chocosolver.solver.variables.IntVar) IMonitorSolution(org.chocosolver.solver.search.loop.monitors.IMonitorSolution) Solution(org.chocosolver.solver.Solution) MeasuresRecorder(org.chocosolver.solver.search.measure.MeasuresRecorder)

Example 9 with IntVar

use of org.chocosolver.solver.variables.IntVar 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 10 with IntVar

use of org.chocosolver.solver.variables.IntVar in project scheduler by btrplace.

the class CShareableResource method beforeSolve.

/**
 * Set the resource usage for each of the VM.
 * If the LB is < 0 , the previous consumption is used to maintain the resource usage.
 * Otherwise, the usage is set to the variable lower bound.
 *
 * @return false if an operation leads to a problem without solution
 */
@Override
public boolean beforeSolve(ReconfigurationProblem p) throws SchedulerException {
    for (VM vm : source.getMapping().getAllVMs()) {
        int vmId = p.getVM(vm);
        int v = getVMAllocation(vmId);
        if (v < 0) {
            int prevUsage = rc.getConsumption(vm);
            minVMAllocation(vmId, prevUsage);
        }
    }
    ChocoView v = rp.getView(Packing.VIEW_ID);
    if (v == null) {
        throw SchedulerModelingException.missingView(rp.getSourceModel(), Packing.VIEW_ID);
    }
    IntVar[] host = new IntVar[p.getFutureRunningVMs().size()];
    int[] demand = new int[host.length];
    int i = 0;
    for (VM vm : p.getFutureRunningVMs()) {
        host[i] = rp.getVMAction(vm).getDSlice().getHoster();
        demand[i] = getVMAllocation(p.getVM(vm));
        i++;
    }
    ((Packing) v).addDim(rc.getResourceIdentifier(), virtRcUsage, demand, host);
    return linkVirtualToPhysicalUsage();
}
Also used : MigrateVM(org.btrplace.plan.event.MigrateVM) VM(org.btrplace.model.VM) IntVar(org.chocosolver.solver.variables.IntVar) SatConstraint(org.btrplace.model.constraint.SatConstraint)

Aggregations

IntVar (org.chocosolver.solver.variables.IntVar)78 VM (org.btrplace.model.VM)35 Model (org.chocosolver.solver.Model)32 Test (org.testng.annotations.Test)30 Node (org.btrplace.model.Node)29 ArrayList (java.util.ArrayList)23 VMTransition (org.btrplace.scheduler.choco.transition.VMTransition)22 BoolVar (org.chocosolver.solver.variables.BoolVar)17 Mapping (org.btrplace.model.Mapping)16 Model (org.btrplace.model.Model)15 RelocatableVM (org.btrplace.scheduler.choco.transition.RelocatableVM)13 HashSet (java.util.HashSet)11 Slice (org.btrplace.scheduler.choco.Slice)10 DefaultModel (org.btrplace.model.DefaultModel)9 TIntArrayList (gnu.trove.list.array.TIntArrayList)8 ShareableResource (org.btrplace.model.view.ShareableResource)8 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)8 Constraint (org.chocosolver.solver.constraints.Constraint)8 List (java.util.List)7 Set (java.util.Set)7