1234567891011121314151617181920212223242526272829303132333435363738 |
- #ifndef OPTIMIZEREVOLUTIONARY_H
- #define OPTIMIZEREVOLUTIONARY_H
- #include "OptimizerBase.h"
- namespace mdd {
- class OptimizerEvolutionary : public OptimizerBase {
- protected:
- static int random_num(double min, double max, double inc = 1.0)
- {
- int range = (max - min)/inc + 1;
- return min + inc*(std::rand() % range);
- }
- struct Individual {
- public:
- json dna;
- double fitness;
- };
- Individual generateIndividual();
- Individual combine(Individual par1, Individual par2);
- std::vector<Individual> _children;
- Individual _best;
- int _min_generations;
- double _max_fitness;
- size_t _grow_generation;
- void evolve(std::vector<Individual> parents);
- void evaluate(size_t ignore_len = 0);
- json mutateGene(json limit, json seed = json());
- public:
- OptimizerEvolutionary(std::shared_ptr<IModule> module, size_t grow_generation = 20, double max_fitness = 0.0, int min_generations = -1);
- json update() override;
- };
- }
- #endif
|