Elitism and CopyChromosomes()
This commit is contained in:
38
Population.h
38
Population.h
@ -55,6 +55,13 @@ namespace BitEvolver
|
||||
//
|
||||
void SetMutationRate(double r);
|
||||
double GetMutationRate();
|
||||
//
|
||||
void SetElitismType(Enums::ElitismType t);
|
||||
Enums::ElitismType GetElitismType();
|
||||
void SetElitismRate(double r);
|
||||
double GetElitismRate();
|
||||
void SetElitismCount(int c);
|
||||
int GetElitismCount();
|
||||
|
||||
//
|
||||
void EvaluateFitness(std::function<double(std::shared_ptr<Chromosome>)> evaluation_callback);
|
||||
@ -69,8 +76,11 @@ namespace BitEvolver
|
||||
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 int DEFAULT_POPULATION_SIZE = 100;
|
||||
const static Enums::ElitismType DEFAULT_ELITISM_TYPE = Enums::ElitismType::Rate;
|
||||
constexpr static double DEFAULT_ELITISM_RATE = 0.01;
|
||||
const static int DEFAULT_ELITISM_COUNT = 1;
|
||||
constexpr static double DEFAULT_MUTATION_RATE = 0.01;
|
||||
//
|
||||
const static Enums::CrossoverType DEFAULT_CROSSOVER_TYPE = Enums::CrossoverType::Sexual;
|
||||
const static int DEFAULT_CROSSOVER_POINT = 0.7;
|
||||
@ -86,10 +96,15 @@ namespace BitEvolver
|
||||
std::vector<std::shared_ptr<class Chromosome>> chromosomes;
|
||||
int population_size;
|
||||
bool population_needs_sorting;
|
||||
int evolution_number;
|
||||
|
||||
//
|
||||
Enums::CrossoverType crossover_type;
|
||||
double crossover_point;
|
||||
double mutation_rate;
|
||||
int evolution_number;
|
||||
Enums::ElitismType elitism_type;
|
||||
double elitism_rate;
|
||||
int elitism_count;
|
||||
|
||||
//
|
||||
std::shared_ptr<class RouletteWheel> roulette_wheel;
|
||||
@ -98,7 +113,8 @@ namespace BitEvolver
|
||||
std::recursive_mutex
|
||||
population_modification_mutex,
|
||||
breed_mutex,
|
||||
evaluate_fitness_mutex
|
||||
evaluate_fitness_mutex,
|
||||
copy_chromosomes_mutex
|
||||
;
|
||||
|
||||
//
|
||||
@ -113,6 +129,10 @@ namespace BitEvolver
|
||||
void BreedNewPopulation(std::shared_ptr<std::vector<std::shared_ptr<Chromosome>>> population_new, int size);
|
||||
void BreedNewPopulation_Thread(std::shared_ptr<std::vector<std::shared_ptr<Chromosome>>> population_new, int size);
|
||||
|
||||
//
|
||||
int DetermineEliteCount();
|
||||
void SeedPopulationWithElites(std::shared_ptr<std::vector<std::shared_ptr<Chromosome>>> population_new);
|
||||
|
||||
//
|
||||
void EvaluateFitness_Thread(
|
||||
std::shared_ptr<std::vector<std::shared_ptr<Chromosome>>> _chromosomes,
|
||||
@ -123,6 +143,16 @@ namespace BitEvolver
|
||||
std::function<double(std::shared_ptr<Chromosome>)> evaluation_callback
|
||||
);
|
||||
|
||||
//
|
||||
void CopyChromosomes(
|
||||
std::shared_ptr<std::vector<std::shared_ptr<Chromosome>>> _chromosomes_source,
|
||||
std::shared_ptr<std::vector<std::shared_ptr<Chromosome>>> _chromosomes_destination
|
||||
);
|
||||
void CopyChromosomes_Thread(
|
||||
std::shared_ptr<std::vector<std::shared_ptr<Chromosome>>> _chromosomes_source,
|
||||
std::shared_ptr<std::vector<std::shared_ptr<Chromosome>>> _chromosomes_destination
|
||||
);
|
||||
|
||||
//
|
||||
std::shared_ptr<Chromosome> BreedChild();
|
||||
|
||||
|
Reference in New Issue
Block a user