WIP: Rücktransformation der Inversionspaare in Punkte der Eingabe
This commit is contained in:
parent
202673272c
commit
04bcaa0f24
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,12 @@
|
|||
package Presenter.Algorithms;
|
||||
|
||||
import Model.Line;
|
||||
import Model.Pair;
|
||||
import Model.Point;
|
||||
import Model.Slab;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -18,30 +24,11 @@ public class InversionCounter {
|
|||
private ArrayList<Integer> substituted;
|
||||
private ArrayList<Pair> inversions;
|
||||
|
||||
private class Pair{
|
||||
private Integer p1;
|
||||
private Integer p2;
|
||||
public Pair(Integer p1, Integer p2) {
|
||||
this.p1 = p1;
|
||||
this.p2 = p2;
|
||||
}
|
||||
//indexieren der Punkte damit die schnittpunkte berechnet werden können
|
||||
private HashMap<Integer, Integer> secondaryIndex;
|
||||
private ArrayList<Point> umin;
|
||||
private ArrayList<Point> umax;
|
||||
|
||||
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){
|
||||
|
||||
|
@ -65,8 +52,6 @@ public class InversionCounter {
|
|||
|
||||
int ret = countInversions(substituted, 0, substituted.size()-1, temp);
|
||||
|
||||
|
||||
getInversionPairs();
|
||||
dictionaryTO = null;
|
||||
substituted = null;
|
||||
inversions = null;
|
||||
|
@ -75,6 +60,47 @@ public class InversionCounter {
|
|||
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.
|
||||
|
@ -122,17 +148,18 @@ public class InversionCounter {
|
|||
}
|
||||
|
||||
|
||||
public void getInversionPairs(){
|
||||
public ArrayList<Pair> getInversionPairs(){
|
||||
ArrayList<Pair> result = new ArrayList<>();
|
||||
|
||||
for (int i=0;i<inversions.size();i++){
|
||||
result.add(new Pair(dictionaryBACK.get(inversions.get(i).getP1()), dictionaryBACK.get(inversions.get(i).getP2())));
|
||||
}
|
||||
|
||||
//for (Pair p : result){
|
||||
// System.out.println(p.getP1() + " <==> " + p.getP2());
|
||||
//}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ public class LeastMedianOfSquaresEstimator extends Observable implements Algorit
|
|||
private Line sigmaMin;
|
||||
private double heightsigmaMin;
|
||||
private Double intersectionsPoint;
|
||||
private Double constant = 1d;
|
||||
private Double constant;
|
||||
|
||||
public LeastMedianOfSquaresEstimator(LinkedList<Line> set, LinkedList<Point> intersections, Presenter presenter) {
|
||||
this.set = set;
|
||||
|
@ -54,10 +54,6 @@ public class LeastMedianOfSquaresEstimator extends Observable implements Algorit
|
|||
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) {
|
||||
|
||||
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
|
||||
//for (int i=0;i<listA.size();i++){
|
||||
// System.out.println(listA.get(i)+", "+listB.get(i));
|
||||
//}
|
||||
|
||||
numberOfInversions = invCounter.run(listA, listB);
|
||||
numberOfInversions = invCounter.run(set,slab);
|
||||
|
||||
return numberOfInversions;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package Presenter.Algorithms;
|
||||
|
||||
import Model.Line;
|
||||
import Model.Pair;
|
||||
import Model.Slab;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -19,6 +20,7 @@ public class RepeatedMedianEstimator implements Algorithm {
|
|||
|
||||
private LinkedList<Line> set;
|
||||
private Slab interval;
|
||||
private InversionCounter invCounter = new InversionCounter();
|
||||
|
||||
//in der Literatur als L_i, C_i, und R_i bekannt
|
||||
private Integer countLeftSlab;
|
||||
|
@ -134,16 +136,7 @@ public class RepeatedMedianEstimator implements Algorithm {
|
|||
}
|
||||
|
||||
public void estimateMedianIntersectionAbscissas(ArrayList<Line> sampledLines){
|
||||
ArrayList<Double> low = new ArrayList<>();
|
||||
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);
|
||||
|
||||
int inversions = invCounter.run(sampledLines, interval);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ public class Presenter implements Observer {
|
|||
getView().createPlot(result.getM(), result.getB());
|
||||
getView().setLmsIsComplete(true);
|
||||
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) {
|
||||
Double constant =Double.parseDouble(input[0]);
|
||||
Double constant = Double.parseDouble(input[0]);
|
||||
Double error = Double.parseDouble(input[1]);
|
||||
lms = new LeastMedianOfSquaresEstimator(model.getLines(), model.getNodes(), this);
|
||||
lms.setConstant(constant);
|
||||
|
|
|
@ -43,7 +43,6 @@ public class MainFrame extends JFrame{
|
|||
|
||||
private ArrangementDialog arrangement;
|
||||
private JDialog arrangementDialog;
|
||||
private JDialog plotDialog;
|
||||
private PlotDialog plot;
|
||||
|
||||
|
||||
|
@ -91,8 +90,7 @@ public class MainFrame extends JFrame{
|
|||
SwingUtilities.invokeLater(() -> {
|
||||
plot.createPlot(getPresenter().getLines());
|
||||
plot.addLineToPlot(m, b);
|
||||
plotDialog.add(plot);
|
||||
plotDialog.setVisible(true);
|
||||
sidepanel.setPlotDialog(plot);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -104,7 +102,6 @@ public class MainFrame extends JFrame{
|
|||
private void setTitles(){
|
||||
this.setTitle("MainFrame");
|
||||
arrangementDialog.setTitle("Dual Representation - Dialog");
|
||||
plotDialog.setTitle("Scatter Plot - Dialog");
|
||||
button3.setText("Import");
|
||||
arrangementButton.setText("Dualraum");
|
||||
}
|
||||
|
@ -138,15 +135,12 @@ public class MainFrame extends JFrame{
|
|||
private void setCloseOperations(){
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
arrangementDialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
|
||||
plotDialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
|
||||
}
|
||||
|
||||
private void setDimensions(){
|
||||
this.setSize(1900, 1000);
|
||||
sidepanel.setMinimumSize(new Dimension(400,500));
|
||||
arrangementDialog.setSize(new Dimension(800, 800));
|
||||
plotDialog.setSize(new Dimension(700, 470));
|
||||
plotDialog.setResizable(false);
|
||||
output.setMinimumSize(new Dimension(400,500));
|
||||
}
|
||||
|
||||
|
@ -163,7 +157,6 @@ public class MainFrame extends JFrame{
|
|||
|
||||
//Dialogs
|
||||
arrangementDialog = new JDialog();
|
||||
plotDialog = new JDialog();
|
||||
|
||||
//Panes
|
||||
tabbedPane = new JTabbedPane();
|
||||
|
@ -175,7 +168,6 @@ public class MainFrame extends JFrame{
|
|||
button3 = new JButton();
|
||||
}
|
||||
|
||||
|
||||
private void setActionListeners(){
|
||||
arrangementButton.addActionListener((ActionEvent e) -> {
|
||||
Thread t = new Thread(() -> getPresenter().startArrangementVisualization());
|
||||
|
@ -192,7 +184,6 @@ public class MainFrame extends JFrame{
|
|||
/*******************************************************************************************************************
|
||||
* log Methode
|
||||
******************************************************************************************************************/
|
||||
|
||||
public void log(String s) {
|
||||
SwingUtilities.invokeLater(() -> output.appendParagraph(s));
|
||||
}
|
||||
|
@ -272,14 +263,6 @@ public class MainFrame extends JFrame{
|
|||
this.arrangementDialog = arrangementDialog;
|
||||
}
|
||||
|
||||
public JDialog getPlotDialog() {
|
||||
return plotDialog;
|
||||
}
|
||||
|
||||
public void setPlotDialog(JDialog plotDialog) {
|
||||
this.plotDialog = plotDialog;
|
||||
}
|
||||
|
||||
public OutputPanel getOutput() {
|
||||
return output;
|
||||
}
|
||||
|
|
|
@ -94,7 +94,6 @@ public class PlotDialog extends JPanel {
|
|||
|
||||
public void addLineToPlot(double m, double b) {
|
||||
linesA = new XYSeries("linesA");
|
||||
JOptionPane.showMessageDialog(null, "m: "+m+" b: "+b);
|
||||
linesA.add(min.intValue(), min.intValue() * m + b );
|
||||
linesA.add(max.intValue(), max.intValue() * m + b );
|
||||
|
||||
|
|
|
@ -18,34 +18,46 @@ public class SidePanel extends JPanel {
|
|||
private JTextField[] input;
|
||||
private JButton startButton;
|
||||
private JPanel continer;
|
||||
private JPanel northPanel;
|
||||
private JPanel centerPanel;
|
||||
private PlotDialog plotDialog;
|
||||
private GridBagConstraints gbc;
|
||||
|
||||
public SidePanel(){
|
||||
this.setBorder(new TitledBorder("Eingabefelder"));
|
||||
public SidePanel() {
|
||||
this.labels = new JLabel[10];
|
||||
this.input = new JTextField[10];
|
||||
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();
|
||||
continer.setLayout(new GridBagLayout());;
|
||||
gbc = new GridBagConstraints();
|
||||
gbc.anchor = GridBagConstraints.NORTH;
|
||||
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||
this.continer.setLayout(new GridBagLayout());
|
||||
|
||||
addTextfieldAndInput(0, "Konstante", 1.0);
|
||||
addTextfieldAndInput(1, "Fehler", 0.005);
|
||||
this.gbc = new GridBagConstraints();
|
||||
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);
|
||||
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.input[row] = new JTextField();
|
||||
this.input[row].setText(""+value);
|
||||
this.input[row] = new JTextField();
|
||||
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.gridy = row;
|
||||
gbc.weightx = 0.05;
|
||||
|
@ -56,13 +68,13 @@ public class SidePanel extends JPanel {
|
|||
gbc.gridy = row;
|
||||
gbc.weightx = 0.9;
|
||||
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);
|
||||
}
|
||||
|
||||
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.gridy = row;
|
||||
gbc.weightx = 0.05;
|
||||
|
@ -85,4 +97,16 @@ public class SidePanel extends JPanel {
|
|||
public void setInput(JTextField[] 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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue