Skip to content

Commit 9ebdece

Browse files
author
Lukáš Plevač
committed
fixing in mutation
1 parent c739260 commit 9ebdece

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/genome.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ namespace genome {
7777
std::normal_distribution<> rand_numof_muts(center, sigma);
7878
std::uniform_int_distribution<io_id_t> rand_mut_pos(this->last_input + 1, this->size() + this->wire_out.size() - 1);
7979
std::uniform_int_distribution<io_id_t> rand_type(type_min, type_max);
80+
std::uniform_int_distribution<io_id_t> rand_mut_gen_pos(0, this->gene_inputs_count);
8081

8182
int mutations = std::round(rand_numof_muts(rand_gen));
8283
if (mutations <= 0) return 0; //no mutations
@@ -109,16 +110,17 @@ namespace genome {
109110

110111
} else { //regular gene
111112
auto mut_gene = this->get_gene_ptr(rand_pos);
113+
auto mut_pos_in_gene = rand_mut_gen_pos(rand_gen);
112114

113115
//generate random for gene inputs
114-
for (unsigned i = 0; i < this->gene_inputs_count; i++) {
116+
if (this->gene_inputs_count != mut_pos_in_gene) {
115117
int rand_pos_min = 0;
116118
int rand_pos_max = rand_pos - 1;
117119

118120
// l_back is enabled
119121
if (l_back > 0) {
120-
rand_pos_min = mut_gene->Inputs[i] - l_back;
121-
rand_pos_max = mut_gene->Inputs[i] + l_back;
122+
rand_pos_min = mut_gene->Inputs[mut_pos_in_gene] - l_back;
123+
rand_pos_max = mut_gene->Inputs[mut_pos_in_gene] + l_back;
122124

123125
if (rand_pos_min < 0) rand_pos_min = 0;
124126
if ((io_id_t)rand_pos_max >= rand_pos) rand_pos_max = rand_pos - 1;
@@ -127,11 +129,11 @@ namespace genome {
127129
std::uniform_int_distribution<io_id_t> rand_mut_inputs(rand_pos_min, rand_pos_max);
128130

129131

130-
mut_gene->Inputs[i] = rand_mut_inputs(rand_gen);
132+
mut_gene->Inputs[mut_pos_in_gene] = rand_mut_inputs(rand_gen);
133+
} else {
134+
//type mutation
135+
mut_gene->type = rand_type(rand_gen);
131136
}
132-
133-
//type mutation
134-
mut_gene->type = rand_type(rand_gen);
135137
}
136138
}
137139

0 commit comments

Comments
 (0)