Advertisement
Guest User

CARRERO AGAIN

a guest
Apr 9th, 2020
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.45 KB | None | 0 0
  1. void TestAlgoritmo::costeCasoEmpirico(int numerocaso)
  2. {
  3.     /* ESCRIBIR PARA COMPLETAR LA PRÁCTICA*/
  4.  
  5.  
  6.     ofstream f(nombreAlgoritmoCaso[numerocaso] + "Empirico.dat");
  7.     system("cls");
  8.     cout << endl << "Busqueda Secuencial" << nombreAlgoritmoCaso[numerocaso] + " Empirico";
  9.     cout << "Tiempos de ejecucion " << endl << endl;
  10.     cout << "\tTalla\t\tTiempo (oe)" << endl << endl;
  11.  
  12.  
  13.     double tiempo = 0;
  14.     int talla;
  15.     int key;
  16.     int posicion;
  17.     Mtime t;
  18.     LARGE_INTEGER t_ini, t_fin;
  19.     double secs=0;
  20.     ConjuntoInt* v;
  21.  
  22.  
  23.     for (int talla = tallaIni; talla <= tallaFin; talla += incTalla)
  24.     {
  25.  
  26.         v = new ConjuntoInt(talla);
  27.         v->GeneraVector(talla);
  28.  
  29.         switch (numerocaso) {
  30.         case SECUENCIALPEOR: /*Caso peor (T(n)= 7n+9)*/
  31.         {
  32.             for (int r = 0; r < NUMREPETICIONES; r++)
  33.             {
  34.                 key = -1;
  35.                 QueryPerformanceCounter(&t_ini);
  36.                 /* ...hacer algo... */
  37.                 // Buscar la clave en el array
  38.                 posicion = v->busquedaSecuencial(key);
  39.                 QueryPerformanceCounter(&t_fin);
  40.                 secs = t.performancecounter_diff(&t_fin, &t_ini);
  41.  
  42.                 tiempo = tiempo + secs;
  43.             }
  44.             tiempo = tiempo / NUMREPETICIONES;
  45.         }
  46.         break;
  47.         case SECUENCIALMEDIO:/*Caso medio (T(n)= (7/2)n+9)*/
  48.         {
  49.             for (int r = 0; r < NUMREPETICIONES; r++)
  50.             {
  51.                 key = v->generaKey();
  52.                 QueryPerformanceCounter(&t_ini);
  53.                 /* ...hacer algo... */
  54.                 // Buscar la clave en el array
  55.                 posicion = v->busquedaSecuencial(key);
  56.                 QueryPerformanceCounter(&t_fin);
  57.                 secs = t.performancecounter_diff(&t_fin, &t_ini);
  58.  
  59.                 tiempo = tiempo + secs;
  60.             }
  61.             tiempo = tiempo / NUMREPETICIONES;
  62.  
  63.         }
  64.         break;
  65.         case SECUENCIALMEJOR:/*Caso mejor (T(n)= 9)*/
  66.         {
  67.             for (int r = 0; r < NUMREPETICIONES; r++)
  68.             {
  69.                 key = v->getPrimero();
  70.                 QueryPerformanceCounter(&t_ini);
  71.                 /* ...hacer algo... */
  72.                 // Buscar la clave en el array
  73.                 posicion = v->busquedaSecuencial(key);
  74.                 QueryPerformanceCounter(&t_fin);
  75.                 secs = t.performancecounter_diff(&t_fin, &t_ini);
  76.  
  77.                 tiempo = tiempo + secs;
  78.             }
  79.             tiempo = tiempo / NUMREPETICIONES;
  80.         }
  81.         break;
  82.         }
  83.         f << talla << "\t" << tiempo << endl;
  84.         cout << "\t" << talla << "\t\t" << setw(10) << setprecision(2) << (double)tiempo << " \t\t" << endl;
  85.     }
  86.     f.close();
  87.     cout << endl << "Datos guardados en el fichero " << nombreAlgoritmoCaso[numerocaso] << "Empirico.dat " << endl;
  88.  
  89.     /* Generar grafica */
  90.     char opc;
  91.     cout << endl << "Generar grafica de resultados? (s/n): ";
  92.     cin >> opc;
  93.     switch (opc) {
  94.     case 's':
  95.     case 'S': {
  96.         switch (numerocaso) {
  97.         case SECUENCIALMEJOR: {
  98.             /* Ejecutar el fichero por lotes (comandos)*/
  99.             system("CmdMejorEmpirico.gpl"); system("cls");
  100.             cout << endl << "Grafica guardada en el fichero " << nombreAlgoritmoCaso[numerocaso] + "Empirico" << ".pdf" << endl;
  101.         }break;
  102.         case SECUENCIALPEOR: {
  103.             /* Ejecutar el fichero por lotes (comandos)*/
  104.             system("CmdPeorEmpirico.gpl"); system("cls");
  105.             cout << endl << "Grafica guardada en el fichero " << nombreAlgoritmoCaso[numerocaso] + "Empirico" << ".pdf" << endl;
  106.         }break;
  107.         case SECUENCIALMEDIO: {
  108.             /* Ejecutar el fichero por lotes (comandos)*/
  109.             system("CmdMedioEmpirico.gpl");
  110.             system("cls");
  111.             //system((gpl).c_str());
  112.             cout << endl << "Grafica guardada en el fichero " << nombreAlgoritmoCaso[numerocaso] + "Empirico" << ".pdf" << endl;
  113.         }break;
  114.         default: {cout << "Error caso " << endl; }break;
  115.         }
  116.     default: {cout << "Grafica no guardada en fichero " << endl;
  117.     }break;
  118.     }
  119.     }
  120.     cout << endl;
  121.     system("pause");
  122.     system("cls");
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement