@@ -20,7 +20,7 @@ Population::Population(int size, int MaxDur, double prob_cross) {
20
20
void Population::new_generation () {
21
21
std::vector<Chromosome> new_generation{static_cast <size_t >(population_size)};
22
22
23
- int n_percent = population_size * 0.1 ;
23
+ int n_percent = static_cast < int >( population_size * 0.1 ) ;
24
24
std::sort (population_array.begin (), population_array.end (),
25
25
[](Chromosome x, Chromosome y) { return Chromosome::cost_function (x) > Chromosome::cost_function (y); });
26
26
@@ -44,17 +44,15 @@ void Population::new_generation() {
44
44
while (parent_one_index == parent_two_index) {
45
45
parent_two_index = dist (rng);
46
46
}
47
- new_generation[i] = Chromosome::cross (this ->population_array [parent_one_index],
48
- this ->population_array [parent_two_index]);
47
+ new_generation[i] = Chromosome::cross (this ->population_array [parent_one_index], this ->population_array [parent_two_index]);
49
48
}
50
49
std::cout << " Crossover process completed.\n " ;
51
50
52
51
std::cout << " The rest of new population is randomly generated to prevent early convergence.\n " ;
53
52
// one or more new members of the population are randomly generated
54
53
// from the same distribution as the original population
55
54
for (; i < population_size; ++i) {
56
- new_generation.emplace_back (
57
- Chromosome (population_size, new_generation[0 ].get_max_dur (), new_generation[0 ].get_prob_cross ()));
55
+ new_generation.emplace_back (Chromosome (population_size, new_generation[0 ].get_max_dur (), new_generation[0 ].get_prob_cross ()));
58
56
}
59
57
this ->population_array .clear ();
60
58
this ->population_array = new_generation;
0 commit comments