@@ -77,6 +77,7 @@ namespace genome {
77
77
std::normal_distribution<> rand_numof_muts (center, sigma);
78
78
std::uniform_int_distribution<io_id_t > rand_mut_pos (this ->last_input + 1 , this ->size () + this ->wire_out .size () - 1 );
79
79
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 );
80
81
81
82
int mutations = std::round (rand_numof_muts (rand_gen));
82
83
if (mutations <= 0 ) return 0 ; // no mutations
@@ -109,16 +110,17 @@ namespace genome {
109
110
110
111
} else { // regular gene
111
112
auto mut_gene = this ->get_gene_ptr (rand_pos);
113
+ auto mut_pos_in_gene = rand_mut_gen_pos (rand_gen);
112
114
113
115
// 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 ) {
115
117
int rand_pos_min = 0 ;
116
118
int rand_pos_max = rand_pos - 1 ;
117
119
118
120
// l_back is enabled
119
121
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;
122
124
123
125
if (rand_pos_min < 0 ) rand_pos_min = 0 ;
124
126
if ((io_id_t )rand_pos_max >= rand_pos) rand_pos_max = rand_pos - 1 ;
@@ -127,11 +129,11 @@ namespace genome {
127
129
std::uniform_int_distribution<io_id_t > rand_mut_inputs (rand_pos_min, rand_pos_max);
128
130
129
131
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);
131
136
}
132
-
133
- // type mutation
134
- mut_gene->type = rand_type (rand_gen);
135
137
}
136
138
}
137
139
0 commit comments