Additions/changes in server & clientinfo

Préparation à la séparation de Server::fastViterbiLike() en deux
fonctions : monitorClient() qui contiendra tous les traitements
génériques aux algorithmes de calcul de la position, et
fastViterbiLike() qui ne contiendra que le calcul en lui-même. Ceci afin
de permettre l'ajout aisé d'autres algorithmes.

guinumo.hh : fichier d'en-tête global avec les #define de débogage.

clientinfo.{hh,cc} :
* Ajout d'un constructeur par copie.
* Ajout des opérateurs = et ==.
* Ajout de viterbi_iteration et son accesseur getRef_viterbi_iteration().
* Ajout de print_viterbi_V().
* Changement du type de viterbi_V : passage d'un tableau classique à un
  multi_array de la bibliothèque Boost.
* Ajout d'informations de débogage (trace).

server.{hh,cc} :
* Adaptation pour viterbi_V.
* Ajout de createClient() pour ajouter un client à client_list.
* Ajout d'informations de débogage (trace).

git-svn-id: https://pif.pu-pm.univ-fcomte.fr/svn/loc@41 785a6c6c-259e-4ff1-8b91-dc31627914f0
This commit is contained in:
Matteo Cypriani 2008-06-11 15:04:50 +00:00
parent 4844c58cd0
commit 1b222af80c
7 changed files with 213 additions and 42 deletions

View File

@ -1,7 +1,7 @@
GXX=g++ GXX=g++
GXXFLAGS=-Wall -O2 GXXFLAGS=-g -Wall -pedantic -O2
LD=g++ LD=g++
LDFLAGS=-Wall -lm -O2 LDFLAGS=-g -Wall -pedantic -lm -O2
HEADER= HEADER=

View File

@ -3,29 +3,138 @@
ClientInfo::ClientInfo(const string &ip, const int &port, const float &antg) ClientInfo::ClientInfo(const string &ip, const int &port, const float &antg)
{ {
#ifdef DEBUG_T
cout << "//--> ClientInfo::ClientInfo()" << endl ; fflush(stdout) ;
#endif // DEBUG_T
client_ip = ip; client_ip = ip;
antenna_gain = antg; antenna_gain = antg;
client_listen_port = port; client_listen_port = port;
int N = VITERBI_N, K = VITERBI_K ; viterbi_iteration = 1 ;
viterbi_V = new float*[N-1] ;
for (int n=0 ; n < N-1 ; n++)
{
viterbi_V[n] = new float[K] ;
for (int k=0 ; k < K ; k++)
viterbi_V[n][k] = 0 ;
}
int N = VITERBI_N, K = VITERBI_K ;
viterbi_V.resize(boost::extents[N-1][K]) ; // Allocation du tableau à la bonne taille (les cases sont initialisées à 0 automatiquement).
#ifdef DEBUG_T
cout << "//<-- ClientInfo::ClientInfo()" << endl ; fflush(stdout) ;
#endif // DEBUG_T
} }
ClientInfo::ClientInfo(const ClientInfo &c)
{
#ifdef DEBUG_T
cout << "//--> ClientInfo::ClientInfo(ClientInfo)" << endl ; fflush(stdout) ;
#endif // DEBUG_T
client_ip = c.client_ip ;
antenna_gain = c.antenna_gain ;
client_listen_port = c.client_listen_port ;
viterbi_iteration = c.viterbi_iteration ;
const float_array::size_type *s = c.viterbi_V.shape() ; // Récupération des dimensions de c.viterbi_V.
viterbi_V.resize(boost::extents[s[0]][s[1]]) ; // Redimensionnement de viterbi_V aux dimensions de c.viterbi_V.
viterbi_V = c.viterbi_V ; // Copie du contenu de c.viterbi_V dans viterbi_V.
#ifdef DEBUG_T
cout << "//<-- ClientInfo::ClientInfo(ClientInfo)" << endl ; fflush(stdout) ;
#endif // DEBUG_T
}
ClientInfo::~ClientInfo() ClientInfo::~ClientInfo()
{ {
#ifdef DEBUG_T
cout << "//--> ClientInfo::~ClientInfo()" << endl ; fflush(stdout) ;
#endif // DEBUG_T
viterbi_Eprevious.clear(); viterbi_Eprevious.clear();
viterbi_Ecurrent.clear(); viterbi_Ecurrent.clear();
int N = VITERBI_N ; #ifdef DEBUG_T
for(int n=0; n < N-1 ; n++) cout << "//<-- ClientInfo::~ClientInfo()" << endl ; fflush(stdout) ;
delete[] viterbi_V[n] ; #endif // DEBUG_T
delete viterbi_V ;
} }
ClientInfo ClientInfo::operator=(const ClientInfo &c)
{
#ifdef DEBUG_T
cout << "//--> ClientInfo::operator=()" << endl ; fflush(stdout) ;
#endif // DEBUG_T
if (this == &c)
return *this ;
client_ip = c.client_ip ;
antenna_gain = c.antenna_gain ;
client_listen_port = c.client_listen_port ;
viterbi_iteration = c.viterbi_iteration ;
const float_array::size_type *s = c.viterbi_V.shape() ; // Récupération des dimensions de c.viterbi_V.
viterbi_V.resize(boost::extents[s[0]][s[1]]) ; // Redimensionnement de viterbi_V aux dimensions de c.viterbi_V.
viterbi_V = c.viterbi_V ; // Copie du contenu de c.viterbi_V dans viterbi_V.
#ifdef DEBUG_T
cout << "//<-- ClientInfo::operator=()" << endl ; fflush(stdout) ;
#endif // DEBUG_T
return *this ;
}
bool ClientInfo::operator==(const ClientInfo &c)
{
#ifdef DEBUG_T
cout << "//--> ClientInfo::operator==()" << endl ; fflush(stdout) ;
#endif // DEBUG_T
if (this == &c)
return true ;
if (client_ip != c.client_ip)
return false ;
if (antenna_gain != c.antenna_gain)
return false ;
if (client_listen_port != c.client_listen_port)
return false ;
if (viterbi_iteration != c.viterbi_iteration)
return false ;
if (viterbi_V != c.viterbi_V)
return false ;
return true ;
#ifdef DEBUG_T
cout << "//<-- ClientInfo::operator==()" << endl ; fflush(stdout) ;
#endif // DEBUG_T
}
void ClientInfo::print_viterbi_V() const
{
#ifdef DEBUG_T
cout << "//--> ClientInfo::print_viterbi_V()" << endl ; fflush(stdout) ;
#endif // DEBUG_T
for (float_index n=0 ; n < viterbi_V.shape()[0] ; n++)
{
for (float_index k=0 ; k < viterbi_V.shape()[1] ; k++)
cout << "[" << viterbi_V[n][k] << "]" ;
cout << endl ;
}
#ifdef DEBUG_T
cout << "//<-- ClientInfo::print_viterbi_V()" << endl ; fflush(stdout) ;
#endif // DEBUG_T
}

