Ajout de FRBHM basique
git-svn-id: https://pif.pu-pm.univ-fcomte.fr/svn/loc@43 785a6c6c-259e-4ff1-8b91-dc31627914f0
This commit is contained in:
parent
67525c445e
commit
cc1222f67f
|
@ -19,7 +19,7 @@ int main(int argc, char ** argv)
|
||||||
Server server ;
|
Server server ;
|
||||||
|
|
||||||
server.createClient() ;
|
server.createClient() ;
|
||||||
server.monitorClient(0) ;
|
server.monitorClient(0,2) ;
|
||||||
|
|
||||||
cout << argv[0] << " : fin." << endl ;
|
cout << argv[0] << " : fin." << endl ;
|
||||||
fflush(stdout) ;
|
fflush(stdout) ;
|
||||||
|
|
|
@ -72,12 +72,23 @@ ostream &operator<<(ostream &os, ReferencePoint &rp)
|
||||||
bool ReferencePoint::getPowerForAp(const string &ap_mac, float *p)const
|
bool ReferencePoint::getPowerForAp(const string &ap_mac, float *p)const
|
||||||
{
|
{
|
||||||
unsigned int i;
|
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]);
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0 ; i < measurement_list.size() ; i++)
|
for (i = 0 ; i < measurement_list.size() ; i++)
|
||||||
if(measurement_list[i].getMacAddr() == ap_mac)
|
if(measurement_list[i].getMacAddr() == str)
|
||||||
{
|
{
|
||||||
*p = measurement_list[i].getAverage();
|
*p = measurement_list[i].getAverage();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -347,11 +347,19 @@ unsigned int Server::pointIndex(const vector<ReferencePoint> &point_list, const
|
||||||
bool Server::apExists(const string &ap_addr)const
|
bool Server::apExists(const string &ap_addr)const
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
string str;
|
||||||
|
|
||||||
for (i = 0 ; i < access_point_list.size() ; i++)
|
for (i = 0 ; i < access_point_list.size() ; i++){
|
||||||
if (access_point_list[i].getApAddr() == ap_addr)
|
str=access_point_list[i].getApAddr();
|
||||||
return true;
|
const int length=str.length();
|
||||||
|
for(int j=0; j < length; ++j)
|
||||||
|
{
|
||||||
|
str[j] = std::tolower(str[j]);
|
||||||
|
}
|
||||||
|
for (i = 0 ; i < access_point_list.size() ; i++)
|
||||||
|
if (str == ap_addr)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -615,6 +623,60 @@ Point Server::fbcm(const vector<Measurement> &m, const int &client_idx)const
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*second version of fbcm with as parameter vector<Measurement> &m and a list of friis index*/
|
||||||
|
Point Server::fbcm_friis( const vector<Measurement> &m, const vector<float> friis_idx_list)const
|
||||||
|
{
|
||||||
|
Point ret(0, 0, 0);
|
||||||
|
vector<string> addr;
|
||||||
|
vector<float> dist_vect;
|
||||||
|
vector<Point> centres;
|
||||||
|
unsigned int i, j, ap_idx;
|
||||||
|
float constant_term, minmax_res, minmax_max;
|
||||||
|
float x = MINMAX_X_START, y = MINMAX_Y_START;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
//cout << "FBCM: ";
|
||||||
|
for (i = 0 ; i < m.size() ; i++){cout<<"m[i].getMacAddr()"<<m[i].getMacAddr()<<endl;
|
||||||
|
if (apExists(m[i].getMacAddr()))
|
||||||
|
{
|
||||||
|
ap_idx = apIndex(m[i].getMacAddr());
|
||||||
|
//cout << "AP idx: " << ap_idx << " ";
|
||||||
|
centres.push_back(access_point_list[ap_idx].getCoordinates());
|
||||||
|
addr.push_back(m[i].getMacAddr());
|
||||||
|
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));
|
||||||
|
for(j=0; j<friis_idx_list.size() ; j++)
|
||||||
|
{
|
||||||
|
dist_vect.push_back(pow(10, (constant_term - m[i].getAverage()) / (10 * friis_idx_list[j])));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Then: min-max */
|
||||||
|
minmax_res = 1000000;
|
||||||
|
for (x = MINMAX_X_START ; x < MINMAX_X_STOP ; x += MINMAX_STEP)
|
||||||
|
for (y = MINMAX_Y_START ; y < MINMAX_Y_STOP ; y += MINMAX_STEP)
|
||||||
|
{
|
||||||
|
minmax_max = 0;
|
||||||
|
for (i = 0 ; i < centres.size() ; i++)
|
||||||
|
if ((centres[i].squareDistance(x, y, 3) - (dist_vect[i]*dist_vect[i])) > minmax_max)
|
||||||
|
minmax_max = centres[i].squareDistance(x, y, 3) - (dist_vect[i] * dist_vect[i]);
|
||||||
|
if (minmax_max < minmax_res)
|
||||||
|
{
|
||||||
|
ret.setX(x);
|
||||||
|
ret.setY(y);
|
||||||
|
minmax_res = minmax_max;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Clear all vectors */
|
||||||
|
addr.clear();
|
||||||
|
dist_vect.clear();
|
||||||
|
centres.clear();
|
||||||
|
cout<<"RESULTAT DU FRBHM ---> "<<ret<<endl;
|
||||||
|
/* Return position */
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Point Server::interlink(const vector<Measurement> &m, const int &client_idx)const
|
Point Server::interlink(const vector<Measurement> &m, const int &client_idx)const
|
||||||
|
@ -1112,6 +1174,48 @@ void Server::computeFriisFromRefList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*Deuxième version de computeFriisFromRefList qui prend en entrée un point et retourne la liste d'index de friis équivalent*/
|
||||||
|
vector<float> Server::computeFriisFromRefList(const Point &p, const vector<Measurement> &m)
|
||||||
|
{
|
||||||
|
vector<float> friis_idx_list;
|
||||||
|
Point pt_coords, ap_coords;
|
||||||
|
float ap_power, ap_gain, calib_gain = 2, const_term, mes_power/*, friis_sum*/;
|
||||||
|
unsigned int ap_freq;
|
||||||
|
string ap_mac;
|
||||||
|
|
||||||
|
|
||||||
|
/* Compute an index for each ref point. List stored in friis_idx_list */
|
||||||
|
/* Compute an index for Point p. List stored in friis_idx_list */
|
||||||
|
for (unsigned int j = 0 ; j < reference_point_list.size() ; j++)
|
||||||
|
{
|
||||||
|
pt_coords = reference_point_list[j].getCoordinates();
|
||||||
|
if (pt_coords==p)
|
||||||
|
{
|
||||||
|
for (unsigned int i = 0 ; i < access_point_list.size() ; i++)
|
||||||
|
{
|
||||||
|
ap_power = access_point_list[i].getOutputPower();
|
||||||
|
ap_coords = access_point_list[i].getCoordinates();
|
||||||
|
ap_freq = access_point_list[i].getFrequency();
|
||||||
|
ap_gain = access_point_list[i].getAntennaGain();
|
||||||
|
ap_mac = access_point_list[i].getApAddr();
|
||||||
|
|
||||||
|
/* Compute main general term, independant from scans */
|
||||||
|
const_term = calib_gain + ap_gain;
|
||||||
|
const_term -= 20 * log10(4 * M_PI);
|
||||||
|
const_term += 20 * log10 (300000000.0 / ap_freq) + ap_power;
|
||||||
|
|
||||||
|
if (reference_point_list[j].getPowerForAp(ap_mac, &mes_power)){
|
||||||
|
friis_idx_list.push_back((const_term - mes_power) / (10 * log10(ap_coords.distance(pt_coords))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (unsigned int k=0; k < friis_idx_list.size();k++)
|
||||||
|
cout<<"friis_idx_list"<< k <<": "<<friis_idx_list[k]<<endl;//
|
||||||
|
|
||||||
|
return friis_idx_list;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Ajoute un client (ClientInfo) à la liste "client_list", et renvoie une référence sur l'élément ajouté. */
|
/* Ajoute un client (ClientInfo) à la liste "client_list", et renvoie une référence sur l'élément ajouté. */
|
||||||
|
@ -1124,8 +1228,10 @@ ClientInfo& Server::createClient()
|
||||||
|
|
||||||
|
|
||||||
/* Localise le client d'identifiant "client_id" en appliquant l'algorithme voulu. */
|
/* Localise le client d'identifiant "client_id" en appliquant l'algorithme voulu. */
|
||||||
void Server::monitorClient(const unsigned int &client_id)
|
void Server::monitorClient(const unsigned int &client_id, int algo)
|
||||||
{
|
{
|
||||||
|
Point pointFastViterbi;
|
||||||
|
vector<float> friisFromList;
|
||||||
#ifdef DEBUG_T
|
#ifdef DEBUG_T
|
||||||
cout << "//--> Server::monitorClient()" << endl ; fflush(stdout) ;
|
cout << "//--> Server::monitorClient()" << endl ; fflush(stdout) ;
|
||||||
#endif // DEBUG_T
|
#endif // DEBUG_T
|
||||||
|
@ -1188,9 +1294,20 @@ void Server::monitorClient(const unsigned int &client_id)
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
cout << "Point courant : " << peregrination_point_list[pt] ;
|
cout << "Point courant : " << peregrination_point_list[pt] ;
|
||||||
#endif // DEBUG
|
#endif // DEBUG
|
||||||
|
switch(algo)
|
||||||
/* Application de l'algorithme Viterbi */
|
{
|
||||||
fastViterbiLike(client_id, NULL) ;
|
case 1:/* Application de l'algorithme Viterbi */
|
||||||
|
fastViterbiLike(client_id, NULL) ;
|
||||||
|
break;
|
||||||
|
case 2 :/*Application de l'algorithme FRBHM basique*/
|
||||||
|
cout<<"-------FRBHM---------"<<endl;
|
||||||
|
computeFriisFromRefList();
|
||||||
|
pointFastViterbi=fastViterbiLike(client_id, NULL) ;
|
||||||
|
friisFromList= computeFriisFromRefList(pointFastViterbi,vm);
|
||||||
|
fbcm_friis(vm, friisFromList);
|
||||||
|
break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef TEST
|
#ifdef TEST
|
||||||
pt++ ;
|
pt++ ;
|
||||||
|
|
|
@ -91,6 +91,7 @@ public:
|
||||||
|
|
||||||
Point kPointsAverage(const vector<Point> &vp)const;
|
Point kPointsAverage(const vector<Point> &vp)const;
|
||||||
Point fbcm(const vector<Measurement> &m, const int &client_idx)const;
|
Point fbcm(const vector<Measurement> &m, const int &client_idx)const;
|
||||||
|
Point fbcm_friis( const vector<Measurement> &m, const vector<float> friis_idx_list)const;
|
||||||
Point interlink(const vector<Measurement> &m, const int &client_idx)const;
|
Point interlink(const vector<Measurement> &m, const int &client_idx)const;
|
||||||
|
|
||||||
void makeReferencePointListFromFile(const string &filename);
|
void makeReferencePointListFromFile(const string &filename);
|
||||||
|
@ -105,10 +106,11 @@ public:
|
||||||
void printAccessPointList();
|
void printAccessPointList();
|
||||||
|
|
||||||
void computeFriisFromRefList();
|
void computeFriisFromRefList();
|
||||||
|
vector<float> computeFriisFromRefList(const Point &p, const vector<Measurement> &m);
|
||||||
|
|
||||||
unsigned int getNbReferencePoints()const { return reference_point_list.size(); };
|
unsigned int getNbReferencePoints()const { return reference_point_list.size(); };
|
||||||
|
|
||||||
void monitorClient(const unsigned int &client_id) ;
|
void monitorClient(const unsigned int &client_id, int algo) ;
|
||||||
Point fastViterbiLike(const unsigned int &id_client, float **distance_matrix) ;
|
Point fastViterbiLike(const unsigned int &id_client, float **distance_matrix) ;
|
||||||
|
|
||||||
/* For experimentation purpose only ! */
|
/* For experimentation purpose only ! */
|
||||||
|
|
Loading…
Reference in New Issue