Commit 8ab3165f authored by Gauthier Quesnel's avatar Gauthier Quesnel
Browse files

optimizer: adding more random solution

parent e6489f9b
......@@ -61,6 +61,7 @@ private:
std::vector<int> m_indices;
std::vector<raw_result<Mode>> m_data;
bit_array m_bastert;
bit_array m_random;
std::normal_distribution<> m_choose_sol_dist;
std::bernoulli_distribution m_crossover_bastert_insertion;
......@@ -129,6 +130,7 @@ public:
, m_indices(population_size)
, m_data(population_size)
, m_bastert(variables)
, m_random(variables)
, m_choose_sol_dist(crossover_solution_selection_mean,
crossover_solution_selection_stddev)
, m_crossover_bastert_insertion(crossover_bastert_insertion)
......@@ -348,17 +350,30 @@ public:
void crossover(random_engine& rng, bit_array& x)
{
if (m_crossover_bastert_insertion(rng)) {
int first = m_indices[choose_a_solution(rng)];
m_data_reader lock_data_1{ m_data_mutex[first] };
crossover(rng, x, m_data[first].x, m_bastert);
to_log(stdout,
7u,
"- crossover between {} ({}) and bastert\n",
first,
m_data[first].value);
if (m_crossover_bastert_insertion(rng)) {
int first = m_indices[choose_a_solution(rng)];
m_data_reader lock_data_1{ m_data_mutex[first] };
crossover(rng, x, m_data[first].x, m_bastert);
to_log(stdout,
7u,
"- crossover between {} ({}) and bastert\n",
first,
m_data[first].value);
} else {
int first = m_indices[choose_a_solution(rng)];
init_with_random(m_random, rng, x.size(), 0.5);
m_data_reader lock_data_1{ m_data_mutex[first] };
crossover(rng, x, m_data[first].x, m_random);
to_log(stdout,
7u,
"- crossover between {} ({}) and bastert\n",
first,
m_data[first].value);
}
} else {
int first = m_indices[choose_a_solution(rng)];
int second = m_indices[choose_a_solution(rng)];
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment