Réorganisation du code dans server.cc
server.{cc,hh} : * Mutualisation du code des deux fonctions pointExists(). * Idem avec les deux fonctions pointIndex(). * makePointListFromFile() : correction pour la généricité de la fonction (lecture pour la liste des points de référence / lecture pour la liste de pérégrination). git-svn-id: https://pif.pu-pm.univ-fcomte.fr/svn/loc@31 785a6c6c-259e-4ff1-8b91-dc31627914f0
This commit is contained in:
parent
54d788586f
commit
6641aef72b
|
@ -137,7 +137,7 @@ inline vector<string> extractReferencePointInfoFromBuffer(const string &buffer_i
|
|||
ret.push_back(tmp_field);
|
||||
tmp_field.clear();
|
||||
i++;
|
||||
#endif
|
||||
#endif // FRED_CSV_FORMAT
|
||||
|
||||
/* Extract direction (not used now) */
|
||||
while (buffer_in[i] != ';')
|
||||
|
@ -168,14 +168,14 @@ inline vector<string> extractReferencePointInfoFromBuffer(const string &buffer_i
|
|||
}
|
||||
ret.push_back(tmp_field);
|
||||
tmp_field.clear();
|
||||
#else
|
||||
#else // FRED_CSV_FORMAT
|
||||
while (i <= buffer_in.size())
|
||||
{
|
||||
if ((buffer_in[i] == ';' || i == buffer_in.size()) && !tmp_field.empty()) // Si on est sur un séparateur et que la valeur lue n'est pas vide,
|
||||
{
|
||||
#ifdef DEBUG_2
|
||||
cout << "Ajout de la valeur lue : " << tmp_field << endl ;
|
||||
#endif
|
||||
#endif // DEBUG_2
|
||||
ret.push_back(tmp_field) ; // on met la valeur lue dans les valeurs de retour.
|
||||
tmp_field.clear() ;
|
||||
}
|
||||
|
@ -184,7 +184,7 @@ inline vector<string> extractReferencePointInfoFromBuffer(const string &buffer_i
|
|||
|
||||
i++ ;
|
||||
}
|
||||
#endif
|
||||
#endif // FRED_CSV_FORMAT
|
||||
|
||||
/* Return the vector with each data */
|
||||
return ret;
|
||||
|
@ -244,13 +244,39 @@ int Server::receive_data()
|
|||
|
||||
|
||||
|
||||
/* FONCTION POUR RÉTRO-COMPATIBILITÉ.
|
||||
* Recherche un point de coordonnées (x;y;z) dans la liste reference_point_list, retourne true s'il existe, false sinon. */
|
||||
bool Server::pointExists(const float &x, const float &y, const float &z)const
|
||||
{
|
||||
Point p(x, y, z);
|
||||
return pointExists(reference_point_list, Point(x, y, z)) ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* FONCTION POUR RÉTRO-COMPATIBILITÉ.
|
||||
* Recherche un Point dans la liste reference_point_list, retourne true s'il existe, false sinon. */
|
||||
bool Server::pointExists(const Point &p)const
|
||||
{
|
||||
return pointExists(reference_point_list, p) ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Recherche un point de coordonnées (x;y;z) dans la liste "point_list", retourne true s'il existe, false sinon. */
|
||||
bool Server::pointExists(const vector<ReferencePoint> &point_list, const float &x, const float &y, const float &z) const
|
||||
{
|
||||
return pointExists(point_list, Point(x, y, z)) ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Recherche un Point dans la liste "point_list", retourne true s'il existe, false sinon. */
|
||||
bool Server::pointExists(const vector<ReferencePoint> &point_list, const Point &p) const
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0 ; i < reference_point_list.size() ; i++)
|
||||
if (p == reference_point_list[i].getCoordinates())
|
||||
for (i = 0 ; i < point_list.size() ; i++)
|
||||
if (p == point_list[i].getCoordinates())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
@ -261,7 +287,28 @@ bool Server::pointExists(const float &x, const float &y, const float &z)const
|
|||
/* Do not forget to call pointExists() before this one */
|
||||
unsigned int Server::pointIndex(const float &x, const float &y, const float &z)const
|
||||
{
|
||||
Point p(x, y, z);
|
||||
return pointIndex(reference_point_list, Point(x, y, z)) ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Do not forget to call pointExists() before this one */
|
||||
unsigned int Server::pointIndex(const Point &p)const
|
||||
{
|
||||
return pointIndex(reference_point_list, p) ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
unsigned int Server::pointIndex(const vector<ReferencePoint> &point_list, const float &x, const float &y, const float &z) const
|
||||
{
|
||||
return pointIndex(point_list, Point(x, y, z)) ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
unsigned int Server::pointIndex(const vector<ReferencePoint> &point_list, const Point &p) const
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0 ; i < reference_point_list.size() ; i++)
|
||||
|
@ -273,19 +320,6 @@ unsigned int Server::pointIndex(const float &x, const float &y, const float &z)c
|
|||
|
||||
|
||||
|
||||
bool Server::pointExists(const Point &p)const
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0 ; i < reference_point_list.size() ; i++)
|
||||
if (p == reference_point_list[i].getCoordinates())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Server::apExists(const string &ap_addr)const
|
||||
{
|
||||
unsigned int i;
|
||||
|
@ -312,20 +346,6 @@ unsigned int Server::apIndex(const string &ap_addr)const
|
|||
|
||||
|
||||
|
||||
/* Do not forget to call pointExists() before this one */
|
||||
unsigned int Server::pointIndex(const Point &p)const
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0 ; i < reference_point_list.size() ; i++)
|
||||
if (p == reference_point_list[i].getCoordinates())
|
||||
return i;
|
||||
|
||||
return 0; // Should never happen
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Selects the "k" closest points from the measurement "m", in the SS space.
|
||||
* Returns an empty vector if no points are found, which should never happen.
|
||||
*/
|
||||
|
@ -412,7 +432,7 @@ vector<Point> Server::getkClosestInSs(const vector<Measurement> &m, const unsign
|
|||
else
|
||||
for (i = 0 ; i < distances_vector.size() - 1 ; i++)
|
||||
cout << distances_vector[i] << " : " << points_vector[i] << endl ;
|
||||
#endif
|
||||
#endif // DEBUG
|
||||
|
||||
return points_vector;
|
||||
}
|
||||
|
@ -619,13 +639,23 @@ Point Server::interlink(const vector<Measurement> &m, const int &client_idx)cons
|
|||
* Crée la liste des points de référence dans la liste reference_point_list. */
|
||||
void Server::makeReferencePointListFromFile(const string &filename)
|
||||
{
|
||||
makePointListFromFile(reference_point_list, filename) ;
|
||||
makePointListFromFile(reference_point_list, filename, true) ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Lit le fichier de mesures (CSV) nommé "filename", et place les informations dans la liste "dest_point_list". */
|
||||
void Server::makePointListFromFile(vector<ReferencePoint> &dest_point_list, const string &filename)
|
||||
{
|
||||
makePointListFromFile(dest_point_list, filename, true) ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Lit le fichier de mesures (CSV) nommé "filename", et place les informations dans la liste "dest_point_list".
|
||||
* Si "uniq_point" est vrai, on vérifiera l'existence d'un point avant tout ajout d'information, de manière à ne pas créer de doublon : si le point existe déjà, les informations lui seront ajoutées, sinon un nouveau point sera créé dans la liste.
|
||||
* Si "uniq_point" est faux, un nouveau point sera créé pour chaque ligne du fichier.
|
||||
*/
|
||||
void Server::makePointListFromFile(vector<ReferencePoint> &dest_point_list, const string &filename, const bool uniq_point)
|
||||
{
|
||||
ifstream input_file ; // Flux d'entrée du fichier.
|
||||
char buffer[BUFFER_LENGTH]; // Buffer lu dans le fichier.
|
||||
|
@ -633,7 +663,7 @@ void Server::makePointListFromFile(vector<ReferencePoint> &dest_point_list, cons
|
|||
ReferencePoint rp;
|
||||
Point tmp_point;
|
||||
float x, y, z ; // Coordonnées des points.
|
||||
unsigned int pt_idx ; // Position du point lu dans la liste.
|
||||
unsigned int pt_idx = 0 ; // Position du point lu dans la liste.
|
||||
vector<string> infos ; // Liste des informations lues dans une ligne du fichier.
|
||||
|
||||
input_file.open(filename.c_str()) ;
|
||||
|
@ -648,7 +678,7 @@ void Server::makePointListFromFile(vector<ReferencePoint> &dest_point_list, cons
|
|||
cout << "Lecture du fichier « " << filename << " »..." ;
|
||||
int nlines = 0 ;
|
||||
int npoints = 0 ;
|
||||
#endif
|
||||
#endif // DEBUG
|
||||
|
||||
while (!input_file.eof())
|
||||
{
|
||||
|
@ -657,7 +687,7 @@ void Server::makePointListFromFile(vector<ReferencePoint> &dest_point_list, cons
|
|||
printf("\n%5d", nlines) ;
|
||||
cout << '.' ;
|
||||
nlines++ ;
|
||||
#endif
|
||||
#endif // DEBUG
|
||||
|
||||
input_file.getline(buffer, BUFFER_LENGTH);
|
||||
|
||||
|
@ -667,14 +697,15 @@ void Server::makePointListFromFile(vector<ReferencePoint> &dest_point_list, cons
|
|||
cpp_buffer = buffer;
|
||||
if (cpp_buffer.size() == 0) // Ignorer une ligne vide
|
||||
continue ;
|
||||
|
||||
infos = extractReferencePointInfoFromBuffer(cpp_buffer);
|
||||
x = string2float(infos[0]);
|
||||
y = string2float(infos[1]);
|
||||
#ifdef FRED_CSV_FORMAT
|
||||
z = DEFAULT_Z ;
|
||||
#else
|
||||
#else // FRED_CSV_FORMAT
|
||||
z = string2float(infos[2]) ;
|
||||
#endif
|
||||
#endif // FRED_CSV_FORMAT
|
||||
|
||||
/* Set point coordinates */
|
||||
tmp_point.setX(x);
|
||||
|
@ -682,50 +713,53 @@ void Server::makePointListFromFile(vector<ReferencePoint> &dest_point_list, cons
|
|||
tmp_point.setZ(z);
|
||||
|
||||
/* Use C++ string format */
|
||||
if (!pointExists(tmp_point))
|
||||
if (!uniq_point || !pointExists(dest_point_list, tmp_point)) // Si on ne veut pas de points unique, ou que le point n'existe pas encore,
|
||||
{
|
||||
rp.setCoordinates(tmp_point);
|
||||
dest_point_list.push_back(rp);
|
||||
dest_point_list.push_back(rp) ; // on le crée.
|
||||
pt_idx = dest_point_list.size() - 1 ; // Le point que l'on vient d'ajouter est le dernier du vector.
|
||||
#ifdef DEBUG
|
||||
npoints++ ;
|
||||
#endif
|
||||
#endif // DEBUG
|
||||
#ifdef DEBUG_2
|
||||
cout << tmp_point << " : ajouté." << endl ;
|
||||
#endif // DEBUG_2
|
||||
}
|
||||
else
|
||||
else // Le point existe déjà :
|
||||
{
|
||||
#ifdef DEBUG_2
|
||||
cout << tmp_point << " : existe déjà." << endl ;
|
||||
#endif
|
||||
#endif // DEBUG_2
|
||||
pt_idx = pointIndex(dest_point_list, tmp_point) ; // On recherche le point auquel on veut ajouter les informations.
|
||||
}
|
||||
pt_idx = pointIndex(tmp_point);
|
||||
|
||||
#ifdef FRED_CSV_FORMAT
|
||||
vector<int> measures_vector = extractValues(infos[4]) ;
|
||||
for (unsigned int i = 0 ; i < measures_vector.size() ; i++)
|
||||
dest_point_list[pt_idx].addMeasurement(infos[3], measures_vector[i]);
|
||||
measures_vector.clear();
|
||||
#else
|
||||
#else // FRED_CSV_FORMAT
|
||||
for (unsigned int i = 4 ; i < infos.size() ; i++)
|
||||
{
|
||||
#ifdef DEBUG_2
|
||||
cout << "Lecture de la valeur : " << infos[i] << "... " ;
|
||||
#endif
|
||||
#endif // DEBUG_2
|
||||
if (i + 1 < infos.size())
|
||||
{
|
||||
dest_point_list[pt_idx].addMeasurement(infos[i], string2int(infos[i+1])) ;
|
||||
#ifdef DEBUG_2
|
||||
cout << "Mesure ajoutée : AP = " << infos[i] << " | SS = " << string2int(infos[i+1]) << endl ;
|
||||
#endif
|
||||
#endif // DEBUG_2
|
||||
i++ ;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif // FRED_CSV_FORMAT
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
cout << '\n' << nlines << " lignes lues, " << npoints << " points différents ajoutés.\n" << endl ;
|
||||
#endif
|
||||
#endif // DEBUG
|
||||
|
||||
input_file.close();
|
||||
infos.clear() ;
|
||||
|
@ -749,7 +783,7 @@ void Server::makeApListFromFile(const string &filename)
|
|||
|
||||
#ifdef DEBUG
|
||||
cout << "Lecture du fichier « " << filename << " »..." << endl ;
|
||||
#endif
|
||||
#endif // DEBUG
|
||||
|
||||
while (!input_file.eof())
|
||||
{
|
||||
|
@ -765,7 +799,7 @@ void Server::makeApListFromFile(const string &filename)
|
|||
ap_infos = explode(buffer, ';');
|
||||
#ifdef DEBUG
|
||||
cout << "AP : " << buffer ;
|
||||
#endif
|
||||
#endif // DEBUG
|
||||
tmp_ap.setApAddr(ap_infos[0]);
|
||||
tmp_ap.setCoordinates(string2float(ap_infos[1]), string2float(ap_infos[2]), string2float(ap_infos[3]));
|
||||
tmp_ap.setFrequency(string2uint(ap_infos[4]));
|
||||
|
@ -775,13 +809,13 @@ void Server::makeApListFromFile(const string &filename)
|
|||
ap_infos.clear();
|
||||
#ifdef DEBUG
|
||||
cout << " ajouté." << endl ;
|
||||
#endif
|
||||
#endif // DEBUG
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
cout << endl ;
|
||||
#endif
|
||||
#endif // DEBUG
|
||||
|
||||
|
||||
input_file.close();
|
||||
|
@ -873,13 +907,13 @@ void Server::fastViterbiLike(const unsigned short &N, const unsigned short &K, c
|
|||
&E_current = cl.getRef_viterbi_Ecurrent(),
|
||||
&E_previous = cl.getRef_viterbi_Eprevious() ;
|
||||
vector<ReferencePoint> peregrination_point_list ;
|
||||
makePointListFromFile(peregrination_point_list, DEFAULT_TRACKING_FILE) ;
|
||||
#else
|
||||
makePointListFromFile(peregrination_point_list, DEFAULT_TRACKING_FILE, false) ;
|
||||
#else // TEST
|
||||
float **V = client_list[id_client].get_viterbi_V() ;
|
||||
vector<Point>
|
||||
&E_current = client_list[id_client].getRef_viterbi_Ecurrent(),
|
||||
&E_previous = client_list[id_client].getRef_viterbi_Eprevious() ;
|
||||
#endif
|
||||
#endif // TEST
|
||||
|
||||
int i = 1 ; // Nombre d'ensembles d'historique qu'on a déjà passés
|
||||
|
||||
|
@ -891,19 +925,20 @@ void Server::fastViterbiLike(const unsigned short &N, const unsigned short &K, c
|
|||
|
||||
#ifdef TEST
|
||||
unsigned int pt = 0 ;
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG
|
||||
cout << reference_point_list.size() << " points de référence, " << peregrination_point_list.size() << " points de pérégrination." << endl ;
|
||||
|
||||
cout << "***** Liste : *****" << endl ;
|
||||
for (int c = 0 ; c < peregrination_point_list.size() ; c++)
|
||||
cout << peregrination_point_list[c] << endl ;
|
||||
cout << "*******************" << endl ;
|
||||
#endif
|
||||
|
||||
cout << "***** Liste pts référence : *****" << endl ;
|
||||
printReferencePointList() ;
|
||||
cout << "***** Liste pérégrination : *****" << endl ;
|
||||
printPointList(peregrination_point_list) ;
|
||||
cout << "*********************************" << endl ;
|
||||
#endif // DEBUG
|
||||
|
||||
while (pt < peregrination_point_list.size())
|
||||
#else
|
||||
#else // TEST
|
||||
while (true)
|
||||
#endif
|
||||
#endif // TEST
|
||||
{
|
||||
vector<Measurement> vm ;
|
||||
|
||||
|
@ -911,14 +946,14 @@ void Server::fastViterbiLike(const unsigned short &N, const unsigned short &K, c
|
|||
/* Get point measurements */
|
||||
//vm.clear();
|
||||
vm = peregrination_point_list[pt].getMeasurementList();
|
||||
#endif
|
||||
#endif // TEST
|
||||
|
||||
E_previous = E_current ;
|
||||
E_current = getkClosestInSs(vm, K) ; // Création de l'ensemble des K points les plus proches dans l'espace des puissances.
|
||||
|
||||
#ifdef DEBUG
|
||||
cout << "Point courant : " << peregrination_point_list[pt] ;
|
||||
#endif
|
||||
#endif // DEBUG
|
||||
|
||||
if (i > 1) // Si on n'est plus à la première itération
|
||||
{
|
||||
|
@ -971,14 +1006,14 @@ void Server::fastViterbiLike(const unsigned short &N, const unsigned short &K, c
|
|||
cout << endl ;
|
||||
}
|
||||
cout << "\n--------------------------" << endl ;
|
||||
#endif
|
||||
#endif // DEBUG
|
||||
|
||||
if (i < N-1)
|
||||
i++ ;
|
||||
|
||||
#ifdef TEST
|
||||
pt++ ;
|
||||
#endif
|
||||
#endif // TEST
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -52,34 +52,52 @@ protected:
|
|||
public:
|
||||
Server(const string &ip_addr = DEFAULT_IP, const int &listen_port = DEFAULT_LISTEN_PORT);
|
||||
~Server();
|
||||
|
||||
void send_to_client(const int &cl);
|
||||
int receive_data();
|
||||
|
||||
bool pointExists(const float &x, const float &y, const float &z)const;
|
||||
unsigned int pointIndex(const float &x, const float &y, const float &z)const;
|
||||
bool pointExists(const Point &p)const;
|
||||
bool pointExists(const vector<ReferencePoint> &point_list, const float &x, const float &y, const float &z) const ;
|
||||
bool pointExists(const vector<ReferencePoint> &point_list, const Point &p) const ;
|
||||
|
||||
unsigned int pointIndex(const float &x, const float &y, const float &z)const;
|
||||
unsigned int pointIndex(const Point &p)const;
|
||||
unsigned int pointIndex(const vector<ReferencePoint> &point_list, const float &x, const float &y, const float &z) const ;
|
||||
unsigned int pointIndex(const vector<ReferencePoint> &point_list, const Point &p) const ;
|
||||
|
||||
bool apExists(const string &ap_addr)const;
|
||||
unsigned int apIndex(const string &ap_addr)const;
|
||||
unsigned int pointIndex(const Point &p)const;
|
||||
|
||||
vector<Point> getkClosestInSs(const vector<Measurement> &m, const unsigned int &k)const ;
|
||||
vector<Point> getkClosestInSs(const vector<Measurement> &m, const unsigned int &k, const Point *point_ignored)const ;
|
||||
|
||||
Point getkWeightedInSs(const vector<Measurement> &m, const unsigned int &k)const ;
|
||||
Point getkWeightedInSs(const vector<Measurement> &m, const unsigned int &k, const Point *point_ignored)const ;
|
||||
|
||||
Point kPointsAverage(const vector<Point> &vp)const;
|
||||
Point fbcm(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 makePointListFromFile(vector<ReferencePoint> &dest_point_list, const string &filename) ;
|
||||
void makePointListFromFile(vector<ReferencePoint> &dest_point_list, const string &filename, const bool uniq_point) ;
|
||||
|
||||
void makeApListFromFile(const string &filename);
|
||||
|
||||
void printReferencePointList();
|
||||
void printPointList(vector<ReferencePoint> &point_list) ;
|
||||
|
||||
void printAccessPointList();
|
||||
|
||||
void computeFriisFromRefList();
|
||||
|
||||
unsigned int getNbReferencePoints()const { return reference_point_list.size(); };
|
||||
|
||||
void fastViterbiLike(const unsigned short &N, const unsigned short &K, const unsigned int &id_client) ;
|
||||
|
||||
/* For experimentation purpose only ! */
|
||||
void radar_exp();
|
||||
|
||||
void fastViterbiLike(const unsigned short &N, const unsigned short &K, const unsigned int &id_client) ;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue