summaryrefslogtreecommitdiffstats
path: root/lookup/BTSLut.java
diff options
context:
space:
mode:
authorRichard Zahoransky2011-11-07 16:29:56 +0100
committerRichard Zahoransky2011-11-07 16:29:56 +0100
commit08d5f7b0a0b24c042aa5976f66bf3a1b5b754478 (patch)
treeba5388774100c1b218cb264927c3bb3669fd7e06 /lookup/BTSLut.java
parentinit (diff)
downloadlocalization-08d5f7b0a0b24c042aa5976f66bf3a1b5b754478.tar.gz
localization-08d5f7b0a0b24c042aa5976f66bf3a1b5b754478.tar.xz
localization-08d5f7b0a0b24c042aa5976f66bf3a1b5b754478.zip
Localization Code. How-To will follow...
Diffstat (limited to 'lookup/BTSLut.java')
-rw-r--r--lookup/BTSLut.java200
1 files changed, 200 insertions, 0 deletions
diff --git a/lookup/BTSLut.java b/lookup/BTSLut.java
new file mode 100644
index 0000000..6abfcb8
--- /dev/null
+++ b/lookup/BTSLut.java
@@ -0,0 +1,200 @@
+package lookup;
+
+import helper.ListGPS;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.ListIterator;
+
+import DataStructure.GPScoordinate;
+import DataStructure.GSMMap;
+import DataStructure.SingleBTS;
+
+/**
+ * No longer used!
+ *
+ * @author richy
+ *
+ */
+public class BTSLut implements ILut {
+ private LinkedList<GPScoordinate>[] possible_coords_DL = new LinkedList[69];
+ private LinkedList<GPScoordinate>[] possible_coords_UL = new LinkedList[69];
+ public int bts; // which bts does this Object store
+ public int threshold_dB;
+ public int threshold_m;
+
+ /**
+ * create empty LUT
+ *
+ * @param ARFCN
+ * set BTS-ARFCN this object will take measurements and requests
+ */
+ public BTSLut(int ARFCN, int threshold_dB, int threshold_m) {
+ this.bts = ARFCN;
+ this.threshold_dB = threshold_dB;
+ this.threshold_m = threshold_m;
+ // initialize strength array: -47 ... -115
+ for (int i = 0; i < 69; i++) {
+ possible_coords_DL[i] = new LinkedList<GPScoordinate>();
+ possible_coords_UL[i] = new LinkedList<GPScoordinate>();
+ }
+
+ }
+
+ public BTSLut(int ARFCN, GSMMap map, int threshold, int threshold_m) {
+ this.bts = ARFCN;
+ this.threshold_dB = threshold;
+ this.threshold_m = threshold_m;
+ for (int i = 0; i < 69; i++) {
+ possible_coords_DL[i] = new LinkedList<GPScoordinate>();
+ possible_coords_UL[i] = new LinkedList<GPScoordinate>();
+ }
+ // fill the LUT
+ for (int x = 0; x < map.Xcoords.length; x++) {
+ for (int y = 0; y < map.Ycoords.length; y++) {
+ fill(map.getCoord(x, y), map.map[x][y]);
+ }
+ }
+
+ }
+
+ @Override
+ public LinkedList<GPScoordinate> get(SingleBTS MR) {
+ // hier muss noch das threshold_dB berücksichtigt werden!
+ if (MR == null)
+ return null;
+ LinkedList<GPScoordinate> result = new LinkedList<GPScoordinate>();
+ for (int i = threshold_dB * (-1); i <= threshold_dB; i++) {
+ try {
+ if (MR.fullBTS && MR.getDLcount() > 0) {
+ // get coords for DL and UL and do a intersection
+ // fix: do no intersection
+ LinkedList<GPScoordinate> listUL = new LinkedList<GPScoordinate>();
+ LinkedList<GPScoordinate> listDL = new LinkedList<GPScoordinate>();
+ listUL = possible_coords_UL[getIndex(MR.getUldB()
+ + threshold_dB)];
+ listDL = possible_coords_DL[getIndex(MR.getDldB()
+ + threshold_dB)];
+ listUL = ListGPS.removeNullElements(listUL);
+ listDL = ListGPS.removeNullElements(listDL);
+ // result.addAll(helper.ListGPS.intersect(listDL,
+ // listUL,threshold_m));
+ result.addAll(listUL);
+ result.addAll(listDL);
+ } else {
+ result.addAll(possible_coords_DL[(getIndex(MR.getDldB()
+ + threshold_dB))]);
+ }
+ } catch (Exception e) {
+ // only index out of bound... ignore
+
+ }
+ }
+ return result;
+
+ }
+
+ /**
+ * Takes list. Returns the lookup. Result is the intersection between all
+ * SingleBTSs in MR. That is, only Coordinates that are in common are
+ * returned
+ */
+
+ @SuppressWarnings("unused")
+ public LinkedList<GPScoordinate> get(List<SingleBTS> MR) {
+ // create result list for each function call
+ LinkedList<GPScoordinate> list = new LinkedList<GPScoordinate>();
+ // create a nested-linked-list in order to compute the intersection
+ LinkedList<LinkedList<GPScoordinate>> nestedlist = new LinkedList<LinkedList<GPScoordinate>>();
+
+ // one list for all
+ LinkedList<GPScoordinate> resultset = new LinkedList<GPScoordinate>();
+
+ ListIterator<SingleBTS> itr = MR.listIterator();
+ while (itr.hasNext()) {
+ SingleBTS current = itr.next();
+ resultset.addAll(get(current));
+ }
+ if (true)
+ return resultset;
+
+ for (SingleBTS current : MR) {
+ // clear list
+ list = new LinkedList<GPScoordinate>();
+ // save results in that list. do that list into the list-list
+ list.addAll(get(current));
+ list = ListGPS.removeNullElements(list);
+ if (list != null && !list.isEmpty())
+ nestedlist.addLast(list);
+ }
+
+ // -------
+ // from here on only calculating intersect
+ // -------
+
+ // reuse list. take it to store final result
+ nestedlist = ListGPS.removeAllNullElements(nestedlist);
+ if (list != null)
+ list.clear();
+ if (nestedlist == null || nestedlist.isEmpty())
+ return null;
+ if (nestedlist.size() == 1)
+ return nestedlist.getFirst();
+ // nestedlist has at least 2 elements. do intersect with both. Store in
+ // list.
+ list.addAll(ListGPS.intersect(nestedlist.removeFirst(),
+ nestedlist.removeLast(), threshold_m));
+ // now do intersect with the rest. This could get a speedup by using
+ // pairwise intersection. would be O(log n) then.
+ while (!nestedlist.isEmpty()) {
+ list = ListGPS.intersect(list, nestedlist.removeFirst(),
+ threshold_m);
+ }
+ // TODO: only null elements are here!
+ return list;
+
+ }
+
+ /**
+ * Returns index where the strength (dBm) is stored in the array
+ *
+ * @param strength
+ * . Gets rounded
+ * @return
+ */
+ private int getIndex(double strength) {
+ int rounded = (int) Math.round(strength);
+ // this could be done with math.abs
+ if (strength < 0) {
+ return -47 - rounded;
+ } else {
+ return rounded - 47;
+ }
+
+ }
+
+ @Override
+ public void fill(GPScoordinate where, SingleBTS what) {
+ if (what == null || what.ARFCN != bts)
+ return;
+ int hit = 0;
+ if (what.getDldB() != 0) {
+ hit = getIndex(what.getDldB());
+ possible_coords_DL[hit].add(where);
+ }
+ if (what.getUldB() != 0) {
+ hit = getIndex(what.getUldB());
+ possible_coords_UL[hit].add(where);
+ }
+
+ }
+
+ public void fill(GPScoordinate where, List<SingleBTS> what) {
+ if (what == null)
+ return;
+ for (SingleBTS current : what) {
+ fill(where, current);
+ }
+ }
+
+}