aboutsummaryrefslogtreecommitdiffstats
path: root/src/engine/Evolver.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine/Evolver.cpp')
-rw-r--r--src/engine/Evolver.cpp67
1 files changed, 39 insertions, 28 deletions
diff --git a/src/engine/Evolver.cpp b/src/engine/Evolver.cpp
index eb697b6..906e888 100644
--- a/src/engine/Evolver.cpp
+++ b/src/engine/Evolver.cpp
@@ -26,8 +26,7 @@
#include "Problem.hpp"
using namespace std;
-using namespace Eugene;
-using namespace boost;
+using namespace eugene;
namespace machina {
@@ -37,39 +36,51 @@ Evolver::Evolver(TimeUnit unit,
: _problem(new Problem(unit, target_midi, seed))
, _seed_fitness(-FLT_MAX)
{
- SPtr<Eugene::HybridMutation<Machine> > m(new HybridMutation<Machine>());
+ SPtr<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> >(
+ m->append_mutation(1 / 6.0f, std::shared_ptr< eugene::Mutation<Machine> >(
+ new Mutation::Compress()));
+ m->append_mutation(1 / 6.0f, std::shared_ptr< eugene::Mutation<Machine> >(
+ new Mutation::AddNode()));
+ //m->append_mutation(1/6.0f, std::shared_ptr< eugene::Mutation<Machine> >(
// new Mutation::RemoveNode()));
- //m->append_mutation(1/6.0f, boost::shared_ptr< Eugene::Mutation<Machine> >(
+ //m->append_mutation(1/6.0f, std::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));
- boost::shared_ptr< Crossover<Machine> > crossover;
+ m->append_mutation(1 / 6.0f, std::shared_ptr< eugene::Mutation<Machine> >(
+ new Mutation::SwapNodes()));
+ m->append_mutation(1 / 6.0f, std::shared_ptr< eugene::Mutation<Machine> >(
+ new Mutation::AddEdge()));
+ m->append_mutation(1 / 6.0f, std::shared_ptr< eugene::Mutation<Machine> >(
+ new Mutation::RemoveEdge()));
+ m->append_mutation(1 / 6.0f, std::shared_ptr< eugene::Mutation<Machine> >(
+ new Mutation::AdjustEdge()));
+
+ std::shared_ptr< Selection<Machine> > s(
+ new TournamentSelection<Machine>(*_problem.get(), 3, 0.8));
+ std::shared_ptr< Crossover<Machine> > crossover;
+ size_t gene_length = 20; // FIXME
+ Problem::Population pop;
_ga = SPtr<MachinaGA>(
- new MachinaGA(_problem, s, crossover, m, 20, 20, 2, 1.0, 0.0));
+ new MachinaGA(_rng,
+ _problem,
+ s,
+ crossover,
+ m,
+ pop,
+ gene_length,
+ 20,
+ 2,
+ 1.0,
+ 0.0));
}
void
Evolver::seed(SPtr<Machine> parent)
{
/*_best = SPtr<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());
+ _seed_fitness = _problem->evaluate(*parent.get());
}
void
@@ -89,10 +100,10 @@ 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)) {