GuiNuMo : gestion topologie

server.{hh,cc} :
* Utilisation d'une map plutôt que d'une multimap pour stocker la liste
  des pièces. Conséquence : les noms des zones doivent être uniques, il
  faut donc numéroter les zones des pièces composites (par exemple
  « Couloir N1 A » et « Couloir N1 B »).
* Ajout de la fonction inWhichAreas() qui permet d'obtenir la liste des
  zones auxquelles appartient un point.
* Modification de la fonction makeWaypointDistancesFromFile() (renommée
  makeWaypointListFromFile()) de manière à ce qu'elle calcule la matrice
  des distances entre points de passage (lecture d'une liste de points).
  Abandon du format décrivant les points en visibilité (voir le fichier
  cfg/distances.csv, supprimé à cette révision), puisque nous nous
  servons des points de passage et de la description des zones pour
  calculer les liens entre points. RESTE À FAIRE : prise en comppte de
  la topologie dans le calcul de distance.
* Ajout de deux fonctions areaConnection() qui permettent de récupérer
  la liste des points de passage d'une zone, ou faisant l'intersection
  entre deux zones.
* Ajout de la fonction distanceTopology, qui calcule la distance entre
  deux points en tenant compte de la topologie (zones et points de
  passage entre elles).
* Ajout de la fonction makeReferencePointDistances(), qui calcule les
  distances entre points de référence, en tenant compte de la
  topologie.
* Ajout de la fonction point_vector_idx(), semblable à point_tab_idx()
  mais pour un vector<Point>.

referencepoint.{hh,cc} :
* Ajout de l'operator de cast en Point (operator Point()).

area.{hh,cc} :
* Ajout de l'operator==(Area).

cfg/distances.csv
* Suppression de ce fichier obsolète.

git-svn-id: https://pif.pu-pm.univ-fcomte.fr/svn/loc@47 785a6c6c-259e-4ff1-8b91-dc31627914f0
This commit is contained in:
Matteo Cypriani 2008-06-25 14:19:07 +00:00
parent 03b4143100
commit 085b348670
7 changed files with 454 additions and 125 deletions

View File

@ -43,6 +43,23 @@ bool Area::containsPoint(const Point &p)const
bool Area::operator==(const Area &a)const
{
if (area_name == a.area_name &&
x_min == a.x_min &&
x_max == a.x_max &&
y_min == a.y_min &&
y_max == a.y_max &&
z_min == a.z_min &&
z_max == a.z_max
)
return true ;
return false ;
}
ostream &operator<<(ostream &os, const Area &a)
{
os << a.area_name << ';' << a.x_min << ';' << a.x_max << ';' << a.y_min << ';' << a.y_max << ';' << a.z_min << ';' << a.z_max ;

View File

@ -42,6 +42,7 @@ public:
void setZmin(const float &v) { z_min = v; } ;
void setZmax(const float &v) { z_max = v; } ;
bool operator==(const Area &a)const ;
friend ostream &operator<<(ostream &os, const Area &a) ;
};

View File

@ -1,25 +0,0 @@
# Pour chaque pièce on prend le point (0;3) du référentiel pièce.
# X;Y;Z;D1;X1;Y1;Z1;D2;X2;Y2;Z2;…;Dn;Xn;Yn;Zn
# Le point (X;Y;Z) est en visibilité du point (Xn;Yn;Zn). Dn est un entier dont la valeur est égale à 1 si le lien est bidirectionnel, et à 0 s'il est unidirectionnel (auquel cas le lien sera enregistré comme allant uniquement de (X;Y;Z) à (Xn;Yn;Zn)).
# Pour chaque point, on enregistre seulement les points en visibilité directe les plus proche dans chaque direction ; autrement dit, si trois points A, B et C sont alignés, ou du moins suffisamment alignés pour qu'en se positionnant sur A et en regardant vers B on voit aussi C, alors on enregistre le lien de A vers B et le lien de B vers C, mais pas celui de A vers C.
# 1100
3.00;5.48;3.00;1;7.50;7.00;3.00
# 0190
3.00;9.09;3.00;1;7.50;7.00;3.00
# 0180
3.00;12.67;3.00;1;8.00;14.00;3.00
# 1070
3.00;16.30;3.00;1;8.00;14.00;3.00
# 1060 (Vérifier coordonnées)
4.00;22.00;3.00;1;7.50;22.00;3.00
# 1050
4.00;28.00;3.00;1;7.50;28.00;3.00
# CouloirN1
7.50;7.00;3.00;1;8.00;14.00;3.00;1;7.50;22.00;3.00;1;7.50;28.00;3.00
1 # Pour chaque pièce on prend le point (0;3) du référentiel pièce.
2 # X;Y;Z;D1;X1;Y1;Z1;D2;X2;Y2;Z2;…;Dn;Xn;Yn;Zn
3 # Le point (X;Y;Z) est en visibilité du point (Xn;Yn;Zn). Dn est un entier dont la valeur est égale à 1 si le lien est bidirectionnel, et à 0 s'il est unidirectionnel (auquel cas le lien sera enregistré comme allant uniquement de (X;Y;Z) à (Xn;Yn;Zn)).
4 # Pour chaque point, on enregistre seulement les points en visibilité directe les plus proche dans chaque direction ; autrement dit, si trois points A, B et C sont alignés, ou du moins suffisamment alignés pour qu'en se positionnant sur A et en regardant vers B on voit aussi C, alors on enregistre le lien de A vers B et le lien de B vers C, mais pas celui de A vers C.
5 # 1100
6 3.00;5.48;3.00;1;7.50;7.00;3.00
7 # 0190
8 3.00;9.09;3.00;1;7.50;7.00;3.00
9 # 0180
10 3.00;12.67;3.00;1;8.00;14.00;3.00
11 # 1070
12 3.00;16.30;3.00;1;8.00;14.00;3.00
13 # 1060 (Vérifier coordonnées)
14 4.00;22.00;3.00;1;7.50;22.00;3.00
15 # 1050
16 4.00;28.00;3.00;1;7.50;28.00;3.00
17 # CouloirN1
18 7.50;7.00;3.00;1;8.00;14.00;3.00;1;7.50;22.00;3.00;1;7.50;28.00;3.00

View File

@ -1,5 +1,7 @@
#include "referencepoint.hh"
float ReferencePoint::getSsSquareDistance(const vector<Measurement> &m)const
{
unsigned int i, j;
@ -24,6 +26,8 @@ float ReferencePoint::getSsSquareDistance(const vector<Measurement> &m)const
return ret;
}
void ReferencePoint::addMeasurement(const string &mac_a, const int &value)
{
unsigned int i;
@ -45,6 +49,34 @@ void ReferencePoint::addMeasurement(const string &mac_a, const int &value)
}
}
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]);
}
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)
@ -55,6 +87,8 @@ ReferencePoint ReferencePoint::operator=(const ReferencePoint &rp)
return *this;
}
ostream &operator<<(ostream &os, ReferencePoint &rp)
{
unsigned int i;
@ -69,26 +103,10 @@ ostream &operator<<(ostream &os, ReferencePoint &rp)
return os;
}
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]);
}
for (i = 0 ; i < measurement_list.size() ; i++)
if(measurement_list[i].getMacAddr() == str)
{
*p = measurement_list[i].getAverage();
return true;
}
return false;
/* Opérateur de cast en Point */
ReferencePoint::operator Point() const
{
return coordinates ;
}

