#include "gene.h"
-using namespace std;
-
namespace genetic {
/**
* Chromosome of given Genes.
#include "chromosome.h"
#include "generation.h"
-using namespace std;
-
namespace genetic {
/**
* Base Condition class.
#include "condition.h"
-using namespace std;
-
namespace genetic {
/**
* Condition class. It is used for checking if algorithm should stop after
*/
template < typename _Chromosome>
class GenerationLimitCondition : public Condition<_Chromosome> {
- public:
protected:
/**
* Variable indicating current generation
#ifndef __CROSSOVER_CROSSOVER_H
#define __CROSSOVER_CROSSOVER_H
+#include <vector>
+
#include "chromosome.h"
#include "generation.h"
// }
// }
- vector<GeneType> crossedChromosome;
+ std::vector<GeneType> crossedChromosome;
for (unsigned int i = 0; i < chromosomeSize; i++) {
if (i < splitPlace) {
crossedChromosome.push_back(first[i].get());
#include <vector>
-#include <gene.h>
-#include <chromosome.h>
-
-using namespace std;
+#include "gene.h"
+#include "chromosome.h"
namespace genetic {
/**
/**
* Chromosomes in the given Generation
*/
- vector<_Chromosome> chromosomes;
+ std::vector<_Chromosome> chromosomes;
template<typename> friend class Generation;
public:
* @param generationSize Indicates size of the generation
* @param chromosomeSize Indicates size of the chromosome
*/
- BitGenerator(unsigned int generationSize, unsigned int chromosomeSize)
+ BitGenerator(const unsigned int generationSize, const unsigned int chromosomeSize)
: Generator<_Chromosome>(generationSize, chromosomeSize) {
}
};
#ifndef __GENERATOR_GENERATOR_H
#define __GENERATOR_GENERATOR_H
+#include <ctime>
#include <cstdlib>
#include "../gene.h"
/**
* Size of the generation to generate
*/
- unsigned int generationSize;
+ const unsigned int generationSize;
/**
* Size of the chromosome to generate
*/
- unsigned int chromosomeSize;
+ const unsigned int chromosomeSize;
/**
* Breeding calculations should be done here...
* @param generationSize Indicates size of the generation
* @param chromosomeSize Indicates size of the chromosome
*/
- Generator(unsigned int generationSize, unsigned int chromosomeSize) {
- this->generationSize = generationSize;
- this->chromosomeSize = chromosomeSize;
+ Generator(const unsigned int generationSize, const unsigned int chromosomeSize)
+ : generationSize(generationSize), chromosomeSize(chromosomeSize) {
time_t t;
srand((unsigned)time(&t));
#ifndef __MUTATION_MUTATION_H
#define __MUTATION_MUTATION_H
-#include <iostream>
+#include <vector>
#include "chromosome.h"
#include "generation.h"
-using namespace std;
-
namespace genetic {
// namespace mutation {
/**
Generation<_Chromosome> mutate(Generation<_Chromosome>& _generation) {
const unsigned int generationSize = _generation.size();
const unsigned int chromosomeSize = _generation[0].size();
- vector<_Chromosome> newGeneration;
+ std::vector<_Chromosome> newGeneration;
for (unsigned int i = 0; i < generationSize; i++) {
MutationChanceType random = (rand() % 10000) / 10000.0;
#include "fitness/fitness.h"
#include "selection/selection.h"
-using namespace std;
-
namespace genetic {
// namespace selection {
/**
#include "chromosome.h"
#include "selection.h"
-using namespace std;
-
namespace genetic {
// namespace selection {
/**
#include "generation.h"
#include "../fitness/fitness.h"
-using namespace std;
-
namespace genetic {
// namespace selection {
/**
-#include <iostream>
-#include <vector>
-#include <map>
-#include <string>
-
#include "gene.h"
#include "chromosome.h"
#include "generation.h"
#include "condition/condition.h"
#include "condition/generationLimitCondition.h"
-using namespace std;
using namespace genetic;
int main() {