for(int i = 0; i < this->numberOfGenerations; i++) {
cout << i;
_Selection selection(this->generation, fitness);
-// cout << "[+] Algorithm::Selection.draw()\n";
this->generation = selection.draw();
-// cout << "[+] Crossover\n";
this->generation = crossover.cross(this->generation);
-// cout << "[+] Mutate\n";
this->generation = mutation.mutate(this->generation);
// cout << "New Generation:\n";
cout << "\n";
}
}
-
+
void showAvgFitness() {
double avg = 0;
-// cout << "Fitness:\n";
for (unsigned int i = 0; i < this->generation.get().size(); i++) {
-// cout << "# " << i << ") ";
WSTI<_Chromosome, FitnessValueType> fit(this->generation.get()[i], 0.5, 2.5);
-// cout << fit.calculate() << "\n";
avg += fit.calculate();
}
cout << " " << avg / this->generation.get().size();
}
-
+
void showBestFitness() {
double best = -100000;
for (unsigned int i = 0; i < this->generation.get().size(); i++) {
-// cout << "# " << i << ") ";
WSTI<_Chromosome, FitnessValueType> fit(this->generation.get()[i], 0.5, 2.5);
-// cout << fit.calculate() << "\n";
double tmp = fit.calculate();
if (tmp > best) {
best = tmp;