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