Search in sources :

Example 1 with Solution

use of org.chocosolver.solver.Solution 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 2 with Solution

use of org.chocosolver.solver.Solution in project scheduler by btrplace.

the class RelocatableVMTest method testWorthyReInstantiation.

/**
 * The re-instantiation is possible and worthy.
 *
 * @throws org.btrplace.scheduler.SchedulerException
 * @throws ContradictionException
 */
@Test
public void testWorthyReInstantiation() throws SchedulerException, ContradictionException {
    Model mo = new DefaultModel();
    Mapping map = mo.getMapping();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    VM vm10 = mo.newVM();
    map.addOnlineNode(n1);
    map.addOnlineNode(n2);
    // Not using vm1 because intPool starts at 0 so their will be multiple (0,1) VMs.
    map.addRunningVM(vm10, n1);
    Parameters ps = new DefaultParameters();
    DurationEvaluators dev = ps.getDurationEvaluators();
    dev.register(org.btrplace.plan.event.MigrateVM.class, new ConstantActionDuration<>(20));
    dev.register(org.btrplace.plan.event.ForgeVM.class, new ConstantActionDuration<>(3));
    dev.register(org.btrplace.plan.event.BootVM.class, new ConstantActionDuration<>(2));
    dev.register(org.btrplace.plan.event.ShutdownVM.class, new ConstantActionDuration<>(1));
    mo.getAttributes().put(vm10, "template", "small");
    mo.getAttributes().put(vm10, "clone", true);
    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setNextVMsStates(Collections.emptySet(), map.getAllVMs(), Collections.emptySet(), Collections.emptySet()).setParams(ps).setManageableVMs(map.getAllVMs()).build();
    RelocatableVM am = (RelocatableVM) rp.getVMAction(vm10);
    am.getDSlice().getHoster().instantiateTo(rp.getNode(n2), Cause.Null);
    Solution sol = new Solution(rp.getModel());
    sol.record();
    rp.getSolver().plugMonitor((IMonitorSolution) () -> {
        sol.record();
    });
    new CMinMTTR().inject(ps, rp);
    ReconfigurationPlan p = rp.solve(10, true);
    Assert.assertNotNull(p);
    Assert.assertEquals(sol.getIntVal(am.getRelocationMethod()), 1);
    Assert.assertEquals(p.getSize(), 3);
    Model res = p.getResult();
    // Check the VM has been relocated
    Assert.assertEquals(res.getMapping().getRunningVMs(n1).size(), 0);
    Assert.assertEquals(res.getMapping().getRunningVMs(n2).size(), 1);
    Assert.assertNotNull(p);
    for (Action a : p) {
        Assert.assertTrue(a.getStart() >= 0, a.toString());
        Assert.assertTrue(a.getEnd() >= a.getStart(), a.toString());
    }
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Action(org.btrplace.plan.event.Action) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) Parameters(org.btrplace.scheduler.choco.Parameters) Node(org.btrplace.model.Node) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Mapping(org.btrplace.model.Mapping) ReconfigurationProblem(org.btrplace.scheduler.choco.ReconfigurationProblem) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) MigrateVM(org.btrplace.plan.event.MigrateVM) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) DurationEvaluators(org.btrplace.scheduler.choco.duration.DurationEvaluators) DefaultReconfigurationProblemBuilder(org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder) CMinMTTR(org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR) IMonitorSolution(org.chocosolver.solver.search.loop.monitors.IMonitorSolution) Solution(org.chocosolver.solver.Solution) Test(org.testng.annotations.Test)

Example 3 with Solution

use of org.chocosolver.solver.Solution in project scheduler by btrplace.

the class VectorPackingTest method testPack.

public void testPack(int nbExpectedSols) {
    List<Solution> sols = s.getSolver().findAllSolutions();
    int nbComputedSols = sols.size();
    Assert.assertEquals(s.getSolver().isFeasible(), ESat.eval(nbExpectedSols != 0), "SAT");
    if (nbExpectedSols > 0) {
        Assert.assertEquals(nbComputedSols, nbExpectedSols, "#SOL");
    }
}
Also used : Solution(org.chocosolver.solver.Solution) Constraint(org.chocosolver.solver.constraints.Constraint)

