aboutsummaryrefslogtreecommitdiffstats
path: root/src/engine/Problem.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2013-01-15 21:53:48 +0000
committerDavid Robillard <d@drobilla.net>2013-01-15 21:53:48 +0000
commit69c8cde985cc012b6cae2a49d489553c5be67202 (patch)
tree08411dfc9fcf48660c7467d9140f3c35b16464ee /src/engine/Problem.cpp
parent987eaa018039cb891ffeca60b413a00b1f7da299 (diff)
downloadmachina-69c8cde985cc012b6cae2a49d489553c5be67202.tar.gz
machina-69c8cde985cc012b6cae2a49d489553c5be67202.tar.bz2
machina-69c8cde985cc012b6cae2a49d489553c5be67202.zip
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
Diffstat (limited to 'src/engine/Problem.cpp')
-rw-r--r--src/engine/Problem.cpp47
1 files changed, 24 insertions, 23 deletions
diff --git a/src/engine/Problem.cpp b/src/engine/Problem.cpp
index cbb360b..3b05fed 100644
--- a/src/engine/Problem.cpp
+++ b/src/engine/Problem.cpp
@@ -17,21 +17,23 @@
#define __STDC_LIMIT_MACROS 1
#include <stdint.h>
+
#include <set>
#include <vector>
#include <iostream>
+#include "lv2/lv2plug.in/ns/ext/midi/midi.h"
+
#include "eugene/Problem.hpp"
-#include "machina/Edge.hpp"
#include "machina/Machine.hpp"
-#include "raul/SMFReader.hpp"
-#include "raul/midi_events.h"
-
-#include "machina_config.h"
#include "ActionFactory.hpp"
+#include "Edge.hpp"
+#include "MidiAction.hpp"
#include "Problem.hpp"
+#include "SMFReader.hpp"
+#include "machina_config.h"
using namespace std;
@@ -74,8 +76,9 @@ Problem::Problem(TimeUnit unit,
}
float
-Problem::fitness(const Machine& const_machine) const
+Problem::evaluate(const Machine& const_machine) const
{
+ #if 0
//cout << "(";
// kluuudge
@@ -89,8 +92,6 @@ Problem::fitness(const Machine& const_machine) const
SPtr<Evaluator> eval(new Evaluator(*this));
//machine.reset();
- machine.deactivate();
- machine.activate();
machine.set_sink(eval);
// FIXME: timing stuff here isn't right at all...
@@ -167,6 +168,8 @@ Problem::fitness(const Machine& const_machine) const
_fitness[&machine] = f;
return f;
+ #endif
+ return 0.0f;
}
void
@@ -174,7 +177,7 @@ Problem::Evaluator::write_event(Raul::TimeStamp time,
size_t ev_size,
const uint8_t* ev) throw (std::logic_error)
{
- if ((ev[0] & 0xF0) == MIDI_CMD_NOTE_ON) {
+ if ((ev[0] & 0xF0) == LV2_MIDI_MSG_NOTE_ON) {
const uint8_t note = ev[1];
@@ -197,9 +200,9 @@ Problem::Evaluator::write_event(Raul::TimeStamp time,
for (size_t i = 0; i < _read.length(); ++i) {
const string pattern = _read.substr(i);
- Patterns::iterator i = _patterns.find(pattern);
- if (i != _patterns.end()) {
- ++(i->second);
+ Patterns::iterator p = _patterns.find(pattern);
+ if (p != _patterns.end()) {
+ ++(p->second);
} else {
_patterns[pattern] = 1;
}
@@ -223,11 +226,12 @@ Problem::Evaluator::compute()
}*/
}
-boost::shared_ptr<Problem::Population>
-Problem::initial_population(size_t gene_size, size_t pop_size) const
+void
+Problem::initial_population(eugene::Random& rng,
+ Population& pop,
+ size_t gene_size,
+ size_t pop_size) const
{
- boost::shared_ptr<Population> ret(new std::vector<Machine>());
-
// FIXME: ignores _seed and builds based on MIDI
// evolution of the visible machine would be nice..
SPtr<Machine> base = SPtr<Machine>(new Machine(_unit));
@@ -247,20 +251,19 @@ Problem::initial_population(size_t gene_size, size_t pop_size) const
Machine m(*base.get());
set< SPtr<Node> > unreachable;
- SPtr<Node> initial;
for (Machine::Nodes::iterator i = m.nodes().begin(); i != m.nodes().end();
++i) {
if (dynamic_ptr_cast<MidiAction>((*i)->enter_action())->event()[1] ==
_target.first_note()) {
- (*i)->set_initial(true);
- initial = *i;
+ m.initial_node()->add_edge(
+ SPtr<Edge>(new Edge(m.initial_node(), *i)));
} else {
unreachable.insert(*i);
}
}
- SPtr<Node> cur = initial;
+ SPtr<Node> cur = m.initial_node();
unreachable.erase(cur);
SPtr<Node> head;
@@ -278,13 +281,11 @@ Problem::initial_population(size_t gene_size, size_t pop_size) const
}
}
- ret->push_back(m);
+ pop.push_back(m);
/*cout << "initial # nodes: " << m.nodes().size();
cout << "initial fitness: " << fitness(m) << endl;*/
}
-
- return ret;
}
/** levenshtein distance (edit distance) */