paar anpassungen u.a. RM Estimator
This commit is contained in:
parent
484bd3a2c9
commit
a1c3d2c933
7
pom.xml
7
pom.xml
|
@ -35,5 +35,12 @@
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<version>4.12</version>
|
<version>4.12</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- OpenCSV-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.opencsv</groupId>
|
||||||
|
<artifactId>opencsv</artifactId>
|
||||||
|
<version>3.9</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
|
@ -139,8 +139,7 @@ public class LeastMedianOfSquaresEstimator extends Observable implements Algorit
|
||||||
setChanged();
|
setChanged();
|
||||||
double m = (getSigmaMin().getX2() + getSigmaMin().getX1()) * -0.5;
|
double m = (getSigmaMin().getX2() + getSigmaMin().getX1()) * -0.5;
|
||||||
double b = (getSigmaMin().getY2() + getSigmaMin().getY1()) * 0.5;
|
double b = (getSigmaMin().getY2() + getSigmaMin().getY1()) * 0.5;
|
||||||
Line result = new Line(m, b);
|
String[] result = {"lms", m+"", b+""};
|
||||||
result.setId("lms");
|
|
||||||
notifyObservers(result);
|
notifyObservers(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.Observable;
|
import java.util.Observable;
|
||||||
|
import java.util.Random;
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -77,6 +78,7 @@ public class RepeatedMedianEstimator extends Observable implements Algorithm {
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
while (linesInCenterSlab.size() != 1) {
|
while (linesInCenterSlab.size() != 1) {
|
||||||
|
n = linesInCenterSlab.size();
|
||||||
r = Math.ceil(Math.pow(n, beta));
|
r = Math.ceil(Math.pow(n, beta));
|
||||||
ArrayList<Line> lines = sampleLines(linesInCenterSlab, r);
|
ArrayList<Line> lines = sampleLines(linesInCenterSlab, r);
|
||||||
|
|
||||||
|
@ -92,16 +94,18 @@ public class RepeatedMedianEstimator extends Observable implements Algorithm {
|
||||||
}
|
}
|
||||||
|
|
||||||
//rank of the repeated median in C
|
//rank of the repeated median in C
|
||||||
k = (Math.floor(n * 0.5) - linesInLeftSlab.size());
|
k = Math.max(1,Math.min(set.size(),(Math.ceil(n * 0.5) - linesInLeftSlab.size())));
|
||||||
|
|
||||||
//compute k_lo and k_hi
|
//compute k_lo and k_hi
|
||||||
computeSlabBorders();
|
computeSlabBorders();
|
||||||
|
|
||||||
|
|
||||||
|
if (medianIntersectionAbscissas.size() < kLow || medianIntersectionAbscissas.size()<kHigh || kLow < 0 || kHigh<0 )
|
||||||
|
System.err.print("#medianIntersectionAbscissa: "+medianIntersectionAbscissas.size()+"\t\t klow: "+kLow+" kHigh: "+kHigh+"\n\n");
|
||||||
|
|
||||||
//Employ fast selection algorithm to determine the Elements Theta_lo and Theta_hi
|
//Employ fast selection algorithm to determine the Elements Theta_lo and Theta_hi
|
||||||
thetaLow = randomizedSelect(medianIntersectionAbscissas, 0,
|
thetaLow = randomizedSelect(medianIntersectionAbscissas, kLow);
|
||||||
medianIntersectionAbscissas.size() - 1, kLow);
|
thetaHigh = randomizedSelect(medianIntersectionAbscissas, kHigh);
|
||||||
thetaHigh = randomizedSelect(medianIntersectionAbscissas, 0,
|
|
||||||
medianIntersectionAbscissas.size() - 1, kHigh);
|
|
||||||
|
|
||||||
//For each dual Line in C count the number of intersection abscissas that lie
|
//For each dual Line in C count the number of intersection abscissas that lie
|
||||||
//in each of the intervals.
|
//in each of the intervals.
|
||||||
|
@ -119,8 +123,7 @@ public class RepeatedMedianEstimator extends Observable implements Algorithm {
|
||||||
double b = (
|
double b = (
|
||||||
(linesInCenterSlab.get(0).getM() * (thetaLow)) + linesInCenterSlab.get(0)
|
(linesInCenterSlab.get(0).getM() * (thetaLow)) + linesInCenterSlab.get(0)
|
||||||
.getB());
|
.getB());
|
||||||
Line result = new Line(m, b);
|
String[] result = {"rm", m+"", b+""};
|
||||||
result.setId("rm");
|
|
||||||
notifyObservers(result);
|
notifyObservers(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -187,32 +190,50 @@ public class RepeatedMedianEstimator extends Observable implements Algorithm {
|
||||||
*/
|
*/
|
||||||
public void computeSlabBorders() {
|
public void computeSlabBorders() {
|
||||||
kLow = Math
|
kLow = Math
|
||||||
.max(1, Math.floor(((r * k) / (linesInCenterSlab.size())) - ((3 * Math.sqrt(r)) / (2))));
|
.max(1, Math.floor(
|
||||||
|
( (r * k) / (linesInCenterSlab.size()))
|
||||||
|
- ( (3 * Math.sqrt(r)) / (2))
|
||||||
|
)
|
||||||
|
);
|
||||||
kHigh = Math
|
kHigh = Math
|
||||||
.min(r, Math.floor(((r * k) / (linesInCenterSlab.size())) + ((3 * Math.sqrt(r)) / (2))));
|
.min(r, Math.floor(
|
||||||
|
((r * k) / (linesInCenterSlab.size()))
|
||||||
|
+ ((3 * Math.sqrt(r)) / (2))
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param a
|
* @param a
|
||||||
* @param start
|
|
||||||
* @param end
|
|
||||||
* @param i
|
* @param i
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Double randomizedSelect(ArrayList<Double> a, int start, int end, double i) {
|
public Double randomizedSelect(ArrayList<Double> a, double i) {
|
||||||
if (start == end) {
|
int start = 0;
|
||||||
return a.get(start);
|
int end = a.size()-1;
|
||||||
|
if (i >= end+1){
|
||||||
|
return a.get(end);
|
||||||
}
|
}
|
||||||
int q = randomizedPartition(a, start, end);
|
|
||||||
int tmpPivot = q - start + 1;
|
|
||||||
|
|
||||||
if (i == tmpPivot) {
|
while(true){
|
||||||
return a.get(q);
|
if(start == end){
|
||||||
} else if (i < tmpPivot) {
|
return a.get(start);
|
||||||
return randomizedSelect(a, start, q - 1, i);
|
}
|
||||||
} else {
|
int q = randomizedPartition(a, start, end);
|
||||||
return randomizedSelect(a, q + 1, end, i - tmpPivot);
|
int k = q-start+1;
|
||||||
|
|
||||||
|
if(i == k){
|
||||||
|
return a.get(q);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
if(i <k){
|
||||||
|
end = q -1;
|
||||||
|
}else{
|
||||||
|
i = i - k;
|
||||||
|
start = q + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,8 +245,16 @@ public class RepeatedMedianEstimator extends Observable implements Algorithm {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public int randomizedPartition(ArrayList<Double> a, int start, int end) {
|
public int randomizedPartition(ArrayList<Double> a, int start, int end) {
|
||||||
int delta = Math.abs(end - start);
|
int i = 0;
|
||||||
int i = start + ThreadLocalRandom.current().nextInt(0, delta);
|
Random random = new Random(System.currentTimeMillis());
|
||||||
|
|
||||||
|
//alternative: ThreadLocalRandom.current()
|
||||||
|
if(start < end){
|
||||||
|
i = start + random.nextInt(end-start);
|
||||||
|
}else{
|
||||||
|
i = end + random.nextInt(start-end);
|
||||||
|
}
|
||||||
|
|
||||||
Collections.swap(a, end, i);
|
Collections.swap(a, end, i);
|
||||||
return partition(a, start, end);
|
return partition(a, start, end);
|
||||||
}
|
}
|
||||||
|
@ -240,14 +269,14 @@ public class RepeatedMedianEstimator extends Observable implements Algorithm {
|
||||||
public int partition(ArrayList<Double> a, int start, int end) {
|
public int partition(ArrayList<Double> a, int start, int end) {
|
||||||
Double x = a.get(end);
|
Double x = a.get(end);
|
||||||
int i = start - 1;
|
int i = start - 1;
|
||||||
for (int j = start; j < end; j++) {
|
for (int j = start; j <= end-1; j++) {
|
||||||
if (a.get(j) <= x) {
|
if (a.get(j) <= x) {
|
||||||
i++;
|
i++;
|
||||||
Collections.swap(a, i, j);
|
Collections.swap(a, i, j);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Collections.swap(a, i + 1, end);
|
Collections.swap(a, i+1, end);
|
||||||
return i + 1;
|
return i+1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -284,8 +313,6 @@ public class RepeatedMedianEstimator extends Observable implements Algorithm {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public void contractIntervals() {
|
public void contractIntervals() {
|
||||||
//if (linesInLeftSlab.size() < Math.floor(n / 2) && Math.floor(n / 2) <= (linesInLeftSlab.size()
|
|
||||||
// + linesInCenterSlab.size())) {
|
|
||||||
for (int i = 0; i < linesInCenterSlab.size(); i++) {
|
for (int i = 0; i < linesInCenterSlab.size(); i++) {
|
||||||
|
|
||||||
int left = countLeftSlab.get(i);
|
int left = countLeftSlab.get(i);
|
||||||
|
|
|
@ -1,15 +1,18 @@
|
||||||
package Presenter.Import;
|
package Presenter.Import;
|
||||||
|
|
||||||
import Model.Arrangement;
|
import Model.Arrangement;
|
||||||
import java.io.BufferedReader;
|
import Model.Line;
|
||||||
import java.io.FileInputStream;
|
import com.opencsv.CSVReader;
|
||||||
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.util.List;
|
||||||
import java.io.InputStreamReader;
|
import java.util.Observable;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
|
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
|
||||||
*
|
*
|
||||||
|
@ -17,72 +20,49 @@ import javax.swing.JOptionPane;
|
||||||
* @Email: a_wolf28@uni-muenster.de
|
* @Email: a_wolf28@uni-muenster.de
|
||||||
* @Date: 21.06.2017.
|
* @Date: 21.06.2017.
|
||||||
*/
|
*/
|
||||||
public class DataImporter {
|
public class DataImporter extends Observable{
|
||||||
|
|
||||||
private String path;
|
private File file;
|
||||||
private InputStream inputStream;
|
private CSVReader reader;
|
||||||
private Arrangement model;
|
private Arrangement model;
|
||||||
final String separator = " ";
|
|
||||||
|
|
||||||
public DataImporter(String path, Arrangement model) {
|
public DataImporter(File file, Arrangement model) {
|
||||||
this.path = path;
|
|
||||||
this.model = model;
|
this.model = model;
|
||||||
|
this.file = file;
|
||||||
try {
|
try {
|
||||||
inputStream = new FileInputStream(path);
|
|
||||||
|
this.reader = new CSVReader(new FileReader(file));
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
JOptionPane.showMessageDialog(null, e.getMessage());
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run(){
|
||||||
try (BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"))) {
|
|
||||||
String line;
|
try {
|
||||||
while ((line = br.readLine()) != null) {
|
List<String[]> lines = reader.readAll();
|
||||||
// process the line.
|
int counter = 0;
|
||||||
|
String[] result = {"import", lines.size()+"", ""};
|
||||||
|
//System.out.println("+-------------------------------------------------------------------------------+");
|
||||||
|
for(String[] nextLine : lines) {
|
||||||
|
counter++;
|
||||||
|
// nextLine[] is an array of values from the line
|
||||||
|
int id = Integer.parseInt(nextLine[0]);
|
||||||
|
Double x = Double.parseDouble(nextLine[1]);
|
||||||
|
Double y = Double.parseDouble(nextLine[2]);
|
||||||
|
Line line = new Line(x,y);
|
||||||
|
line.setId(id+"");
|
||||||
|
model.addLine(line);
|
||||||
|
//System.out.format("|\t\t\t\t\t %-11d \t|\t\t\t\t\t %-11f \t|\t\t\t\t\t %-11f \t\t\t\t\t|\n", id,x,y);
|
||||||
|
setChanged();
|
||||||
|
result[2] = counter + "";
|
||||||
|
notifyObservers(result);
|
||||||
}
|
}
|
||||||
br.close();
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
//System.out.println("+-------------------------------------------------------------------------------+");
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void parseLine(String line) {
|
|
||||||
if (line.substring(0, 1) == "#") {
|
|
||||||
return;
|
|
||||||
} else if (isNumeric(line.substring(line.lastIndexOf(separator), line.length() - 1))) {
|
|
||||||
String id = line.substring(0, line.indexOf(separator));
|
|
||||||
Double x = Double.parseDouble(line.substring(line.indexOf(separator), line.lastIndexOf(separator)));
|
|
||||||
Double y = Double.parseDouble(line.substring(line.lastIndexOf(separator), line.length()-1));
|
|
||||||
System.out.println("ID: "+id+" x: "+x+"\t y: "+y);
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isNumeric(String str) {
|
|
||||||
try {
|
|
||||||
double d = Double.parseDouble(str);
|
|
||||||
} catch (NumberFormatException nfe) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPath() {
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPath(String path) {
|
|
||||||
path = path;
|
|
||||||
}
|
|
||||||
|
|
||||||
public InputStream getInputStream() {
|
|
||||||
return inputStream;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setInputStream(InputStream inputStream) {
|
|
||||||
this.inputStream = inputStream;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,11 +5,14 @@ import Model.Line;
|
||||||
import Model.Point;
|
import Model.Point;
|
||||||
import Presenter.Algorithms.LeastMedianOfSquaresEstimator;
|
import Presenter.Algorithms.LeastMedianOfSquaresEstimator;
|
||||||
import Presenter.Algorithms.RepeatedMedianEstimator;
|
import Presenter.Algorithms.RepeatedMedianEstimator;
|
||||||
|
import Presenter.Import.DataImporter;
|
||||||
import View.MainFrame;
|
import View.MainFrame;
|
||||||
|
import java.io.File;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Observable;
|
import java.util.Observable;
|
||||||
import java.util.Observer;
|
import java.util.Observer;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
|
|
||||||
|
|
||||||
|
@ -33,68 +36,92 @@ public class Presenter implements Observer {
|
||||||
public Presenter(Arrangement model, MainFrame view) {
|
public Presenter(Arrangement model, MainFrame view) {
|
||||||
this.model = model;
|
this.model = model;
|
||||||
this.view = view;
|
this.view = view;
|
||||||
// Double[] x = {1d, 2d, 3d, 4d, 10d, 12d, 18d};
|
// Double[] x = {1d, 2d, 3d, 4d, 10d, 12d, 18d};
|
||||||
// Double[] y = {9d, 15d, 19d, 20d, 45d, 55d, 78d};
|
// Double[] y = {9d, 15d, 19d, 20d, 45d, 55d, 78d};
|
||||||
Double[] x = {18d, 24d, 30d, 34d, 38d};
|
// Double[] x = {18d, 24d, 30d, 34d, 38d};
|
||||||
Double[] y = {18d, 26d, 30d, 40d, 70d};
|
// Double[] y = {18d, 26d, 30d, 40d, 70d};
|
||||||
// Double[] x = {1d,3d,4d,5d,8d};
|
// Double[] x = {1d,3d,4d,5d,8d};
|
||||||
// Double[] y = {4d,2d,1d,0d,0d};
|
// Double[] y = {4d,2d,1d,0d,0d};
|
||||||
view.logHeading("Duale Darstellung der Punkte als Geraden:");
|
// view.logHeading("Duale Darstellung der Punkte als Geraden:");
|
||||||
for (int j = 0; j < x.length; j++) {
|
// for (int j = 0; j < x.length; j++) {
|
||||||
Line p = new Line(x[j], y[j]);
|
// Line p = new Line(x[j], y[j]);
|
||||||
p.setId(j+"");
|
// p.setId(j+"");
|
||||||
view.log("f(x) = " + p.getM() + "x + " + p.getB());
|
// view.log("f(x) = " + p.getM() + "x + " + p.getB());
|
||||||
this.model.addLine(p);
|
// this.model.addLine(p);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
calcArrangementNodes();
|
// calcArrangementNodes();
|
||||||
//print
|
// //print
|
||||||
List<String> heading = new LinkedList<>();
|
// List<String> heading = new LinkedList<>();
|
||||||
List<List<String>> rows = new LinkedList<>();
|
// List<List<String>> rows = new LinkedList<>();
|
||||||
heading.add("X - Koordinate");
|
// heading.add("X - Koordinate");
|
||||||
heading.add("Y - Koordinate");
|
// heading.add("Y - Koordinate");
|
||||||
for (Point p : model.getNodes()) {
|
// for (Point p : model.getNodes()) {
|
||||||
LinkedList<String> rowEntry = new LinkedList<>();
|
// LinkedList<String> rowEntry = new LinkedList<>();
|
||||||
rowEntry.add(p.getX().toString());
|
// rowEntry.add(p.getX().toString());
|
||||||
rowEntry.add(p.getY().toString());
|
// rowEntry.add(p.getY().toString());
|
||||||
rows.add(rowEntry);
|
// rows.add(rowEntry);
|
||||||
}
|
// }
|
||||||
view.logHeading("Schnittpunkte der Dualen Geraden:");
|
// view.logHeading("Schnittpunkte der Dualen Geraden:");
|
||||||
view.createTable(heading, rows);
|
// view.createTable(heading, rows);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(Observable o, Object arg) {
|
public void update(Observable o, Object arg) {
|
||||||
Line result = ((Line) arg);
|
String[] result = ((String[]) arg);
|
||||||
if (result.getId() == "lms"){
|
if (result[0] == "lms"){
|
||||||
SwingUtilities.invokeLater(() -> {
|
SwingUtilities.invokeLater(() -> {
|
||||||
getView().visualizeLMS(result.getM(), result.getB());
|
getView().visualizeLMS(Double.parseDouble(result[1]), Double.parseDouble(result[2]));
|
||||||
//getView().setLmsIsComplete(true);
|
//getView().setLmsIsComplete(true);
|
||||||
getView().logHeading("Least Median of Squares");
|
getView().logHeading("Least Median of Squares");
|
||||||
getView().log("<b>m:</b> " + result.getM());
|
getView().log("<b>m:</b> " + result[1]);
|
||||||
getView().log("<b>b:</b> " + result.getB());
|
getView().log("<b>b:</b> " + result[2]);
|
||||||
getView().logSuccess("Berechnung wurde Erfolgreich durchgeführt");
|
getView().logSuccess("Berechnung wurde Erfolgreich durchgeführt");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.getId() == "rm"){
|
if (result[0] == "rm"){
|
||||||
SwingUtilities.invokeLater(() -> {
|
SwingUtilities.invokeLater(() -> {
|
||||||
getView().visualizeRM(result.getM(), result.getB());
|
getView().visualizeRM(Double.parseDouble(result[1]), Double.parseDouble(result[2]));
|
||||||
getView().logHeading("Repeated Median Estimator");
|
getView().logHeading("Repeated Median Estimator");
|
||||||
getView().log("<b>m:</b> " + result.getM());
|
getView().log("<b>m:</b> " + result[1]);
|
||||||
getView().log("<b>b:</b> " + result.getB());
|
getView().log("<b>b:</b> " + result[2]);
|
||||||
getView().logSuccess("Berechnung wurde Erfolgreich durchgeführt");
|
getView().logSuccess("Berechnung wurde Erfolgreich durchgeführt");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (result[0] == "import"){
|
||||||
|
Double max = Double.parseDouble(result[1]);
|
||||||
|
Double current = Double.parseDouble(result[2]);
|
||||||
|
Integer progress = (int) (100 * (current/max));
|
||||||
|
//100% erreicht
|
||||||
|
if (progress == 100){
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
getView().showImportProgress(progress);
|
||||||
|
getView().enableFunctionality();
|
||||||
|
getView().getProgressDialog().dispose();
|
||||||
|
});
|
||||||
|
setup();
|
||||||
|
} else {
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
getView().showImportProgress(progress);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void startArrangementVisualization() {
|
public void visualizeDualLines() {
|
||||||
view.createArrangement();
|
view.createArrangement();
|
||||||
}
|
}
|
||||||
|
/***************************************************************************************************************************
|
||||||
|
* Ausführung der Algorithmen
|
||||||
|
***************************************************************************************************************************/
|
||||||
public void calculateLMS(String[] input) {
|
public void calculateLMS(String[] input) {
|
||||||
Double constant = Double.parseDouble(input[0]);
|
Double constant = Double.parseDouble(input[0]);
|
||||||
Double error = Double.parseDouble(input[1]);
|
Double error = Double.parseDouble(input[1]);
|
||||||
|
@ -112,6 +139,33 @@ public class Presenter implements Observer {
|
||||||
rm.run();
|
rm.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/***************************************************************************************************************************
|
||||||
|
* Hilfsmethoden
|
||||||
|
***************************************************************************************************************************/
|
||||||
|
public void setup(){
|
||||||
|
getView().logHeading("Duale Darstellung der Punkte als Geraden:");
|
||||||
|
|
||||||
|
for (int j = 0; j < getModel().getLines().size(); j++) {
|
||||||
|
Line p = getModel().getLines().get(j);
|
||||||
|
p.setId(j+"");
|
||||||
|
getView().log("f(x) = " + p.getM() + "x + " + p.getB());
|
||||||
|
}
|
||||||
|
calcArrangementNodes();
|
||||||
|
|
||||||
|
//Darstellung der Schnittpunkte in einer Tabelle
|
||||||
|
// List<String> heading = new LinkedList<>();
|
||||||
|
// List<List<String>> rows = new LinkedList<>();
|
||||||
|
// heading.add("X - Koordinate");
|
||||||
|
// heading.add("Y - Koordinate");
|
||||||
|
// for (Point p : getModel().getNodes()) {
|
||||||
|
// LinkedList<String> rowEntry = new LinkedList<>();
|
||||||
|
// rowEntry.add(p.getX().toString());
|
||||||
|
// rowEntry.add(p.getY().toString());
|
||||||
|
// rows.add(rowEntry);
|
||||||
|
// }
|
||||||
|
// getView().logHeading("Schnittpunkte der Dualen Geraden:");
|
||||||
|
// getView().createTable(heading, rows);
|
||||||
|
}
|
||||||
|
|
||||||
public Point calcIntersection(Line a, Line b) {
|
public Point calcIntersection(Line a, Line b) {
|
||||||
Line p1 = a;
|
Line p1 = a;
|
||||||
|
@ -142,23 +196,28 @@ public class Presenter implements Observer {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public LinkedList<LinkedList<Point>> calcArrangementLines() {
|
public LinkedList<Line> calcArrangementLines() {
|
||||||
LinkedList<LinkedList<Point>> lineCoordinates = new LinkedList<>();
|
LinkedList<Line> lineCoordinates = new LinkedList<>();
|
||||||
double x1 = -1000;
|
double x1 = -1000;
|
||||||
double x2 = 1000;
|
double x2 = 1000;
|
||||||
|
|
||||||
for (Line point : model.getLines()) {
|
for (Line point : model.getLines()) {
|
||||||
LinkedList line = new LinkedList();
|
|
||||||
double y1 = (point.getM() * x1 + point.getB());
|
double y1 = (point.getM() * x1 + point.getB());
|
||||||
double y2 = (point.getM() * x2 + point.getB());
|
double y2 = (point.getM() * x2 + point.getB());
|
||||||
line.add(new Point(x1, y1));
|
Line line = new Line(x1, x2, y1, y2);
|
||||||
line.add(new Point(x2, y2));
|
line.setId(point.getId());
|
||||||
lineCoordinates.add(line);
|
lineCoordinates.add(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
return lineCoordinates;
|
return lineCoordinates;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void startImport(File file){
|
||||||
|
DataImporter importer = new DataImporter(file, getModel());
|
||||||
|
importer.addObserver(this);
|
||||||
|
importer.run();
|
||||||
|
}
|
||||||
|
|
||||||
/***************************************************************************************************************************
|
/***************************************************************************************************************************
|
||||||
* Getter und Setter Methoden
|
* Getter und Setter Methoden
|
||||||
***************************************************************************************************************************/
|
***************************************************************************************************************************/
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package View;
|
package View;
|
||||||
|
|
||||||
|
import Model.Line;
|
||||||
import Model.Point;
|
import Model.Point;
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
@ -30,7 +31,7 @@ import org.jfree.util.ShapeUtilities;
|
||||||
*/
|
*/
|
||||||
public class ArrangementDialog extends JPanel {
|
public class ArrangementDialog extends JPanel {
|
||||||
|
|
||||||
private LinkedList<LinkedList<Point>> lines;
|
private LinkedList<Line> lines;
|
||||||
private LinkedList<Point> points;
|
private LinkedList<Point> points;
|
||||||
private double max;
|
private double max;
|
||||||
private double min;
|
private double min;
|
||||||
|
@ -52,7 +53,7 @@ public class ArrangementDialog extends JPanel {
|
||||||
this.hslider = new JSlider(SwingConstants.HORIZONTAL, 10, 1000, 500);
|
this.hslider = new JSlider(SwingConstants.HORIZONTAL, 10, 1000, 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPrameters(LinkedList<LinkedList<Point>> lines, LinkedList<Point> points) {
|
public void setPrameters(LinkedList<Line> lines, LinkedList<Point> points) {
|
||||||
this.lines = lines;
|
this.lines = lines;
|
||||||
this.points = points;
|
this.points = points;
|
||||||
this.domainMin = Double.MAX_VALUE;
|
this.domainMin = Double.MAX_VALUE;
|
||||||
|
@ -64,10 +65,10 @@ public class ArrangementDialog extends JPanel {
|
||||||
public void createArrangement() {
|
public void createArrangement() {
|
||||||
XYSeriesCollection dataset = new XYSeriesCollection();
|
XYSeriesCollection dataset = new XYSeriesCollection();
|
||||||
|
|
||||||
for (LinkedList<Point> p : lines) {
|
for (Line p : lines) {
|
||||||
XYSeries series = new XYSeries(p.get(0).getX() + p.get(0).getY());
|
XYSeries series = new XYSeries(p.getId());
|
||||||
series.add(p.get(0).getX(), p.get(0).getY());
|
series.add(p.getX1(), p.getY1());
|
||||||
series.add(p.get(1).getX(), p.get(1).getY());
|
series.add(p.getX2(), p.getY2());
|
||||||
dataset.addSeries(series);
|
dataset.addSeries(series);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,18 +7,26 @@ import View.Panels.MenuPanel;
|
||||||
import View.Panels.OutputPanel;
|
import View.Panels.OutputPanel;
|
||||||
import View.Panels.RMPanel;
|
import View.Panels.RMPanel;
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.Container;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.FlowLayout;
|
import java.awt.FlowLayout;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import javax.swing.BorderFactory;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JDialog;
|
import javax.swing.JDialog;
|
||||||
|
import javax.swing.JFileChooser;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JProgressBar;
|
||||||
import javax.swing.JScrollPane;
|
import javax.swing.JScrollPane;
|
||||||
import javax.swing.JSplitPane;
|
import javax.swing.JSplitPane;
|
||||||
import javax.swing.JTabbedPane;
|
import javax.swing.JTabbedPane;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
|
import javax.swing.border.Border;
|
||||||
|
import javax.swing.filechooser.FileFilter;
|
||||||
|
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
|
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
|
||||||
|
@ -34,10 +42,8 @@ public class MainFrame extends JFrame {
|
||||||
private Boolean rmIsComplete = false;
|
private Boolean rmIsComplete = false;
|
||||||
private Boolean tsIsComplete = false;
|
private Boolean tsIsComplete = false;
|
||||||
|
|
||||||
|
|
||||||
//TODO refactoring
|
|
||||||
private JButton arrangementButton;
|
private JButton arrangementButton;
|
||||||
private JButton button3;
|
private JButton importButton;
|
||||||
|
|
||||||
private OutputPanel output;
|
private OutputPanel output;
|
||||||
private MenuPanel menupanel;
|
private MenuPanel menupanel;
|
||||||
|
@ -50,12 +56,14 @@ public class MainFrame extends JFrame {
|
||||||
private PlotDialog plotLMS;
|
private PlotDialog plotLMS;
|
||||||
private PlotDialog plotRM;
|
private PlotDialog plotRM;
|
||||||
private PlotDialog plotTS;
|
private PlotDialog plotTS;
|
||||||
|
private JDialog progressDialog;
|
||||||
|
private Container progressContent;
|
||||||
|
private JProgressBar progressBar;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private JSplitPane splitpane;
|
private JSplitPane splitpane;
|
||||||
private JScrollPane scrollPane;
|
private JScrollPane scrollPane;
|
||||||
|
|
||||||
private JTabbedPane tabbedPane;
|
private JTabbedPane tabbedPane;
|
||||||
|
|
||||||
public MainFrame() {
|
public MainFrame() {
|
||||||
|
@ -69,6 +77,7 @@ public class MainFrame extends JFrame {
|
||||||
setCloseOperations();
|
setCloseOperations();
|
||||||
setActionListeners();
|
setActionListeners();
|
||||||
|
|
||||||
|
disableFunctionality();
|
||||||
this.setVisible(true);
|
this.setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,13 +122,19 @@ public class MainFrame extends JFrame {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void showImportProgress(Integer progress){
|
||||||
|
progressBar.setValue(progress);
|
||||||
|
progressBar.setStringPainted(true);
|
||||||
|
progressDialog.setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
/*******************************************************************************************************************
|
/*******************************************************************************************************************
|
||||||
* init GUI
|
* init GUI
|
||||||
******************************************************************************************************************/
|
******************************************************************************************************************/
|
||||||
private void setTitles() {
|
private void setTitles() {
|
||||||
this.setTitle("MainFrame");
|
this.setTitle("MainFrame");
|
||||||
arrangementDialog.setTitle("Dual Representation - Dialog");
|
arrangementDialog.setTitle("Dual Representation - Dialog");
|
||||||
button3.setText("Import");
|
importButton.setText("Import");
|
||||||
arrangementButton.setText("Dualraum");
|
arrangementButton.setText("Dualraum");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,11 +146,14 @@ public class MainFrame extends JFrame {
|
||||||
|
|
||||||
private void addComponents() {
|
private void addComponents() {
|
||||||
pane.add(arrangementButton);
|
pane.add(arrangementButton);
|
||||||
pane.add(button3);
|
pane.add(importButton);
|
||||||
|
|
||||||
setupSplitPane();
|
setupSplitPane();
|
||||||
setupTabbedPane();
|
setupTabbedPane();
|
||||||
|
|
||||||
|
progressContent.add(progressBar, BorderLayout.NORTH);
|
||||||
|
progressBar.setBorder(BorderFactory.createTitledBorder("Import..."));
|
||||||
|
|
||||||
this.add(pane, BorderLayout.SOUTH);
|
this.add(pane, BorderLayout.SOUTH);
|
||||||
this.add(splitpane, BorderLayout.CENTER);
|
this.add(splitpane, BorderLayout.CENTER);
|
||||||
this.add(menupanel, BorderLayout.NORTH);
|
this.add(menupanel, BorderLayout.NORTH);
|
||||||
|
@ -152,6 +170,7 @@ public class MainFrame extends JFrame {
|
||||||
private void setCloseOperations() {
|
private void setCloseOperations() {
|
||||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
arrangementDialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
|
arrangementDialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
|
||||||
|
progressDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setDimensions() {
|
private void setDimensions() {
|
||||||
|
@ -161,9 +180,9 @@ public class MainFrame extends JFrame {
|
||||||
rmPanel.setMinimumSize(new Dimension(400, 500));
|
rmPanel.setMinimumSize(new Dimension(400, 500));
|
||||||
arrangementDialog.setSize(new Dimension(800, 800));
|
arrangementDialog.setSize(new Dimension(800, 800));
|
||||||
output.setMinimumSize(new Dimension(400, 500));
|
output.setMinimumSize(new Dimension(400, 500));
|
||||||
|
progressDialog.setSize(300, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void setLayouts() {
|
private void setLayouts() {
|
||||||
this.setLayout(new BorderLayout());
|
this.setLayout(new BorderLayout());
|
||||||
pane.setLayout(new FlowLayout());
|
pane.setLayout(new FlowLayout());
|
||||||
|
@ -178,6 +197,10 @@ public class MainFrame extends JFrame {
|
||||||
|
|
||||||
//Dialogs
|
//Dialogs
|
||||||
arrangementDialog = new JDialog();
|
arrangementDialog = new JDialog();
|
||||||
|
progressDialog = new JDialog();
|
||||||
|
progressDialog.setLocationRelativeTo(null);
|
||||||
|
progressContent = progressDialog.getContentPane();
|
||||||
|
progressBar = new JProgressBar();
|
||||||
|
|
||||||
//Panes
|
//Panes
|
||||||
tabbedPane = new JTabbedPane();
|
tabbedPane = new JTabbedPane();
|
||||||
|
@ -186,12 +209,12 @@ public class MainFrame extends JFrame {
|
||||||
|
|
||||||
//Buttons
|
//Buttons
|
||||||
arrangementButton = new JButton();
|
arrangementButton = new JButton();
|
||||||
button3 = new JButton();
|
importButton = new JButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setActionListeners() {
|
private void setActionListeners() {
|
||||||
arrangementButton.addActionListener((ActionEvent e) -> {
|
arrangementButton.addActionListener((ActionEvent e) -> {
|
||||||
Thread t = new Thread(() -> getPresenter().startArrangementVisualization());
|
Thread t = new Thread(() -> getPresenter().visualizeDualLines());
|
||||||
t.start();
|
t.start();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -206,8 +229,42 @@ public class MainFrame extends JFrame {
|
||||||
() -> this.getPresenter().calculateRM(rmPanel.getInput()));
|
() -> this.getPresenter().calculateRM(rmPanel.getInput()));
|
||||||
t.start();
|
t.start();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
importButton.addActionListener((ActionEvent e) -> {
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
File file = null;
|
||||||
|
JFileChooser chooser = new JFileChooser();
|
||||||
|
chooser.setPreferredSize(new Dimension(800,700));
|
||||||
|
chooser.setFileFilter(new FileNameExtensionFilter("Comma-Separated Value", "csv", "text"));
|
||||||
|
|
||||||
|
chooser.setMultiSelectionEnabled(false);
|
||||||
|
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
|
||||||
|
|
||||||
|
|
||||||
|
if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION){
|
||||||
|
System.out.println ("Datei "+chooser.getSelectedFile()+
|
||||||
|
" ausgewählt.");
|
||||||
|
file = chooser.getSelectedFile();
|
||||||
|
final File input = file;
|
||||||
|
Thread t = new Thread(() -> this.getPresenter().startImport(input));
|
||||||
|
t.start();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void enableFunctionality(){
|
||||||
|
this.getLmsPanel().getStartButton().setEnabled(true);
|
||||||
|
this.getRmPanel().getStartButton().setEnabled(true);
|
||||||
|
this.getArrangementButton().setEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void disableFunctionality(){
|
||||||
|
this.getLmsPanel().getStartButton().setEnabled(false);
|
||||||
|
this.getRmPanel().getStartButton().setEnabled(false);
|
||||||
|
this.getArrangementButton().setEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
/*******************************************************************************************************************
|
/*******************************************************************************************************************
|
||||||
* log Methode
|
* log Methode
|
||||||
|
@ -268,12 +325,12 @@ public class MainFrame extends JFrame {
|
||||||
this.arrangementButton = arrangementButton;
|
this.arrangementButton = arrangementButton;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JButton getButton3() {
|
public JButton getImportButton() {
|
||||||
return button3;
|
return importButton;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setButton3(JButton button3) {
|
public void setImportButton(JButton importButton) {
|
||||||
this.button3 = button3;
|
this.importButton = importButton;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JPanel getPane() {
|
public JPanel getPane() {
|
||||||
|
@ -300,11 +357,11 @@ public class MainFrame extends JFrame {
|
||||||
this.output = output;
|
this.output = output;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JPanel getMenupanel() {
|
public MenuPanel getMenupanel() {
|
||||||
return menupanel;
|
return menupanel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JPanel getLmsPanel() {
|
public LMSPanel getLmsPanel() {
|
||||||
return lmsPanel;
|
return lmsPanel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -324,6 +381,13 @@ public class MainFrame extends JFrame {
|
||||||
this.scrollPane = scrollPane;
|
this.scrollPane = scrollPane;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RMPanel getRmPanel() {
|
||||||
|
return rmPanel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRmPanel(RMPanel rmPanel) {
|
||||||
|
this.rmPanel = rmPanel;
|
||||||
|
}
|
||||||
|
|
||||||
public PlotDialog getPlotLMS() {
|
public PlotDialog getPlotLMS() {
|
||||||
return plotLMS;
|
return plotLMS;
|
||||||
|
@ -340,4 +404,12 @@ public class MainFrame extends JFrame {
|
||||||
public void setPresenter(Presenter presenter) {
|
public void setPresenter(Presenter presenter) {
|
||||||
this.presenter = presenter;
|
this.presenter = presenter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public JDialog getProgressDialog() {
|
||||||
|
return progressDialog;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProgressDialog(JDialog progressDialog) {
|
||||||
|
this.progressDialog = progressDialog;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,14 +14,16 @@ import org.junit.Test;
|
||||||
*/
|
*/
|
||||||
public class DataImporterTest {
|
public class DataImporterTest {
|
||||||
|
|
||||||
|
private DataImporter importer;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
DataImporter importer = new DataImporter("", null);
|
//importer = new DataImporter("C:\\Users\\Armin\\Desktop\\test.csv", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void run() throws Exception {
|
public void run() throws Exception {
|
||||||
|
//importer.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue