#include "crossover/crossover.h"
#include "mutation/mutation.h"
+#include "condition/condition.h"
+
using namespace std;
namespace genetic {
*/
Generation<_Chromosome> generation;
- const int numberOfGenerations = 100;
+ void do_search() {
+ _Selection selection(this->generation, fitness);
+ this->generation = selection.draw();
+ this->generation = crossover.cross(this->generation);
+ this->generation = mutation.mutate(this->generation);
+ }
public:
Algorithm(
generator::Generation<_Chromosome>& _generator,
this->generation = this->generator.breed();
}
- void searchForResult() {
- cout << "generation avg best" << endl;
- for(int i = 0; i < this->numberOfGenerations; i++) {
+ void searchForResult(Condition<_Chromosome>& condition) {
+ unsigned int i = 0;
+ cout << "generation avg best\n";
+ do {
cout << i;
- _Selection selection(this->generation, fitness);
- this->generation = selection.draw();
- this->generation = crossover.cross(this->generation);
- this->generation = mutation.mutate(this->generation);
+ do_search();
// cout << "New Generation:\n";
// this->showGeneration();
this->showAvgFitness();
this->showBestFitness();
- }
+ } while(condition.check(this->generation) && ++i);
}
void showGeneration() {