diff options
author | David Robillard <d@drobilla.net> | 2007-12-07 03:05:20 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2007-12-07 03:05:20 +0000 |
commit | ffb37e6de2934aa227c3483f8a00118e3604b5e5 (patch) | |
tree | 8c40493f8de562677e1e54cc4b26a1fbbb493d26 /src/engine/machina/Problem.hpp | |
parent | 33e9991326a1cd90a4956f3221f5a48d03d5af89 (diff) | |
download | machina-ffb37e6de2934aa227c3483f8a00118e3604b5e5.tar.gz machina-ffb37e6de2934aa227c3483f8a00118e3604b5e5.tar.bz2 machina-ffb37e6de2934aa227c3483f8a00118e3604b5e5.zip |
It's evolution, baby.
git-svn-id: http://svn.drobilla.net/lad/machina@958 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/engine/machina/Problem.hpp')
-rw-r--r-- | src/engine/machina/Problem.hpp | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/engine/machina/Problem.hpp b/src/engine/machina/Problem.hpp index d221e5c..abfc534 100644 --- a/src/engine/machina/Problem.hpp +++ b/src/engine/machina/Problem.hpp @@ -19,21 +19,28 @@ #define MACHINA_PROBLEM_HPP #include <raul/MIDISink.hpp> +#include <eugene/core/Problem.hpp> +#include <machina/Machine.hpp> namespace Machina { -class Machine; - -class Problem { +class Problem : public Eugene::Problem<Machine> { public: - Problem(const std::string& target_midi); + Problem(const std::string& target_midi, SharedPtr<Machine> seed = SharedPtr<Machine>()); + + void seed(SharedPtr<Machine> parent) { _seed = parent; } - float fitness(Machine& machine); + float fitness(const Machine& machine) const; + + bool fitness_less_than(float a, float b) const { return a < b; } + + boost::shared_ptr<Population> + initial_population(size_t gene_size, size_t pop_size) const; private: struct Evaluator : public Raul::MIDISink { - Evaluator(Problem& problem) : _problem(problem), _n_notes(0) { + Evaluator(const Problem& problem) : _problem(problem), _n_notes(0) { for (uint8_t i=0; i < 128; ++i) _note_frequency[i] = 0; } @@ -41,13 +48,14 @@ private: size_t ev_size, const uint8_t* ev) throw (std::logic_error); void compute(); - Problem& _problem; + const Problem& _problem; float _note_frequency[128]; size_t _n_notes; }; - Evaluator _target; + Evaluator _target; + SharedPtr<Machine> _seed; }; |