-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
146 lines (116 loc) · 5.68 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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include <iostream>
#include <cstdlib>
#include "ctpl_stl.h"
#include "alg.h"
std::pair<std::vector<organism>, std::vector<organism>> random_haplotypes(const simulation_params &sp,
const fourier &bacteria_fitness,
const fourier &plant_fitness,
const unsigned ancestor_size,
const double mn, const double mx)
{
std::vector<organism> b_pop, p_pop;
std::mt19937 random_generator(std::random_device{}());
while (true)
{
gene_c b_haplotype{sp.b_gene_size},
p_haplotype{sp.p_gene_size};
for (auto &i : b_haplotype)
i = rnd1(random_generator);
for (auto &i : p_haplotype)
i = rnd1(random_generator);
const auto d = distance(bacteria_fitness(b_haplotype), plant_fitness(p_haplotype));
if (d > mn && d < mx)
{
auto bacteria = organism{b_haplotype, bacteria_fitness(b_haplotype), {1 + static_cast<unsigned>(log2(ancestor_size) + 0.01)}, nullptr};
auto plant = organism{p_haplotype, plant_fitness(p_haplotype), {1 + static_cast<unsigned>(log2(ancestor_size) + 0.01)}, nullptr};
for (auto i = 0u; i < sp.b_pop_size; i++)
{
b_pop.push_back(bacteria);
}
for (auto i = 0u; i < sp.p_pop_size; i++)
{
p_pop.push_back(plant);
}
return {b_pop, p_pop};
}
}
}
//std::pair<org_vec, org_vec> full_random(const simulation_params& sp,
// const fourier& bacteria_fitness,
// const fourier& plant_fitness,
// const unsigned ancestor_size) {
// org_vec b_pop, p_pop;
// std::mt19937 random_generator(std::random_device{}());
// for (auto i = 0u; i < sp.b_pop_size; i++) {
// auto bacteria = std::make_shared<organism>(rnd1_vec(bacteria_fitness.input_size, random_generator));
// bacteria->ancestors.resize(1 + static_cast<unsigned>(log2(ancestor_size) + 0.01));
// bacteria->t_gene = bacteria_fitness(bacteria->gene);
// b_pop.push_back(bacteria);
// }
// for (auto i = 0u; i < sp.p_pop_size; i++) {
// auto plant = std::make_shared<organism>(rnd1_vec(plant_fitness.input_size, random_generator));
// plant->ancestors.resize(1 + static_cast<unsigned>(log2(ancestor_size) + 0.01));
// plant->t_gene = plant_fitness(plant->gene);
// p_pop.push_back(plant);
// }
//
// return {b_pop, p_pop};
//}
void run_simulation(int id, const simulation_params &sp)
{
const fourier bacteria_fitness(sp.b_gene_size, sp.inter_size, 1.2, 30u);
const fourier plant_fitness(sp.p_gene_size, sp.inter_size, 1.2, 30u);
const unsigned ancestor_size = 50;
auto [b_pop, p_pop] = random_haplotypes(sp, bacteria_fitness, plant_fitness, ancestor_size, 1.25, 1.4);
b_pop.reserve(sp.b_pop_size);
p_pop.reserve(sp.p_pop_size);
std::filesystem::create_directory(sp.out_path);
std::mt19937 random_generator((std::random_device())());
std::cout << sp.p_pop_size << std::endl;
population bacteria(sp.bm, sp.bv, bacteria_fitness, sp.b_pop_size, ancestor_size, 0, b_pop);
population plant(sp.bm, sp.bv, plant_fitness, sp.p_pop_size, ancestor_size, 0, p_pop);
simulation sim{bacteria, plant, sp.generations, sp.out_path};
sim.run();
}
int main(int argc, char *argv[])
{
std::ios_base::sync_with_stdio(false);
std::vector<std::tuple<unsigned, unsigned>> pop_sizes({{100000, 1000}});
std::vector<std::tuple<double, double>> p_mut_params({{0.06, 0.15}});
std::vector<std::tuple<double, double>> b_mut_params({{1e-4, 1}, {1e-5, 1}, {5e-6, 1}});
std::vector<std::tuple<unsigned, unsigned>> fitness_params({{5, 2}});
std::vector<simulation_params> sp;
if (argc != 2)
{
std::cout << "missing file with parameters" << std::endl;
return 0;
}
std::filesystem::path out_path(std::filesystem::current_path());
out_path.append("bacterial_m_equal_to_1_try");
std::filesystem::create_directory(out_path);
for (auto id = 0; id < 400; id++)
for (auto &ps : pop_sizes)
for (auto &b_params : b_mut_params)
for (auto &p_params : p_mut_params)
for (auto &f_params : fitness_params)
{
std::filesystem::path out_path_in(out_path);
std::ostringstream oss;
oss << "(" << std::get<0>(f_params) << "," << std::get<0>(f_params) << "," << std::get<1>(f_params) << "),";
print(oss, ps);
oss << ",";
print(oss, b_params);
oss << ",";
print(oss, p_params);
oss << ",2500," << (std::random_device())();
out_path_in.append(oss.str());
sp.push_back({2500u, std::get<0>(f_params), std::get<0>(f_params), std::get<1>(f_params),
std::get<0>(ps), std::get<1>(ps),
std::get<0>(b_params) / std::get<0>(f_params), std::get<1>(b_params),
std::get<0>(p_params) / std::get<0>(f_params), std::get<1>(p_params), out_path_in});
}
ctpl::thread_pool pool(std::strtol(argv[1], nullptr, 10));
for (auto &i : sp)
pool.push(run_simulation, i);
return 0;
}