|
@@ -12,6 +12,26 @@ namespace mdd {
|
|
|
_inputs[j]->setValue() = it->dna[j];
|
|
|
}
|
|
|
auto opt = updateOutputs();
|
|
|
+ json ret;
|
|
|
+ ret["generation"] = generation;
|
|
|
+ json jind;
|
|
|
+ jind["fitness"] = it->fitness;
|
|
|
+ jind["dna"] = it->dna;
|
|
|
+ ret["individual"] = jind;
|
|
|
+ if (opt.module_state == state::STATE_ERROR)
|
|
|
+ {
|
|
|
+ ret["state"] = "error";
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ ret["state"] = "ok";
|
|
|
+ }
|
|
|
+ ret["processor"] = _module->dump();
|
|
|
+ json jcall;
|
|
|
+ jcall["operation"] = "change";
|
|
|
+ jcall["args"]["subject"] = getIdentifier();
|
|
|
+ jcall["args"]["object"] = ret;
|
|
|
+ _callback(jcall);
|
|
|
+
|
|
|
if (opt.module_state == state::STATE_ERROR) {
|
|
|
_children.erase(it);
|
|
|
}
|
|
@@ -45,6 +65,21 @@ namespace mdd {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ json ret;
|
|
|
+ ret["generation"] = generation;
|
|
|
+ for (auto& ind : _bests)
|
|
|
+ {
|
|
|
+ json jind;
|
|
|
+ jind["fitness"] = ind.fitness;
|
|
|
+ jind["dna"] = ind.dna;
|
|
|
+ ret["bests"].push_back(jind);
|
|
|
+ }
|
|
|
+ json jcall;
|
|
|
+ jcall["operation"] = "add";
|
|
|
+ jcall["args"]["subject"] = getIdentifier();
|
|
|
+ jcall["args"]["object"] = ret;
|
|
|
+ _callback(jcall);
|
|
|
}
|
|
|
|
|
|
OptimizerEvolutionary::OptimizerEvolutionary()
|
|
@@ -147,7 +182,7 @@ namespace mdd {
|
|
|
|
|
|
double OptimizerEvolutionary::update()
|
|
|
{
|
|
|
- int gen = -1;
|
|
|
+ generation = -1;
|
|
|
bool check;
|
|
|
Individual old_best;
|
|
|
size_t same_counter = 0;
|
|
@@ -158,17 +193,31 @@ namespace mdd {
|
|
|
}
|
|
|
do
|
|
|
{
|
|
|
- std::cout << _children.size() << " | " << gen << std::endl;
|
|
|
+ std::cout << _children.size() << " | " << generation << std::endl;
|
|
|
if (_children.empty())
|
|
|
{
|
|
|
for (size_t i = 0; i < _grow_generation*2; i++)
|
|
|
{
|
|
|
_children.push_back(generateIndividual());
|
|
|
}
|
|
|
+ json ret;
|
|
|
+ ret["generation"] = generation;
|
|
|
+ for (auto& ind : _children)
|
|
|
+ {
|
|
|
+ json jind;
|
|
|
+ jind["fitness"] = ind.fitness;
|
|
|
+ jind["dna"] = ind.dna;
|
|
|
+ ret["individuals"] = jind;
|
|
|
+ }
|
|
|
+ json jcall;
|
|
|
+ jcall["operation"] = "add";
|
|
|
+ jcall["args"]["subject"] = getIdentifier();
|
|
|
+ jcall["args"]["object"] = ret;
|
|
|
+ _callback(jcall);
|
|
|
evaluate();
|
|
|
}
|
|
|
else {
|
|
|
- if (gen != -1)
|
|
|
+ if (generation != -1)
|
|
|
{
|
|
|
evolve(_children);
|
|
|
}
|
|
@@ -177,8 +226,8 @@ namespace mdd {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- ++gen;
|
|
|
- check = gen < _min_generations || _bests[0].fitness > _max_fitness;
|
|
|
+ ++generation;
|
|
|
+ check = generation < _min_generations || _bests[0].fitness > _max_fitness;
|
|
|
if (!check && _converges > 0)
|
|
|
{
|
|
|
bool found = false;
|
|
@@ -338,6 +387,20 @@ namespace mdd {
|
|
|
int p2 = (int)random_num(0, gen_pool.size() - 1);
|
|
|
_children.push_back(combine(gen_pool[p1], gen_pool[p2]));
|
|
|
}
|
|
|
+ json ret;
|
|
|
+ ret["generation"] = generation;
|
|
|
+ for (auto& ind : _children)
|
|
|
+ {
|
|
|
+ json jind;
|
|
|
+ jind["fitness"] = ind.fitness;
|
|
|
+ jind["dna"] = ind.dna;
|
|
|
+ ret["individuals"] = jind;
|
|
|
+ }
|
|
|
+ json jcall;
|
|
|
+ jcall["operation"] = "add";
|
|
|
+ jcall["args"]["subject"] = getIdentifier();
|
|
|
+ jcall["args"]["object"] = ret;
|
|
|
+ _callback(jcall);
|
|
|
evaluate(init_len);
|
|
|
}
|
|
|
|