-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUtils.cpp
64 lines (54 loc) · 1.76 KB
/
Utils.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 "Utils.h"
namespace Utils {
std::map<std::string, std::string> readSettingsFrom(QString path){
QFile f(path);
QStringList s;
std::map<std::string, std::string> temp;
if (f.open(QFile::ReadOnly | QFile::Text)){
QTextStream in(&f);
while(!in.atEnd()){
QString first_line = in.readLine();
s = first_line.split("=");
temp[s[0].toStdString()] = s[1].toStdString();
}
}
f.close();
return temp;
}
std::vector<float> readBestGenomeFrom(QString path){
QFile f(path);
QStringList s;
std::vector<float> return_vector;
if (f.open(QFile::ReadOnly | QFile::Text)){
QTextStream in(&f);
QString line = in.readLine();
s = line.split(" ");
}
f.close();
s.removeAt(0); // remove first fitness entry
for(auto const& f : s){
return_vector.push_back(f.toFloat());
}
return return_vector;
}
std::vector<std::vector<float>> readAllGenomesFrom(QString path){
QFile f(path);
QStringList s;
std::vector<std::vector<float>> return_vector;
if (f.open(QFile::ReadOnly | QFile::Text)){
QTextStream in(&f);
while(!in.atEnd()){
QString line = in.readLine();
s = line.split(" ");
s.removeAt(0); // remove first fitness entry
std::vector<float> temp_vector;
for(auto const& f : s){
temp_vector.push_back(f.toFloat());
}
return_vector.push_back(temp_vector);
}
}
f.close();
return return_vector;
}
}