Added functions to control crossover rate and type

This commit is contained in:
2018-04-14 01:07:56 -07:00
parent 5f0b8a4c13
commit b0da515139
5 changed files with 92 additions and 10 deletions

View File

@ -46,8 +46,14 @@ namespace BitEvolver
double GetAverageFitness();
double GetAverageFitness(std::vector<std::shared_ptr<class Chromosome>> _chromosomes);
//
void SetCrossoverPoint(double p);
double GetCrossoverPoint();
void SetCrossoverType(Enums::CrossoverType t);
Enums::CrossoverType GetCrossoverType();
//
void SetMutationRate(double r);
double GetMutationRate();
//
void Evolve();
@ -57,6 +63,13 @@ namespace BitEvolver
void PrintPopulation();
void PrintPopulation(std::vector<std::shared_ptr<class Chromosome>> _chromosomes);
// Constants
const static int DEFAULT_POPULATION_SIZE = 100;
const static int DEFAULT_MUTATION_RATE = 0.01;
//
const static Enums::CrossoverType DEFAULT_CROSSOVER_TYPE = Enums::CrossoverType::Sexual;
const static int DEFAULT_CROSSOVER_POINT = 0.7;
//
private:
@ -68,6 +81,8 @@ namespace BitEvolver
std::vector<std::shared_ptr<class Chromosome>> chromosomes;
int population_size;
bool population_needs_sorting;
Enums::CrossoverType crossover_type;
double crossover_point;
double mutation_rate;
int evolution_number;