-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexperiment_hash.cc
119 lines (89 loc) · 2.66 KB
/
experiment_hash.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include "./SuperSopa/superSopa.hh"
#include <iostream>
#include <fstream>
#include <chrono>
using namespace std;
void llegir_fitxer (vector<string>& v, const string& path) {
ifstream fp_in;
string a;
fp_in.open(path);
while (fp_in >> a) {
v.push_back(a);
}
fp_in.close();
}
//retorna el moment actual
auto moment () {
return chrono::steady_clock::now();
}
void afegir_prefix (HashTableDictionary& d, string s) {
int n = s.size();
string aux = "";
for (int i = 0; i < n-1; ++i) {
aux.push_back(s[i]);
if (not d.comprovar(aux)) {
d.afegir(aux);
}
}
}
void mitjana (vector<double>& execucions, double& temps) {
int n = execucions.size();
double sumaT = 0;
for (int i = 0; i < n; ++i) {
sumaT += execucions[i];
}
temps = sumaT/n;
}
int main () {
ifstream fp_in;
ofstream fp_out;
superSopa super_sopa;
string pathSopes = "sopes.txt";
string pathResultat = "./resultats/resultatHash.txt";
string pathDiccionari = "./diccionaris/quijote-vocabulary-6.txt";
vector<string> diccionari;
llegir_fitxer(diccionari, pathDiccionari);
HashTableDictionary hash_table(diccionari.size());
HashTableDictionary prefixos(diccionari.size()*3);
auto begin = moment();
for (int i = 0; i < diccionari.size(); ++i) {
afegir_prefix(prefixos, diccionari[i]);
hash_table.afegir(diccionari[i]);
}
auto end = moment();
double ta = chrono::duration_cast<chrono::microseconds>(end - begin).count();
//EXPERIMENT COMPROVAR
fp_in.open(pathSopes);
fp_out.open(pathResultat);
fp_out << ta << endl;
char s;
int n;
for (int nSopes = 0; nSopes < 100; ++nSopes) {
//cout << nSopes << endl;
//llegir sopa
fp_in >> n;
Sopa sopa = Sopa(n, vector<char>(n, '#'));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
fp_in >> s;
sopa[i][j] = s;
}
}
//resoldre-la 10 cops
vector<double> execucions; //temps de cada execució
int result = 0;
for (int cops = 0; cops < 10; ++cops) {
auto begin = moment();
result += super_sopa.resoldre(hash_table, prefixos, sopa);
auto end = moment();
double t = chrono::duration_cast<chrono::microseconds>(end - begin).count();
execucions.push_back(t);
}
double t;
mitjana(execucions, t);
result /= 10;
fp_out << nSopes+1 << ' ' << n << ' ' << t << ' ' << result << endl;
}
fp_in.close();
fp_out.close();
}