//Calcul de v1 et v0 et de L void calcul_sommet_L(double *aretes, int *v0, int *v1, double *L,int dimension){ int i,j,vl; double max,tmp; //v0 et v1 max = 0;*v0 = 0;*v1 = 0; for(i=1 ; i < dimension ; i++){ for(j=1 ; j < i ; j++){ tmp = aretes[indice(i,j,dimension)]; if ( tmp > max){ max = tmp; *v0 = i; *v1 = j; } } } //L max = 0;vl = 1; for(i=2 ; i < dimension ; i++){ if(i != *v1){ tmp = aretes[indice(*v0,i,dimension)]; if ( tmp > max){ max = tmp; vl = i; } } } *L = aretes[indice(*v0,vl,dimension)] + aretes[indice(vl,*v1,dimension)]; return; }
void cdos(float *prob, QString &texto, int lon) { int n_letras[28]; for(int i = 0; i<28; i++) n_letras[i]=0; QByteArray bytes = texto.toAscii(); char* frase = bytes.data(); int i=0, n=0; int ind=indice(frase[0]); while((ind==-1)&&(i<lon)) { ind=indice2(texto[i].toAscii()); if(ind==-1) { i++; indice(frase[i]); } } int aux = ind; for(; i<lon;) { while(ind==-1) { ind=indice2(texto[i].toAscii()); if(ind==-1) { i++; ind = indice(frase[i]); } } i++; if(i==lon) break; aux = ind; ind = indice(frase[i]); if(ind==-1) ind=indice2(texto[i].toAscii()); if(ind !=-1) { prob[aux*28+ind]++; n_letras[aux]++; n++; } } for(int j=0; j<28; j++) if(n_letras[j]!=0) for(i=0; i<28; i++) prob[j*28+i] /= (float)n_letras[j]; i = i; }
//Calcul de la matrice d'incidence double *calcul_aretes(double *tab, int dimension){ double *aretes = new double [dimension*dimension]; int i,j; double tmp; for(i=0 ; i < dimension ; i++){ for(j=0 ; j < i ; j++){ tmp = sqrt((double)(tab[indice(j,0,2)]-tab[indice(i,0,2)])*(tab[indice(j,0,2)]-tab[indice(i,0,2)])+(double)(tab[indice(j,1,2)]-tab[indice(i,1,2)])*(tab[indice(j,1,2)]-tab[indice(i,1,2)])); aretes[indice(i,j,dimension)] = tmp; aretes[indice(j,i,dimension)] = tmp; } } return aretes; }
void cmap(map<QString, float> *mapeo, QString &texto, int lon) { QByteArray bytes = texto.toAscii(); char* frase = bytes.data(); int i=0, n=0, m=0; while(i<lon){ QString palabra; while((frase[i]!=' ')&&((indice(frase[i])!=-1)||(indice2(texto[i].toAscii())!=-1))){ palabra.append(frase[i]); i++; } i++; palabra = palabra.toLower(); if(palabra.size()>0) { map<QString, float>::iterator it = mapeo->find(palabra); if(it==mapeo->end()) { (*mapeo).insert(pair<QString,float>(palabra,1)); m++; } else (*mapeo)[palabra]++; n++; } } map<QString,float>::iterator it = (*mapeo).begin(); for(int j=0; j<m; j++, it++) it->second /=n; }
void DistribuicaoF::criarDistribuicao(string nome_arquivo) { ifstream arquivo; arquivo.open(nome_arquivo.c_str()); string line; getline(arquivo, line); stringstream stream(line, stringstream::in); stream >> _max_d1; stream >> _max_d2; for (int linha = 1; linha <= _max_d2; linha++) { getline(arquivo, line); stringstream stream(line, stringstream::in); for (int coluna = 1; coluna <= _max_d1; coluna++) { float valor; stream >> valor; pair<int, int> indice(coluna, linha); _distribuicao[indice] = valor; } } }
inline bool ICP::select_macth_useAllpoints(){ std::vector<int> indice(1); std::vector<float> distance(1); pcl::PointXYZRGB point_pcl; int k=0; for(int i=0 ; i<cloud_d->size() ; i++){ if (isnan(cloud_d->points[i].z)) continue; //apply RT point_pcl.x = cloud_d->points[i].x*T(0,0) + cloud_d->points[i].y*T(0,1) + cloud_d->points[i].z*T(0,2) + T(0,3); point_pcl.y = cloud_d->points[i].x*T(1,0) + cloud_d->points[i].y*T(1,1) + cloud_d->points[i].z*T(1,2) + T(1,3); point_pcl.z = cloud_d->points[i].x*T(2,0) + cloud_d->points[i].y*T(2,1) + cloud_d->points[i].z*T(2,2) + T(2,3); if ( kdtree_m.nearestKSearch (point_pcl, 1, indice, distance) != 1) continue; if (distance[0] < Dmax*Dmax){ model_indices[k] = indice[0]; data_indices[k] = i; k++; } } model_indices.resize(k); data_indices.resize(k); return true; }
//Afficher les sommets sur xfig void xfig_sommets (const char* nom_fichier, int dimension, double *tab, int v0, int v1){ std::ofstream fichier; int i,couleur; fichier.open(nom_fichier,std::ios::out | std::ios::trunc); if (!fichier){ std::cerr << "Erreur à l'ouverture du fichier\n"; exit(1); } fichier << "#FIG 3.2"<<std::endl; fichier << "Landscape"<<std::endl; fichier << "Center"<<std::endl; fichier << "Metric"<<std::endl; fichier << "A4"<<std::endl; fichier << "100.00"<<std::endl; fichier << "Single"<<std::endl; fichier << "-2"<<std::endl; fichier << "1200 2"<<std::endl; couleur = 1; for(i=0 ; i<dimension ; i++){ if(i == v1 || i == v0 ){ couleur = 4;}else{ couleur = 1;} fichier << "1 4 0 2 "<< couleur <<" 7 50 0 -1 0.000 1 0.0000 " << tab[indice(i,0,2)] << " " << tab[indice(i,1,2)] << " 10 10 0 0 0 0" << std::endl; } fichier.close(); return; }
int joueur(champs C, int x, int y) { int ind = indice(C, y, x); //on vérifie si la parcelle existe if (!(x >= 0 && y >= 0 && x < C->nb_colonnes && y < C->nb_lignes)) //si elle n existe pas on retourne -1 return -1; if (C->tab[ind].status == PASVU) { C->tab[ind].status = DEJAVU; if (C->tab[ind].mine == 0) { if (nb_mines_voisins(C, x, y) == 0) { int i, j; //si le nombre de mines voisins est nul alors on active les parcelles voisines for (i = x - 1; i <= x + 1; i++) for (j = y - 1; j <= y + 1; j++) joueur(C, i, j); } //on retourne 0 si la parcelle n'etait pas encore vu et qu'elle n'ait pas une mine return 0; } else //on retourne 1 si la parcelle n'etait pas encore vu et qu'elle ait une mine return 1; } else //on retourne 2 si la parcelle est deja vu return 2; }
//time O(klog(m*n)) space O(m*n) vector<int> numIslands2(int m, int n, vector<pair<int, int>>& positions) { vector<int> res; vector<int> indice(m*n, -1); int direct[] = {0, -1, 0, 1, 0}; int cnt = 0; for(int i = 0; i < positions.size(); ++i) { ++cnt; int x = positions[i].first, y = positions[i].second; int idx = x * n + y; indice[idx] = idx; for(int d = 0; d < 4; ++d) { int nx = x + direct[d], ny = y + direct[d+1]; int nidx = nx * n + ny; if(nx >= 0 && ny >= 0 && nx < m && ny < n && indice[nidx] != -1){ nidx = find(nidx, indice); if(idx != nidx) { indice[nidx] = idx; cnt--; } } } res.push_back(cnt); } return res; }
uint Aligner::checkPairCache(const overlapStruct& overlap1, const overlapStruct& overlap2, const string& read, uNumber& number, uint errorsAllowed){ if(overlap2.pos-overlap1.pos<k){ //TODO maybe it is a bad idea ... return 0; } string unitig,subRead(read.substr(overlap1.pos+k-1,overlap2.pos-overlap1.pos-(k-1))); auto rangeUnitigs1(overlap1.unitig); auto rangeUnitigs2(overlap2.unitig); uint minMissMatch(errorsAllowed+1),indice(0); string unitig1, unitig2; for(uint i(0); i<rangeUnitigs1.size(); ++i){ unitig1=rangeUnitigs1[i]; for(uint j(0); j<rangeUnitigs2.size(); ++j){ unitig2=rangeUnitigs2[j]; if(unitig2==unitig1){ if(unitig1.size()-2*(k-1)==subRead.size()){ uint missmatch(missmatchNumber(unitig1.substr(k-1,subRead.size()), subRead, errorsAllowed)); if(missmatch<minMissMatch){ minMissMatch=missmatch; indice=i; } } } } } if(minMissMatch<=errorsAllowed){number=(overlap1.unitigNumbers[indice]);} return minMissMatch; }
double calculer_trajet(double *aretes, std::vector< std::vector<int> >& T, int num_trajet, int dimension){ int j;double trajet; trajet = 0; for(j=1 ; j<T[num_trajet].size() ; j++){ trajet = trajet + aretes[indice(T[num_trajet][j-1],T[num_trajet][j],dimension)]; } return trajet; }
template<class Key1, class Key2, class Cont, template<class,class> class Pair> void operator()(Pair<Pair<Key1,Key2>,Cont>& obj) const { auto& indice = bundle.template indices<Key1,Key2>(); auto& table = obj.second; table.indice.set_max(bundle.template at_opt<Key1>().size(),bundle.template at_opt<Key2>().size()); for(auto i = indice.first() ; i < indice.size() ; ++i) for(auto j = indice.first(i) ; j < indice.size(i) ; ++j) table.indice.add(i,indice(i,j)); }
int nb_mines_voisins(champs C, int x, int y) { int i, j, nb_mines = 0; for (i = x - 1; i <= x + 1; i++) for (j = y - 1; j <= y + 1; j++) { //on verifie si la parcelle existe if (i >= 0 && j >= 0 && i < C->nb_colonnes && j < C->nb_lignes) //on verifie si la parcelle est differente de celle qu'on doit trouver le nombre de mines voisins et que si la parcelle a une bombe :D if ((indice(C, j, i) != indice(C, y, x)) && (C->tab[indice(C, j, i)].mine == 1)) //on incrémente le nombre de mines trouvées nb_mines++; } //on retourne le nombre de mines trouvées return nb_mines; }
//Lecture sur un fichier standard double *lire_fichier(const char *nom_fichier, int *dimension){ std::ifstream fichier; fichier.open(nom_fichier, std::ifstream::in); if (!fichier){ std::cerr << "Erreur à l'ouverture du fichier\n"; exit(1); } int n,i; double x,y,min_x,min_y,max_x,max_y; std::string ligne; // *dimension = 0; while (std::getline(fichier, ligne)){ (*dimension)++; } *dimension = *dimension - 7; fichier.close(); // fichier.open(nom_fichier, std::ifstream::in); while (ligne.compare("NODE_COORD_SECTION") != 0){ std::getline(fichier, ligne); } double *tab = new double[(*dimension)*2]; n = 0; x = 0; y = 0; min_x = 10000 ; min_y = 10000; max_x = 0 ; max_y = 0; for(i= 1; i <= *dimension ; i++){ fichier >> n >> x >> y; tab[indice(n-1,0,2)] = x; tab[indice(n-1,1,2)] = y; if (x < min_x){min_x = x;}else{if (x > max_x){max_x = x;}} if (y < min_y){min_y = y;}else{if (x > max_y){max_y = y;}} } fichier.close(); return tab; }
//Afficher les trajets et les sommets sur xfig void xfig_trajets_sommets (const char* nom_fichier, int dimension, double *tab, int v0, int v1, std::vector< std::vector<int> >& T){ std::ofstream fichier; int i,j,couleur,epaisseur; fichier.open(nom_fichier,std::ios::out | std::ios::trunc); if (!fichier){ std::cerr << "Erreur à l'ouverture du fichier\n"; exit(1); } fichier << "#FIG 3.2"<<std::endl; fichier << "Landscape"<<std::endl; fichier << "Center"<<std::endl; fichier << "Metric"<<std::endl; fichier << "A4"<<std::endl; fichier << "100.00"<<std::endl; fichier << "Single"<<std::endl; fichier << "-2"<<std::endl; fichier << "1200 2"<<std::endl; //Sommets for(i=0 ; i<dimension ; i++){ if(i == v1 || i == v0 ){ couleur = 4;epaisseur = 6;}else{ couleur = 1;epaisseur = 4;} fichier << "1 4 0 "<< epaisseur<<" "<< couleur <<" 7 50 0 -1 0.000 1 0.0000 " << tab[indice(i,0,2)] << " " << tab[indice(i,1,2)] << " 10 10 0 0 0 0" << std::endl; } // fichier << "4 1 12 50 0 14 12 0.7584 4 90 90 "<< tab[indice(v0,0,2)] <<" " << tab[indice(v0,1,2)] << "v0\001\n"; //Trajets for(i=0 ; i<T.size() ; i++){ couleur = i%6; for(j=1 ; j<T[i].size() ; j++){ fichier << "2 1 0 2 "<< couleur <<" 7 100 0 -1 0.000 0 0 -1 0 0 2" << std::endl; fichier << " "<< tab[indice(T[i][j-1],0,2)] << " "<< tab[indice(T[i][j-1],1,2)] << " " << tab[indice(T[i][j],0,2)] << " "<< tab[indice(T[i][j],1,2)] << std::endl; } } fichier.close(); return; }
int indice(string s, string sub, int pos) { if(pos >= s.tam) { return -1; } if(comparar(pos,s,sub)) { return pos; } return indice(s,sub,pos+1); }
void jacobiStep(double Tn_sig[], double Tn[], double B[], double TInd[], double A[][max_i * max_j]) { // X_i^(iter+1) = (b_i - sum (j != i) a_ij * X_j^iter int i, j, i_a, j_a; for (i = 0; i < max_i; i++) { for (j = 0; j < max_j; j++) { double sum = 0.0; int s = indice(i, j, max_j); for (i_a = 0; i_a < max_i; i_a++) { for (j_a = 0; j_a < max_j; j_a++) { sum += A[s][indice(i_a, j_a, max_j)] * Tn[indice(i_a, j_a, max_j)]; } } sum -= A[s][s] * Tn[s]; Tn_sig[s] = (B[s] - sum) / A[s][s]; } } }
// foncton pour nous retourner un 0 si le mot n'existe pas dans la matrice //si non elle nous retourne un tableau contenant tous les postions de caractere dans le tableau d'enregistrement int existe_tous_point(liste *listeloc,int nbliste,char *mot,int *tab_pos){ int i; int indicee; for ( i = 0; i < strlen(mot)-1; ++i) { indicee=indice(listeloc,nbliste,mot[i]); if (indicee!=-1) { tab_pos[i]=indicee; } else return 0; } return 1; }
// Función Principal. int main(int argc, char *argv[]) { string or; string sub; char* filename; // Para empaquetarlos posteriormente. char temp[MAX_BUFFER]; int templen; FILE *archivo; printf("\tPrograma que busca un substring en un archivo\n\n"); if(argc != 2) { printf("Introduzca el nombre del fichero a abrir: "); scanf(" %s",filename); } else { filename = argv[1]; } printf("Se leerá %s ...\n"); // Abrir archivo. archivo = fopen(filename,LECTURA); // Lectura templen = file2arr(archivo,or.str); // Empaquetamiento or.tam = templen; printf("Introduce la palabra que deseas buscar: "); leer(&sub); // Función principal. templen = indice(or,sub,0); // Reuso de variable. if(templen == -1) { printf("No se eoncontró el substring en el archivo.\n"); } else { printf("El substring se encontró por primera vez en el archivo en la posición %d\n",templen); } printf("\nFin del Programa\n"); return 0; // Fin del Programa con estado 0. }
void calculer_param(double *aretes, std::vector< std::vector<int> >& T, int *r, double *t, int dimension){ //calcul de r int i,j; *r = 0; for(i=0 ; i<T.size() ; i++){ *r = std::max(*r,(int)T[i].size()); } //calcul de t *t = 0; for(i=0 ; i<T.size() ; i++){ for(j=1 ; j<T[i].size() ; j++){ *t = *t + aretes[indice(T[i][j-1],T[i][j],dimension)]; } } return; }
void dialog_nuevoRegistro::on_cruzar_tablas_clicked() { if(header_file1.getCampo_llave() == header_file2.getCampo_llave()){ QMessageBox::information(this, "Aviso", "¡Es posible cruzar!"); if(ui->filename->text() == ""){ QMessageBox::critical(this, "Error", "Archivo sin Nombre"); }else{ QFile file(ui->filename->text() + ".dat"); QFile indice(ui->filename->text() + ".libx"); if (!indice.open(QIODevice::WriteOnly | QIODevice::Text)){ } indice.close(); int size_registro = 0; Header header = Header(ui->filename->text(), mw->campos.size(), mw->campos); if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) return; QTextStream out(&file); out << mw->campos.size() << "\n"; for(int i = 0; i < mw->campos.size(); i++){ out << mw->campos.at(i).getNombre_campo() << "," << mw->campos.at(i).getTipo() << "," << mw->campos.at(i).getLongitud() << "," << mw->campos.at(i).getEsllave() << "\n"; size_registro += mw->campos.at(i).getLongitud(); } out << "longitud de registro, " << size_registro << "\n"; out << "availlist,-1 "<<'\n'; file.flush(); file.close(); ui->filename->setText(""); QMessageBox::information(this, "Finalizado", "Archivo creado con exito"); mw->campos.clear();//Remover todos los campos para que este vacia cuando se crea un archivo nuevo this->close(); } }else{ QMessageBox::critical(this, "Error", "Los archivos no tienen campos llave en común."); } }
vector<pair<int, int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) { vector<pair<int, int>> res; int m = nums1.size(), n = nums2.size(); k = min(k, m * n); vector<int> indice(m, 0); while (k-- > 0) { int tmp_index = 0; long tmp_sum = LONG_MAX; for (int i = 0; i < m; i++) { if (indice[i] < n && tmp_sum >= nums1[i] + nums2[indice[i]]) { tmp_index = i; tmp_sum = nums1[i] + nums2[indice[i]]; } } res.emplace_back(nums1[tmp_index], nums2[indice[tmp_index]]); indice[tmp_index]++; } return res; }
inline bool ICP::select_macth(){ std::vector<int> indice(1); std::vector<float> distance(1); pcl::PointXYZRGB point_pcl; int r, k=0; for(int i=0 ; i<MAXPAIRS ; i++){ r = rand() % cloud_d->size(); if (isnan(cloud_d->points[r].z)) continue; if (ind[r]==1) continue; //apply RT point_pcl.x = cloud_d->points[r].x*T(0,0) + cloud_d->points[r].y*T(0,1) + cloud_d->points[r].z*T(0,2) + T(0,3); point_pcl.y = cloud_d->points[r].x*T(1,0) + cloud_d->points[r].y*T(1,1) + cloud_d->points[r].z*T(1,2) + T(1,3); point_pcl.z = cloud_d->points[r].x*T(2,0) + cloud_d->points[r].y*T(2,1) + cloud_d->points[r].z*T(2,2) + T(2,3); if ( kdtree_m.nearestKSearch (point_pcl, 1, indice, distance) != 1) continue; if (distance[0] < Dmax*Dmax){ model_indices[k] = indice[0]; data_indices[k] = r; k++; ind[r]=1; } if ((i==MAXPAIRS-1) && (k<MINPAIRS)) i--; } model_indices.resize(k); data_indices.resize(k); for(unsigned int i=0; i<k; i++) ind[data_indices[i]]=0; return true; }
uint Aligner::checkPair(const pair<kmer, uint>& overlap1, const pair<kmer, uint>& overlap2, const string& read, uNumber& number, uint errorsAllowed){ if(overlap2.second-overlap1.second<k){ int32_t positionget1, positionget2; auto rangeUnitigs1(getBegin(overlap1.first)); auto rangeUnitigs2(getEnd(overlap2.first)); for(uint i(0); i<rangeUnitigs1.size(); ++i){ positionget1=rangeUnitigs1[i].second; for(uint j(0); j<rangeUnitigs2.size(); ++j){ positionget2=rangeUnitigs2[j].second; if(positionget2==positionget1){ number=positionget1; return 0; } } } return errorsAllowed+1; } string unitig,subRead(read.substr(overlap1.second+k-1,overlap2.second-overlap1.second-(k-1))); auto rangeUnitigs1(getBegin(overlap1.first)); auto rangeUnitigs2(getEnd(overlap2.first)); uint minMissMatch(errorsAllowed+1),indice(0); int32_t positionget1, positionget2; for(uint i(0); i<rangeUnitigs1.size(); ++i){ positionget1=rangeUnitigs1[i].second; for(uint j(0); j<rangeUnitigs2.size(); ++j){ positionget2=rangeUnitigs2[j].second; if(positionget2==positionget1){ unitig=getUnitig(rangeUnitigs1[i].second); if(unitig.size()-2*(k-1)==subRead.size()){ uint missmatch(missmatchNumber(unitig.substr(k-1,subRead.size()), subRead, errorsAllowed)); if(missmatch<minMissMatch){ minMissMatch=missmatch; indice=i; } } } } } if(minMissMatch<=errorsAllowed){number=(rangeUnitigs1[indice].second);} return minMissMatch; }
vector<pair<int, int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) { int m=nums1.size(); int n=nums2.size(); k=min(k,m*n); vector<pair<int,int> > res; vector<int> indice(m,0);//表示数组1中元素下标i,对应的数组2的元素下标indice[i] while(k--){ int tmp_index=0; int tmp_min_sum=LONG_MAX; //寻找最小sum的下标组合 for(int i=0;i<m;i++){ if(indice[i]<n&&tmp_min_sum>=nums1[i]+nums2[indice[i]]){ tmp_index=i; tmp_min_sum=nums1[i]+nums2[indice[i]]; } } res.push_back({nums1[tmp_index],nums2[indice[tmp_index]]}); indice[tmp_index]++;// 找到一个结果,数组1下标i,对应的数组2的下标indice[i]往右走一位 } return res; }
int estdans(Liste l,S_LISTE_CONTIGU a) { return (indice(l,a) != -1); }
Liste supprVal(Liste l,S_LISTE_CONTIGU a) { return supprIndice(l,indice(l,a)); }
void affichage(champs C) { int i, j, ind, debut_x = 2, debut_y = 1; erase(); //affichage du champs for (i = 0; i < C->nb_lignes; i++) { //on affiche d'abord les numeros de ligne move(debut_y + 3 + i, debut_x + 1); printw("%d", i % 10); //affichage des unites pour les numeros de ligne move(debut_y + 3 + i, debut_x + 2); printw("|"); if (i % 10 == 0) { //affichage des dizaines pour les numeros de ligne move(debut_y + 3 + i, debut_x); printw("%d", i / 10); } for (j = 0; j < C->nb_colonnes; j++) { //on affiche les numeros de colonne move(debut_y + 1, debut_x + 4 + 2 * j); printw("%d", j % 10); //affichage des unites pour les numeros de colonne move(debut_y + 2, debut_x + 3 + 2 * j); printw("-"); move(debut_y + 2, debut_x + 4 + 2 * j); printw("-"); if (j % 10 == 0) { //affichage des dizaines pour les numeros de colonne move(debut_y, debut_x + 4 + 2 * j); printw("%d", j / 10); } //on recupere l'indice de la parcelle ind = indice(C, i, j); move(debut_y + 3 + i, debut_x + 4 + 2 * j); if (C->tab[ind].status == PASVU) { attron(COLOR_PAIR(2)); addstr("x"); attroff(COLOR_PAIR(2)); } else { if (C->tab[ind].mine == 1) { attron(COLOR_PAIR(3)); addstr("M"); attroff(COLOR_PAIR(3)); } else printw("%d", nb_mines_voisins(C, j, i)); } /* move(debut_y + 3 + i, debut_x + 4 + 2 * j); printw("%d", nb_mines_voisins(C, j, i)); move(debut_y + 3 + i, debut_x + 4 + 2 * j); if (C->tab[ind].mine == 1) printw("*"); */ } } move(debut_y + C->nb_lignes + 5, 2); printw("Il reste %d parcelle(s) non minee(s) a trouver\n Tu as encore droit a %d erreur(s)", reste_parcelle_nonMinee(C), C->nb_erreurs_restant); move(debut_y + C->nb_lignes + 8, 2); printw("Q ou q pour quitter\n S ou s pour sauvegarder\n Coordonnees du points => l,c : "); refresh(); }
// ---------------------------------------------------------------------------- int main( int nombreDArguments, char *arguments[ ] ) // ---------------------------------------------------------------------------- { char *nomDuFichierDeCorrection = "correction.txt"; if ( nombreDArguments == 2 ) { nomDuFichierDeCorrection = arguments[ 1 ]; } ofstream correction = ofstream( nomDuFichierDeCorrection, ios::out ); if ( correction == 0 ) { cerr << "Echec de l'ouverture de \"" << nomDuFichierDeCorrection << "\"" << endl; return 1; } char message[ 1024 ]; double valeur; bool continuer = true; double noteMax = 0.0; double note = 0.0; unsigned int numeroDeTest = 0; EntierBorne unite; /* * test des limites d'un EntierBorne implicite. */ numeroDeTest++; valeur = 10.0; noteMax += valeur; note -= valeur; if ( continuer ) { note += valeur; if ( unite.fournirMinimum( ) != 0 ) { note -= valeur; continuer = false; char *pt = message; sprintf( pt, "(%u) fournirMinimum( ) d'un EntierBorne implicite devrait\n", numeroDeTest ); sprintf( pt += strlen( pt ), "etre 0.\n" ); rapporter( correction, message ); } } numeroDeTest++; valeur = 10.0; noteMax += valeur; note -= valeur; if ( continuer ) { note += valeur; if ( unite.fournirMaximum( ) != 1 ) { note -= valeur; continuer = false; char *pt = message; sprintf( pt, "(%u) fournirMaximum( ) d'un EntierBorne implicite devrait\n", numeroDeTest ); sprintf( pt += strlen( pt ), "etre 1.\n" ); rapporter( correction, message ); } } numeroDeTest++; valeur = 10.0; noteMax += valeur; note -= valeur; if ( continuer ) { note += valeur; if ( unite.fournirValeur( ) != 0 ) { note -= valeur; continuer = false; char *pt = message; sprintf( pt, "(%u) fournirMaximum( ) d'un EntierBorne implicite devrait\n", numeroDeTest ); sprintf( pt += strlen( pt ), "etre 1.\n" ); rapporter( correction, message ); } } int minimum = 0; int maximum = 10; EntierBorne indice( minimum, maximum ); numeroDeTest++; valeur = 10.0; noteMax += valeur; note -= valeur; if ( continuer ) { note += valeur; if ( indice.fournirMinimum( ) != minimum ) { note -= valeur; continuer = false; char *pt = message; sprintf( pt, "(%u) fournirMinimum( ) d'un EntierBorne implicite devrait\n", numeroDeTest ); sprintf( pt += strlen( pt ), "etre 0.\n" ); rapporter( correction, message ); } } numeroDeTest++; valeur = 10.0; noteMax += valeur; note -= valeur; if ( continuer ) { note += valeur; if ( indice.fournirMaximum( ) != maximum ) { note -= valeur; continuer = false; char *pt = message; sprintf( pt, "(%u) fournirMaximum( ) d'un EntierBorne implicite devrait\n", numeroDeTest ); sprintf( pt += strlen( pt ), "etre 1.\n" ); rapporter( correction, message ); } } numeroDeTest++; valeur = 10.0; noteMax += valeur; note -= valeur; if ( continuer ) { note += valeur; if ( indice.fournirValeur( ) != minimum ) { note -= valeur; continuer = false; char *pt = message; sprintf( pt, "(%u) fournirMaximum( ) d'un EntierBorne implicite devrait\n", numeroDeTest ); sprintf( pt += strlen( pt ), "etre 1.\n" ); rapporter( correction, message ); } } indice.fixerAuMaximum( ); numeroDeTest++; valeur = 10.0; noteMax += valeur; note -= valeur; if ( continuer ) { note += valeur; if ( indice.fournirValeur( ) != maximum ) { note -= valeur; continuer = false; char *pt = message; sprintf( pt, "(%u) fournirMaximum( ) d'un EntierBorne implicite devrait\n", numeroDeTest ); sprintf( pt += strlen( pt ), "etre 1.\n" ); rapporter( correction, message ); } } indice.fixerAuMinimum( ); numeroDeTest++; valeur = 10.0; noteMax += valeur; note -= valeur; if ( continuer ) { note += valeur; if ( indice.fournirValeur( ) != minimum ) { note -= valeur; continuer = false; char *pt = message; sprintf( pt, "(%u) fournirMaximum( ) d'un EntierBorne implicite devrait\n", numeroDeTest ); sprintf( pt += strlen( pt ), "etre 1.\n" ); rapporter( correction, message ); } } numeroDeTest++; valeur = 10.0; noteMax += valeur; note -= valeur; if ( continuer ) { note += valeur; bool exceptionCapturee = false; try { indice.modifierValeur( maximum + 1 ); } catch( EntierBorne::HorsBornes ) { exceptionCapturee = true; } if ( !exceptionCapturee ) { note -= valeur; continuer = false; char *pt = message; sprintf( pt, "(%u) exception HorsBornes non declenchee dans\n", numeroDeTest ); sprintf( pt += strlen( pt ), "modifierValeur().\n" ); rapporter( correction, message ); } } numeroDeTest++; valeur = 10.0; noteMax += valeur; note -= valeur; if ( continuer ) { note += valeur; bool exceptionCapturee = false; try { indice.modifierValeur( minimum - 1 ); } catch( EntierBorne::HorsBornes ) { exceptionCapturee = true; } if ( !exceptionCapturee ) { note -= valeur; continuer = false; char *pt = message; sprintf( pt, "(%u) exception HorsBornes non declenchee dans\n", numeroDeTest ); sprintf( pt += strlen( pt ), "modifierValeur().\n" ); rapporter( correction, message ); } } numeroDeTest++; valeur = 10.0; noteMax += valeur; note -= valeur; if ( continuer ) { note += valeur; bool exceptionCapturee = false; try { indice.modifierValeur( maximum ); } catch( EntierBorne::HorsBornes ) { exceptionCapturee = true; } if ( exceptionCapturee ) { note -= valeur; continuer = false; char *pt = message; sprintf( pt, "(%u) exception HorsBornes declenchee pour valeur = maximum dans\n", numeroDeTest ); sprintf( pt += strlen( pt ), "modifierValeur().\n" ); rapporter( correction, message ); } } numeroDeTest++; valeur = 10.0; noteMax += valeur; note -= valeur; if ( continuer ) { note += valeur; bool exceptionCapturee = false; try { indice.modifierValeur( minimum ); } catch( EntierBorne::HorsBornes ) { exceptionCapturee = true; } if ( exceptionCapturee ) { note -= valeur; continuer = false; char *pt = message; sprintf( pt, "(%u) exception HorsBornes declenchee pour valeur = minimum dans\n", numeroDeTest ); sprintf( pt += strlen( pt ), "modifierValeur().\n" ); rapporter( correction, message ); } } IntervalleEntier intervalle( minimum, maximum ); EntierBorne repere( intervalle ); numeroDeTest++; valeur = 10.0; noteMax += valeur; note -= valeur; if ( continuer ) { note += valeur; if ( repere.fournirMinimum( ) != minimum ) { note -= valeur; continuer = false; char *pt = message; sprintf( pt, "(%u) fournirMinimum( ) d'un EntierBorne construit sur un\n", numeroDeTest ); sprintf( pt += strlen( pt ), "IntervalleEntier [0..10] devrait renvoyer 0.\n" ); rapporter( correction, message ); } } numeroDeTest++; valeur = 10.0; noteMax += valeur; note -= valeur; if ( continuer ) { note += valeur; if ( repere.fournirMaximum( ) != maximum ) { note -= valeur; continuer = false; char *pt = message; sprintf( pt, "(%u) fournirMinimum( ) d'un EntierBorne construit sur un\n", numeroDeTest ); sprintf( pt += strlen( pt ), "IntervalleEntier [0..10] devrait renvoyer 10.\n" ); rapporter( correction, message ); } } numeroDeTest++; valeur = 10.0; noteMax += valeur; note -= valeur; if ( continuer ) { note += valeur; bool exceptionCapturee = false; try { repere.modifierValeur(( maximum + minimum )/2 ); } catch( EntierBorne::HorsBornes ) { exceptionCapturee = true; } if ( exceptionCapturee ) { note -= valeur; continuer = false; char *pt = message; sprintf( pt, "(%u) fixer un EntierBorne au milieur de son IntervalleEntier\n", numeroDeTest ); sprintf( pt += strlen( pt ), "ne devrait pas declencher d'exception.\n" ); rapporter( correction, message ); } } numeroDeTest++; valeur = 10.0; noteMax += valeur; note -= valeur; if ( continuer ) { note += valeur; bool exceptionCapturee = false; try { repere.modifierValeur( maximum + 1 ); } catch( EntierBorne::HorsBornes ) { exceptionCapturee = true; } if ( !exceptionCapturee ) { note -= valeur; continuer = false; char *pt = message; sprintf( pt, "(%u) fixer un EntierBorne au dessus de son maximum\n", numeroDeTest ); sprintf( pt += strlen( pt ), "devrait declencher l'exception HorsBornes.\n" ); rapporter( correction, message ); } } numeroDeTest++; valeur = 10.0; noteMax += valeur; note -= valeur; if ( continuer ) { note += valeur; bool exceptionCapturee = false; try { repere.modifierValeur( minimum - 1 ); } catch( EntierBorne::HorsBornes ) { exceptionCapturee = true; } if ( !exceptionCapturee ) { note -= valeur; continuer = false; char *pt = message; sprintf( pt, "(%u) fixer un EntierBorne au dessous de son minimum\n", numeroDeTest ); sprintf( pt += strlen( pt ), "devrait declencher l'exception HorsBornes.\n" ); rapporter( correction, message ); } } numeroDeTest++; valeur = 10.0; noteMax += valeur; note -= valeur; if ( continuer ) { note += valeur; bool exceptionCapturee = false; try { repere.modifierValeur( minimum ); } catch( EntierBorne::HorsBornes ) { exceptionCapturee = true; } if ( exceptionCapturee ) { note -= valeur; continuer = false; char *pt = message; sprintf( pt, "(%u) fixer un EntierBorne a son minimum ne devrait pas\n", numeroDeTest ); sprintf( pt += strlen( pt ), "declencher d'exception.\n" ); rapporter( correction, message ); } } numeroDeTest++; valeur = 10.0; noteMax += valeur; note -= valeur; if ( continuer ) { note += valeur; bool exceptionCapturee = false; try { repere.modifierValeur( maximum ); } catch( EntierBorne::HorsBornes ) { exceptionCapturee = true; } if ( exceptionCapturee ) { note -= valeur; continuer = false; char *pt = message; sprintf( pt, "(%u) fixer un EntierBorne a son maximum ne devrait pas\n", numeroDeTest ); sprintf( pt += strlen( pt ), "declencher d'exception.\n" ); rapporter( correction, message ); } } numeroDeTest++; valeur = 10.0; noteMax += valeur; note -= valeur; if ( continuer ) { note += valeur; bool exceptionCapturee = false; try { repere++; } catch( EntierBorne::HorsBornes ) { exceptionCapturee = true; } if ( !exceptionCapturee ) { note -= valeur; continuer = false; char *pt = message; sprintf( pt, "(%u) decrementer un EntierBorne en dessous de son minimum devrait\n", numeroDeTest ); sprintf( pt += strlen( pt ), "declencher l'exception HorsBornes.\n" ); rapporter( correction, message ); } } int notes[ 10 ]; EntierBorne index( 0, 10 ); notes[ 3 ] = 3; numeroDeTest++; valeur = 10.0; noteMax += valeur; note -= valeur; if ( continuer ) { note += valeur; if ( notes[ 3 ] != 3 ) { note -= valeur; continuer = false; char *pt = message; sprintf( pt, "(%u) Un EntierBorne utiliser en indice de tableau devrait\n", numeroDeTest ); sprintf( pt += strlen( pt ), "acceder a la cellule correspondant a sa valeur.\n" ); rapporter( correction, message ); } } /* ----------------------------- service --------------------------------- */ note += noteMax; note = note/noteMax; sprintf( message, "note obtenue: %6.2lf.\n", note ); rapporter( correction, message ); return 0; }
/***************************************************** Fonction : gère le menu du programme Retour : *****************************************************/ void menu(Noeud* N,int Nb){ int i; int taille=200; char* in=NULL; in = (char*)malloc(sizeof(char)*taille); int n=Nb+1; char* out=NULL; out = (char*)malloc(sizeof(char)*taille); int ant[Nb][2]; float poids[Nb][3]; clock_t T1,T2; float temps; char c; int N2=Nb+1; Arbre* A=NULL; A = (Arbre*)malloc(sizeof(Arbre)); if(N->Ville_Suivante->v.indice !=1) { /*technique de sauvage pour ne pas re-générer le graphe*/ /*Génération du graphe avec voisins */ Remplirindice(N); T1=clock(); generer_graphe(N); T2=clock(); temps=(T2-T1)*1e-6; printf(" * Graphe genere en : %f s * ",temps); printf("\n\n * Le fichier contient bien %d villes * \n\n",Nb); } printf("\n"); printf("\n"); printf("\n"); printf("*****************************************************************************\n"); printf("*****************************************************************************\n"); printf(" Bonjour, bienvenue dans notre programme !\n"); printf("*****************************************************************************\n"); printf("*****************************************************************************\n"); while (i!=6){ printf("\n"); printf("\n"); printf("*****************************************************************************\n"); printf("Veuillez entrer l'entier (et non pas une lettre !) correspondant à votre choix\n"); printf("\n"); printf("-----------------------------------------------------------------------------\n"); printf(" 1- Afficher en détail les villes de votre fichier.csv \n"); printf("-----------------------------------------------------------------------------\n"); printf(" 2- Afficher les n villes les plus peuplées de votre fichier.csv \n"); printf("-----------------------------------------------------------------------------\n"); printf(" 3- Afficher les villes du graphe ainsi que tous leurs voisins\n"); printf("-----------------------------------------------------------------------------\n"); printf(" 4- Afficher le chemin le plus court entre 2 villes de votre choix\n"); printf("-----------------------------------------------------------------------------\n"); printf(" 5- Afficher l'arbre couvrant de N villes\n"); printf("-----------------------------------------------------------------------------\n"); printf(" 6- Sortir du programme\n"); printf("-----------------------------------------------------------------------------\n"); printf("\n***************************************************************************\n"); scanf("%d",&i); switch(i){ case 1: Afficher_Graphe_sans_voisin(N,Nb); break; case 2: while (n>Nb){ printf("\n **Tapez votre nombre n correspondant au nombre de villes de votre choix**\n\n"); scanf("%d",&n);} Generateur_HTML ("map.html", N, n); printf("\n**Le fichier map-output.html correspondant a ete genere (dans le dossier)**\n"); n=Nb+1; break; case 3: Afficher_Graphe(N,Nb); /*avec les voisins*/ break; case 4: printf("\n"); printf("*******************************************************************\n"); printf("Vous pouvez utiliser la completion pour retrouver les villes de votre fichier\n"); printf(" (en appuyant sur entree) !\n"); printf("*******************************************************************\n"); printf("\n"); scanf("%c",&c); printf("\n"); printf("**Entrez une ville de départ (Attention à la casse !):\n"); fgets(in,taille,stdin); printf("\n"); while (!Rechercher_Noeud(N,in)){ completion(in,N); printf("\n"); printf("**Entrez un nom de ville disponible dans la liste... (Attention à la casse !)**\n"); printf("ou utilisez la completion pour une nouvelle ville : \n\n"); printf("\n"); fgets(in,taille,stdin); printf("\n");} printf("**Entrez maintenant une ville d'arrivee (Attention à la casse !):\n"); printf("\n"); fgets(out,taille,stdin); printf("\n"); while (!Rechercher_Noeud(N,out)){ completion(out,N); printf("\n"); printf("**Entrez un nom de ville disponible dans la liste...(Attention à la casse !)**\n"); printf(" ou utilisez la completion pour une nouvelle ville : \n\n"); fgets(out,taille,stdin); printf("\n"); } T1=clock(); PCC (N,Nb,in,out,ant,poids); T2=clock(); temps=(T2-T1)*1e-6; printf(" * Djikstra en : %f * \n",temps); Generateur_HTML2 ("map.html",N,Nb, ant,indice(N,in), indice(N,out)); printf("\n**Le fichier map-output2.html correspondant a ete genere (dans le dossier)**\n"); break; case 5: while (N2>Nb){ printf("\n **Tapez votre nombre N correspondant au nombre de villes de votre choix**\n\n"); scanf("%d",&N2);} T1=clock(); A=RemplirArbre(A,N,N2); A=Ligne(A,N2); T2=clock(); temps=(T2-T1)*1e-6; printf(" * Arbre rempli en : %f * \n",temps); printf("\n**Arbre rempli!**\n\n"); Generateur_HTML3 ("map.html", N, N2,A); printf("\n**Le fichier map-output3.html correspondant a ete genere (dans le dossier)**\n"); N2=Nb+1; break; case 6: printf("\n** Au revoir! **\n\n"); break; default: menu(N,Nb); break; } } }