From 0647ffd070bdf8a6eaa2f58b15cbecd42f5295cb Mon Sep 17 00:00:00 2001 From: Elena Date: Tue, 7 Feb 2023 23:50:51 +0100 Subject: [PATCH] =?UTF-8?q?=C3=9Altimos=20cambios=20para=20detectar=20nodo?= =?UTF-8?q?s=20a=20distinta=20elevaci=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Olivia/olv.cpp | 17 +++- Olivia/olv_limp.h | 2 +- Olivia/olv_limp_def.h | 28 +++++- Olivia/olv_limp_thr.cpp | 126 +++++++++++++++++++++------ OliviaTasks/OliviaTasks.vcxproj.user | 2 +- includes/Utiles/CartoBaseElements.h | 2 +- includes/Utiles/CartoElements.h | 2 +- includes/Utiles/GeometryFunction.h | 2 +- 8 files changed, 146 insertions(+), 35 deletions(-) diff --git a/Olivia/olv.cpp b/Olivia/olv.cpp index 45021eb..bf452a2 100644 --- a/Olivia/olv.cpp +++ b/Olivia/olv.cpp @@ -391,7 +391,7 @@ void COlivia::prueba() /////////////////// //solo para debug elena olivia - i=1; + i=2; if(fin) { @@ -423,6 +423,19 @@ void COlivia::prueba() "/path_data:D:\\Proyectos\\Olivia\\Instal3.0\\data_prueba_2\\data_T00_A0405_20230111_233224.shp "\ "/path_nw:D:\\Proyectos\\Olivia\\Instal3.0\\data_prueba_2\\nw_20230111_233224.shp "); break; + case 2: + sprintf_s(config, max_char_cap, "/CONFIG_PLANIF /campo_capaci:CAPACIDAD /kg_max:7500 /campo_kgrecog:KGRECO /campo_uds:UNIDADES /recogida_kg:200 /carga_cont:0 "\ + "/densidad:-1 /t_conv:480 /t_descan:30 /t_vacia:90 /t_descarg:40 /t_sallleg:25 /h_inicio:420 /trafico:80 "\ + "/n_ptsctrl:3 /n_secdef:3 /anch_vehi:0 /giro_vehi:175 /coor_inst_x:544038,5064 /coor_inst_y:4624375,9191 "\ + "/coor_desc_x:543887,2812 /coor_desc_y:4623093,8184 "\ + "/sens_id:0 /sens_url:0 /sens_fechai:0 /sens_fechaf:0 /md_pet:0 /aislados:1 /lateralidad:0 "\ + "/cons_onew:ONEWAY /cons_kph:KPH /cons_fow:FOW /cons_name:NAME "\ + "/atr_TF:TF /atr_FT:FT /atr_N:N /atr_pedes:14 /str_tto:Resto "\ + "/Camp_sector:SECTOR /Camp_secuencia:SECUENCIA /Camp_objectid:FID "\ + "/Giro_max_vehiculo:175 /Desv_max_rel:0.15 /Desv_max_abs:1000 "\ + "/path_data:D:\\Proyectos\\Olivia\\Instal3.0\\data_prueba_put_1\\data_F01_C01_20230207_112246.shp "\ + "/path_nw:D:\\Proyectos\\Olivia\\Instal3.0\\data_prueba_put_1\\nw_20230207_112246.shp "); + break; case 3://nw de arcmap sprintf_s(config, max_char_cap, "/CONFIG /t_tto:2900 /restr_cir:0 /u_tto:3 /v_despl:5 /t_conv:480 /t_descan:30 /t_despl:25 /t_carg:40 "\ "/h_inicio:450 /trafico:80 /n_ptsctrl:3 /n_secdef:3 /anch_med:2 /coor_inst_x:0 /coor_inst_y:0 /aislados:1 /cons_obser:OBSERVACIONES "\ @@ -431,7 +444,7 @@ void COlivia::prueba() "/atr_TF:TF /atr_FT:FT /atr_N:N /atr_pedes:14 /str_tto:Barrido_man "\ "/path_data:D:\\Proyectos\\Olivia\\Instal2.0\\data\\data_T00_A04050607_NNivel7_20220327_155737.shp /path_nw:D:\\Proyectos\\Olivia\\Instal2.0\\data\\nw_20220327_170516.shp "); break; - case 2://orig arcmap + case 5://orig arcmap sprintf_s(config, max_char_cap, "/CONFIG /t_tto:2900 /restr_cir:0 /u_tto:3 /v_despl:5 /t_conv:480 /t_descan:30 /t_despl:25 /t_carg:40 "\ "/h_inicio:420 /trafico:80 /n_ptsctrl:3 /n_secdef:3 /anch_med:2 /coor_inst_x:0 /coor_inst_y:0 /aislados:0 /cons_obser:OBSERVACIONES "\ "/cons_anch_tip:ANCHO_TIPO /cons_tipolo:TIPOLOGIA /cons_tip_ent:NOM_TIPO_ENTIDAD /atr_aparc:Banda Aparcamiento /atr_bord:Bordillo Libre "\ diff --git a/Olivia/olv_limp.h b/Olivia/olv_limp.h index 3e848c8..24a5f71 100644 --- a/Olivia/olv_limp.h +++ b/Olivia/olv_limp.h @@ -89,7 +89,7 @@ public: std::map iaso; /// *tramos; - std::map iaso_elev; /// iaso_elev; /// #include +#include ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////// @@ -578,5 +579,30 @@ typedef struct Info_aso_conj_elev_aux */ typedef struct Info_aso_conj_elev { - std::vector conj_nw[N_ELEV]; //dos maps con las entidades de la nw que están a nivel 0 y a nivel 1 en la misma conjunción + std::vector conj_nw[N_ELEV]; //dos maps con las entidades de la nw que están a nivel 0 y a nivel 1 en la misma conjunción + char key_coord[64]; //indica la key de la coordenada }Info_aso_conj_elev; +/* +* Estructura para almacenar los id de los nodos a los que llegan ent de la nw con distinta elevación de cada subthread +*/ +typedef struct th_param_dist_elev_thr +{ + std::vector conj_elev_i; //la clave son las coordenadas x-y en formato texto +}th_param_dist_elev_thr; +/** + * Parametros de los thead que buscan nodos a dist elev + */ +typedef struct th_param_dist_elev +{ + BOOL pirate;//indica a los thread que hay que irse + BOOL abs; + int id_curro;//id de curro + int modo;//indica el modo de curro + long nth;//numero de thread currando + long nth_tot; + int id_th;//indica al thread el id que tiene + int n_nw; + int milis_sleep; + th_param_dist_elev_thr *conj_th; + std::vector iaso_elev; /// UINT th_planificacion(LPVOID pp); +UINT th_busca_elev_dist(LPVOID pp); /** * @file olv_limp_thr.cpp * Archivo de implementaciones del thread de control de la utilidad de limpieza viaria del programa Olivia. @@ -1239,22 +1240,23 @@ void Colv_limp_thr::rellena_elev_nw() n = 0; CartoBaseInfoEntity ient; int npts; + Info_aso_nw_elev info; while (idd == 1) { //inicia - olv_limp->iaso_elev[n].inod_check[FROM] = olv_limp->iaso_elev[n].inod_check[TO] = false; - olv_limp->iaso_elev[n].i_nw = n; + info.inod_check[FROM] = info.inod_check[TO] = false; + info.i_nw = n; //conj - olv_limp->iaso_elev[n].inod[TO] = -1; - olv_limp->iaso_elev[n].inod[FROM] = -1; + info.inod[TO] = -1; + info.inod[FROM] = -1; ient = olv_limp->carto.getEntity(n + olv_limp->n_amb); npts = ient.getNumberPtos(); - memcpy(olv_limp->iaso_elev[n].coord[FROM], ient.getPto(0), 3 * sizeof(double)); - memcpy(olv_limp->iaso_elev[n].coord[TO], ient.getPto(npts - 1), 3 * sizeof(double)); + memcpy(info.coord[FROM], ient.getPto(0), 3 * sizeof(double)); + memcpy(info.coord[TO], ient.getPto(npts - 1), 3 * sizeof(double)); //elev - olv_limp->iaso_elev[n].elev[TO] = dbf.getI(ic_elev_to); - olv_limp->iaso_elev[n].elev[FROM] = dbf.getI(ic_elev_from); - + info.elev[TO] = dbf.getI(ic_elev_to); + info.elev[FROM] = dbf.getI(ic_elev_from); + olv_limp->iaso_elev.push_back(info); n++; idd = dbf.leeNexRow(); @@ -1294,30 +1296,98 @@ BOOL Colv_limp_thr::revisa_elev_nw() std::vector Colv_limp_thr::busca_elev_nw() { std::vector conj_elev; + int nthr = n_subthr; + th_param_dist_elev thp; + memset(&thp, 0, sizeof(thp)); + thp.milis_sleep = 1; + thp.abs = TRUE; + thp.nth_tot = nthr; + thp.n_nw = olv_limp->n_nw; + thp.conj_th = (th_param_dist_elev_thr*)malloc(sizeof(th_param_dist_elev_thr) * nthr); + memset(thp.conj_th, 0, sizeof(th_param_dist_elev_thr) * nthr); + thp.iaso_elev = olv_limp->iaso_elev; + + olvlog(LOG_TODO, "olv_limp_t", "Buscando nodos con elevaciones distintas"); + + for (int i = 0; i < nthr; i++) + { + thp.id_th = i; + lck_sum_atm(&thp.nth, 1); + AfxBeginThread(th_busca_elev_dist, (LPVOID)&thp, THREAD_PRIORITY_NORMAL, 0, 0, NULL); + while (thp.id_th >= 0) + Sleep(1); + } + while (thp.nth > 0) + Sleep(10); + //////////////////////////////////////////////// + //reune toda la información + //recorre el array de todos los threads, buscando repetidos + std::vector::iterator it2; + int i1; + bool ya_esta = false; + for (int i = 0; i < nthr; i++) + { + for(i1=0;i1< thp.conj_th[i].conj_elev_i.size();i1++) + { + ya_esta = false; + //busca que no esté esta coordenada ya en el array + it2 = conj_elev.begin(); + while (it2 != conj_elev.end() && !ya_esta) + { + if (strcmp(thp.conj_th[i].conj_elev_i[i1].key_coord, it2->key_coord) == 0) + ya_esta = true; + it2++; + } + if (!ya_esta) + { + //la almacena en el vector + conj_elev.push_back(thp.conj_th[i].conj_elev_i[i1]); + } + } + } + + if (thp.conj_th) + { + free(thp.conj_th); + } + return conj_elev; +} +//************************************************************************************* +/** + * Thread para cálculo multiproceso de búsqueda de nodos a distinta elevación + */ +UINT th_busca_elev_dist(LPVOID pp) +{ + th_param_dist_elev* p = (th_param_dist_elev*)pp; + int ithr = p->id_th; + Info_aso_conj_elev conj_elev_i1; Info_aso_conj_elev_aux conj_elev_nw_i1, conj_elev_nw_i2; - std::map::iterator it1; - std::map::iterator it2; - int i1, i2,elev1,elev2; + int i1, i2,elev1,elev2,it2; Info_aso_nw_elev* info1, * info2; + std::vector conj_elev_i; - it1 = olv_limp->iaso_elev.begin(); - while (it1 != olv_limp->iaso_elev.end()) + int n_desp = (int)ceil(1.0 * p->n_nw / p->nth_tot); + int n_ini = min(ithr * n_desp, p->n_nw); + int n_fin = min((ithr + 1) * n_desp, p->n_nw); + + //avisa de que ya empieza + p->id_th = -1; + + for (int in = n_ini; in < n_fin && !p->pirate; in++) { - info1 = &it1->second; + info1 = &((p->iaso_elev)[in]); for (i1 = 0; i1 < N_NODOS; i1++) { if (info1->inod_check[i1]) //si ya se ha comprobado, pasa continue; conj_elev_i1.conj_nw[MISMA_ELEV].clear(); conj_elev_i1.conj_nw[DIST_ELEV].clear(); - it2 = olv_limp->iaso_elev.begin(); - while (it2 != olv_limp->iaso_elev.end()) + for (it2 = 0; it2 < p->n_nw && !p->pirate; it2++) { - info2 = &it2->second; + info2 = &((p->iaso_elev)[it2]); if (info2->i_nw == info1->i_nw) - { - it2++; + { continue;//mismo elemento } for (i2 = 0; i2 < N_NODOS; i2++) @@ -1339,10 +1409,10 @@ std::vector Colv_limp_thr::busca_elev_nw() //misma elev conj_elev_i1.conj_nw[MISMA_ELEV].push_back(conj_elev_nw_i2); } + info2->inod_check[i2] = true; } } - /////////////////////////////////////// - it2++; + /////////////////////////////////////// } info1->inod_check[i1] = true; //solo los almacena si tiene alguno en dist elev, si todos son la misma, no @@ -1351,14 +1421,16 @@ std::vector Colv_limp_thr::busca_elev_nw() //se añade a sí mismo conj_elev_nw_i1.set(info1->i_nw, i1); conj_elev_i1.conj_nw[MISMA_ELEV].push_back(conj_elev_nw_i1); - conj_elev.push_back(conj_elev_i1); - + sprintf_s(conj_elev_i1.key_coord, 64, "%lf-%lf", info1->coord[i1][0], info1->coord[i1][1]); + conj_elev_i.push_back(conj_elev_i1); } } - it1++; } + p->conj_th[ithr].conj_elev_i = conj_elev_i; + //salida de thread------------------------- + lck_sum_atm(&p->nth, -1); - return conj_elev; + return 0; } //************************************************************************************* #define MUEVE_COOR_METROS 5 @@ -1967,7 +2039,7 @@ BOOL Colv_limp_thr::busca_inw_dmin(int i_amb) prime_ptos = prime_ptos_f; //necesita una función que dé la distancia media de prime_ptos a ientnw - daux=prime_ptos.disMedLines(&ientnw,&desv); //coge la dis media para quedarse con la min + daux=prime_ptos.disMedLines(&ientnw,&desv, olv_limp->revisa_elev); //coge la dis media para quedarse con la min ientnw.DisPtoLine(prime_ptos.getPto(0),&ip, &lamb, olv_limp->revisa_elev); //coge el punto donde se da la min } else if(KK==OLV_AMB_PUN) diff --git a/OliviaTasks/OliviaTasks.vcxproj.user b/OliviaTasks/OliviaTasks.vcxproj.user index 04f8b11..1622917 100644 --- a/OliviaTasks/OliviaTasks.vcxproj.user +++ b/OliviaTasks/OliviaTasks.vcxproj.user @@ -14,7 +14,7 @@ ..\bin\$(IntDir) WindowsLocalDebugger C:\Desa\v2017\Olivia\bin\$(IntDir)$(TargetFileName) - /tipo:0 /ip:192.168.2.61 /port:19995 /tout:20 /path_temp:D:\Proyectos\Olivia\Instal3.0\temp\ /path_cfgeo: /debug + /tipo:1 /ip:192.168.2.61 /port:19995 /tout:20 /path_temp:D:\Proyectos\Olivia\Instal3.0\temp\ /path_cfgeo: /debug ..\bin\$(IntDir) diff --git a/includes/Utiles/CartoBaseElements.h b/includes/Utiles/CartoBaseElements.h index 3e8185c..806ea37 100644 --- a/includes/Utiles/CartoBaseElements.h +++ b/includes/Utiles/CartoBaseElements.h @@ -111,7 +111,7 @@ public: void* getIa(); double getLong(); double disMedLines(SetPtsR *line2, double l_avan, double *desv=NULL); - double disMedLines(SetPtsR *line2, double *desv=NULL); + double disMedLines(SetPtsR *line2, double *desv=NULL, BOOL usa_z = FALSE); double DisPtoLine(double*p, int* idpto=NULL, double *lamb=NULL, BOOL usa_z=FALSE); SetPtsW *GetNPrimePtos(SetPtsW *ldst, int nptos, double dis, BOOL avanza); bool DivLine(SetPtsW* ldst1, SetPtsW* ldst2, int ip, double lamb); diff --git a/includes/Utiles/CartoElements.h b/includes/Utiles/CartoElements.h index aaffae3..31e8ab4 100644 --- a/includes/Utiles/CartoElements.h +++ b/includes/Utiles/CartoElements.h @@ -31,7 +31,7 @@ public: virtual double* getPto(int i){return 0;} virtual int getNumberPtos(){return 0;} - virtual double disMedLines(SetPtsR *line2, double *desv=NULL); + virtual double disMedLines(SetPtsR *line2, double *desv=NULL, BOOL usa_z =FALSE); }; diff --git a/includes/Utiles/GeometryFunction.h b/includes/Utiles/GeometryFunction.h index 452f799..f156fc7 100644 --- a/includes/Utiles/GeometryFunction.h +++ b/includes/Utiles/GeometryFunction.h @@ -34,7 +34,7 @@ public: //distancia de un punto a una linea static double DisPtoLine(SetPtsR* line, double*p, int* idpto=NULL, double *lamb=NULL, BOOL usa_z = FALSE); //distancia media entre dos líneas - static double DisMedLines( SetPtsR* line1, SetPtsR* line2, double *desv=NULL); + static double DisMedLines( SetPtsR* line1, SetPtsR* line2, double *desv=NULL, BOOL usa_z =FALSE); static double DisMedLines( SetPtsR* line1, SetPtsR* line2, double l_avan, double *desv=NULL); //parte una linea en 2 static bool DivLine(SetPtsR* linesrc, SetPtsW* ldst1, SetPtsW* ldst2, double dis);