View File

@ -4,10 +4,13 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <vector> #include <vector>
#include <boost/multi_array.hpp>
#include "guinumo.hh"
#include "point.hh" #include "point.hh"
using namespace std; using namespace std;
using std::string;
#define CLIENT_DEFAULT_PORT 7778 #define CLIENT_DEFAULT_PORT 7778
#define CLIENT_DEFAULT_IP "127.0.0.1" #define CLIENT_DEFAULT_IP "127.0.0.1"
@ -18,6 +21,10 @@ using std::string;
class ClientInfo class ClientInfo
{ {
public :
typedef boost::multi_array<float, 2> float_array ; // On utilise boost::multi_array pour viterbi_V.
typedef float_array::index float_index ;
protected: protected:
string client_ip; string client_ip;
float antenna_gain; float antenna_gain;
@ -25,15 +32,24 @@ protected:
vector<Point> viterbi_Ecurrent; // Last vector vector<Point> viterbi_Ecurrent; // Last vector
vector<Point> viterbi_Eprevious; // Previous vector vector<Point> viterbi_Eprevious; // Previous vector
// float viterbi_distances[5]; // float viterbi_distances[5];
float **viterbi_V ; float_array viterbi_V ;
unsigned int viterbi_iteration ; // Nombre d'ensembles d'historique qu'on a déjà passés
public: public:
ClientInfo(const string &ip = CLIENT_DEFAULT_IP, const int &port = CLIENT_DEFAULT_PORT, const float &antg = CLIENT_DEFAULT_ANTENNA_GAIN); ClientInfo(const string &ip = CLIENT_DEFAULT_IP, const int &port = CLIENT_DEFAULT_PORT, const float &antg = CLIENT_DEFAULT_ANTENNA_GAIN);
ClientInfo(const ClientInfo &c) ;
~ClientInfo(); ~ClientInfo();
ClientInfo operator=(const ClientInfo &c) ;
bool operator==(const ClientInfo &c) ;
float getAntennaGain()const { return antenna_gain; }; float getAntennaGain()const { return antenna_gain; };
vector<Point>& getRef_viterbi_Ecurrent() { return viterbi_Ecurrent; } ; vector<Point>& getRef_viterbi_Ecurrent() { return viterbi_Ecurrent; } ;
vector<Point>& getRef_viterbi_Eprevious() { return viterbi_Eprevious; } ; vector<Point>& getRef_viterbi_Eprevious() { return viterbi_Eprevious; } ;
float** get_viterbi_V() { return viterbi_V; } ; unsigned int& getRef_viterbi_iteration() { return viterbi_iteration ; } ;
float_array& getRef_viterbi_V() { return viterbi_V; } ;
void print_viterbi_V() const ;
}; };
#endif #endif // _CLIENTINFO_HH_

