00001
00002
00003 #ifndef GrafoH
00004 #define GrafoH
00005
00006
00007 #include "../kernel/TeSTElementSet.h"
00008 #include "../kernel/TeNeighbours.h"
00009 #include "lista.h"
00010
00011 #define RAIO 4
00012
00013 class STAT_DLL TSkaterGrafo {
00014
00015 public:
00016
00017 typedef struct No_Grafo
00018 {
00019 char Label[50];
00020 double X;
00021 double Y;
00022 TListaVizinho *Vizinhos;
00023 TListaVizinho *ArViz;
00024 double *Variaveis;
00025 int Populacao;
00026 char Mark;
00027 } Grafo_t, *Grafo_ptr;
00028
00029 typedef struct Grafo
00030 {
00031 Grafo_ptr Nos;
00032 int Num_Var;
00033 int Size;
00034 }MyGrafo_t,*MyGrafo_ptr;
00035
00036
00037 TSkaterGrafo(bool hasPop);
00038 template<typename Matrix> bool MontaGrafo(TeSTElementSet& regSet, Matrix* proxMatrix);
00039 void Escalona(double *,double *);
00040 void Escala(int,int);
00041 void Adjacente(int *,double *,int i);
00042 void Adjacente1(int *,double *,int i);
00043 int Size() {return GetSize();}
00044 double MinX() {return X_min;}
00045 double MaxX() {return X_max;}
00046 double MinY() {return Y_min;}
00047 double MaxY() {return Y_max;}
00048 double Coord_X(int Indice){return Get_X(Indice);}
00049 double Coord_Y(int Indice) {return Get_Y(Indice);}
00050 int Num_Var() {return GetNum_Var();}
00051
00052
00053
00054 private:
00055 MyGrafo_ptr MyGrafo;
00056 std::map<std::string,unsigned int> Hash_;
00057
00058 double X_min,X_max;
00059 double Y_min,Y_max;
00060 double Cx,Gamax;
00061 double Cy,Gamay;
00062
00063 double Distancia(int,int);
00064 double Get_X(int Indice);
00065 double Get_Y(int Indice);
00066 int GetSize();
00067 int GetNum_Var();
00068
00069
00070 char *NArq;
00071 char *NViz;
00072 char Tem_Pop;
00073
00074 friend class TArvore;
00075 friend class TParticao;
00076 friend class TPrincipal;
00077 friend class TEstatistica;
00078 };
00079
00080 template<typename Matrix> bool
00081 TSkaterGrafo::MontaGrafo(TeSTElementSet& regSet, Matrix* proxMatrix)
00082 {
00083
00084
00085
00086 typename TeSTElementSet::iterator it = regSet.begin();
00087 int nCov = (*it).getProperties().size();
00088
00089
00090
00091
00092 TeCoord2D centroid;
00093 (*it).centroid(centroid);
00094 X_min=X_max=centroid.x();
00095 Y_min=Y_max=centroid.y();
00096
00097 if (this->Tem_Pop)
00098 MyGrafo->Num_Var = nCov-1;
00099 else
00100 MyGrafo->Num_Var = nCov;
00101
00102 string val;
00103 int i;
00104
00105
00106 while (it != regSet.end())
00107 {
00108 (*it).centroid(centroid);
00109 MyGrafo->Nos =
00110 (Grafo_ptr) realloc(MyGrafo->Nos,sizeof(Grafo_t)*((MyGrafo->Size)+1));
00111 sprintf(MyGrafo->Nos[MyGrafo->Size].Label,"%s",(*it).objectId().c_str());
00112 MyGrafo->Nos[MyGrafo->Size].Vizinhos = NULL;
00113 MyGrafo->Nos[MyGrafo->Size].ArViz = NULL;
00114
00115 Hash_[std::string(MyGrafo->Nos[MyGrafo->Size].Label)] = MyGrafo->Size;
00116
00117 MyGrafo->Nos[MyGrafo->Size].X = centroid.x();
00118 if(centroid.x() < X_min) X_min =centroid.x();
00119 else if(centroid.x() > X_max) X_max = centroid.x();
00120
00121 MyGrafo->Nos[MyGrafo->Size].Y =centroid.y();
00122 if(centroid.y()< Y_min) Y_min = centroid.y();
00123 else if(centroid.y() > Y_max) Y_max = centroid.y();
00124
00125 MyGrafo->Nos[MyGrafo->Size].Variaveis =
00126 (double *) malloc(sizeof(double)*MyGrafo->Num_Var);
00127 for(i=0;i<MyGrafo->Num_Var;i++) {
00128 (*it).getPropertyValue(val, i);
00129 MyGrafo->Nos[MyGrafo->Size].Variaveis[i] = atof(val.c_str());
00130 }
00131 if (Tem_Pop) {
00132 (*it).getPropertyValue(val, MyGrafo->Num_Var);
00133 MyGrafo->Nos[MyGrafo->Size].Populacao = (int)atof(val.c_str());
00134 }
00135 else
00136 MyGrafo->Nos[MyGrafo->Size].Populacao = 0;
00137
00138 MyGrafo->Nos[MyGrafo->Size].Mark=1;
00139 (MyGrafo->Size)++;
00140 (++it);
00141 }
00142
00143 int L_indice,V_indice;
00144 double dist;
00145
00146 it = regSet.begin();
00147
00148 while ( it != regSet.end())
00149 {
00150 TeNeighboursMap neighbors = proxMatrix->getMapNeighbours((*it).objectId());
00151
00152
00153 if (neighbors.size() == 0)
00154 {
00155 Hash_.clear();
00156 return false;
00157 }
00158
00159 std::map<std::string,unsigned int>::iterator ith = Hash_.find((*it).objectId());
00160 if (ith != Hash_.end())
00161 L_indice = ith->second;
00162 else
00163 L_indice = 0;
00164
00165 MyGrafo->Nos[L_indice].Vizinhos = new TListaVizinho;
00166 MyGrafo->Nos[L_indice].ArViz = new TListaVizinho;
00167
00168 typename TeNeighboursMap::iterator itNeigs = neighbors.begin();
00169
00170 while(itNeigs != neighbors.end())
00171 {
00172 ith = Hash_.find((*itNeigs).first);
00173 if (ith != Hash_.end())
00174 V_indice = ith->second;
00175 else
00176 V_indice = 0;
00177 dist = Distancia(L_indice,V_indice);
00178 MyGrafo->Nos[L_indice].Vizinhos->Insere(V_indice,dist);
00179 (++itNeigs);
00180 }
00181 (++it);
00182 }
00183
00184 Hash_.clear();
00185 return true;
00186 }
00187
00188 #endif