algorithms-for-computing-li.../LinearRegressionTool/src/main/java/de/wwwu/awolf/App.java

112 lines
4.2 KiB
Java

package de.wwwu.awolf;
import de.wwwu.awolf.model.Line;
import de.wwwu.awolf.model.LineModel;
import de.wwwu.awolf.model.Point;
import de.wwwu.awolf.presenter.Presenter;
import de.wwwu.awolf.presenter.algorithms.advanced.LeastMedianOfSquaresEstimator;
import de.wwwu.awolf.presenter.algorithms.advanced.RepeatedMedianEstimator;
import de.wwwu.awolf.presenter.algorithms.advanced.TheilSenEstimator;
import de.wwwu.awolf.presenter.algorithms.naiv.NaivLeastMedianOfSquaresEstimator;
import de.wwwu.awolf.presenter.algorithms.naiv.NaivRepeatedMedianEstimator;
import de.wwwu.awolf.presenter.algorithms.naiv.NaivTheilSenEstimator;
import de.wwwu.awolf.presenter.generator.DatasetGenerator;
import de.wwwu.awolf.presenter.util.IntersectionComputer;
import de.wwwu.awolf.presenter.util.Logging;
import de.wwwu.awolf.view.MainFrame;
import org.apache.commons.cli.*;
import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
*
* @Author: Armin Wolf
* @Email: a_wolf28@uni-muenster.de
* @Date: 28.05.2017.
*/
public class App {
/**
* Schriftart wird neu gesetzt
*
* @param f Schriftart
*/
private static void setUIFont(javax.swing.plaf.FontUIResource f) {
java.util.Enumeration<Object> keys = UIManager.getDefaults().keys();
while (keys.hasMoreElements()) {
Object key = keys.nextElement();
Object value = UIManager.get(key);
if (value instanceof javax.swing.plaf.FontUIResource) {
UIManager.put(key, f);
}
}
}
/**
* Die Methode rechnet für gegebene Größen die Algorithmen durch und gibt jeweils die benötigte Zeit
*/
public static void benchmark() {
ExecutorService executorService = Executors.newFixedThreadPool(6);
Logging.logInfo("---- Datasetgröße: " + 100 + " ----");
DatasetGenerator generator = new DatasetGenerator();
LinkedList<Line> lines = generator.generateDataCloud(10000);
IntersectionComputer computer = new IntersectionComputer(lines);
ArrayList<Point> points = computer.compute();
executorService.submit(new NaivLeastMedianOfSquaresEstimator(lines));
executorService.submit(new NaivRepeatedMedianEstimator(lines));
executorService.submit(new NaivTheilSenEstimator(lines));
executorService.submit(new LeastMedianOfSquaresEstimator(lines, points));
executorService.submit(new RepeatedMedianEstimator(lines));
executorService.submit(new TheilSenEstimator(lines, points));
}
/**
* Maim Methode
*
* @param argv
*/
public static void main(String[] argv) {
Options options = new Options();
options.addOption("benchmark", "Start stresstest");
options.addOption("", "default");
CommandLineParser parser = new DefaultParser();
try {
CommandLine line = parser.parse(options, argv); // Sensitive
String[] args = line.getArgs();
if (args.length > 0 && args[0].equals("benchmark")) {
benchmark();
} else {
final Presenter presenter = new Presenter(new LineModel(), null);
SwingUtilities.invokeLater(() -> {
MainFrame view = new MainFrame();
setUIFont(new javax.swing.plaf.FontUIResource(new Font("SansSerif", Font.PLAIN, 12)));
try {
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
} catch (ClassNotFoundException | UnsupportedLookAndFeelException | IllegalAccessException | InstantiationException e) {
Logging.logError("Error with the UI. ", e);
}
view.setPresenter(presenter);
view.setActionListeners();
presenter.setView(view);
});
}
} catch (ParseException e) {
Logging.logError("Error while parsing the command line arguments.", e);
}
}
}