Search in sources :

Example 1 with MeasuresRecorder

use of org.chocosolver.solver.search.measure.MeasuresRecorder 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 MeasuresRecorder

use of org.chocosolver.solver.search.measure.MeasuresRecorder in project scheduler by btrplace.

the class StagedSolvingStatisticsTest method testSingle.

@Test
public void testSingle() {
    SingleRunnerStatistics s = new SingleRunnerStatistics(ps, i, st);
    MeasuresRecorder mr = new MeasuresRecorder("");
    s.setMetrics(new Metrics(mr));
    StagedSolvingStatistics stats = new StagedSolvingStatistics(s);
    Assert.assertEquals(stats.getSolutions().size(), 0);
    Assert.assertEquals(stats.getStage(0), s);
    Assert.assertEquals(stats.getNbManagedVMs(), -1);
    Assert.assertEquals(stats.getStart(), st);
    Assert.assertEquals(stats.getInstance(), i);
    Assert.assertEquals(stats.getNbStages(), 1);
    Assert.assertEquals(stats.getCoreBuildDuration(), -1);
    Assert.assertEquals(stats.getSpecializationDuration(), -1);
    Assert.assertEquals(stats.completed(), false);
}
Also used : SingleRunnerStatistics(org.btrplace.scheduler.choco.runner.single.SingleRunnerStatistics) MeasuresRecorder(org.chocosolver.solver.search.measure.MeasuresRecorder) Test(org.testng.annotations.Test)

Aggregations

MeasuresRecorder (org.chocosolver.solver.search.measure.MeasuresRecorder)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Callable (java.util.concurrent.Callable)1 Instance (org.btrplace.model.Instance)1 Model (org.btrplace.model.Model)1 Node (org.btrplace.model.Node)1 VM (org.btrplace.model.VM)1 Constraint (org.btrplace.model.constraint.Constraint)1 Killed (org.btrplace.model.constraint.Killed)1 OptConstraint (org.btrplace.model.constraint.OptConstraint)1 Ready (org.btrplace.model.constraint.Ready)1 Running (org.btrplace.model.constraint.Running)1 SatConstraint (org.btrplace.model.constraint.SatConstraint)1 Sleeping (org.btrplace.model.constraint.Sleeping)1 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)1