Use a genetic algorithm to evolve populations of bit strings.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

69 lines
1.1 KiB

  1. //
  2. #pragma once
  3. //
  4. #include <vector>
  5. #include <mutex>
  6. #include <memory>
  7. //
  8. namespace BitEvolver
  9. {
  10. //
  11. class RouletteWheel
  12. {
  13. //
  14. public:
  15. //
  16. RouletteWheel();
  17. //
  18. void Reset();
  19. //
  20. void ClearChromosomes();
  21. void SetChromosomes(std::vector<std::shared_ptr<class Chromosome>> _chromosomes);
  22. void AddChromosome(std::shared_ptr<class Chromosome> _chromosome);
  23. void AddChromosomes(std::vector<std::shared_ptr<class Chromosome>> _chromosomes);
  24. //
  25. std::shared_ptr<Chromosome> Spin();
  26. //
  27. private:
  28. //
  29. std::shared_ptr<class Random> random;
  30. //
  31. std::vector<std::shared_ptr<class Chromosome>> chromosomes;
  32. std::recursive_mutex chromosomes_mutex;
  33. bool chromosomes_need_sorting;
  34. //
  35. std::vector<std::pair<double,std::shared_ptr<class Chromosome>>> wheel_slots;
  36. bool slots_need_population;
  37. //
  38. void Instantiate();
  39. //
  40. std::vector<std::pair<double, std::shared_ptr<class Chromosome>>> GetNormalizedChromosomeFitness();
  41. void SortChromosomes();
  42. void PopulateSlots();
  43. //
  44. void ChromosomesChanged();
  45. };
  46. };