From 69c8cde985cc012b6cae2a49d489553c5be67202 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 15 Jan 2013 21:53:48 +0000 Subject: Compile against latest Eugene (evolution still doesn't work, though). git-svn-id: http://svn.drobilla.net/lad/trunk/machina@4994 a436a847-0d15-0410-975c-d299462d15a1 --- src/engine/machina/Evolver.hpp | 24 ++++++++++++------------ src/engine/machina/Machine.hpp | 9 ++++++--- src/engine/machina/Mutation.hpp | 26 ++++++++++++++++---------- 3 files changed, 34 insertions(+), 25 deletions(-) (limited to 'src/engine/machina') diff --git a/src/engine/machina/Evolver.hpp b/src/engine/machina/Evolver.hpp index 17fae05..e14fc4a 100644 --- a/src/engine/machina/Evolver.hpp +++ b/src/engine/machina/Evolver.hpp @@ -17,41 +17,41 @@ #ifndef MACHINA_EVOLVER_HPP #define MACHINA_EVOLVER_HPP -#include "eugene/GAImpl.hpp" +#include "eugene/GA.hpp" +#include "eugene/Random.hpp" #include "machina/types.hpp" #include "raul/Thread.hpp" #include "raul/TimeStamp.hpp" +#include "Machine.hpp" #include "Schrodinbit.hpp" -namespace Eugene { -template -class HybridMutation; +namespace eugene { +template class HybridMutation; } namespace machina { -class Machine; class Problem; -class Evolver - : public Raul::Thread +class Evolver : public Raul::Thread { public: - Evolver(Raul::TimeUnit unit, - const string& target_midi, - SPtr seed); + Evolver(Raul::TimeUnit unit, + const std::string& target_midi, + SPtr seed); void seed(SPtr parent); bool improvement() { return _improvement; } - SPtr best() { return _ga->best(); } + const Machine& best() { return _ga->best(); } - typedef Eugene::GAImpl MachinaGA; + typedef eugene::GA MachinaGA; private: void _run(); + eugene::Random _rng; SPtr _ga; SPtr _problem; float _seed_fitness; diff --git a/src/engine/machina/Machine.hpp b/src/engine/machina/Machine.hpp index a4d0262..cd94391 100644 --- a/src/engine/machina/Machine.hpp +++ b/src/engine/machina/Machine.hpp @@ -19,7 +19,6 @@ #include #include -#include #include "machina/types.hpp" #include "raul/Atom.hpp" @@ -37,8 +36,7 @@ class LearnRequest; /** A (Finite State) Machine. */ -class Machine - : public Stateful +class Machine : public Stateful { public: explicit Machine(TimeUnit unit); @@ -53,6 +51,8 @@ public: /** Completely replace this machine's contents with a deep copy. */ Machine& operator=(const Machine& copy); + bool operator==(const Machine& rhs) const; + /** Merge another machine into this machine. */ void merge(const Machine& machine); @@ -95,6 +95,8 @@ public: SPtr random_node(); SPtr random_edge(); + float fitness; // For GA + private: // Audio context SPtr earliest_node() const; @@ -117,6 +119,7 @@ private: SPtr _pending_learn; Nodes _nodes; Raul::TimeStamp _time; + bool _is_finished; }; diff --git a/src/engine/machina/Mutation.hpp b/src/engine/machina/Mutation.hpp index d811a50..69f5ee4 100644 --- a/src/engine/machina/Mutation.hpp +++ b/src/engine/machina/Mutation.hpp @@ -21,13 +21,19 @@ #ifdef HAVE_EUGENE # include "eugene/Mutation.hpp" -# define SUPER : public Eugene::Mutation +# define SUPER : public eugene::Mutation #else # define SUPER : public Mutation #endif namespace machina { +#ifdef HAVE_EUGENE +typedef eugene::Random Random; +#else +struct Random {}; +#endif + class Machine; namespace Mutation { @@ -35,17 +41,17 @@ namespace Mutation { struct Mutation { virtual ~Mutation() {} - virtual void mutate(Machine& machine) = 0; + virtual void mutate(Random& rng, Machine& machine) = 0; }; -struct Compress SUPER { void mutate(Machine& machine); }; -struct AddNode SUPER { void mutate(Machine& machine); }; -struct RemoveNode SUPER { void mutate(Machine& machine); }; -struct AdjustNode SUPER { void mutate(Machine& machine); }; -struct SwapNodes SUPER { void mutate(Machine& machine); }; -struct AddEdge SUPER { void mutate(Machine& machine); }; -struct RemoveEdge SUPER { void mutate(Machine& machine); }; -struct AdjustEdge SUPER { void mutate(Machine& machine); }; +struct Compress SUPER { void mutate(Random& rng, Machine& machine); }; +struct AddNode SUPER { void mutate(Random& rng, Machine& machine); }; +struct RemoveNode SUPER { void mutate(Random& rng, Machine& machine); }; +struct AdjustNode SUPER { void mutate(Random& rng, Machine& machine); }; +struct SwapNodes SUPER { void mutate(Random& rng, Machine& machine); }; +struct AddEdge SUPER { void mutate(Random& rng, Machine& machine); }; +struct RemoveEdge SUPER { void mutate(Random& rng, Machine& machine); }; +struct AdjustEdge SUPER { void mutate(Random& rng, Machine& machine); }; } // namespace Mutation -- cgit v1.2.1