Search in sources :

Example 1 with UnstatableProblemException

use of org.btrplace.scheduler.UnstatableProblemException in project scheduler by btrplace.

the class DefaultReconfigurationProblemTest method testTimeout.

/**
 * Test the report of a timeout.
 */
@Test(expectedExceptions = { UnstatableProblemException.class })
public void testTimeout() throws UnstatableProblemException {
    Model mo = new DefaultModel();
    Mapping map = mo.getMapping();
    for (int i = 0; i < 10; i++) {
        Node n = mo.newNode();
        VM vm = mo.newVM();
        map.addOnlineNode(n);
        map.addRunningVM(vm, n);
    }
    Parameters ps = new DefaultParameters();
    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).build();
    Solver s = rp.getSolver();
    IntVar nbNodes = rp.getModel().intVar("nbNodes", 1, map.getAllNodes().size(), true);
    Stream<Slice> dSlices = rp.getVMActions().stream().filter(t -> t.getDSlice() != null).map(VMTransition::getDSlice);
    IntVar[] hosters = dSlices.map(Slice::getHoster).toArray(IntVar[]::new);
    rp.getModel().post(rp.getModel().atMostNValues(hosters, nbNodes, true));
    rp.setObjective(true, nbNodes);
    // 1 ms
    rp.getSolver().limitTime(1);
    // -1 will be ignored as it is a negative value (assumed no timeout)
    ReconfigurationPlan plan = rp.solve(-1, true);
    Assert.assertNotNull(plan);
    Assert.assertEquals(s.getMeasures().getSolutionCount(), 1);
    Mapping dst = plan.getResult().getMapping();
    Assert.assertEquals(usedNodes(dst), 1);
}
Also used : ShutdownableNode(org.btrplace.scheduler.choco.transition.ShutdownableNode) ChocoView(org.btrplace.scheduler.choco.view.ChocoView) Arrays(java.util.Arrays) SchedulerException(org.btrplace.scheduler.SchedulerException) SuspendVM(org.btrplace.scheduler.choco.transition.SuspendVM) Node(org.btrplace.model.Node) ModelView(org.btrplace.model.view.ModelView) UnstatableProblemException(org.btrplace.scheduler.UnstatableProblemException) NodeTransition(org.btrplace.scheduler.choco.transition.NodeTransition) ContradictionException(org.chocosolver.solver.exception.ContradictionException) Test(org.testng.annotations.Test) Solver(org.chocosolver.solver.Solver) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) HashSet(java.util.HashSet) VM(org.btrplace.model.VM) BootableNode(org.btrplace.scheduler.choco.transition.BootableNode) Assert(org.testng.Assert) Mapping(org.btrplace.model.Mapping) StayAwayVM(org.btrplace.scheduler.choco.transition.StayAwayVM) Model(org.btrplace.model.Model) DurationEvaluators(org.btrplace.scheduler.choco.duration.DurationEvaluators) ResumeVM(org.btrplace.scheduler.choco.transition.ResumeVM) Set(java.util.Set) DefaultModel(org.btrplace.model.DefaultModel) Cause(org.chocosolver.solver.Cause) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) IntVar(org.chocosolver.solver.variables.IntVar) Stream(java.util.stream.Stream) KillVM(org.btrplace.scheduler.choco.transition.KillVM) CMinMTTR(org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR) BootVM(org.btrplace.scheduler.choco.transition.BootVM) ForgeVM(org.btrplace.scheduler.choco.transition.ForgeVM) ShutdownVM(org.btrplace.scheduler.choco.transition.ShutdownVM) ShareableResource(org.btrplace.model.view.ShareableResource) Solution(org.chocosolver.solver.Solution) Collections(java.util.Collections) DefaultModel(org.btrplace.model.DefaultModel) Solver(org.chocosolver.solver.Solver) ShutdownableNode(org.btrplace.scheduler.choco.transition.ShutdownableNode) Node(org.btrplace.model.Node) BootableNode(org.btrplace.scheduler.choco.transition.BootableNode) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) Mapping(org.btrplace.model.Mapping) IntVar(org.chocosolver.solver.variables.IntVar) SuspendVM(org.btrplace.scheduler.choco.transition.SuspendVM) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) VM(org.btrplace.model.VM) StayAwayVM(org.btrplace.scheduler.choco.transition.StayAwayVM) ResumeVM(org.btrplace.scheduler.choco.transition.ResumeVM) KillVM(org.btrplace.scheduler.choco.transition.KillVM) BootVM(org.btrplace.scheduler.choco.transition.BootVM) ForgeVM(org.btrplace.scheduler.choco.transition.ForgeVM) ShutdownVM(org.btrplace.scheduler.choco.transition.ShutdownVM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Test(org.testng.annotations.Test)

Example 2 with UnstatableProblemException

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

Example 3 with UnstatableProblemException

use of org.btrplace.scheduler.UnstatableProblemException in project scheduler by btrplace.

the class Bench method solve.

private static void solve(LabelledInstance i, Parameters ps) throws IOException {
    ChocoScheduler s = new DefaultChocoScheduler().setParameters(ps);
    String status = "OK";
    try {
        s.solve(i);
    } catch (@SuppressWarnings("unused") UnstatableProblemException ex) {
        status = "TO";
    } catch (@SuppressWarnings("unused") SchedulerException ex) {
        status = "FAIL";
    }
    if (opts.single()) {
        out(0, "%s%n", s.getStatistics());
    } else {
        SolvingStatistics stats = s.getStatistics();
        if (stats.getSolutions().isEmpty()) {
            status = "KO*";
        } else {
            status = "OK";
            if (stats.completed()) {
                status += "*";
            }
        }
        if (opts.verbosity() == 0) {
            out(0, "%s: %s%n", i.label, status);
        } else {
            out(1, "----- %s -----%n", i.label);
            out(1, "%s%n", stats);
            out(1, "%n");
        }
        File output = opts.output();
        store(i, stats, output);
    }
}
Also used : DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) SchedulerException(org.btrplace.scheduler.SchedulerException) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) UnstatableProblemException(org.btrplace.scheduler.UnstatableProblemException) SolvingStatistics(org.btrplace.scheduler.choco.runner.SolvingStatistics) File(java.io.File)

Aggregations

UnstatableProblemException (org.btrplace.scheduler.UnstatableProblemException)3 SchedulerException (org.btrplace.scheduler.SchedulerException)2 Solution (org.chocosolver.solver.Solution)2 File (java.io.File)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Stream (java.util.stream.Stream)1 DefaultModel (org.btrplace.model.DefaultModel)1 Mapping (org.btrplace.model.Mapping)1 Model (org.btrplace.model.Model)1 Node (org.btrplace.model.Node)1 VM (org.btrplace.model.VM)1 ModelView (org.btrplace.model.view.ModelView)1 ShareableResource (org.btrplace.model.view.ShareableResource)1 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)1 ChocoScheduler (org.btrplace.scheduler.choco.ChocoScheduler)1 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)1 CMinMTTR (org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR)1