WIP: Rücktransformation der Inversionspaare in Punkte der Eingabe

This commit is contained in:
Armin Wolf 2017-06-19 13:55:31 +02:00
parent 202673272c
commit 04bcaa0f24
8 changed files with 136 additions and 120 deletions

View File

@ -0,0 +1,33 @@
package Model;
/**
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
*
* @Author: Armin Wolf
* @Email: a_wolf28@uni-muenster.de
* @Date: 19.06.2017.
*/
public class Pair {
private Integer p1;
private Integer p2;
public Pair(Integer p1, Integer p2) {
this.p1 = p1;
this.p2 = p2;
}
public Integer getP1() {
return p1;
}
public void setP1(Integer p1) {
this.p1 = p1;
}
public Integer getP2() {
return p2;
}
public void setP2(Integer p2) {
this.p2 = p2;
}
}

View File

@ -1,6 +1,12 @@
package Presenter.Algorithms; package Presenter.Algorithms;
import Model.Line;
import Model.Pair;
import Model.Point;
import Model.Slab;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -18,30 +24,11 @@ public class InversionCounter {
private ArrayList<Integer> substituted; private ArrayList<Integer> substituted;
private ArrayList<Pair> inversions; private ArrayList<Pair> inversions;
private class Pair{ //indexieren der Punkte damit die schnittpunkte berechnet werden können
private Integer p1; private HashMap<Integer, Integer> secondaryIndex;
private Integer p2; private ArrayList<Point> umin;
public Pair(Integer p1, Integer p2) { private ArrayList<Point> umax;
this.p1 = p1;
this.p2 = p2;
}
public Integer getP1() {
return p1;
}
public void setP1(Integer p1) {
this.p1 = p1;
}
public Integer getP2() {
return p2;
}
public void setP2(Integer p2) {
this.p2 = p2;
}
}
public int run(List<Integer> a, List<Integer> b){ public int run(List<Integer> a, List<Integer> b){
@ -65,8 +52,6 @@ public class InversionCounter {
int ret = countInversions(substituted, 0, substituted.size()-1, temp); int ret = countInversions(substituted, 0, substituted.size()-1, temp);
getInversionPairs();
dictionaryTO = null; dictionaryTO = null;
substituted = null; substituted = null;
inversions = null; inversions = null;
@ -75,6 +60,47 @@ public class InversionCounter {
return ret; return ret;
} }
public int run(List<Line> set, Slab slab){
ArrayList<Integer> listA = new ArrayList<>();
ArrayList<Integer> listB = new ArrayList<>();
prepareData(set, slab, listA, listB);
return run(listA, listB);
}
private void prepareData(List<Line> set, Slab slab, ArrayList<Integer> listA, ArrayList<Integer> listB){
secondaryIndex = new HashMap<>();
umin = new ArrayList<>();
umax = new ArrayList<>();
int counter = 0;
for (Line p : set) {
//vertauscht das Point standardmäßig die x lexikografische Ordnung betrachtet
umin.add(new Point(slab.getLower() * p.getM() + p.getB(),p.getM(), counter+""));
umax.add(new Point(slab.getUpper() * p.getM() + p.getB(),p.getM() ,counter+""));
counter++;
}
for (int i=0; i<umin.size();i++){
int id = Integer.parseInt(umin.get(i).getId());
secondaryIndex.put(id, i);
}
Collections.sort(umin);
Collections.sort(umax);
for (Point p : umax){
int x = Integer.parseInt(p.getId());
listB.add(secondaryIndex.get(x));
}
for (Point q : umin){
int x = Integer.parseInt(q.getId());
listA.add(secondaryIndex.get(x));
}
}
/** /**
* Angepasster Merge-Sort Algorithmus. * Angepasster Merge-Sort Algorithmus.
@ -122,17 +148,18 @@ public class InversionCounter {
} }
public void getInversionPairs(){ public ArrayList<Pair> getInversionPairs(){
ArrayList<Pair> result = new ArrayList<>(); ArrayList<Pair> result = new ArrayList<>();
for (int i=0;i<inversions.size();i++){ for (int i=0;i<inversions.size();i++){
result.add(new Pair(dictionaryBACK.get(inversions.get(i).getP1()), dictionaryBACK.get(inversions.get(i).getP2()))); result.add(new Pair(dictionaryBACK.get(inversions.get(i).getP1()), dictionaryBACK.get(inversions.get(i).getP2())));
} }
//for (Pair p : result){ //for (Pair p : result){
// System.out.println(p.getP1() + " <==> " + p.getP2()); // System.out.println(p.getP1() + " <==> " + p.getP2());
//} //}
return result;
} }
} }

View File

@ -33,7 +33,7 @@ public class LeastMedianOfSquaresEstimator extends Observable implements Algorit
private Line sigmaMin; private Line sigmaMin;
private double heightsigmaMin; private double heightsigmaMin;
private Double intersectionsPoint; private Double intersectionsPoint;
private Double constant = 1d; private Double constant;
public LeastMedianOfSquaresEstimator(LinkedList<Line> set, LinkedList<Point> intersections, Presenter presenter) { public LeastMedianOfSquaresEstimator(LinkedList<Line> set, LinkedList<Point> intersections, Presenter presenter) {
this.set = set; this.set = set;
@ -54,10 +54,6 @@ public class LeastMedianOfSquaresEstimator extends Observable implements Algorit
this(set, intersections, null); this(set, intersections, null);
} }
public void printResult(){
System.out.println("RESULT: X1: "+sigmaMin.getX1() + ", X2: "+sigmaMin.getX2()+"\t Y1: "+sigmaMin.getY1()+", Y2: "+sigmaMin.getY2());
}
/** /**
* *
*/ */
@ -146,50 +142,11 @@ public class LeastMedianOfSquaresEstimator extends Observable implements Algorit
public int countInversions(Slab slab) { public int countInversions(Slab slab) {
int numberOfInversions = 0; int numberOfInversions = 0;
ArrayList<Double> randomIntersection = new ArrayList<>();
ArrayList<Point> umin = new ArrayList<>();
ArrayList<Point> umax = new ArrayList<>();
HashMap<Integer, Integer> secondaryIndex = new HashMap<>();
ArrayList<Integer> listA = new ArrayList<>();
ArrayList<Integer> listB = new ArrayList<>();
int counter = 0;
for (Line p : set) {
//vertauscht das Point standardmäßig die x lexikografische Ordnung betrachtet
umin.add(new Point(slab.getLower() * p.getM() + p.getB(),p.getM(), counter+""));
umax.add(new Point(slab.getUpper() * p.getM() + p.getB(),p.getM() ,counter+""));
counter++;
}
for (int i=0; i<umin.size();i++){
int id = Integer.parseInt(umin.get(i).getId());
secondaryIndex.put(id, i);
}
Collections.sort(umin);
Collections.sort(umax);
for (Point p : umax){
int x = Integer.parseInt(p.getId());
listB.add(secondaryIndex.get(x));
}
for (Point q : umin){
int x = Integer.parseInt(q.getId());
listA.add(secondaryIndex.get(x));
}
// debug // debug
//for (int i=0;i<listA.size();i++){ //for (int i=0;i<listA.size();i++){
// System.out.println(listA.get(i)+", "+listB.get(i)); // System.out.println(listA.get(i)+", "+listB.get(i));
//} //}
numberOfInversions = invCounter.run(set,slab);
numberOfInversions = invCounter.run(listA, listB);
return numberOfInversions; return numberOfInversions;
} }

View File

@ -1,6 +1,7 @@
package Presenter.Algorithms; package Presenter.Algorithms;
import Model.Line; import Model.Line;
import Model.Pair;
import Model.Slab; import Model.Slab;
import java.util.ArrayList; import java.util.ArrayList;
@ -19,6 +20,7 @@ public class RepeatedMedianEstimator implements Algorithm {
private LinkedList<Line> set; private LinkedList<Line> set;
private Slab interval; private Slab interval;
private InversionCounter invCounter = new InversionCounter();
//in der Literatur als L_i, C_i, und R_i bekannt //in der Literatur als L_i, C_i, und R_i bekannt
private Integer countLeftSlab; private Integer countLeftSlab;
@ -134,16 +136,7 @@ public class RepeatedMedianEstimator implements Algorithm {
} }
public void estimateMedianIntersectionAbscissas(ArrayList<Line> sampledLines){ public void estimateMedianIntersectionAbscissas(ArrayList<Line> sampledLines){
ArrayList<Double> low = new ArrayList<>(); int inversions = invCounter.run(sampledLines, interval);
ArrayList<Double> high = new ArrayList<>();
for (Line line : sampledLines){
low.add(interval.getLower() * line.getM() + line.getB());
high.add(interval.getUpper() * line.getM() + line.getB());
}
//int inversions = InversionCounter.countInversions(low, 0, low.size()-1, high);
} }
} }

View File

@ -73,7 +73,7 @@ public class Presenter implements Observer {
getView().createPlot(result.getM(), result.getB()); getView().createPlot(result.getM(), result.getB());
getView().setLmsIsComplete(true); getView().setLmsIsComplete(true);
getView().logSuccess("Berechnung wurde Erfolgreich durchgeführt"); getView().logSuccess("Berechnung wurde Erfolgreich durchgeführt");
getView().log("m: "+result.getM()+" b: "+result.getB()); getView().log("m: "+result.getM()+"\t b: "+result.getB());
}); });
} }
@ -84,7 +84,7 @@ public class Presenter implements Observer {
} }
public void startScatterPlotVisualization(String[] input) { public void startScatterPlotVisualization(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]);
lms = new LeastMedianOfSquaresEstimator(model.getLines(), model.getNodes(), this); lms = new LeastMedianOfSquaresEstimator(model.getLines(), model.getNodes(), this);
lms.setConstant(constant); lms.setConstant(constant);

