OptimizerEvolutionary.h 948 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #ifndef OPTIMIZEREVOLUTIONARY_H
  2. #define OPTIMIZEREVOLUTIONARY_H
  3. #include "OptimizerBase.h"
  4. namespace mdd {
  5. class OptimizerEvolutionary : public OptimizerBase {
  6. protected:
  7. static int random_num(double min, double max, double inc = 1.0)
  8. {
  9. int range = (max - min)/inc + 1;
  10. return min + inc*(std::rand() % range);
  11. }
  12. struct Individual {
  13. public:
  14. json dna;
  15. double fitness;
  16. };
  17. Individual generateIndividual();
  18. Individual combine(Individual par1, Individual par2);
  19. std::vector<Individual> _children;
  20. Individual _best;
  21. int _min_generations;
  22. double _max_fitness;
  23. size_t _grow_generation;
  24. void evolve(std::vector<Individual> parents);
  25. void evaluate(size_t ignore_len = 0);
  26. json mutateGene(json limit, json seed = json());
  27. public:
  28. OptimizerEvolutionary(std::shared_ptr<IModule> module, size_t grow_generation = 20, double max_fitness = 0.0, int min_generations = -1);
  29. json update() override;
  30. };
  31. }
  32. #endif