-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.cpp
77 lines (67 loc) · 1.66 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
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
#define CORE_NUM 1
#define DETERMINISTIC
#include <iostream>
#include <ctime>
#include "Utils.h"
#include "Hillclimbing.h"
#include "Genetic.h"
#include "Solution.h"
#include <thread>
#include <stdio.h>
#include <vector>
#include "SAnnealing.h"
int main()
{
Utils::read_file();
std::cout << "File has been loaded\n";
Utils::calculate_distances();
std::cout << "Distances have been calculated\n";
//Hillclimbing::run();
srand(time(nullptr));
std::vector<std::thread> threads;
for (auto i = 0; i < CORE_NUM; ++i)
{
threads.push_back(std::thread([]()
{
#ifdef DETERMINISTIC
auto seed = 1;
#else
int seed = time(nullptr);
#endif
srand(seed);
//Hillclimbing
/*std::cout << "Seed: " << seed << "\n";
std::cout << "Hilclimbing, 200 solutions, max_fails: 10000\n";
for (auto j = 0; j < 1000; ++j)
{
auto solution = Hillclimbing::run(10000);
std::cout << solution->weight << ", ";
delete solution;
}*/
//Genetic algorithm
std::cout << "\nGenetic algorithm, 200 solutions, population limit: 10; max_iter: 10000\n";
for(auto j = 0; j < 200; ++j)
{
Genetic::population_limit = 20;
auto solution = Genetic::run(-1);
std::cout << solution->weight << ", ";
Genetic::clear();
}
//Simulated annealing
/*std::cout << "\nSimulated annealing, 200 solutions, temp: 100; min_temp: 0; tmp_lost_per_it: 0.01\n";
for (auto j = 0; j < 1; ++j)
{
auto solution = SAnnealing::run(100, 0, 0.00001);
std::cout << solution->weight << ", ";
delete solution;
}*/
}
));
}
for (auto it = threads.begin(); it != threads.end(); ++it)
{
(*it).join();
}
std::cout << "\nEnd.\n";
system("pause");
}