Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void TestAlgoritmo::costeCasoEmpirico(int numerocaso)
- {
- /* ESCRIBIR PARA COMPLETAR LA PRÁCTICA*/
- ofstream f(nombreAlgoritmoCaso[numerocaso] + "Empirico.dat");
- system("cls");
- cout << endl << "Busqueda Secuencial" << nombreAlgoritmoCaso[numerocaso] + " Empirico";
- cout << "Tiempos de ejecucion " << endl << endl;
- cout << "\tTalla\t\tTiempo (oe)" << endl << endl;
- double tiempo = 0;
- int talla;
- int key;
- int posicion;
- Mtime t;
- LARGE_INTEGER t_ini, t_fin;
- double secs=0;
- ConjuntoInt* v;
- for (int talla = tallaIni; talla <= tallaFin; talla += incTalla)
- {
- v = new ConjuntoInt(talla);
- v->GeneraVector(talla);
- switch (numerocaso) {
- case SECUENCIALPEOR: /*Caso peor (T(n)= 7n+9)*/
- {
- for (int r = 0; r < NUMREPETICIONES; r++)
- {
- key = -1;
- QueryPerformanceCounter(&t_ini);
- /* ...hacer algo... */
- // Buscar la clave en el array
- posicion = v->busquedaSecuencial(key);
- QueryPerformanceCounter(&t_fin);
- secs = t.performancecounter_diff(&t_fin, &t_ini);
- tiempo = tiempo + secs;
- }
- tiempo = tiempo / NUMREPETICIONES;
- }
- break;
- case SECUENCIALMEDIO:/*Caso medio (T(n)= (7/2)n+9)*/
- {
- for (int r = 0; r < NUMREPETICIONES; r++)
- {
- key = v->generaKey();
- QueryPerformanceCounter(&t_ini);
- /* ...hacer algo... */
- // Buscar la clave en el array
- posicion = v->busquedaSecuencial(key);
- QueryPerformanceCounter(&t_fin);
- secs = t.performancecounter_diff(&t_fin, &t_ini);
- tiempo = tiempo + secs;
- }
- tiempo = tiempo / NUMREPETICIONES;
- }
- break;
- case SECUENCIALMEJOR:/*Caso mejor (T(n)= 9)*/
- {
- for (int r = 0; r < NUMREPETICIONES; r++)
- {
- key = v->getPrimero();
- QueryPerformanceCounter(&t_ini);
- /* ...hacer algo... */
- // Buscar la clave en el array
- posicion = v->busquedaSecuencial(key);
- QueryPerformanceCounter(&t_fin);
- secs = t.performancecounter_diff(&t_fin, &t_ini);
- tiempo = tiempo + secs;
- }
- tiempo = tiempo / NUMREPETICIONES;
- }
- break;
- }
- f << talla << "\t" << tiempo << endl;
- cout << "\t" << talla << "\t\t" << setw(10) << setprecision(2) << (double)tiempo << " \t\t" << endl;
- }
- f.close();
- cout << endl << "Datos guardados en el fichero " << nombreAlgoritmoCaso[numerocaso] << "Empirico.dat " << endl;
- /* Generar grafica */
- char opc;
- cout << endl << "Generar grafica de resultados? (s/n): ";
- cin >> opc;
- switch (opc) {
- case 's':
- case 'S': {
- switch (numerocaso) {
- case SECUENCIALMEJOR: {
- /* Ejecutar el fichero por lotes (comandos)*/
- system("CmdMejorEmpirico.gpl"); system("cls");
- cout << endl << "Grafica guardada en el fichero " << nombreAlgoritmoCaso[numerocaso] + "Empirico" << ".pdf" << endl;
- }break;
- case SECUENCIALPEOR: {
- /* Ejecutar el fichero por lotes (comandos)*/
- system("CmdPeorEmpirico.gpl"); system("cls");
- cout << endl << "Grafica guardada en el fichero " << nombreAlgoritmoCaso[numerocaso] + "Empirico" << ".pdf" << endl;
- }break;
- case SECUENCIALMEDIO: {
- /* Ejecutar el fichero por lotes (comandos)*/
- system("CmdMedioEmpirico.gpl");
- system("cls");
- //system((gpl).c_str());
- cout << endl << "Grafica guardada en el fichero " << nombreAlgoritmoCaso[numerocaso] + "Empirico" << ".pdf" << endl;
- }break;
- default: {cout << "Error caso " << endl; }break;
- }
- default: {cout << "Grafica no guardada en fichero " << endl;
- }break;
- }
- }
- cout << endl;
- system("pause");
- system("cls");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement