genetic-bit-string-evolver/RouletteWheel.h
2018-04-14 02:23:43 -07:00

69 lines
1.1 KiB
C++

//
#pragma once
//
#include <vector>
#include <mutex>
#include <memory>
//
namespace BitEvolver
{
//
class RouletteWheel
{
//
public:
//
RouletteWheel();
//
void Reset();
//
void ClearChromosomes();
void SetChromosomes(std::vector<std::shared_ptr<class Chromosome>> _chromosomes);
void AddChromosome(std::shared_ptr<class Chromosome> _chromosome);
void AddChromosomes(std::vector<std::shared_ptr<class Chromosome>> _chromosomes);
//
std::shared_ptr<Chromosome> Spin();
//
private:
//
std::shared_ptr<class Random> random;
//
std::vector<std::shared_ptr<class Chromosome>> chromosomes;
std::recursive_mutex chromosomes_mutex;
bool chromosomes_need_sorting;
//
std::vector<std::pair<double,std::shared_ptr<class Chromosome>>> wheel_slots;
bool slots_need_population;
//
void Instantiate();
//
std::vector<std::pair<double, std::shared_ptr<class Chromosome>>> GetNormalizedChromosomeFitness();
void SortChromosomes();
void PopulateSlots();
//
void ChromosomesChanged();
};
};