diff options
author | David Robillard <d@drobilla.net> | 2013-01-12 03:17:47 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2013-01-12 03:17:47 +0000 |
commit | e1a63732f796c8057751cb7f8ac98a595b91692e (patch) | |
tree | 764392d055901118ee285dd20f233ff33e0cd04a /src/engine/Evolver.cpp | |
parent | bb62bf2c23ba84f547e37b70b3ef31b51ba987ab (diff) | |
download | machina-e1a63732f796c8057751cb7f8ac98a595b91692e.tar.gz machina-e1a63732f796c8057751cb7f8ac98a595b91692e.tar.bz2 machina-e1a63732f796c8057751cb7f8ac98a595b91692e.zip |
Bulk reformat.
git-svn-id: http://svn.drobilla.net/lad/trunk/machina@4929 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/engine/Evolver.cpp')
-rw-r--r-- | src/engine/Evolver.cpp | 47 |
1 files changed, 24 insertions, 23 deletions
diff --git a/src/engine/Evolver.cpp b/src/engine/Evolver.cpp index 83b0d75..a71d64b 100644 --- a/src/engine/Evolver.cpp +++ b/src/engine/Evolver.cpp @@ -32,40 +32,42 @@ using namespace boost; namespace Machina { -Evolver::Evolver(TimeUnit unit, const string& target_midi, SharedPtr<Machine> seed) +Evolver::Evolver(TimeUnit unit, const string& target_midi, + SharedPtr<Machine> seed) : _problem(new Problem(unit, target_midi, seed)) , _seed_fitness(-FLT_MAX) { SharedPtr<Eugene::HybridMutation<Machine> > m(new HybridMutation<Machine>()); - m->append_mutation(1/6.0f, boost::shared_ptr< Eugene::Mutation<Machine> >( - new Mutation::Compress())); - m->append_mutation(1/6.0f, boost::shared_ptr< Eugene::Mutation<Machine> >( - new Mutation::AddNode())); + m->append_mutation(1 / 6.0f, boost::shared_ptr< Eugene::Mutation<Machine> >( + new Mutation::Compress())); + m->append_mutation(1 / 6.0f, boost::shared_ptr< Eugene::Mutation<Machine> >( + new Mutation::AddNode())); //m->append_mutation(1/6.0f, boost::shared_ptr< Eugene::Mutation<Machine> >( // new Mutation::RemoveNode())); //m->append_mutation(1/6.0f, boost::shared_ptr< Eugene::Mutation<Machine> >( // new Mutation::AdjustNode())); - m->append_mutation(1/6.0f, boost::shared_ptr< Eugene::Mutation<Machine> >( - new Mutation::SwapNodes())); - m->append_mutation(1/6.0f, boost::shared_ptr< Eugene::Mutation<Machine> >( - new Mutation::AddEdge())); - m->append_mutation(1/6.0f, boost::shared_ptr< Eugene::Mutation<Machine> >( - new Mutation::RemoveEdge())); - m->append_mutation(1/6.0f, boost::shared_ptr< Eugene::Mutation<Machine> >( - new Mutation::AdjustEdge())); - - boost::shared_ptr< Selection<Machine> > s(new TournamentSelection<Machine>(_problem, 3, 0.8)); + m->append_mutation(1 / 6.0f, boost::shared_ptr< Eugene::Mutation<Machine> >( + new Mutation::SwapNodes())); + m->append_mutation(1 / 6.0f, boost::shared_ptr< Eugene::Mutation<Machine> >( + new Mutation::AddEdge())); + m->append_mutation(1 / 6.0f, boost::shared_ptr< Eugene::Mutation<Machine> >( + new Mutation::RemoveEdge())); + m->append_mutation(1 / 6.0f, boost::shared_ptr< Eugene::Mutation<Machine> >( + new Mutation::AdjustEdge())); + + boost::shared_ptr< Selection<Machine> > s(new TournamentSelection<Machine>( + _problem, 3, 0.8)); boost::shared_ptr< Crossover<Machine> > crossover; _ga = SharedPtr<MachinaGA>(new MachinaGA(_problem, s, crossover, m, - 20, 20, 2, 1.0, 0.0)); + 20, 20, 2, 1.0, 0.0)); } void Evolver::seed(SharedPtr<Machine> parent) { /*_best = SharedPtr<Machine>(new Machine(*parent.get())); - _best_fitness = _problem->fitness(*_best.get());*/ + _best_fitness = _problem->fitness(*_best.get());*/ _problem->seed(parent); _seed_fitness = _problem->fitness(*parent.get()); } @@ -87,15 +89,15 @@ Evolver::_run() float new_best = _ga->best_fitness(); /*cout << _problem->fitness_less(old_best, *_ga->best().get()) << endl; - cout << "best: " << _ga->best().get() << endl; - cout << "best fitness: " << _problem->fitness(*_ga->best().get()) << endl; - cout << "old best: " << old_best << endl; - cout << "new best: " << new_best << endl;*/ + cout << "best: " << _ga->best().get() << endl; + cout << "best fitness: " << _problem->fitness(*_ga->best().get()) << endl; + cout << "old best: " << old_best << endl; + cout << "new best: " << new_best << endl;*/ cout << "generation best: " << new_best << endl; if (_problem->fitness_less_than(old_best, new_best)) { _improvement = true; - old_best = new_best; + old_best = new_best; cout << "*** NEW BEST: " << new_best << endl; } @@ -104,4 +106,3 @@ Evolver::_run() } } // namespace Machina - |