|
|
|
@ -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 ;
|
|
|
|
|