Search in sources :

Example 1 with InstanceSolverRunner

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

Aggregations

ArrayList (java.util.ArrayList)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorCompletionService (java.util.concurrent.ExecutorCompletionService)1 ExecutorService (java.util.concurrent.ExecutorService)1 Instance (org.btrplace.model.Instance)1 SolvingStatistics (org.btrplace.scheduler.choco.runner.SolvingStatistics)1 InstanceSolverRunner (org.btrplace.scheduler.choco.runner.single.InstanceSolverRunner)1