Example 4 with Solution

use of org.chocosolver.solver.Solution in project scheduler by btrplace.

the class CShareableResource method insertActions.

@Override
public boolean insertActions(ReconfigurationProblem r, Solution s, ReconfigurationPlan p) {
    Mapping srcMapping = r.getSourceModel().getMapping();
    // Encache the VM -> Action to ease the event injection.
    Map<VM, Action> actions = new HashMap<>();
    p.getActions().stream().filter(RunningVMPlacement.class::isInstance).map(a -> (RunningVMPlacement) a).forEach(a -> actions.put(destVM(a.getVM()), (Action) a));
    for (VM vm : r.getFutureRunningVMs()) {
        Slice dSlice = r.getVMAction(vm).getDSlice();
        Node destNode = r.getNode(s.getIntVal(dSlice.getHoster()));
        if (srcMapping.isRunning(vm) && destNode.equals(srcMapping.getVMLocation(vm))) {
            // Was running and stay on the same node
            // Check if the VM has been cloned
            // TODO: might be too late depending on the symmetry breaking on the actions schedule
            insertAllocateAction(p, vm, destNode, s.getIntVal(dSlice.getStart()));
        } else {
            VM dVM = destVM(vm);
            Action a = actions.get(dVM);
            if (a instanceof MigrateVM) {
                // For a migrated VM, we allocate once the migration over
                insertAllocateEvent(a, Action.Hook.POST, dVM);
            } else {
                // Resume or Boot VM
                // As the VM was not running, we pre-allocate
                insertAllocateEvent(a, Action.Hook.PRE, dVM);
            }
        }
    }
    return true;
}
Also used : Slice(org.btrplace.scheduler.choco.Slice) Arrays(java.util.Arrays) SchedulerException(org.btrplace.scheduler.SchedulerException) TIntArrayList(gnu.trove.list.array.TIntArrayList) Node(org.btrplace.model.Node) Preserve(org.btrplace.model.constraint.Preserve) Overbook(org.btrplace.model.constraint.Overbook) TDoubleList(gnu.trove.list.TDoubleList) ContradictionException(org.chocosolver.solver.exception.ContradictionException) MigrateVM(org.btrplace.plan.event.MigrateVM) HashMap(java.util.HashMap) RoundedUpDivision(org.btrplace.scheduler.choco.extensions.RoundedUpDivision) TObjectIntMap(gnu.trove.map.TObjectIntMap) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ArrayList(java.util.ArrayList) TObjectDoubleHashMap(gnu.trove.map.hash.TObjectDoubleHashMap) HashSet(java.util.HashSet) TObjectDoubleMap(gnu.trove.map.TObjectDoubleMap) VM(org.btrplace.model.VM) SchedulerModelingException(org.btrplace.scheduler.SchedulerModelingException) Mapping(org.btrplace.model.Mapping) Map(java.util.Map) ReconfigurationProblem(org.btrplace.scheduler.choco.ReconfigurationProblem) SatConstraint(org.btrplace.model.constraint.SatConstraint) Model(org.btrplace.model.Model) TIntList(gnu.trove.list.TIntList) TObjectIntHashMap(gnu.trove.map.hash.TObjectIntHashMap) Set(java.util.Set) Cause(org.chocosolver.solver.Cause) Parameters(org.btrplace.scheduler.choco.Parameters) AllocateEvent(org.btrplace.plan.event.AllocateEvent) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) IntVar(org.chocosolver.solver.variables.IntVar) List(java.util.List) TDoubleArrayList(gnu.trove.list.array.TDoubleArrayList) RunningVMPlacement(org.btrplace.plan.event.RunningVMPlacement) ResourceRelated(org.btrplace.model.view.ResourceRelated) Allocate(org.btrplace.plan.event.Allocate) ShareableResource(org.btrplace.model.view.ShareableResource) Solution(org.chocosolver.solver.Solution) Instance(org.btrplace.model.Instance) ResourceCapacity(org.btrplace.model.constraint.ResourceCapacity) Action(org.btrplace.plan.event.Action) Collections(java.util.Collections) Action(org.btrplace.plan.event.Action) RunningVMPlacement(org.btrplace.plan.event.RunningVMPlacement) HashMap(java.util.HashMap) TObjectDoubleHashMap(gnu.trove.map.hash.TObjectDoubleHashMap) TObjectIntHashMap(gnu.trove.map.hash.TObjectIntHashMap) Slice(org.btrplace.scheduler.choco.Slice) MigrateVM(org.btrplace.plan.event.MigrateVM) VM(org.btrplace.model.VM) Node(org.btrplace.model.Node) Mapping(org.btrplace.model.Mapping) MigrateVM(org.btrplace.plan.event.MigrateVM)

