algorithms-for-computing-li.../LinearRegressionTool/src/main/java/de/wwwu/awolf/presenter/evaluation/AlgorithmComparison.java

49 lines
1.6 KiB
Java
Raw Normal View History

2020-03-21 19:54:03 +00:00
package de.wwwu.awolf.presenter.evaluation;
import de.wwwu.awolf.model.Line;
import de.wwwu.awolf.model.evaluation.ComparisonResult;
import de.wwwu.awolf.presenter.algorithms.Algorithm;
import de.wwwu.awolf.presenter.algorithms.AlgorithmHandler;
2020-03-21 19:54:03 +00:00
import java.util.List;
import java.util.Set;
import java.util.concurrent.CompletionService;
import java.util.concurrent.ExecutorCompletionService;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
2020-03-21 19:54:03 +00:00
public class AlgorithmComparison {
private final List<Algorithm.Type> types;
private final ExecutorService executorService;
private final CompletionService<Line> completionService;
private final Set<Line> lines;
2020-03-21 19:54:03 +00:00
public AlgorithmComparison(List<Algorithm.Type> types, Set<Line> lines) {
2020-03-21 19:54:03 +00:00
this.types = types;
this.lines = lines;
2020-03-21 19:54:03 +00:00
this.executorService = Executors.newFixedThreadPool(3);
completionService = new ExecutorCompletionService<>(this.executorService);
}
public ComparisonResult compare() {
ComparisonResult comparisonResult = new ComparisonResult();
AlgorithmHandler algorithmHandler = AlgorithmHandler.getInstance();
2020-03-21 19:54:03 +00:00
for (Algorithm.Type value : getTypes()) {
Algorithm.Type type;
synchronized (types) {
type = value;
}
Line line = algorithmHandler.runAlgorithmByType(type, lines);
comparisonResult.put(type, line);
2020-03-21 19:54:03 +00:00
}
return comparisonResult;
}
private List<Algorithm.Type> getTypes() {
return types;
}
}