View File

@ -43,7 +43,6 @@ public class MainFrame extends JFrame{
private ArrangementDialog arrangement; private ArrangementDialog arrangement;
private JDialog arrangementDialog; private JDialog arrangementDialog;
private JDialog plotDialog;
private PlotDialog plot; private PlotDialog plot;
@ -91,8 +90,7 @@ public class MainFrame extends JFrame{
SwingUtilities.invokeLater(() -> { SwingUtilities.invokeLater(() -> {
plot.createPlot(getPresenter().getLines()); plot.createPlot(getPresenter().getLines());
plot.addLineToPlot(m, b); plot.addLineToPlot(m, b);
plotDialog.add(plot); sidepanel.setPlotDialog(plot);
plotDialog.setVisible(true);
}); });
} }
@ -104,7 +102,6 @@ public class MainFrame extends JFrame{
private void setTitles(){ private void setTitles(){
this.setTitle("MainFrame"); this.setTitle("MainFrame");
arrangementDialog.setTitle("Dual Representation - Dialog"); arrangementDialog.setTitle("Dual Representation - Dialog");
plotDialog.setTitle("Scatter Plot - Dialog");
button3.setText("Import"); button3.setText("Import");
arrangementButton.setText("Dualraum"); arrangementButton.setText("Dualraum");
} }
@ -138,15 +135,12 @@ 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);
plotDialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
} }
private void setDimensions(){ private void setDimensions(){
this.setSize(1900, 1000); this.setSize(1900, 1000);
sidepanel.setMinimumSize(new Dimension(400,500)); sidepanel.setMinimumSize(new Dimension(400,500));
arrangementDialog.setSize(new Dimension(800, 800)); arrangementDialog.setSize(new Dimension(800, 800));
plotDialog.setSize(new Dimension(700, 470));
plotDialog.setResizable(false);
output.setMinimumSize(new Dimension(400,500)); output.setMinimumSize(new Dimension(400,500));
} }
@ -163,7 +157,6 @@ public class MainFrame extends JFrame{
//Dialogs //Dialogs
arrangementDialog = new JDialog(); arrangementDialog = new JDialog();
plotDialog = new JDialog();
//Panes //Panes
tabbedPane = new JTabbedPane(); tabbedPane = new JTabbedPane();
@ -175,7 +168,6 @@ public class MainFrame extends JFrame{
button3 = new JButton(); button3 = 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().startArrangementVisualization());
@ -192,7 +184,6 @@ public class MainFrame extends JFrame{
/******************************************************************************************************************* /*******************************************************************************************************************
* log Methode * log Methode
******************************************************************************************************************/ ******************************************************************************************************************/
public void log(String s) { public void log(String s) {
SwingUtilities.invokeLater(() -> output.appendParagraph(s)); SwingUtilities.invokeLater(() -> output.appendParagraph(s));
} }
@ -272,14 +263,6 @@ public class MainFrame extends JFrame{
this.arrangementDialog = arrangementDialog; this.arrangementDialog = arrangementDialog;
} }
public JDialog getPlotDialog() {
return plotDialog;
}
public void setPlotDialog(JDialog plotDialog) {
this.plotDialog = plotDialog;
}
public OutputPanel getOutput() { public OutputPanel getOutput() {
return output; return output;
} }

View File

@ -94,7 +94,6 @@ public class PlotDialog extends JPanel {
public void addLineToPlot(double m, double b) { public void addLineToPlot(double m, double b) {
linesA = new XYSeries("linesA"); linesA = new XYSeries("linesA");
JOptionPane.showMessageDialog(null, "m: "+m+" b: "+b);
linesA.add(min.intValue(), min.intValue() * m + b ); linesA.add(min.intValue(), min.intValue() * m + b );
linesA.add(max.intValue(), max.intValue() * m + b ); linesA.add(max.intValue(), max.intValue() * m + b );

View File

@ -18,34 +18,46 @@ public class SidePanel extends JPanel {
private JTextField[] input; private JTextField[] input;
private JButton startButton; private JButton startButton;
private JPanel continer; private JPanel continer;
private JPanel northPanel;
private JPanel centerPanel;
private PlotDialog plotDialog;
private GridBagConstraints gbc; private GridBagConstraints gbc;
public SidePanel(){ public SidePanel() {
this.setBorder(new TitledBorder("Eingabefelder"));
this.labels = new JLabel[10]; this.labels = new JLabel[10];
this.input = new JTextField[10]; this.input = new JTextField[10];
this.setLayout(new BorderLayout()); this.setLayout(new BorderLayout());
this.northPanel = new JPanel(new BorderLayout());
this.centerPanel = new JPanel(new BorderLayout());
this.northPanel.setBorder(new TitledBorder("Konfiguration"));
this.centerPanel.setBorder(new TitledBorder("Visualisierung"));
this.continer = new JPanel(); this.continer = new JPanel();
continer.setLayout(new GridBagLayout());; this.continer.setLayout(new GridBagLayout());
gbc = new GridBagConstraints();
gbc.anchor = GridBagConstraints.NORTH;
gbc.fill = GridBagConstraints.HORIZONTAL;
addTextfieldAndInput(0, "Konstante", 1.0); this.gbc = new GridBagConstraints();
addTextfieldAndInput(1, "Fehler", 0.005); this.gbc.anchor = GridBagConstraints.NORTH;
this.gbc.fill = GridBagConstraints.HORIZONTAL;
startButton = new JButton("start"); addTextfieldAndInput(0, "Konstante", 0.5);
addTextfieldAndInput(1, "Fehler", 0.05);
this.startButton = new JButton("start");
addButton(2, startButton); addButton(2, startButton);
this.add(continer, BorderLayout.NORTH);
this.northPanel.add(continer, BorderLayout.CENTER);
this.add(northPanel, BorderLayout.NORTH);
this.add(centerPanel, BorderLayout.CENTER);
} }
private void addTextfieldAndInput(int row, String name, Double value){ private void addTextfieldAndInput(int row, String name, Double value) {
this.labels[row] = new JLabel(name); this.labels[row] = new JLabel(name);
this.input[row] = new JTextField(); this.input[row] = new JTextField();
this.input[row].setText(""+value); this.input[row].setText("" + value);
gbc.insets = new Insets(0, 5,0,0); gbc.insets = new Insets(0, 5, 0, 0);
gbc.gridx = 0; gbc.gridx = 0;
gbc.gridy = row; gbc.gridy = row;
gbc.weightx = 0.05; gbc.weightx = 0.05;
@ -56,13 +68,13 @@ public class SidePanel extends JPanel {
gbc.gridy = row; gbc.gridy = row;
gbc.weightx = 0.9; gbc.weightx = 0.9;
gbc.weighty = 0.05; gbc.weighty = 0.05;
gbc.insets = new Insets(0, 0,0,5); gbc.insets = new Insets(0, 0, 0, 5);
continer.add(this.input[row], gbc); continer.add(this.input[row], gbc);
} }
private void addButton(int row, JButton button){ private void addButton(int row, JButton button) {
gbc.insets = new Insets(30, 5,0,0); gbc.insets = new Insets(30, 5, 10, 0);
gbc.gridx = 0; gbc.gridx = 0;
gbc.gridy = row; gbc.gridy = row;
gbc.weightx = 0.05; gbc.weightx = 0.05;
@ -85,4 +97,16 @@ public class SidePanel extends JPanel {
public void setInput(JTextField[] input) { public void setInput(JTextField[] input) {
this.input = input; this.input = input;
} }
public PlotDialog getPlotDialog() {
return plotDialog;
}
public void setPlotDialog(PlotDialog plotDialog) {
this.plotDialog = plotDialog;
this.centerPanel.add(plotDialog, BorderLayout.CENTER);
this.plotDialog.setVisible(true);
this.repaint();
this.revalidate();
}
} }