- void TestBusqueda::comparar(int metodo1, int metodo2)
- {
- system("cls");
- cout << endl;
- cout << "\t*****COMPARACION DE LOS ALGORITMOS: " << nombreAlgoritmo[metodo1] << " y " << nombreAlgoritmo[metodo2] << "***" << endl;
- cout << endl;
- cout << "\t\tTALLA \t\tTIEMPO(ms)" << nombreAlgoritmo[metodo1] << "\tTIEMPO(ms)" << nombreAlgoritmo[metodo2] << endl;
- ofstream file("comparacion" + nombreAlgoritmo[metodo1] + nombreAlgoritmo[metodo2] + ".dat");
- if (file.fail())
- cout << "Error al abrir el archivo";
- double t1;
- double t2;
- int pos1;
- for (int talla = tallaIni; talla <= tallaFin; talla += incTalla)
- {
- ConjuntoInt* v = new ConjuntoInt(talla);
- t1 = 0;
- t2 = 0;
- for (int i = 0; i < NUMREPETICIONES; i++)
- {
- v->GeneraVector(talla);
- t1 += buscaEnArrayInt(v->generaKey(), v->getDatos(), talla, metodo1, pos1);
- v->GeneraVector(talla);
- t2 += buscaEnArrayInt(v->generaKey(), v->getDatos(), talla, metodo2, pos1);
- v->vaciar();
- }
- t1 /= NUMREPETICIONES;
- t2 /= NUMREPETICIONES;
- delete v;
- cout.precision(4);
- cout << "\t\t" << talla << "\t\t " << setw(10) << fixed << setprecision(4) << t1 << "\t " << setw(10) << fixed << setprecision(4) << t2 << "\n";
- if (talla != tallaIni)
- file << talla << "\t" << t1 << "\t" << t2 << "\n";
- }
- file.close();
- char opc;
- vector<string> ComparacionAlg;
- ComparacionAlg.push_back(nombreAlgoritmo[metodo1]);
- ComparacionAlg.push_back(nombreAlgoritmo[metodo2]);
- cout << "\nGenerar grafica (s, n): ";
- cin >> opc;
- if (opc == 's' || opc == 'S') {
- Graficas g;
- g.generarGraficaT(ComparacionAlg);
- cout << "La grafica fue generada.\n\n";
- system("start grafica.gpl");
- }
- else cout << "No se generara la grafica.\n\n";
- system("pause");
- }
- void TestBusqueda::comparaTodos()
- {
- system("cls");
- cout << "**COMPARATIVA DE TODOS LOS ALGORITMOS***";
- cout << endl << endl;
- cout << "\ttalla" << "\t\t Secuencial" << "\t Binaria" << "\t Interpolacion";
- cout << endl;
- ofstream file("AlgoritmosBusqueda.dat");
- if (file.fail())
- cout << "Error al abrir al crear el archivo.\nNo se guardaran los datos.\n";
- double t1 = 0;
- double t2 = 0;
- double t3 = 0;
- int pos1, pos2, pos3;
- for (int talla = tallaIni; talla <= tallaFin; talla += incTalla) {
- ConjuntoInt* v = new ConjuntoInt(talla);
- for (int i = 0; i < nombreAlgoritmo.size(); i++)
- {
- // tiempo[i] = 0;
- for (int j = 0; i < NUMREPETICIONES; i++)
- {
- v->GeneraVector(talla);
- t1 += buscaEnArrayInt(v->generaKey(), v->getDatos(), talla, 0, pos1);
- v->vaciar();
- v->GeneraVector(talla);
- t2 += buscaEnArrayInt(v->generaKey(), v->getDatos(), talla, 1, pos2);
- v->vaciar();
- v->GeneraVector(talla);
- t3 += buscaEnArrayInt(v->generaKey(), v->getDatos(), talla, 2, pos3);
- v->vaciar();
- }
- t1 /= NUMREPETICIONES;
- t2 /= NUMREPETICIONES;
- t3 /= NUMREPETICIONES;
- }
- delete v;
- cout.precision(4);
- cout << "\t" << talla << "\t";
- cout << "\t " << setw(10) << fixed << setprecision(4) << t1
- << "\t " << setw(10) << fixed << setprecision(4) << t2
- << "\t " << setw(10) << fixed << setprecision(4) << t3 << "\n";
- file << talla;
- file << "\t" << t1 << "\t" << t2 << "\t" << t3;
- file << "\n";
- }
- file.close();
- //Generar grafica
- char opt;
- cout << "\nGenerar grafica (s, n): ";
- cin >> opt;
- if (opt == 's' || opt == 'S') {
- Graficas g;
- g.generarGraficaT(nombreAlgoritmo);
- cout << "La grafica fue generada.\n\n";
- system("start grafica.gpl");
- }
- else cout << "No se generara la grafica.\n\n";
- system("pause");
- }