* iteration.
*/
template < typename _Chromosome>
- class GenerationLimit : public Condition<_Chromosome> {
+ class GenerationLimitCondition : public Condition<_Chromosome> {
public:
protected:
/**
*
* @param limit number of generations after which algorithm should stop
*/
- GenerationLimit(unsigned int limit)
+ GenerationLimitCondition(unsigned int limit)
: maxNumberOfGenerations(limit) {
}
};
#include "algorithm.h"
#include "condition/condition.h"
-#include "condition/generationLimit.h"
+#include "condition/generationLimitCondition.h"
using namespace std;
using namespace genetic;
int main() {
- typedef Gene<int> _Gene;
+ typedef Gene<bool> _Gene;
typedef Chromosome<_Gene> _Chromosome;
typedef WSTI<_Chromosome> _Fitness;
typedef generator::BitGenerator<_Chromosome> _Generator;
typedef Algorithm<_Chromosome, _Selection, _Crossover, _Mutation, _Fitness> _Algorithm;
- typedef GenerationLimit<_Chromosome> _Condition;
+ typedef GenerationLimitCondition<_Chromosome> _Condition;
const int chromosomeSize = 10;
const int generationSize = 200;
chromosome_copy.test \
generation_create.test\
generation_copy.test \
- generator_bitGeneratorBreed.test
+ generator_bitGeneratorBreed.test \
+ condition_generationLimitConditionCheck.test
noinst_PROGRAMS = $(TESTS)
-AM_CPPFLAGS = -O2 -I$(top_srcdir)/src
+AM_CXXFLAGS = -O3 -I$(top_srcdir)/src -std=c++11
gene_create_test_SOURCES = gene/create.cpp
gene_copy_test_SOURCES = gene/copy.cpp
generator_bitGeneratorBreed_test_SOURCES = generator/bitGenerator/breed.cpp
+condition_generationLimitConditionCheck_test_SOURCES = condition/generationLimitCondition/check.cpp
+
clean-local:
rm -f *.log
--- /dev/null
+#include <iostream>
+#include <vector>
+
+#include "gene.h"
+#include "chromosome.h"
+#include "generation.h"
+#include "generator/bitGenerator.h"
+#include "condition/generationLimitCondition.h"
+
+using namespace std;
+using namespace genetic;
+
+int main() {
+ typedef Gene<int> _Gene;
+ typedef Chromosome<_Gene> _Chromosome;
+ typedef Generation<_Chromosome> _Generation;
+ typedef generator::BitGenerator<_Chromosome> _Generator;
+ typedef GenerationLimitCondition<_Chromosome> _Condition;
+
+ const unsigned int chromosomeSize = 20;
+ const unsigned int generationSize = 100;
+ const unsigned int numberOfChecks = 20;
+
+ _Generator generator(generationSize, chromosomeSize);
+ _Generation generation = generator.breed();
+ _Condition condition(numberOfChecks);
+
+ unsigned int i = 0;
+ while(condition.check(generation)) {
+ if (i > numberOfChecks) {
+ cout << "GenerationLimitCondition got outside limit\n";
+ return 1;
+ }
+ i++;
+ }
+
+ cout << "BitGenerator breeded correctly\n";
+ return 0;
+}
+