BUGFIX!!! Schnittpunkte werden korrrekt berechnet.
This commit is contained in:
parent
274778b780
commit
16b0ad7bec
|
@ -93,31 +93,10 @@ public abstract class AbstractPresenter implements Observer {
|
|||
Double current = Double.parseDouble(result[2]);
|
||||
Integer progress = (int) (100 * (current / max));
|
||||
//100% erreicht
|
||||
if (progress == 100) {
|
||||
Thread t = new Thread(() -> {
|
||||
calculateIntersections();
|
||||
});
|
||||
t.start();
|
||||
try {
|
||||
t.join();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
getView().showImportProgress(progress);
|
||||
});
|
||||
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
getView().showImportProgress(progress);
|
||||
getView().enableFunctionality();
|
||||
getView().getProgressDialog().dispose();
|
||||
getView().logHeading("Import aus Datei");
|
||||
getView().log("Anzahl der Geraden: " + getModel().getLines().size() + ".");
|
||||
getView().log("Anzahl der Schnittpunkte: " + getModel().getNodes().size() + ".");
|
||||
getView().logSuccess("Import war Erfolgreich! <hr>");
|
||||
});
|
||||
} else {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
getView().showImportProgress(progress);
|
||||
});
|
||||
}
|
||||
}
|
||||
if (result[0] == "export") {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
|
@ -133,33 +112,10 @@ public abstract class AbstractPresenter implements Observer {
|
|||
getView().log(result[1] + "<hr>");
|
||||
});
|
||||
}
|
||||
|
||||
if (result[0] == "import-picture") {
|
||||
//100% erreicht
|
||||
|
||||
Thread t = new Thread(() -> {
|
||||
calculateIntersections();
|
||||
});
|
||||
t.start();
|
||||
try {
|
||||
t.join();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
getView().enableFunctionality();
|
||||
getView().logHeading("Import eines Bildes");
|
||||
getView().log("Anzahl der Geraden: " + getModel().getLines().size() + ".");
|
||||
getView().log("Anzahl der Schnittpunkte: " + getModel().getNodes().size() + ".");
|
||||
getView().logSuccess("Der Import war Erfolgreich! <hr>");
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void calculateIntersections() {
|
||||
private void calculateIntersections() {
|
||||
try {
|
||||
Thread thread = new Thread(() -> {
|
||||
getModel().resetRanges();
|
||||
|
@ -178,6 +134,28 @@ public abstract class AbstractPresenter implements Observer {
|
|||
}
|
||||
}
|
||||
|
||||
protected void computeIntersections(){
|
||||
System.out.println("Anzahl der Geraden: "+ getModel().getLines().size());
|
||||
Thread t = new Thread(() -> {
|
||||
calculateIntersections();
|
||||
});
|
||||
t.start();
|
||||
try {
|
||||
t.join();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
getView().enableFunctionality();
|
||||
getView().getProgressDialog().dispose();
|
||||
getView().logHeading("Informationen zu dem aktuellen Modell");
|
||||
getView().log("Anzahl der Geraden: " + getModel().getLines().size() + ".");
|
||||
getView().log("Anzahl der Schnittpunkte: " + getModel().getNodes().size() + ".");
|
||||
getView().logSuccess("Import war Erfolgreich! <hr>");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public LineModel getModel() {
|
||||
return model;
|
||||
|
|
|
@ -48,6 +48,11 @@ public class Presenter extends AbstractPresenter {
|
|||
/***************************************************************************************************************************
|
||||
* Ausführung der Algorithmen
|
||||
***************************************************************************************************************************/
|
||||
|
||||
/**
|
||||
* Die Berechnung durch des Algorithmus zum LMS-Schätzer wird gestartet.
|
||||
* @param input Parameter für den Algorithmus
|
||||
*/
|
||||
public void calculateLMS(String[] input) {
|
||||
if (input[0] != null && input[1] != null) {
|
||||
if (lmsThread == null || !lmsThread.isAlive()) {
|
||||
|
@ -71,6 +76,10 @@ public class Presenter extends AbstractPresenter {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Die Berechnung durch des Algorithmus zum RM-Schätzer wird gestartet.
|
||||
* @param input Parameter für den Algorithmus
|
||||
*/
|
||||
public void calculateRM(String input) {
|
||||
if (input != null) {
|
||||
if (rmThread == null || !rmThread.isAlive()) {
|
||||
|
@ -92,6 +101,10 @@ public class Presenter extends AbstractPresenter {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Die Berechnung durch des Algorithmus zum TS-Schätzer wird gestartet.
|
||||
* @param input Parameter für den Algorithmus
|
||||
*/
|
||||
public void calculateTS(String input) {
|
||||
if (input != null) {
|
||||
if (tsThread == null || !tsThread.isAlive()) {
|
||||
|
@ -115,12 +128,17 @@ public class Presenter extends AbstractPresenter {
|
|||
* Hilfsmethoden
|
||||
***************************************************************************************************************************/
|
||||
|
||||
/**
|
||||
* Startet den Import des Datensatzes.
|
||||
* @param file importierender Datensatz
|
||||
*/
|
||||
public void startImport(File file) {
|
||||
if (importThread == null || !importThread.isAlive()) {
|
||||
importThread = new Thread(() -> {
|
||||
DataImporter importer = new DataImporter(file);
|
||||
importer.addObserver(this);
|
||||
getModel().setLines(importer.run());
|
||||
computeIntersections();
|
||||
});
|
||||
importThread.start();
|
||||
try {
|
||||
|
@ -131,12 +149,17 @@ public class Presenter extends AbstractPresenter {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Startet den Import eines Bildes.
|
||||
* @param file importierendes Bild
|
||||
*/
|
||||
public void startPictureDataImport(File file) {
|
||||
if (importPictureThread == null || !importPictureThread.isAlive()) {
|
||||
importPictureThread = new Thread(() -> {
|
||||
PictureProcessor pictureProcessor = new PictureProcessor(this, file);
|
||||
pictureProcessor.addObserver(this);
|
||||
pictureProcessor.run();
|
||||
computeIntersections();
|
||||
});
|
||||
importPictureThread.start();
|
||||
try {
|
||||
|
@ -149,6 +172,10 @@ public class Presenter extends AbstractPresenter {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Startet den Export des akteullen Datensatzes (nur der Geraden)
|
||||
* @param file Datei in der die Informationen gespeichert werden sollen
|
||||
*/
|
||||
public void startExport(File file) {
|
||||
if (exportThread == null || !exportThread.isAlive()) {
|
||||
exportThread = new Thread(() -> {
|
||||
|
@ -165,6 +192,10 @@ public class Presenter extends AbstractPresenter {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Startet den Export des akteullen Datensatzes im Rahmen der Evaluation (nur der Geraden)
|
||||
* @param file Datei in der die Informationen gespeichert werden sollen
|
||||
*/
|
||||
public void startDatasetExportEvaluation(File file) {
|
||||
if (exportThread == null || !exportThread.isAlive()) {
|
||||
exportThread = new Thread(() -> {
|
||||
|
@ -181,6 +212,11 @@ public class Presenter extends AbstractPresenter {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Startet den Export der Ergebnisse der Evaluation in Form einer LaTeX Datei
|
||||
* @param model TableModel das die Berechnenten Ergebnisse enthält
|
||||
* @param file Datei in die exportiert werden soll
|
||||
*/
|
||||
public void startResultExport(DefaultTableModel model, File file) {
|
||||
if (exportResultThread == null || !exportResultThread.isAlive()) {
|
||||
exportResultThread = new Thread(() -> {
|
||||
|
@ -196,13 +232,32 @@ public class Presenter extends AbstractPresenter {
|
|||
}
|
||||
}
|
||||
|
||||
public void generateDataset(int n) {
|
||||
/**
|
||||
* Startet das generieren der Datensätze der Größe <code>n</code>
|
||||
* @param n Größe des Datensatzes
|
||||
* @param type Art der Datensatzes
|
||||
*/
|
||||
public void generateDataset(int n, int type) {
|
||||
if (generatorThread == null || !generatorThread.isAlive()) {
|
||||
generatorThread = new Thread(() -> {
|
||||
DatasetGenerator generator = new DatasetGenerator();
|
||||
generator.addObserver(this);
|
||||
getModel().setLines(generator.generateDataCloud(n));
|
||||
calculateIntersections();
|
||||
switch (type){
|
||||
case 0:
|
||||
getModel().setLines(generator.generateDataCloud(n));
|
||||
break;
|
||||
case 1:
|
||||
getModel().setLines(generator.generateDataLines(n));
|
||||
break;
|
||||
case 2:
|
||||
getModel().setLines(generator.generateCircle(n));
|
||||
break;
|
||||
default:
|
||||
getModel().setLines(generator.generateDataCloud(n));
|
||||
break;
|
||||
}
|
||||
|
||||
computeIntersections();
|
||||
getView().enableFunctionality();
|
||||
});
|
||||
generatorThread.start();
|
||||
|
@ -214,8 +269,14 @@ public class Presenter extends AbstractPresenter {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param typ
|
||||
* @param n
|
||||
* @param alg
|
||||
* @param datasettyp
|
||||
*/
|
||||
public void startEvaluation(int typ, int n, int alg, String datasettyp) {
|
||||
|
||||
if (evalThread == null || !evalThread.isAlive()) {
|
||||
evalThread = new Thread(() -> {
|
||||
try {
|
||||
|
@ -230,8 +291,14 @@ public class Presenter extends AbstractPresenter {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param typ
|
||||
* @param n
|
||||
* @param alg
|
||||
* @param file
|
||||
*/
|
||||
public void startEvaluation(int typ, int n, int alg, File file) {
|
||||
|
||||
if (evalThread == null || !evalThread.isAlive()) {
|
||||
evalThread = new Thread(() -> {
|
||||
try {
|
||||
|
|
|
@ -18,8 +18,7 @@ import java.util.TreeSet;
|
|||
*/
|
||||
public class IntersectionComputer {
|
||||
|
||||
private LinkedList<Line> lines;
|
||||
private List<Line>[] subList;
|
||||
private LinkedList<Line> lines;
|
||||
private TreeSet<Point> intersections;
|
||||
|
||||
private Double xMinimum;
|
||||
|
@ -32,7 +31,6 @@ public class IntersectionComputer {
|
|||
public IntersectionComputer(LinkedList<Line> lines) {
|
||||
this.lines = lines;
|
||||
this.worker = new Thread[4];
|
||||
this.subList = new LinkedList[4];
|
||||
this.intersections = new TreeSet<>();
|
||||
|
||||
xMinimum = Double.MAX_VALUE;
|
||||
|
@ -41,9 +39,9 @@ public class IntersectionComputer {
|
|||
yMaximum = Double.MIN_VALUE;
|
||||
}
|
||||
|
||||
public ArrayList<Point> compute(double lower, double higher) {
|
||||
public ArrayList<Point> compute(final double lower, final double higher) {
|
||||
|
||||
if (lines.size() >= 12) {
|
||||
if (lines.size() > 10) {
|
||||
worker[0] = new Thread(() -> {
|
||||
work(lines.subList(0, (lines.size() / 4)),lower,higher);
|
||||
});
|
||||
|
@ -81,9 +79,10 @@ public class IntersectionComputer {
|
|||
return compute(-99999, 99999);
|
||||
}
|
||||
|
||||
private synchronized void work(List<Line> lines, double lower, double higher) {
|
||||
private void work(List<Line> lines, double lower, double higher) {
|
||||
IntersectionCounter counter = new IntersectionCounter();
|
||||
counter.run(lines, new Interval(lower, higher));
|
||||
int count = counter.run(lines, new Interval(lower, higher));
|
||||
System.out.println("count: "+count);
|
||||
ArrayList<Point> points = counter.calculateIntersectionAbscissas();
|
||||
for (Point p : points) {
|
||||
if (!isFound(p)) {
|
||||
|
@ -110,26 +109,26 @@ public class IntersectionComputer {
|
|||
}
|
||||
}
|
||||
|
||||
public synchronized void setRanges(Point point) {
|
||||
public void setRanges(Point point) {
|
||||
xMaximum = (point.getX() > xMaximum) ? point.getX() : xMaximum;
|
||||
xMinimum = (point.getX() < xMinimum) ? point.getX() : xMinimum;
|
||||
yMaximum = (point.getY() > yMaximum) ? point.getY() : yMaximum;
|
||||
yMinimum = (point.getY() < yMinimum) ? point.getY() : yMinimum;
|
||||
}
|
||||
|
||||
public Double getxMinimum() {
|
||||
public synchronized Double getxMinimum() {
|
||||
return xMinimum;
|
||||
}
|
||||
|
||||
public Double getxMaximum() {
|
||||
public synchronized Double getxMaximum() {
|
||||
return xMaximum;
|
||||
}
|
||||
|
||||
public Double getyMinimum() {
|
||||
public synchronized Double getyMinimum() {
|
||||
return yMinimum;
|
||||
}
|
||||
|
||||
public Double getyMaximum() {
|
||||
public synchronized Double getyMaximum() {
|
||||
return yMaximum;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import presenter.algorithms.advanced.TheilSenEstimator;
|
|||
import presenter.algorithms.naiv.NaivLeastMedianOfSquaresEstimator;
|
||||
import presenter.algorithms.naiv.NaivRepeatedMedianEstimator;
|
||||
import presenter.algorithms.naiv.NaivTheilSenEstimator;
|
||||
import presenter.algorithms.util.IntersectionComputer;
|
||||
import presenter.algorithms.util.IntersectionCounter;
|
||||
import presenter.generator.DatasetGenerator;
|
||||
import presenter.io.DataImporter;
|
||||
|
@ -85,10 +86,12 @@ public class EvaluateAlgorithms extends Observable {
|
|||
this.iterations = n;
|
||||
this.alg = alg;
|
||||
|
||||
IntersectionCounter counter = new IntersectionCounter();
|
||||
counter.run(arrangement.getLines(), new Interval(-99999, 99999));
|
||||
counter.calculateIntersectionAbscissas(arrangement);
|
||||
//IntersectionCounter counter = new IntersectionCounter();
|
||||
//counter.run(arrangement.getLines(), new Interval(-99999, 99999));
|
||||
//counter.calculateIntersectionAbscissas(arrangement);
|
||||
|
||||
IntersectionComputer computer = new IntersectionComputer(arrangement.getLines());
|
||||
arrangement.setNodes(computer.compute());
|
||||
|
||||
lmsL = new LinkedList<>(arrangement.getLines());
|
||||
rmL = new LinkedList<>(arrangement.getLines());
|
||||
|
@ -109,9 +112,12 @@ public class EvaluateAlgorithms extends Observable {
|
|||
this.iterations = n;
|
||||
this.alg = alg;
|
||||
|
||||
IntersectionCounter counter = new IntersectionCounter();
|
||||
counter.run(arrangement.getLines(), new Interval(-99999, 99999));
|
||||
counter.calculateIntersectionAbscissas(arrangement);
|
||||
//IntersectionCounter counter = new IntersectionCounter();
|
||||
//counter.run(arrangement.getLines(), new Interval(-99999, 99999));
|
||||
//counter.calculateIntersectionAbscissas(arrangement);
|
||||
|
||||
IntersectionComputer computer = new IntersectionComputer(arrangement.getLines());
|
||||
arrangement.setNodes(computer.compute());
|
||||
|
||||
|
||||
lmsL = new LinkedList<>(arrangement.getLines());
|
||||
|
|
|
@ -34,22 +34,28 @@ public class GenerateDataListener implements ActionListener {
|
|||
|
||||
if (dialog == null || !dialog.isVisible()) {
|
||||
dialog = new JDialog();
|
||||
dialog.setTitle("generiere Datensatz");
|
||||
dialog.setAlwaysOnTop(true);
|
||||
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.getDefault());
|
||||
DecimalFormat decimalFormat = (DecimalFormat) numberFormat;
|
||||
decimalFormat.setGroupingUsed(false);
|
||||
JTextField textField = new JFormattedTextField(decimalFormat);
|
||||
textField.setColumns(20);
|
||||
textField.setColumns(10);
|
||||
textField.setText("20");
|
||||
JButton aproveButton = new JButton("start");
|
||||
String[] options = {"Punktwolke", "Gerade", "Kreis und Gerade"};
|
||||
JComboBox<String> datasetTypeComboBox = new JComboBox<>(options);
|
||||
dialog.setSize(350, 70);
|
||||
dialog.setLayout(new FlowLayout());
|
||||
dialog.setResizable(false);
|
||||
dialog.setLocationRelativeTo(presenter.getView());
|
||||
dialog.add(datasetTypeComboBox);
|
||||
dialog.add(textField);
|
||||
dialog.add(aproveButton);
|
||||
aproveButton.addActionListener(e1 -> {
|
||||
int n = Integer.parseInt(textField.getText());
|
||||
Thread t = new Thread(() -> presenter.generateDataset(n));
|
||||
int type = datasetTypeComboBox.getSelectedIndex();
|
||||
Thread t = new Thread(() -> presenter.generateDataset(n,type));
|
||||
t.start();
|
||||
dialog.dispose();
|
||||
});
|
||||
|
|
|
@ -121,10 +121,13 @@ public class DualityPanel extends JPanel {
|
|||
this.setFocusable(true);
|
||||
|
||||
JTextArea info = new JTextArea();
|
||||
info.setText("Um in dem Plot hineinzuzoomen kann das Mausrad verwendett werden. \nUm sich anschließen vertikal bzw. horizontal zu bewegen kann die Kombination (Umschalt/Steuerung)\nund Mausrad verwendett werden.");
|
||||
Font font = new Font("Serif", Font.ITALIC, 12);
|
||||
info.setWrapStyleWord(true);
|
||||
info.setLineWrap(true);
|
||||
info.setAlignmentX(JTextArea.CENTER_ALIGNMENT);
|
||||
info.setText("Um in dem Plot hineinzuzoomen kann das Mausrad verwendett werden. Um sich anschließen vertikal bzw. horizontal zu bewegen kann die Kombination (Umschalt/Steuerung) und Mausrad verwendett werden.");
|
||||
Font font = new Font("Serif", Font.ITALIC, 14);
|
||||
info.setFont(font);
|
||||
info.setForeground(Color.DARK_GRAY);
|
||||
//info.setForeground(Color.DARK_GRAY);
|
||||
info.setEditable(false);
|
||||
info.setWrapStyleWord(true);
|
||||
|
||||
|
|
Loading…
Reference in New Issue