Als fast select Algorithmus wurde der RandomizedSelect Algorithmus aus Cormen et al. implementiert.
This commit is contained in:
parent
24126e8676
commit
da8e5d800c
|
@ -4,7 +4,9 @@ import Model.Line;
|
||||||
import Model.Slab;
|
import Model.Slab;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
|
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
|
||||||
|
@ -35,6 +37,9 @@ public class RepeatedMedianEstimator implements Algorithm {
|
||||||
private Double kHigh;
|
private Double kHigh;
|
||||||
private Double beta;
|
private Double beta;
|
||||||
|
|
||||||
|
private Line thetaLow;
|
||||||
|
private Line thetaHigh;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public RepeatedMedianEstimator(LinkedList<Line> set) {
|
public RepeatedMedianEstimator(LinkedList<Line> set) {
|
||||||
|
@ -58,24 +63,74 @@ public class RepeatedMedianEstimator implements Algorithm {
|
||||||
ArrayList<Line> lines = sampleLines(linesInCenterSlab, r);
|
ArrayList<Line> lines = sampleLines(linesInCenterSlab, r);
|
||||||
|
|
||||||
//TODO: hier kommt der neue Ansatz vom zweiten Algorithmus hin
|
//TODO: hier kommt der neue Ansatz vom zweiten Algorithmus hin
|
||||||
|
estimateMedianIntersectionAbscissas(lines);
|
||||||
|
|
||||||
k = (Math.floor(n * 0.5) - linesInLeftSlab.size());
|
k = (Math.floor(n * 0.5) - linesInLeftSlab.size());
|
||||||
computeSlabBorders();
|
computeSlabBorders();
|
||||||
fastSelectionAlg();
|
thetaLow = randomizedSelect(linesInCenterSlab,0,linesInCenterSlab.size()-1,kLow);
|
||||||
|
thetaHigh = randomizedSelect(linesInCenterSlab,0,linesInCenterSlab.size()-1,kHigh);
|
||||||
countNumberOfIntersectionsAbscissas();
|
countNumberOfIntersectionsAbscissas();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public ArrayList<Line> sampleLines(ArrayList<Line> set, Double r){return null;}
|
|
||||||
|
|
||||||
public void computeSlabBorders(){
|
public void computeSlabBorders(){
|
||||||
kLow = Math.max(1, Math.ceil(((r * k)/(linesInCenterSlab.size()))-((3 * Math.sqrt(r))/(2))));
|
kLow = Math.max(1, Math.ceil(((r * k)/(linesInCenterSlab.size()))-((3 * Math.sqrt(r))/(2))));
|
||||||
kHigh = Math.max(1, Math.ceil(((r * k)/(linesInCenterSlab.size()))+((3 * Math.sqrt(r))/(2))));
|
kHigh = Math.min(1, Math.ceil(((r * k)/(linesInCenterSlab.size()))+((3 * Math.sqrt(r))/(2))));
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Line> sampleLines(ArrayList<Line> set, Double r){
|
||||||
|
|
||||||
|
ArrayList<Line> sampledLines = new ArrayList<>();
|
||||||
|
|
||||||
|
Random random = new Random(n);
|
||||||
|
for (int i=0; i<n; i++){
|
||||||
|
sampledLines.add(set.get(random.nextInt()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return sampledLines;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Line randomizedSelect(ArrayList<Line> a, int start, int end, double i){
|
||||||
|
if (start == end)
|
||||||
|
return a.get(start);
|
||||||
|
int q = randomizedPartition(a, start, end);
|
||||||
|
int tmpPivot = q - start + 1;
|
||||||
|
|
||||||
|
if ( i == tmpPivot ){
|
||||||
|
return a.get(q);
|
||||||
|
} else if ( i < tmpPivot ) {
|
||||||
|
return randomizedSelect(a, start, q-1, i);
|
||||||
|
} else {
|
||||||
|
return randomizedSelect(a, q+1, end, i-tmpPivot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int randomizedPartition(ArrayList<Line> a, int start, int end){
|
||||||
|
int delta = Math.abs(end - start);
|
||||||
|
Random random = new Random(delta);
|
||||||
|
int i = start + random.nextInt();
|
||||||
|
Collections.swap(a, end, i);
|
||||||
|
return partition(a, start, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int partition(ArrayList<Line> a, int start, int end){
|
||||||
|
Line x = a.get(end);
|
||||||
|
int i = start - 1;
|
||||||
|
for (int j=start; j<end; j++){
|
||||||
|
if (a.get(j).getM() <= x.getM()){
|
||||||
|
i++;
|
||||||
|
Collections.swap(a, i, j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Collections.swap(a, i+1, end);
|
||||||
|
return i+1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fastSelectionAlg(){}
|
|
||||||
public void countNumberOfIntersectionsAbscissas(){}
|
public void countNumberOfIntersectionsAbscissas(){}
|
||||||
|
public void estimateMedianIntersectionAbscissas(ArrayList<Line> sampledLines){}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue