Search in sources :

Example 1 with SolvingStatistics

use of org.btrplace.scheduler.choco.runner.SolvingStatistics 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 SolvingStatistics

use of org.btrplace.scheduler.choco.runner.SolvingStatistics in project scheduler by btrplace.

the class DefaultChocoSchedulerTest method testGetStatisticsWithTimeout.

@Test(expectedExceptions = { SchedulerException.class })
public void testGetStatisticsWithTimeout() throws SchedulerException {
    Model mo = new DefaultModel();
    Mapping map = mo.getMapping();
    for (int i = 0; i < 1000; i++) {
        Node n = mo.newNode();
        map.addOnlineNode(n);
        for (int j = 0; j < 10; j++) {
            map.addReadyVM(mo.newVM());
        }
    }
    ChocoScheduler cra = new DefaultChocoScheduler();
    cra.setTimeLimit(1);
    try {
        System.err.println(cra.solve(mo, Running.newRunning(map.getAllVMs())));
    } catch (SchedulerException e) {
        SolvingStatistics stats = cra.getStatistics();
        Assert.assertNotNull(stats);
        System.out.println(stats);
        Assert.assertTrue(stats.getSolutions().isEmpty());
        Assert.assertEquals(stats.getInstance().getModel(), mo);
        throw e;
    }
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) SchedulerException(org.btrplace.scheduler.SchedulerException) Node(org.btrplace.model.Node) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Mapping(org.btrplace.model.Mapping) SolvingStatistics(org.btrplace.scheduler.choco.runner.SolvingStatistics) SatConstraint(org.btrplace.model.constraint.SatConstraint) Test(org.testng.annotations.Test)

Example 3 with SolvingStatistics

use of org.btrplace.scheduler.choco.runner.SolvingStatistics in project scheduler by btrplace.

the class StaticPartitioning method solve.

@Override
public ReconfigurationPlan solve(Parameters cra, Instance orig) throws SchedulerException {
    stats = new StaticPartitioningStatistics(cra, orig, System.currentTimeMillis(), workersCount);
    long d = -System.currentTimeMillis();
    List<Instance> partitions = split(cra, orig);
    d += System.currentTimeMillis();
    stats.setSplittingStatistics(partitions.size(), d);
    ExecutorService exe = Executors.newFixedThreadPool(this.workersCount);
    CompletionService<SolvingStatistics> completionService = new ExecutorCompletionService<>(exe);
    List<SolvingStatistics> results = new ArrayList<>(partitions.size());
    long duration = -System.currentTimeMillis();
    for (Instance partition : partitions) {
        completionService.submit(new InstanceSolverRunner(cra, partition));
    }
    for (int i = 0; i < partitions.size(); i++) {
        try {
            results.add(completionService.take().get());
        } catch (ExecutionException ignore) {
            Throwable cause = ignore.getCause();
            if (cause != null) {
                throw new SplitException(null, cause.getMessage(), ignore);
            }
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new SplitException(orig.getModel(), e.getMessage(), e);
        }
    }
    duration += System.currentTimeMillis();
    stats.setSolvingDuration(duration);
    exe.shutdown();
    return merge(orig, results);
}
Also used : InstanceSolverRunner(org.btrplace.scheduler.choco.runner.single.InstanceSolverRunner) Instance(org.btrplace.model.Instance) ArrayList(java.util.ArrayList) ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService) ExecutorService(java.util.concurrent.ExecutorService) SolvingStatistics(org.btrplace.scheduler.choco.runner.SolvingStatistics) ExecutionException(java.util.concurrent.ExecutionException)

Example 4 with SolvingStatistics

use of org.btrplace.scheduler.choco.runner.SolvingStatistics in project scheduler by btrplace.

the class StaticPartitioning method merge.

private ReconfigurationPlan merge(Instance i, Collection<SolvingStatistics> results) throws SplitException {
    ReconfigurationPlan plan = new DefaultReconfigurationPlan(i.getModel());
    // Only if there is a solution
    for (SolvingStatistics result : results) {
        getStatistics().addPartitionStatistics(result);
        ReconfigurationPlan p = result.lastSolution();
        if (p == null) {
            return null;
        }
        for (Action a : p) {
            if (!plan.add(a)) {
                throw new SplitException(plan.getOrigin(), "Unable to add action '" + a + "' while merging the sub-plans");
            }
        }
    }
    return plan;
}
Also used : DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) Action(org.btrplace.plan.event.Action) DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) SolvingStatistics(org.btrplace.scheduler.choco.runner.SolvingStatistics)

Example 5 with SolvingStatistics

use of org.btrplace.scheduler.choco.runner.SolvingStatistics in project scheduler by btrplace.

the class COfflineTest method testUnsolvableProblem.

@Test
public void testUnsolvableProblem() throws SchedulerException {
    Model mo = new DefaultModel();
    VM vm1 = mo.newVM();
    Node n1 = mo.newNode();
    mo.getMapping().on(n1).run(n1, vm1);
    ChocoScheduler cra = new DefaultChocoScheduler();
    ReconfigurationPlan plan = cra.solve(mo, Collections.singleton(new Offline(n1)));
    Assert.assertNull(plan);
    SolvingStatistics stats = cra.getStatistics();
    Assert.assertTrue(stats.completed());
}
Also used : DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ShutdownNode(org.btrplace.plan.event.ShutdownNode) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Offline(org.btrplace.model.constraint.Offline) SolvingStatistics(org.btrplace.scheduler.choco.runner.SolvingStatistics) Test(org.testng.annotations.Test)

Aggregations

SolvingStatistics (org.btrplace.scheduler.choco.runner.SolvingStatistics)7 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)4 Model (org.btrplace.model.Model)3 Node (org.btrplace.model.Node)3 SchedulerException (org.btrplace.scheduler.SchedulerException)3 Test (org.testng.annotations.Test)3 ArrayList (java.util.ArrayList)2 DefaultModel (org.btrplace.model.DefaultModel)2 Instance (org.btrplace.model.Instance)2 Mapping (org.btrplace.model.Mapping)2 VM (org.btrplace.model.VM)2 Offline (org.btrplace.model.constraint.Offline)2 Running (org.btrplace.model.constraint.Running)2 SatConstraint (org.btrplace.model.constraint.SatConstraint)2 ChocoScheduler (org.btrplace.scheduler.choco.ChocoScheduler)2 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)2 File (java.io.File)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 List (java.util.List)1