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();
}
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;
}
}
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);
}
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;
}
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());
}
Aggregations