View File

@ -19,14 +19,17 @@ public:
ReferencePoint(const ReferencePoint &rp) { coordinates = rp.coordinates; measurement_list = rp.measurement_list; };
ReferencePoint(const Point &c) { coordinates = c; };
~ReferencePoint() { measurement_list.clear(); };
float getSsSquareDistance(const vector<Measurement> &m)const;
Point getCoordinates()const { return coordinates; };
void addMeasurement(const string &mac_a, const int &value);
void setCoordinates(const Point &p) { coordinates = p; };
vector<Measurement> getMeasurementList() const { return measurement_list; } ;
bool getPowerForAp(const string &ap_mac, float *p) const ;
ReferencePoint operator=(const ReferencePoint &rp);
operator Point() const ;
friend ostream &operator<<(ostream &os, ReferencePoint &rp);
vector<Measurement> getMeasurementList()const { return measurement_list; };
bool getPowerForAp(const string &ap_mac, float *p)const;
};
#endif

View File

@ -17,6 +17,18 @@ inline int point_tab_idx(const Point *tab, unsigned int &size, const Point &p)
/* Retourne la position du Point "p" dans le vector "v", ou -1 en cas d'échec. */
inline int point_vector_idx(const vector<Point> &v, const Point &p)
{
for (unsigned int i = 0 ; i < v.size() ; i++)
if (v[i] == p)
return i ;
return -1 ;
}
/* Explodes a string into substrings based on separator sep. Returns a string vector. */
inline vector<string> explode(const string &input, const char &sep)
{
@ -225,7 +237,8 @@ Server::Server(const string &ip_addr, const int &listen_port)
makeReferencePointListFromFile(DEFAULT_REF_POINT_FILE) ; // Initialisation de "reference_point_list".
makeApListFromFile(DEFAULT_AP_FILE) ; // Initialisation de "access_point_list".
makeTopologyFromFile(DEFAULT_TOPOLOGY_FILE) ; // Initialisation de "area_list".
makeWaypointDistancesFromFile(DEFAULT_DISTANCE_FILE) ; // Initialisation de "waypoint_indexes" et "waypoint_matrix".
makeWaypointListFromFile(DEFAULT_WAYPOINT_FILE) ; // Initialisation de "waypoint_list" et "waypoint_matrix".
makeReferencePointDistances() ; // Initialisation de "reference_point_matrix".
#ifdef DEBUG_T
cout << "//<-- Server::Server()" << endl ; fflush(stdout) ;
@ -268,6 +281,228 @@ int Server::receive_data()
/* Cherche dans quelle(s) zone(s) se situe un point.
* Retourne une map<string, Area> contenant la liste des zones auxquelles le Point "p" appartient.
*/
map<string, Area> Server::inWhichAreas(const Point &p)
{
#ifdef DEBUG_T
cout << "//--> Server::inWhichAreas()" << endl ; fflush(stdout) ;
#endif // DEBUG_T
map<string, Area> areas ;
for (map<string, Area>::iterator it = area_list.begin() ; it != area_list.end() ; it++)
if (it->second.containsPoint(p))
areas.insert(make_pair(it->first, it->second)) ;
#ifdef DEBUG_T
cout << "//<-- Server::inWhichAreas()" << endl ; fflush(stdout) ;
#endif // DEBUG_T
return areas ;
}
/* Cherche les points de passage communs aux zones "z1" et "z2".
* Retourne un vector<Point> contenant la liste de ces points.
*/
vector<Point> Server::areaConnection(const Area &z1, const Area &z2)
{
#ifdef DEBUG_T
cout << "//--> Server::areaConnection(Area&, Area&)" << endl ; fflush(stdout) ;
#endif // DEBUG_T
vector<Point> points ;
for (unsigned int i = 0 ; i < reference_point_list.size() ; i++)
{
map<string, Area> areas(inWhichAreas(reference_point_list[i])) ;
if (areas.find(z1.getName()) != areas.end() && areas.find(z2.getName()) != areas.end())
points.push_back(reference_point_list[i]) ;
}
#ifdef DEBUG_T
cout << "//<-- Server::areaConnection(Area&, Area&)" << endl ; fflush(stdout) ;
#endif // DEBUG_T
return points ;
}
/* Cherche les points de passage de la zone "z".
* Retourne un vector<Point> contenant la liste de ces points.
*/
vector<Point> Server::areaConnection(const Area &z)
{
#ifdef DEBUG_T
cout << "//--> Server::areaConnection(Area&)" << endl ; fflush(stdout) ;
#endif // DEBUG_T
vector<Point> points ;
for (unsigned int i = 0 ; i < reference_point_list.size() ; i++)
{
map<string, Area> areas(inWhichAreas(reference_point_list[i])) ;
if (areas.find(z.getName()) != areas.end())
points.push_back(reference_point_list[i]) ;
}
#ifdef DEBUG_T
cout << "//<-- Server::areaConnection(Area&)" << endl ; fflush(stdout) ;
#endif // DEBUG_T
return points ;
}
/* Calcule la distance entre les points "p1" et "p2" en tenant compte de la topologie.
*/
float Server::distanceTopology(const Point &p1, const Point &p2)
{
#ifdef DEBUG_T
cout << "//--> Server::distanceTopology()" << endl ; fflush(stdout) ;
#endif // DEBUG_T
map<string, Area>
zones1(inWhichAreas(p1)),
zones2(inWhichAreas(p2)) ;
if (zones1.size() == 0 || zones2.size() == 0) // Si aucune zone ne contient p1 ou p2,
{
#ifdef DEBUG_T
cout << "//<-- Server::distanceTopology()" << endl ; fflush(stdout) ;
#endif // DEBUG_T
return -1 ; // on quitte.
}
Area
z1(zones1.begin()->second), // Première zone d'appartenance du point p1. // FIXME : vérifier toutes les zones
z2(zones2.begin()->second) ;
vector<Point> connection ;
/* *** Cas de la même zone *** */
if (z1 == z2) // Si les points sont dans la même zone,
{
#ifdef DEBUG_T
cout << "//<-- Server::distanceTopology()" << endl ; fflush(stdout) ;
#endif // DEBUG_T
return p1.distance(p2) ; // la distance entre eux est la distance euclidienne.
}
/* *** Cas de deux zones voisines *** */
if ((connection = areaConnection(z1, z2)).size() != 0) // Si les points sont dans deux zones voisines,
{ // la distance entre eux est la distance euclidienne de chacun jusqu'au plus proche point de passage entre les deux zones.
float dist = p1.distance(connection[0]) + p2.distance(connection[0]) ;
for (unsigned int i = 1 ; i < connection.size() ; i++) // Recherche du point de passage offrant la plus courte distance
{
float tmp_dist = p1.distance(connection[i]) + p2.distance(connection[i]) ;
if (tmp_dist < dist)
dist = tmp_dist ;
}
#ifdef DEBUG_T
cout << "//<-- Server::distanceTopology()" << endl ; fflush(stdout) ;
#endif // DEBUG_T
return dist ;
}
/* *** Les points sont dans des zones non-voisines *** */
vector<Point> // Liste des points de passage appartenant respectivement à z1 et à z2.
wp_z1(areaConnection(z1)),
wp_z2(areaConnection(z2)) ;
int // Indices des points de passage dans la liste :
wp_z1_idx,
wp_z2_idx = -1 ; // z2 ne peut pas être utilisé non initialisé, contrairement à ce que dit GCC, car dans le cas où il n'est pas initialisé on quitte la fonction avant de l'utiliser (cf. "return -1" un peu plus bas);
if (wp_z1.size() == 0 || wp_z2.size() == 0) // Si l'une des deux zones ne comporte aucun point de passage,
{
#ifdef DEBUG_T
cout << "//<-- Server::distanceTopology()" << endl ; fflush(stdout) ;
#endif // DEBUG_T
return -1 ; // on quitte (ceci ne devrait jamais se produire).
}
/* Première itération (voir explication de l'algorithme plus bas) */
unsigned int i1, i2 ;
for (i1 = 0 ; i1 < wp_z1.size() ; i1++) // Recherche des premiers indices valides (où il existe un chemin entre les points de passage)
{
wp_z1_idx = point_vector_idx(waypoint_list, wp_z1[i1]) ;
for (i2 = 0 ; i2 < wp_z2.size() ; i2++)
{
wp_z2_idx = point_vector_idx(waypoint_list, wp_z2[i2]) ;
if (waypoint_matrix[wp_z1_idx][wp_z2_idx] != -1) // Si c'est bon,
break ; // on arrête le parcours.
}
if (waypoint_matrix[wp_z1_idx][wp_z2_idx] != -1) // Si c'est bon,
break ; // on arrête le parcours.
}
if (i1 >= wp_z1.size()) // Si on a parcouru tout le tableau sans trouver de chemin,
{
#ifdef DEBUG_T
cout << "//<-- Server::distanceTopology()" << endl ; fflush(stdout) ;
#endif // DEBUG_T
return -1 ; // on quitte.
}
float
dist = p1.distance(wp_z1[i1]) + waypoint_matrix[wp_z1_idx][wp_z2_idx] + p2.distance(wp_z2[i2]),
tmp_dist ;
for (unsigned int j = i2 + 1 ; j < wp_z2.size() ; j++) // Fin du parcours :
{
wp_z2_idx = point_vector_idx(waypoint_list, wp_z2[j]) ;
if (waypoint_matrix[wp_z1_idx][wp_z2_idx] == -1)
continue ;
tmp_dist = p1.distance(wp_z1[i1]) + waypoint_matrix[wp_z1_idx][wp_z2_idx] + p2.distance(wp_z2[j]) ;
if (tmp_dist < dist)
dist = tmp_dist ;
}
/* Itérations suivantes */
for (unsigned int i = i1 + 1 ; i < wp_z1.size() ; i++)
for (unsigned int j = 0 ; j < wp_z2.size() ; j++)
{
// Indice des points de passage wp_z1[i] et wp_z2[j] dans la liste des points de passage :
wp_z1_idx = point_vector_idx(waypoint_list, wp_z1[i]) ;
wp_z2_idx = point_vector_idx(waypoint_list, wp_z2[j]) ;
if (waypoint_matrix[wp_z1_idx][wp_z2_idx] == -1) // S'il n'existe aucun chemin entre les deux points de passage
continue ;
/* La distance entre p1 et p2 est égale à la somme de :
* - la distance entre p1 et le point de passage courant de z1
* (distance cartésienne car ils appartiennent à la même zone),
* - la distance entre p2 et le point de passage courant de z2 (idem),
* - la distance entre les deux points de passages suscités, qui est
* donnée par la matrice des distances entre points de passage
* (waypoint_matrix).
* On conservera bien sûr la somme qui donne le chemin le plus court.
*/
tmp_dist = p1.distance(wp_z1[i]) + waypoint_matrix[wp_z1_idx][wp_z2_idx] + p2.distance(wp_z2[j]) ;
if (tmp_dist < dist)
dist = tmp_dist ;
}
#ifdef DEBUG_T
cout << "//<-- Server::distanceTopology()" << endl ; fflush(stdout) ;
#endif // DEBUG_T
return dist ;
}
/* 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
@ -907,7 +1142,8 @@ Point Server::interlink(const vector<Measurement> &m, const int &client_idx)cons
/* FONCTION POUR RÉTRO-COMPATIBILITÉ.
* Crée la liste des points de référence dans la liste reference_point_list. */
* Crée la liste des points de référence dans la liste reference_point_list.
*/
void Server::makeReferencePointListFromFile(const string &filename)
{
#ifdef DEBUG_T
@ -1126,6 +1362,7 @@ void Server::makeApListFromFile(const string &filename)
/* Lit la liste des zones homogènes du bâtiment (pièces) dans le fichier "filename", et place le résultat dans "area_list". */
void Server::makeTopologyFromFile(const string &filename)
{
#ifdef DEBUG_T
@ -1162,10 +1399,15 @@ void Server::makeTopologyFromFile(const string &filename)
#ifdef DEBUG
cout << "Pièce : " << buffer ;
#endif // DEBUG
area_list.insert(make_pair(infos[0], Area(infos[0], string2float(infos[1]), string2float(infos[2]), string2float(infos[3]), string2float(infos[4]), string2float(infos[5]), string2float(infos[6])))) ;
if (area_list.find(infos[0]) != area_list.end()) // Si la pièce existe déjà,
cerr << "Erreur ! Déclaration multiple de la zone « " << infos[0] << " »." << endl ; // on le signale ;
else // sinon on l'ajoute :
{
area_list[infos[0]] = Area(infos[0], string2float(infos[1]), string2float(infos[2]), string2float(infos[3]), string2float(infos[4]), string2float(infos[5]), string2float(infos[6])) ;
#ifdef DEBUG
cout << " ajoutée." << endl ;
cout << " ajoutée." << endl ;
#endif // DEBUG
}
infos.clear() ;
}
@ -1173,7 +1415,7 @@ void Server::makeTopologyFromFile(const string &filename)
#ifdef DEBUG
cout << "--> Liste des pièces (" << area_list.size() << ") :" << endl ;
for (multimap<string, Area>::iterator it = area_list.begin() ; it != area_list.end() ; it++)
for (map<string, Area>::iterator it = area_list.begin() ; it != area_list.end() ; it++)
cout << it->first << " : " << it->second << endl ;
cout << endl ;
#endif // DEBUG
@ -1187,22 +1429,28 @@ void Server::makeTopologyFromFile(const string &filename)
void Server::makeWaypointDistancesFromFile(const string &filename)
/* Lit la liste des points de passage dans le fichier "filename" et calcule les distances entre eux. Initialise waypoint_list et waypoint_matrix.
* TODO : tenir compte de la topologie pour les distances entre points.
*/
void Server::makeWaypointListFromFile(const string &filename)
{
#ifdef DEBUG_T
cout << "//--> Server::makeWaypointDistancesFromFile()" << endl ; fflush(stdout) ;
cout << "//--> Server::makeWaypointListFromFile()" << endl ; fflush(stdout) ;
#endif // DEBUG_T
ifstream input_file ;
char buffer[BUFFER_LENGTH] ;
vector<string> infos ;
map<Point, vector<Point> > point_list ;
Point p_cur, p_tmp ;
set<Point> point_list ;
// Point p_cur, p_tmp ;
input_file.open(filename.c_str());
if (input_file.fail())
{
cerr << "Error opening input file « " << filename << " » !" << endl ;
#ifdef DEBUG_T
cout << "//<-- Server::makeWaypointListFromFile()" << endl ; fflush(stdout) ;
#endif // DEBUG_T
return ;
}
@ -1223,33 +1471,19 @@ void Server::makeWaypointDistancesFromFile(const string &filename)
infos = explode(buffer, ';') ;
#ifdef DEBUG
cout << "Lien : " << buffer ; fflush(stdout);
cout << "Point de passage : " << buffer ; fflush(stdout);
#endif // DEBUG
p_cur = Point(string2float(infos[0]), string2float(infos[1]), string2float(infos[2])) ; // On récupère le point courant (le premier de la ligne)
for (unsigned int i = 3 ; i < infos.size() ; i++) // Récupération et ajout des autres points
{
char direction = string2int(infos[i++]) ;
float coord[3] ;
unsigned int j ;
for (j = 0 ; j < 3 && i < infos.size() ; i++, j++)
coord[j] = string2float(infos[i]) ;
if (j == 3) // Si on est allé jusqu'au bout
{
p_tmp = Point(coord) ;
point_list[p_cur].push_back(p_tmp) ;
if (direction != 0) // Si le lien est bidirectionnel
point_list[p_tmp].push_back(p_cur) ;
}
}
/* Ajout du point lu */
Point tmp_pt(string2float(infos[0]), string2float(infos[1]), string2float(infos[2])) ;
if (! point_list.insert(tmp_pt).second)
cerr << "Point " << tmp_pt << " dupliqué !" << endl ;
else
#ifdef DEBUG
cout << " traité." << endl ; fflush(stdout);
#endif // DEBUG
infos.clear() ;
#ifdef DEBUG
cout << " traité." << endl ; fflush(stdout);
#endif // DEBUG
}
}
@ -1258,48 +1492,40 @@ void Server::makeWaypointDistancesFromFile(const string &filename)
/* Construction de la matrice */
unsigned int nb_pts = point_list.size() ; // Nombre de points
waypoint_indexes = new Point[nb_pts] ; // Tableau contenant tous les points (attribut du serveur)
waypoint_matrix = new float*[nb_pts] ; // Matrice des distances entre les points (attribut du serveur)
int cur_idx = 0, tmp_idx = -1 ; // Itérateurs sur les indices des tableaux
unsigned int cur_idx = 0 ; // Itérateur sur l'indice de la matrice.
waypoint_list.reserve(nb_pts) ; // Vector contenant tous les points (attribut du serveur)
waypoint_matrix = new float*[nb_pts] ; // Matrice (carrée) des distances entre les points de passage (attribut du serveur)
for (unsigned int i = 0 ; i < nb_pts ; i++) // Initialisation de la matrice :
{
waypoint_matrix[i] = new float[nb_pts] ;
for (unsigned int k = 0 ; k < nb_pts ; k++) // Initialisation des distances à -1
waypoint_matrix[i][k] = -1 ;
}
#ifdef DEBUG
cout << "--> Liste des points de référence (" << nb_pts << ") :" << endl ; fflush(stdout);
cout << "--> Liste des points de passage (" << nb_pts << ") :" << endl ; fflush(stdout);
#endif // DEBUG
for (map<Point, vector<Point> >::iterator it = point_list.begin() ; it != point_list.end() ; it++) // Pour chaque point enregistré dans le hash
/* Calcul des distances */
for (set<Point>::iterator it = point_list.begin() ; it != point_list.end() ; it++, cur_idx++) // Pour chaque point enregistré
{
#ifdef DEBUG
cout << it->first << " :" ;
cout << *it << " :" ;
#endif // DEBUG
if ((tmp_idx = point_tab_idx(waypoint_indexes, nb_pts, it->first)) == -1) // Si le point n'existe pas encore dans la matrice, on le crée :
{
waypoint_indexes[cur_idx] = it->first ;
waypoint_matrix[cur_idx] = new float[nb_pts] ;
for (unsigned int k = 0 ; k < nb_pts ; k++) // Initialisation des distances à -1
waypoint_matrix[cur_idx][k] = -1 ;
tmp_idx = cur_idx++ ;
}
waypoint_list[cur_idx] = *it ; // Ajout du point dans waypoint_list // FIXME : utiliser plutôt push_back() ?
waypoint_matrix[cur_idx][cur_idx] = 0 ; // La distance du point à lui-même est nulle
for (unsigned int k = 0 ; k < it->second.size() ; k++) // Pour chaque point associé au point courant,
{
for (unsigned int k = 0 ; k < cur_idx ; k++) // Pour chacun des point précédent
{
#ifdef DEBUG
cout << " / " << it->second[k] ;
cout << " / " << waypoint_list[k] ;
#endif // DEBUG
int tmp_idx_2 = point_tab_idx(waypoint_indexes, nb_pts, it->second[k]) ; // Recherche du point associé.
if (tmp_idx_2 == -1) // Si le point associé n'existe pas encore dans la matrice, on le crée :
{
waypoint_indexes[cur_idx] = it->second[k] ;
waypoint_matrix[cur_idx] = new float[nb_pts] ;
for (unsigned int k = 0 ; k < nb_pts ; k++) // Initialisation des distances à -1
waypoint_matrix[cur_idx][k] = -1 ;
tmp_idx_2 = cur_idx++ ;
}
waypoint_matrix[tmp_idx][tmp_idx_2] = waypoint_indexes[tmp_idx].distance(it->second[k]) ; // it->second[k] n'existe pas forcément !
}
float dist = it->distance(waypoint_list[k]) ; // On calcule la distance
waypoint_matrix[cur_idx][k] = dist ; // et on l'insère dans le tableau,
waypoint_matrix[k][cur_idx] = dist ; // dans les deux sens.
}
#ifdef DEBUG
cout << " /" << endl ;
@ -1309,13 +1535,13 @@ void Server::makeWaypointDistancesFromFile(const string &filename)
#ifdef DEBUG
/* Affichage de la matrice */
cout << "--> Matrice des distances :\n\t\t|" ;
cout << "--> Matrice des distances entre points de passage :\n\t\t|" ;
for (unsigned int k = 0 ; k < nb_pts ; k++)
cout << ' ' << waypoint_indexes[k] << "\t|" ;
cout << ' ' << waypoint_list[k] << "\t|" ;
cout << endl ;
for (unsigned int k = 0 ; k < nb_pts ; k++)
{
cout << waypoint_indexes[k] << "\t|" ;
cout << waypoint_list[k] << "\t|" ;
for (unsigned int l = 0 ; l < nb_pts ; l++)
cout << '\t' << waypoint_matrix[k][l] << "\t|" ;
cout << endl ;
@ -1326,7 +1552,88 @@ void Server::makeWaypointDistancesFromFile(const string &filename)
#ifdef DEBUG_T
cout << "//<-- Server::makeWaypointDistancesFromFile()" << endl ; fflush(stdout) ;
cout << "//<-- Server::makeWaypointListFromFile()" << endl ; fflush(stdout) ;
#endif // DEBUG_T
}
/* Calcule la distance entre tous les points de référence en tenant compte de la topologie (initialise reference_point_matrix).
* /!\ La liste des *points de passage*, leur *matrice de distances*, ainsi que la liste des *points de référence*, DOIVENT ÊTRE INITIALISÉES avant l'appel à cette fonction. Il faut donc appeler makeWaypointListFromFile() et makeReferencePointListFromFile() avant makeReferencePointDistances().
*/
void Server::makeReferencePointDistances()
{
#ifdef DEBUG_T
cout << "//--> Server::makeReferencePointDistances()" << endl ; fflush(stdout) ;
#endif // DEBUG_T
unsigned int nb_pts = reference_point_list.size() ; // Nombre de points à traiter.
/* Construction de la matrice des distances */
reference_point_matrix = new float*[nb_pts] ; // Allocation de la première dimension.
for (unsigned int i = 0 ; i < nb_pts ; i++) // Initialisation de la matrice :
{
reference_point_matrix[i] = new float[nb_pts] ;
for (unsigned int k = 0 ; k < nb_pts ; k++) // Initialisation des distances à -1
reference_point_matrix[i][k] = -1 ;
}
#ifdef DEBUG
cout << "--> Liste des points de référence (" << nb_pts << ") :" << endl ; fflush(stdout);
#endif // DEBUG
/* Calcul des distances */
for (unsigned int cur_idx = 0 ; cur_idx < nb_pts ; cur_idx++)
{
#ifdef DEBUG
cout << (Point) reference_point_list[cur_idx] ;
#ifdef DEBUG_2
cout << " :" ;
#endif // DEBUG_2
#endif // DEBUG
reference_point_matrix[cur_idx][cur_idx] = 0 ; // La distance du point à lui-même est nulle
for (unsigned int k = 0 ; k < cur_idx ; k++) // Pour chacun des point précédent
{
#ifdef DEBUG_2
cout << " / " << (Point) reference_point_list[k] ;
#endif // DEBUG_2
float dist = distanceTopology((Point) reference_point_list[cur_idx], (Point) reference_point_list[k]) ; // On calcule la distance
reference_point_matrix[cur_idx][k] = dist ; // et on l'insère dans le tableau,
reference_point_matrix[k][cur_idx] = dist ; // dans les deux sens.
}
#ifdef DEBUG
#ifdef DEBUG_2
cout << " /" ;
#endif // DEBUG_2
cout << endl ;
#endif // DEBUG
}
#ifdef DEBUG_2
/* Affichage de la matrice */
cout << "--> Matrice des distances entre points de référence :\n\t\t|" ;
for (unsigned int k = 0 ; k < nb_pts ; k++)
cout << ' ' << (Point) reference_point_list[k] << "\t|" ;
cout << endl ;
for (unsigned int k = 0 ; k < nb_pts ; k++)
{
cout << (Point) reference_point_list[k] << "\t|" ;
for (unsigned int l = 0 ; l < nb_pts ; l++)
cout << '\t' << reference_point_matrix[k][l] << "\t|" ;
cout << endl ;
}
cout << endl ;
#endif // DEBUG_2
#ifdef DEBUG_T
cout << "//<-- Server::makeReferencePointDistances()" << endl ; fflush(stdout) ;
#endif // DEBUG_T
}
@ -1542,10 +1849,10 @@ void Server::monitorClient(const unsigned int &client_id, const ALGORITHM &algo)
#endif // TEST
#endif // DEBUG
#ifdef DEBUG_2
cout << "***** Liste pts référence : *****" << endl ;
cout << "***** Liste des points de référence : *****" << endl ;
printReferencePointList() ;
#ifdef TEST
cout << "***** Liste pérégrination : *****" << endl ;
cout << "***** Liste des points de pérégrination : *****" << endl ;
printPointList(peregrination_point_list) ;
#endif // TEST
cout << "*********************************" << endl ;

View File

@ -4,6 +4,7 @@
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <fstream>
#include <sstream>
@ -34,7 +35,7 @@ typedef ClientInfo::float_index float_index ;
#define DEFAULT_AP_FILE "cfg/minipc.cfg" // Fichier de configuration des AP
#define DEFAULT_TRACKING_FILE "csv/agreg/divagation6_10_25000.csv" // Fichier de prérégrination
#define DEFAULT_TOPOLOGY_FILE "cfg/topo.csv"
#define DEFAULT_DISTANCE_FILE "cfg/distances.csv"
#define DEFAULT_WAYPOINT_FILE "cfg/waypoints.csv"
#define DEFAULT_IP "127.0.0.1"
#define DEFAULT_LISTEN_PORT 7777
#define LIGHT_SPEED 300000000
@ -53,12 +54,13 @@ typedef enum { ALGO_VLI = 1, ALGO_BASIC_FRBHM } ALGORITHM ;
class Server
{
protected:
vector<ClientInfo> client_list ; // Liste des clients connus
vector<ReferencePoint> reference_point_list ; // Liste des points de référence (calibration)
vector<AccessPoint> access_point_list ; // Liste des AP connus
multimap<string, Area> area_list ; // Liste des zones homogènes (pièces)
Point *waypoint_indexes ; // Liste des points de parcours
float **waypoint_matrix ; // Matrice des distances entre les points de parcours
vector<ClientInfo> client_list ; // Liste des clients connus.
map<string, Area> area_list ; // Liste des zones homogènes (pièces).
vector<ReferencePoint> reference_point_list ; // Liste des points de référence (calibration).
vector<AccessPoint> access_point_list ; // Liste des AP connus.
float **reference_point_matrix ; // Matrice des distances entre les points de référence.
vector<Point> waypoint_list ; // Liste des points de passage entre les zones.
float **waypoint_matrix ; // Matrice des distances entre les points de passage.
struct sockaddr_in server_addr;
int sockListen;
int sockSend;
@ -72,6 +74,11 @@ public:
ClientInfo& createClient() ;
map<string, Area> inWhichAreas(const Point &p) ;
vector<Point> areaConnection(const Area &z1, const Area &z2) ;
vector<Point> areaConnection(const Area &z) ;
float distanceTopology(const Point &p1, const Point &p2) ;
bool pointExists(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 ;
@ -101,7 +108,8 @@ public:
void makePointListFromFile(vector<ReferencePoint> &dest_point_list, const string &filename, const bool uniq_point) ;
void makeApListFromFile(const string &filename);
void makeTopologyFromFile(const string &filename) ;
void makeWaypointDistancesFromFile(const string &filename) ;
void makeWaypointListFromFile(const string &filename) ;
void makeReferencePointDistances() ;
void printReferencePointList();
void printPointList(vector<ReferencePoint> &point_list) ;