AC_CONFIG_FILES([
Makefile
tests/Makefile
- tests/gene/Makefile
- tests/chromosome/Makefile
- tests/generation/Makefile
])
AC_OUTPUT
* Generator for generating entire Generation of Chromosomes (individuals)
*/
template < typename _Chromosome >
- class Bit : public Generator<_Chromosome> {
+ class BitGenerator : public Generator<_Chromosome> {
public:
/**
* Type representing Chromosome Gene
* @param generationSize Indicates size of the generation
* @param chromosomeSize Indicates size of the chromosome
*/
- Bit(unsigned int generationSize, unsigned int chromosomeSize)
+ BitGenerator(unsigned int generationSize, unsigned int chromosomeSize)
: Generator<_Chromosome>(generationSize, chromosomeSize) {
}
};
#include "gene.h"
#include "chromosome.h"
#include "generation.h"
-#include "generator/bit.h"
+#include "generator/bitGenerator.h"
#include "selection/rouletteSelection.h"
#include "selection/linearRankSelection.h"
typedef Crossover<_Chromosome> _Crossover;
typedef Mutation<_Chromosome> _Mutation;
- typedef generator::Bit<_Chromosome> _Generator;
+ typedef generator::BitGenerator<_Chromosome> _Generator;
typedef Algorithm<_Chromosome, _Selection, _Crossover, _Mutation, _Fitness> _Algorithm;
typedef GenerationLimit<_Chromosome> _Condition;
-SUBDIRS = \
- gene \
- chromosome \
- generation
+AUTOMAKE_OPTIONS = subdir-objects
+
+TESTS = \
+ gene_create.test \
+ gene_copy.test \
+ chromosome_create.test\
+ chromosome_copy.test \
+ generation_create.test\
+ generation_copy.test \
+ generator_bitGeneratorBreed.test
+
+noinst_PROGRAMS = $(TESTS)
+
+AM_CPPFLAGS = -O2 -I$(top_srcdir)/src
+
+gene_create_test_SOURCES = gene/create.cpp
+gene_copy_test_SOURCES = gene/copy.cpp
+
+chromosome_create_test_SOURCES = chromosome/create.cpp
+chromosome_copy_test_SOURCES = chromosome/copy.cpp
+
+generation_create_test_SOURCES = generation/create.cpp
+generation_copy_test_SOURCES = generation/copy.cpp
+
+generator_bitGeneratorBreed_test_SOURCES = generator/bitGenerator/breed.cpp
clean-local:
- rm -f *.log
\ No newline at end of file
+ rm -f *.log
+
+all-local:
\ No newline at end of file
+++ /dev/null
-noinst_PROGRAMS = create.test copy.test
-
-create_test_SOURCES = create.cpp
-create_test_CPPFLAGS = -I$(top_srcdir)/src
-
-copy_test_SOURCES = copy.cpp
-copy_test_CPPFLAGS = -I$(top_srcdir)/src
-
-TESTS = \
- create.test \
- copy.test
-
-check-chromosome: create.test copy.test
-
-clean-local:
- rm -f *.test
\ No newline at end of file
+++ /dev/null
-noinst_PROGRAMS = create.test copy.test
-
-create_test_SOURCES = create.cpp
-create_test_CPPFLAGS = -I$(top_srcdir)/src
-
-copy_test_SOURCES = copy.cpp
-copy_test_CPPFLAGS = -I$(top_srcdir)/src
-
-TESTS = \
- create.test \
- copy.test
-
-check-gene: create.test copy.test
-
-clean-local:
- rm -f *.test
\ No newline at end of file
+++ /dev/null
-noinst_PROGRAMS = create.test copy.test
-
-create_test_SOURCES = create.cpp
-create_test_CPPFLAGS = -I$(top_srcdir)/src
-
-copy_test_SOURCES = copy.cpp
-copy_test_CPPFLAGS = -I$(top_srcdir)/src
-
-TESTS = \
- create.test \
- copy.test
-
-check-generation: create.test copy.test
-
-clean-local:
- rm -f *.test
\ No newline at end of file
--- /dev/null
+#include <iostream>
+#include <vector>
+
+#include "gene.h"
+#include "chromosome.h"
+#include "generation.h"
+#include "generator/bitGenerator.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;
+
+ const unsigned int chromosomeSize = 20;
+ const unsigned int generationSize = 100;
+
+ _Generator generator(generationSize, chromosomeSize);
+ _Generation generation = generator.breed();
+
+ if (generation.size() != generationSize) {
+ cout << "Generation contained incorrect size after breeding\n";
+ return 1;
+ }
+
+ for (unsigned int i = 0; i < generation.size(); i++) {
+ if (generation[i].size() != chromosomeSize) {
+ cout << "Chromosome contained bad size after breeding\n";
+ return 1;
+ }
+ for (unsigned int j = 0; j < generation[i].size(); j++) {
+ if ((generation[i][j].get() != 0) &&
+ (generation[i][j].get() != 1)) {
+ cout << "Chromosome breeded by BitGenerator does not have bit Genes\n";
+ }
+ }
+ }
+
+ cout << "BitGenerator breeded correctly\n";
+ return 0;
+}
+