Example 5 with Solution

use of org.chocosolver.solver.Solution in project scheduler by btrplace.

the class DefaultReconfigurationProblem method solve.

@Override
public ReconfigurationPlan solve(int timeLimit, boolean optimize) throws SchedulerException {
    // Check for multiple destination state
    if (!distinctVMStates()) {
        return null;
    }
    if (!optimize) {
        solvingPolicy = ResolutionPolicy.SATISFACTION;
    }
    linkCardinalityWithSlices();
    addContinuousResourceCapacities();
    getView(Packing.VIEW_ID).beforeSolve(this);
    getView(Cumulatives.VIEW_ID).beforeSolve(this);
    getView(AliasedCumulatives.VIEW_ID).beforeSolve(this);
    // Set the timeout
    if (timeLimit > 0) {
        solver.limitTime(timeLimit * 1000L);
    }
    // getLogger().debug("{} constraints; {} integers", csp.getNbCstrs(), csp.getNbIntVar(true));
    if (solver.getSearch() == null) {
        defaultHeuristic();
    }
    solver.plugMonitor((IMonitorSolution) () -> {
        Solution s = new Solution(csp);
        s.record();
        solutions.add(s);
    });
    if (solvingPolicy == ResolutionPolicy.SATISFACTION) {
        solver.findSolution();
    } else {
        solver.findOptimalSolution(objective, solvingPolicy.equals(ResolutionPolicy.MAXIMIZE));
    }
    if (solver.isFeasible() == ESat.UNDEFINED) {
        // We don't know if the CSP has a solution
        throw new UnstatableProblemException(model, timeLimit);
    }
    return makeResultingPlan();
}
Also used : UnstatableProblemException(org.btrplace.scheduler.UnstatableProblemException) IMonitorSolution(org.chocosolver.solver.search.loop.monitors.IMonitorSolution) Solution(org.chocosolver.solver.Solution)

Aggregations

Solution (org.chocosolver.solver.Solution)6 IMonitorSolution (org.chocosolver.solver.search.loop.monitors.IMonitorSolution)4 Model (org.btrplace.model.Model)3 Node (org.btrplace.model.Node)3 VM (org.btrplace.model.VM)3 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)3 Parameters (org.btrplace.scheduler.choco.Parameters)3 ReconfigurationProblem (org.btrplace.scheduler.choco.ReconfigurationProblem)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Set (java.util.Set)2 Instance (org.btrplace.model.Instance)2 Mapping (org.btrplace.model.Mapping)2 SatConstraint (org.btrplace.model.constraint.SatConstraint)2 Action (org.btrplace.plan.event.Action)2 MigrateVM (org.btrplace.plan.event.MigrateVM)2 SchedulerException (org.btrplace.scheduler.SchedulerException)2 SchedulerModelingException (org.btrplace.scheduler.SchedulerModelingException)2 DefaultReconfigurationProblemBuilder (org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder)2