11
GuiNuMo-server/guinumo.hh Normal file
View File

@ -0,0 +1,11 @@
#ifndef _GUINUMO_HH_
#define _GUINUMO_HH_
#define TEST
#define DEBUG // Décommenter pour avoir de l'affichage en plus.
//#define DEBUG_2 // Décommenter pour avoir encore plus d'affichage.
#define DEBUG_T // Décommenter pour afficher chaque entrée et sortie de méthode (trace).
#endif // _GUINUMO_HH_

View File

@ -1,10 +1,5 @@
#include "server.hh" #include "server.hh"
#define TEST
#define DEBUG // Décommenter pour avoir de l'affichage en plus.
//#define DEBUG_2 // Décommenter pour avoir encore plus d'affichage.
/******* Misc. very usefull functions *******/ /******* Misc. very usefull functions *******/
@ -210,6 +205,10 @@ inline vector<string> extractReferencePointInfoFromBuffer(const string &buffer_i
//Server::Server(string ip_addr, int listen_port, int send_port) // FIXME : paramètre send_port inutilisé //Server::Server(string ip_addr, int listen_port, int send_port) // FIXME : paramètre send_port inutilisé
Server::Server(const string &ip_addr, const int &listen_port) Server::Server(const string &ip_addr, const int &listen_port)
{ {
#ifdef DEBUG_T
cout << "//--> Server::Server()" << endl ; fflush(stdout) ;
#endif // DEBUG_T
/* Open socket */ /* Open socket */
sockListen = socket(PF_INET, SOCK_DGRAM, 0); sockListen = socket(PF_INET, SOCK_DGRAM, 0);
sockSend = socket(PF_INET, SOCK_DGRAM, 0); sockSend = socket(PF_INET, SOCK_DGRAM, 0);
@ -227,17 +226,29 @@ Server::Server(const string &ip_addr, const int &listen_port)
makeApListFromFile(DEFAULT_AP_FILE) ; // Initialisation de "access_point_list". makeApListFromFile(DEFAULT_AP_FILE) ; // Initialisation de "access_point_list".
makeTopologyFromFile(DEFAULT_TOPOLOGY_FILE) ; // Initialisation de "area_list". makeTopologyFromFile(DEFAULT_TOPOLOGY_FILE) ; // Initialisation de "area_list".
makeWaypointDistancesFromFile(DEFAULT_DISTANCE_FILE) ; // Initialisation de "waypoint_indexes" et "waypoint_matrix". makeWaypointDistancesFromFile(DEFAULT_DISTANCE_FILE) ; // Initialisation de "waypoint_indexes" et "waypoint_matrix".
#ifdef DEBUG_T
cout << "//<-- Server::Server()" << endl ; fflush(stdout) ;
#endif // DEBUG_T
} }
Server::~Server() Server::~Server()
{ {
client_list.clear(); #ifdef DEBUG_T
reference_point_list.clear(); cout << "//--> Server::~Server()" << endl ; fflush(stdout) ;
access_point_list.clear(); #endif // DEBUG_T
close(sockListen); close(sockListen);
close(sockSend); close(sockSend);
reference_point_list.clear();
access_point_list.clear();
client_list.clear();
#ifdef DEBUG_T
cout << "//<-- Server::~Server()" << endl ; fflush(stdout) ;
#endif // DEBUG_T
} }
@ -1111,16 +1122,21 @@ void Server::computeFriisFromRefList()
*/ */
void Server::fastViterbiLike(const unsigned short &N, const unsigned short &K, const unsigned int &id_client) void Server::fastViterbiLike(const unsigned short &N, const unsigned short &K, const unsigned int &id_client)
{ {
#ifdef DEBUG_T
cout << "//--> Server::fastViterbiLike()" << endl ; fflush(stdout) ;
#endif // DEBUG_T
#ifdef TEST #ifdef TEST
ClientInfo cl ; client_list.push_back(ClientInfo()) ;
float **V = cl.get_viterbi_V() ; ClientInfo &cl = client_list.back() ;
float_array V = cl.getRef_viterbi_V() ;
vector<Point> vector<Point>
&E_current = cl.getRef_viterbi_Ecurrent(), &E_current = cl.getRef_viterbi_Ecurrent(),
&E_previous = cl.getRef_viterbi_Eprevious() ; &E_previous = cl.getRef_viterbi_Eprevious() ;
vector<ReferencePoint> peregrination_point_list ; vector<ReferencePoint> peregrination_point_list ;
makePointListFromFile(peregrination_point_list, DEFAULT_TRACKING_FILE, false) ; makePointListFromFile(peregrination_point_list, DEFAULT_TRACKING_FILE, false) ;
#else // TEST #else // TEST
float **V = client_list[id_client].get_viterbi_V() ; float_array V = client_list[id_client].getRef_viterbi_V() ;
vector<Point> vector<Point>
&E_current = client_list[id_client].getRef_viterbi_Ecurrent(), &E_current = client_list[id_client].getRef_viterbi_Ecurrent(),
&E_previous = client_list[id_client].getRef_viterbi_Eprevious() ; &E_previous = client_list[id_client].getRef_viterbi_Eprevious() ;
@ -1135,6 +1151,8 @@ void Server::fastViterbiLike(const unsigned short &N, const unsigned short &K, c
return ; return ;
} }
client_list.back().print_viterbi_V() ;
#ifdef DEBUG #ifdef DEBUG
cout << reference_point_list.size() << " points de référence" ; cout << reference_point_list.size() << " points de référence" ;
#ifdef TEST #ifdef TEST
@ -1178,11 +1196,11 @@ void Server::fastViterbiLike(const unsigned short &N, const unsigned short &K, c
if (i > 1) // Si on n'est plus à la première itération if (i > 1) // Si on n'est plus à la première itération
{ {
/* Recalcul des plus courtes distances */ /* Recalcul des plus courtes distances */
for (int n = N-1-i ; n < N-2 ; n++) // Pour chaque historique existant (sauf le dernier), for (float_index n = N-1-i ; n < N-2 ; n++) // Pour chaque historique existant (sauf le dernier),
for (int k = 0 ; k < K ; k++) // pour chaque point de l'historique, for (float_index k = 0 ; k < K ; k++) // pour chaque point de l'historique,
{ // on met à jour le chemin minimum entre l'historique précédent et le point : { // on met à jour le chemin minimum entre l'historique précédent et le point :
V[n][k] = V[n+1][0] + E_previous[0].distance(E_current[k]) ; V[n][k] = V[n+1][0] + E_previous[0].distance(E_current[k]) ;
for (int l = 1 ; l < K ; l++) for (float_index l = 1 ; l < K ; l++)
{ {
float f = V[n+1][l] + E_previous[l].distance(E_current[k]) ; float f = V[n+1][l] + E_previous[l].distance(E_current[k]) ;
if (f < V[n][k]) if (f < V[n][k])
@ -1191,10 +1209,10 @@ void Server::fastViterbiLike(const unsigned short &N, const unsigned short &K, c
} }
/* Traitement du dernier historique */ /* Traitement du dernier historique */
for (int k = 0 ; k < K ; k++) // Pour chaque point, for (float_index k = 0 ; k < K ; k++) // Pour chaque point,
{ // on récupère le chemin minimum entre l'historique précédent et le point : { // on récupère le chemin minimum entre l'historique précédent et le point :
V[N-2][k] = E_previous[0].distance(E_current[k]) ; V[N-2][k] = E_previous[0].distance(E_current[k]) ;
for (int l = 1 ; l < K ; l++) for (float_index l = 1 ; l < K ; l++)
{ {
float f = E_previous[l].distance(E_current[k]) ; float f = E_previous[l].distance(E_current[k]) ;
if (f < V[N-2][k]) if (f < V[N-2][k])
@ -1210,7 +1228,7 @@ void Server::fastViterbiLike(const unsigned short &N, const unsigned short &K, c
float V0_min = V[0][0] ; float V0_min = V[0][0] ;
cout << "V[0][0]=" << V[0][0] << " ; V0_min=" << V0_min << " ; V0_min_k=" << V0_min_k << " -- " ; cout << "V[0][0]=" << V[0][0] << " ; V0_min=" << V0_min << " ; V0_min_k=" << V0_min_k << " -- " ;
#endif // DEBUG #endif // DEBUG
for (int k=1 ; k < K ; k++) for (float_index k=1 ; k < K ; k++)
{ {
if (V[0][k] < V0_min) if (V[0][k] < V0_min)
{ {
@ -1232,9 +1250,9 @@ void Server::fastViterbiLike(const unsigned short &N, const unsigned short &K, c
#ifdef DEBUG #ifdef DEBUG
// cout << "(N=" << N << ") - 1 - (i=" << i << ") = " << N-1-i << endl ; // cout << "(N=" << N << ") - 1 - (i=" << i << ") = " << N-1-i << endl ;
cout << "V :" << endl ; cout << "V :" << endl ;
for (int n=0 ; n < N-1 ; n++) for (float_index n=0 ; n < N-1 ; n++)
{ {
for (int k=0 ; k < K ; k++) for (float_index k=0 ; k < K ; k++)
cout << "[" << V[n][k] << "]" ; cout << "[" << V[n][k] << "]" ;
cout << endl ; cout << endl ;
} }
@ -1249,6 +1267,10 @@ void Server::fastViterbiLike(const unsigned short &N, const unsigned short &K, c
pt++ ; pt++ ;
#endif // TEST #endif // TEST
} }
#ifdef DEBUG_T
cout << "//<-- Server::fastViterbiLike()" << endl ; fflush(stdout) ;
#endif // DEBUG_T
} }

View File

@ -14,6 +14,8 @@
#include <string.h> #include <string.h>
#include <math.h> #include <math.h>
#include <stdio.h> #include <stdio.h>
#include "guinumo.hh"
#include "clientinfo.hh" #include "clientinfo.hh"
#include "referencepoint.hh" #include "referencepoint.hh"
#include "accesspoint.hh" #include "accesspoint.hh"
@ -22,7 +24,10 @@
#include "area.hh" #include "area.hh"
using namespace std; using namespace std;
using std::string;
typedef ClientInfo::float_array float_array ;
typedef ClientInfo::float_index float_index ;
#define DEFAULT_LOGFILE "log/radar_exp.csv" // Fichier de sortie #define DEFAULT_LOGFILE "log/radar_exp.csv" // Fichier de sortie
#define DEFAULT_REF_POINT_FILE "csv/agreg/toutes.csv" // Fichier des points de référence #define DEFAULT_REF_POINT_FILE "csv/agreg/toutes.csv" // Fichier des points de référence
@ -63,6 +68,8 @@ public:
void send_to_client(const int &cl); void send_to_client(const int &cl);
int receive_data(); int receive_data();
ClientInfo& createClient() ;
bool pointExists(const float &x, const float &y, const float &z)const; bool pointExists(const float &x, const float &y, const float &z)const;
bool pointExists(const Point &p)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 float &x, const float &y, const float &z) const ;
@ -95,14 +102,16 @@ public:
void printReferencePointList(); void printReferencePointList();
void printPointList(vector<ReferencePoint> &point_list) ; void printPointList(vector<ReferencePoint> &point_list) ;
void printAccessPointList(); void printAccessPointList();
void computeFriisFromRefList(); void computeFriisFromRefList();
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) ;
//Point fastViterbiLike(const unsigned int &id_client, float **distance_matrix) ;
void fastViterbiLike(const unsigned short &N, const unsigned short &K, const unsigned int &id_client) ; void fastViterbiLike(const unsigned short &N, const unsigned short &K, const unsigned int &id_client) ;
void printLastClientV();
/* For experimentation purpose only ! */ /* For experimentation purpose only ! */
void radar_exp(); void radar_exp();

View File

@ -16,10 +16,14 @@ int main(int argc, char ** argv)
{ {
ofstream output_file; ofstream output_file;
string read_file; string read_file;
Server my_server; Server server ;
// my_server.radar_exp(); server.fastViterbiLike(VITERBI_N, VITERBI_K, 0) ;
my_server.fastViterbiLike(VITERBI_N, VITERBI_K, 0) ; /*
server.createClient() ;
server.printLastClientV();
server.monitorClient(0) ;
*/
cout << argv[0] << " : fin." << endl ; cout << argv[0] << " : fin." << endl ;
fflush(stdout) ; fflush(stdout) ;