-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
49 lines (43 loc) · 1.32 KB
/
main.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
#include <iostream>
#include "SpyOpt/config_parser.h"
#include "SpyOpt/spy_opt.h"
#include "SpyOpt/objective_functions.h"
using namespace spy_opt;
int main()
{
Config config;
if (!parseConfig("../resources/config.yaml", config))
{
std::cerr << "[Error] Failed to parse config!" << std::endl;
return -1;
}
std::cout << config << std::endl;
std::function<double(const std::vector<double>&)> objective_function;
if (config.objective_func_name == "Booth")
{
std::cout << "Using Booth function." << std::endl;
objective_function = booth_func;
}
else if (config.objective_func_name == "Eggholder")
{
std::cout << "Using Eggholder function." << std::endl;
objective_function = eggholder_func;
}
else if (config.objective_func_name == "Ackley")
{
std::cout << "Using Ackley function." << std::endl;
objective_function = ackley_function;
}
else
{
std::cerr << "[Error] Invalid objective function name." << std::endl;
return -1;
}
SpyOpt spy_alg(config, objective_function);
spy_alg.optimize();
const auto [fitness, pos] = spy_alg.getBestFitness();
std::cout << "Best solution:" << std::endl;
spy_alg.printBestAgent();
spy_alg.dumpHistory("../results/history.csv");
return 0;
}