-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.cpp
64 lines (50 loc) · 1.49 KB
/
test.cpp
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
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#define CASAS 7
#define NUM_TESTES 3
int main(int argc, char* argv[]) {
std :: ios_base :: sync_with_stdio(false);
std :: cin.tie(nullptr);
if(argc < 3) {
std :: cout << "use ./test <caminho-do-executavel> <pasta-em-instancias> < <arquivo-com-as-instancias>\n";
return 0;
}
int n;
std :: vector<std :: string> paths;
for(std :: string s; std :: getline(std :: cin, s); ) paths.push_back(s);
for(auto& w : paths) {
for(int i = 0; i < NUM_TESTES; ++i) {
std :: string s = std :: string(argv[1]) + " " + "instancias/" + std :: string(argv[2]) + "/" + w + " >> output.txt";
system(s.c_str());
}
}
std :: fstream fs("output.txt", std :: ios_base :: in);
fs.precision(CASAS);
fs.setf(std :: ios_base :: fixed);
std :: cout.precision(CASAS);
std :: cout.setf(std :: ios_base :: fixed);
for(auto&s : paths) {
long double seconds = 0, fitness = 0;
for(int i = 0; i < NUM_TESTES; ++i) {
std :: string fit, sc;
int a0;
long double a1;
std :: getline(fs, fit);
std :: getline(fs, sc);
sscanf(fit.c_str(), "fitness = %d", &a0);
sscanf(sc.c_str(), "seconds = %Lf", &a1);
fitness += a0;
seconds += a1;
}
std :: cout << "instância = " << s << '\n';
std :: cout << "fitness = " << fitness / NUM_TESTES << '\n';
std :: cout << "seconds = " << seconds / NUM_TESTES << '\n';
}
fs.close();
system("echo -n "" > output.txt");
return 0;
}