From 0bc8e3c95550f24abe62aba7acc768f080ed030b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Lassabe?= Date: Mon, 18 Aug 2008 16:19:02 +0000 Subject: [PATCH] Fix getSsSquareDistance(), radar_exp() parameters * server.cc: adjusted radar_exp due to parameters (suppr. pre-processing with #ifdef PEREGRINATION and changed output) * referencepoint.cc: fixed getSsSquareDistance by replacing missing values by -90 dBm signal Performs better than previous versions, however, RADAR remains the best. git-svn-id: https://pif.pu-pm.univ-fcomte.fr/svn/loc@68 785a6c6c-259e-4ff1-8b91-dc31627914f0 --- GuiNuMo-server/guinumo.cc | 7 +- GuiNuMo-server/referencepoint.cc | 181 +++++++++++++++++++------------ GuiNuMo-server/referencepoint.hh | 2 +- GuiNuMo-server/server.cc | 96 ++++------------ 4 files changed, 137 insertions(+), 149 deletions(-) diff --git a/GuiNuMo-server/guinumo.cc b/GuiNuMo-server/guinumo.cc index f60b019..8f6bd75 100644 --- a/GuiNuMo-server/guinumo.cc +++ b/GuiNuMo-server/guinumo.cc @@ -17,7 +17,12 @@ int main(int argc, char ** argv) ofstream output_file; string read_file; - if(argc != 4) + cout << "Called guinumo with args: "; + for(int i = 1 ; i < argc ; i++) + cout << argv[i] << " "; + cout << endl; + + if(argc != 5) cout << "Usage: guinumo AP_file Ref_Pt_file Test_file logfile" << endl; else { diff --git a/GuiNuMo-server/referencepoint.cc b/GuiNuMo-server/referencepoint.cc index a7d19d0..7c560a6 100644 --- a/GuiNuMo-server/referencepoint.cc +++ b/GuiNuMo-server/referencepoint.cc @@ -4,103 +4,140 @@ float ReferencePoint::getSsSquareDistance(const vector &m)const { - unsigned int i, j; - float ret = 0; - bool found; - - for (i = 0 ; i < m.size() ; i++) - { - j = 0; - found = false; - while((j < measurement_list.size())&&(found == false)) - { - if(measurement_list[j].getMacAddr() == m[i].getMacAddr()) - { - found = true; - ret += measurement_list[j].getSsSquareDistance(m[i].getAverage()); - } - j++; - } - } + unsigned int i, j; + float ret = 0; + bool found; + vector ref_m = measurement_list; + vector test_m = m; + Measurement new_meas; - return ret; + new_meas.addSsValue(-95); + + /* Complete measurement vector with unexisting ap (from ref point) */ + for(i = 0 ; i < ref_m.size() ; i++) + { + found = false; + for(j = 0 ; j < test_m.size() && !found ; j++) + if(test_m[j].getMacAddr() == ref_m[i].getMacAddr()) + found = true; + if(!found) + { + new_meas.setMacAddr(measurement_list[i].getMacAddr()); + test_m.push_back(new_meas); + } + } + + /* Now, complete ref. point meas. */ + for(i = 0 ; i < test_m.size() ; i++) + { + found = false; + for(j = 0 ; j < ref_m.size() && !found ; j++) + if(test_m[i].getMacAddr() == ref_m[j].getMacAddr()) + found = true; + if(!found) + { + new_meas.setMacAddr(test_m[i].getMacAddr()); + ref_m.push_back(new_meas); + } + } + + /* Now, compute SS distance */ + for (i = 0 ; i < test_m.size() ; i++) + { + j = 0; + found = false; + while((j < ref_m.size())&&(found == false)) + { + if(ref_m[j].getMacAddr() == test_m[i].getMacAddr()) + { + found = true; + ret += ref_m[j].getSsSquareDistance(test_m[i].getAverage()); + } + j++; + } + } + + ref_m.clear(); + test_m.clear(); + + return ret; } void ReferencePoint::addMeasurement(const string &mac_a, const int &value) { - unsigned int i; - Measurement m; - bool inserted = false; - - for (i = 0 ; i < measurement_list.size() ; i++) - if(measurement_list[i].getMacAddr() == mac_a) - { - measurement_list[i].addSsValue(value); - inserted = true; - break; - } - if(inserted == false) - { - m.setMacAddr(mac_a); - m.addSsValue(value); - measurement_list.push_back(m); - } + unsigned int i; + Measurement m; + bool inserted = false; + + for (i = 0 ; i < measurement_list.size() ; i++) + if(measurement_list[i].getMacAddr() == mac_a) + { + measurement_list[i].addSsValue(value); + inserted = true; + break; + } + if(inserted == false) + { + m.setMacAddr(mac_a); + m.addSsValue(value); + measurement_list.push_back(m); + } } bool ReferencePoint::getPowerForAp(const string &ap_mac, float *p)const { - unsigned int i; - string str; - string macLowerCase; - - str=ap_mac; - - //Pour convertir les majuscules en miniscules - const int length=str.length(); - for(int j=0; j < length; ++j) - { - str[j] = std::tolower(str[j]); - } + unsigned int i; + string str; + string macLowerCase; - for (i = 0 ; i < measurement_list.size() ; i++) - if(measurement_list[i].getMacAddr() == str) - { - *p = measurement_list[i].getAverage(); - return true; - } - return false; + str=ap_mac; + + //Pour convertir les majuscules en miniscules + const int length=str.length(); + for(int j=0; j < length; ++j) + { + str[j] = std::tolower(str[j]); + } + + for (i = 0 ; i < measurement_list.size() ; i++) + if(measurement_list[i].getMacAddr() == str) + { + *p = measurement_list[i].getAverage(); + return true; + } + return false; } ReferencePoint ReferencePoint::operator=(const ReferencePoint &rp) { - if(this == &rp) - return *this; - - coordinates = rp.coordinates; - measurement_list = rp.measurement_list; - return *this; + if(this == &rp) + return *this; + + coordinates = rp.coordinates; + measurement_list = rp.measurement_list; + return *this; } ostream &operator<<(ostream &os, ReferencePoint &rp) { - unsigned int i; - - os << rp.coordinates << endl; - if(rp.measurement_list.size() == 0) - os << "No measurements" << endl; - else - for (i = 0 ; i < rp.measurement_list.size() ; i++) - os << rp.measurement_list[i] << endl; - - return os; + unsigned int i; + + os << rp.coordinates << endl; + if(rp.measurement_list.size() == 0) + os << "No measurements" << endl; + else + for (i = 0 ; i < rp.measurement_list.size() ; i++) + os << rp.measurement_list[i] << endl; + + return os; } @@ -108,5 +145,5 @@ ostream &operator<<(ostream &os, ReferencePoint &rp) /* Opérateur de cast en Point */ ReferencePoint::operator Point() const { - return coordinates ; + return coordinates ; } diff --git a/GuiNuMo-server/referencepoint.hh b/GuiNuMo-server/referencepoint.hh index 07e6446..9214c54 100644 --- a/GuiNuMo-server/referencepoint.hh +++ b/GuiNuMo-server/referencepoint.hh @@ -13,7 +13,7 @@ class ReferencePoint protected: Point coordinates; vector measurement_list; - + public: ReferencePoint(const float &x = 0, const float &y = 0, const float &z = 0) { coordinates.setX(x); coordinates.setY(y); coordinates.setZ(z); }; ReferencePoint(const ReferencePoint &rp) { coordinates = rp.coordinates; measurement_list = rp.measurement_list; }; diff --git a/GuiNuMo-server/server.cc b/GuiNuMo-server/server.cc index bbda785..4ea1e20 100644 --- a/GuiNuMo-server/server.cc +++ b/GuiNuMo-server/server.cc @@ -1144,22 +1144,24 @@ Point Server::fbcm_friis( const vector &m, const vector frii unsigned int i, j, ap_idx; float constant_term, minmax_res, minmax_max; float x = MINMAX_X_START, y = MINMAX_Y_START ; + vector vm = m; //Used when filtering 3 strongest APs + vector friis_idx = friis_idx_list; //Used when filtering 3 strongest APs i = 0; //cout << "FBCM: "; - cout << "Received " << m.size() << " measurements." << endl; - for (i = 0 ; i < m.size() ; i++) + cout << "Received " << vm.size() << " measurements." << endl; + for (i = 0 ; i < vm.size() ; i++) { - if (apExists(m[i].getMacAddr())) + if (apExists(vm[i].getMacAddr())) { - ap_idx = apIndex(m[i].getMacAddr()); - cout << "AP " << m[i].getMacAddr() << " was found at position " << ap_idx << endl; + ap_idx = apIndex(vm[i].getMacAddr()); + cout << "AP " << vm[i].getMacAddr() << " was found at position " << ap_idx << endl; constant_term = access_point_list[ap_idx].getOutputPower() + access_point_list[ap_idx].getAntennaGain() + 2; constant_term += 20 * log10((300000000.0 / (float) access_point_list[ap_idx].getFrequency()) / (4*M_PI)); - if(friis_idx_list[i] != -1) + if(friis_idx[i] != -1) { centres.push_back(access_point_list[ap_idx].getCoordinates()); - dist_vect.push_back(pow(10, (constant_term - m[i].getAverage()) / (10 * friis_idx_list[i]))); + dist_vect.push_back(pow(10, (constant_term - vm[i].getAverage()) / (10 * friis_idx[i]))); } } } @@ -2465,9 +2467,6 @@ void Server::radar_exp(const string &outfile, const string &testfile) createClient() ; } - /* Open a log file */ - /*fname = filename + ".out"; - logfile.open(fname.c_str());*/ logfile.open(outfile.c_str()); if (logfile.fail()) { @@ -2480,70 +2479,14 @@ void Server::radar_exp(const string &outfile, const string &testfile) \tInterlink\t(Error)\ \tRADAR\t(Error)\ \tFBCM\t(Error)\ -\t1 NSS + FBCM\t(Error)\ -\t2 NSS\t(Error)\ -\t3 NSS\t(Error)\ -\t5 NSS\t(Error)" << endl ; +\tFRBHM\t(Error)" << endl ; cout << reference_point_list.size() << " reference points." << endl ; - //#define PEREGRINATION // À décommenter pour utiliser les points du fichier DEFAULT_TRACKING_FILE plutôt que les points de référence. - -#ifdef PEREGRINATION - /* *** Code pour utiliser les points de prérégrination : *** */ - - vector peregrination_point_list ; - makePointListFromFile(peregrination_point_list, DEFAULT_TRACKING_FILE, false) ; - cout << peregrination_point_list.size() << " peregrination points to test." << endl ; - - for (i = 0 ; i < peregrination_point_list.size() ; i++) - { - /* Get point measurements */ - vm = peregrination_point_list[i].getMeasurementList(); - ref_coords = peregrination_point_list[i].getCoordinates(); - - /* Print point coordinates */ - logfile << ref_coords << "\t"; - - /* Interlink Networks */ - solution = interlink(vm, 0) ; - logfile << solution << "\t" << solution.distance(ref_coords) << "\t" ; - - /* RADAR */ - solution = getkClosestInSs(vm, 1, NULL)[0] ; - logfile << solution << "\t" << solution.distance(ref_coords) << "\t" ; - - /* FBCM */ - solution = fbcm(vm, 0) ; - logfile << solution << "\t" << solution.distance(ref_coords) << "\t" ; - - /* 1-NSS + FBCM */ - solution = getkClosestInSs(vm, 1, NULL)[0] ; - solution = fbcm_friis(vm, computeFriisFromRefList(solution, vm), solution.getZ()) ; - logfile << solution << "\t" << solution.distance(ref_coords) << "\t" ; - - /* 2-NSS */ - solution = getkWeightedInSs(vm, 2, NULL); - logfile << solution << "\t" << solution.distance(ref_coords) << "\t"; - - /* 3-NSS */ - solution = getkWeightedInSs(vm, 3, NULL); - logfile << solution << "\t" << solution.distance(ref_coords) << "\t"; - - /* 5-NSS */ - solution = getkWeightedInSs(vm, 5, NULL); - logfile << solution << "\t" << solution.distance(ref_coords) << "\t"; - - logfile << endl ; - vm.clear() ; - } - -#else // PEREGRINATION - /* *** Code pour utiliser les points de référence : *** */ - vector test_point_list ; makePointListFromFile(test_point_list, DEFAULT_REF_POINT_FILE_1M, true) ; cout << test_point_list.size() << " reference points to test." << endl ; + float radar_error = 0, in_error = 0, fbcm_error = 0, frbhm_error = 0; for (i = 0 ; i < test_point_list.size() ; i++) { @@ -2560,38 +2503,41 @@ void Server::radar_exp(const string &outfile, const string &testfile) /* Interlink Networks */ solution = interlink(vm, 0) ; logfile << solution << "\t" << solution.distance(ref_coords) << "\t" ; + in_error += solution.distance(ref_coords); /* RADAR */ solution = getkClosestInSs(vm, 1, &ref_coords)[0] ; logfile << solution << "\t" << solution.distance(ref_coords) << "\t" ; + radar_error += solution.distance(ref_coords); /* FBCM */ solution = fbcm(vm, 0) ; logfile << solution << "\t" << solution.distance(ref_coords) << "\t" ; + fbcm_error += solution.distance(ref_coords); /* 1-NSS + FBCM */ solution = getkClosestInSs(vm, 1, &ref_coords)[0] ; solution = fbcm_friis(vm, computeFriisFromRefList(solution, vm), solution.getZ()) ; logfile << solution << "\t" << solution.distance(ref_coords) << "\t" ; + frbhm_error += solution.distance(ref_coords); - /* 2-NSS */ + /* 2-NSS solution = getkWeightedInSs(vm, 2, &ref_coords); logfile << solution << "\t" << solution.distance(ref_coords) << "\t"; - /* 3-NSS */ + /* 3-NSS solution = getkWeightedInSs(vm, 3, &ref_coords); logfile << solution << "\t" << solution.distance(ref_coords) << "\t"; - /* 5-NSS */ + /* 5-NSS solution = getkWeightedInSs(vm, 5, &ref_coords); - logfile << solution << "\t" << solution.distance(ref_coords) << "\t"; + logfile << solution << "\t" << solution.distance(ref_coords) << "\t";*/ logfile << endl ; vm.clear() ; } -#endif // PEREGRINATION /* Mean values formulas names */ - unsigned int oocalc_line = test_point_list.size() + 1; - logfile << "\t\t=moyenne(C2:C" << oocalc_line << ")\t\t=moyenne(E2:E" << oocalc_line << ")\t\t=moyenne(G2:G" << oocalc_line << ")\t\t=moyenne(I2:I" << oocalc_line << ")\t\t=moyenne(K2:K" << oocalc_line << ")\t\t=moyenne(M2:M" << oocalc_line << ")\t\t=moyenne(O2:O" << oocalc_line << ")" << endl ; + float nb = (float) test_point_list.size(); + logfile << "\t\t" << (in_error / nb) << "\t\t" << (radar_error / nb) << "\t\t" << (fbcm_error / nb) << "\t\t" << (frbhm_error / nb) << endl ; logfile.close(); }