diff options
author | David Robillard <d@drobilla.net> | 2007-12-07 14:31:10 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2007-12-07 14:31:10 +0000 |
commit | 273517a83b9e04e15b07fa1f64c76b10af7c3091 (patch) | |
tree | e9af9b1c48d3db668c4e19822bc3f041d6d2aa8e /src/engine/machina/Problem.hpp | |
parent | 7e8186df9bdb8bcc0177cb572f39ae96fb046004 (diff) | |
download | machina-273517a83b9e04e15b07fa1f64c76b10af7c3091.tar.gz machina-273517a83b9e04e15b07fa1f64c76b10af7c3091.tar.bz2 machina-273517a83b9e04e15b07fa1f64c76b10af7c3091.zip |
Vast quantities of filthy, filthy evolution code.
Also, bugs and crashes.
git-svn-id: http://svn.drobilla.net/lad/machina@961 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/engine/machina/Problem.hpp')
-rw-r--r-- | src/engine/machina/Problem.hpp | 60 |
1 files changed, 58 insertions, 2 deletions
diff --git a/src/engine/machina/Problem.hpp b/src/engine/machina/Problem.hpp index 96ecb39..7605e88 100644 --- a/src/engine/machina/Problem.hpp +++ b/src/engine/machina/Problem.hpp @@ -18,6 +18,7 @@ #ifndef MACHINA_PROBLEM_HPP #define MACHINA_PROBLEM_HPP +#include <map> #include <raul/MIDISink.hpp> #include <eugene/core/Problem.hpp> #include <machina/Machine.hpp> @@ -34,13 +35,20 @@ public: float fitness(const Machine& machine) const; bool fitness_less_than(float a, float b) const { return a < b; } + + void clear_fitness_cache() { _fitness.clear(); } boost::shared_ptr<Population> initial_population(size_t gene_size, size_t pop_size) const; private: - struct Evaluator : public Raul::MIDISink { - Evaluator(const Problem& problem) : _problem(problem), _n_notes(0), _length(0) { + size_t distance(const std::vector<uint8_t>& source, + const std::vector<uint8_t>& target) const; + + // count + /*struct FreqEvaluator : public Raul::MIDISink { + Evaluator(const Problem& problem) + : _problem(problem), _n_notes(0), _length(0) { for (uint8_t i=0; i < 128; ++i) _note_frequency[i] = 0; } @@ -49,14 +57,62 @@ private: const uint8_t* ev) throw (std::logic_error); void compute(); const Problem& _problem; + + size_t n_notes() const { return _n_notes; } float _note_frequency[128]; size_t _n_notes; double _length; + };*/ + + // distance + /*struct Evaluator : public Raul::MIDISink { + Evaluator(const Problem& problem) : _problem(problem) {} + void write_event(Raul::BeatTime time, + size_t ev_size, + const uint8_t* ev) throw (std::logic_error); + void compute(); + const Problem& _problem; + + size_t n_notes() const { return _notes.size(); } + + std::vector<uint8_t> _notes; + float _counts[128]; + };*/ + + struct Evaluator : public Raul::MIDISink { + Evaluator(const Problem& problem) : _problem(problem), _order(8), _n_notes(0), _first_note(0) { + for (uint8_t i=0; i < 128; ++i) + _counts[i] = 0; + } + void write_event(Raul::BeatTime time, + size_t ev_size, + const uint8_t* ev) throw (std::logic_error); + void compute(); + const Problem& _problem; + + size_t n_notes() const { return _n_notes; } + uint8_t first_note() const { return _first_note; } + + const uint32_t _order; + + std::string _read; + + typedef std::map<std::string, uint32_t> Patterns; + Patterns _patterns; + uint32_t _counts[128]; + size_t _n_notes; + uint8_t _first_note; }; Evaluator _target; SharedPtr<Machine> _seed; + + /// for levenshtein distance + mutable std::vector< std::vector<uint16_t> > _matrix; + + /// memoization + mutable std::map<Machine*, float> _fitness; }; |