|
@@ -3,6 +3,37 @@
|
|
|
namespace mdd {
|
|
|
void OptimizerEvolutionary::evaluate(size_t ignore_len)
|
|
|
{
|
|
|
+ //clear duplicates
|
|
|
+ //std::sort(_children.begin(), _children.end(), Permutation::smaller);
|
|
|
+ //_children.erase(std::unique(_children.begin(), _children.end(), Permutation::same), _children.end());
|
|
|
+ std::vector<Permutation> save = _children;
|
|
|
+ _children.clear();
|
|
|
+ for (size_t i = 0; i < save.size(); i++)
|
|
|
+ {
|
|
|
+ bool found = false;
|
|
|
+ for (size_t j = 0; j < _children.size(); j++)
|
|
|
+ {
|
|
|
+ if (save[i] == _children[j])
|
|
|
+ {
|
|
|
+ found = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!found)
|
|
|
+ {
|
|
|
+ _children.push_back(save[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //
|
|
|
+ opt_state def_state;
|
|
|
+ def_state.module_state = state::UNCHANGED;
|
|
|
+ for (int i = 0; i < ignore_len; ++i)
|
|
|
+ {
|
|
|
+ def_state.opt_value = _children[i].fitness;
|
|
|
+ callback_evaluate_opt(def_state, _children[i]);
|
|
|
+ }
|
|
|
+
|
|
|
//calculate fitness
|
|
|
for (auto it = _children.begin() + ignore_len; it != _children.end(); ++it)
|
|
|
{
|
|
@@ -11,7 +42,7 @@ namespace mdd {
|
|
|
//std::cout << "set: " << j << ": " << it->dna[j] << std::endl;
|
|
|
_inputs[j]->setValue() = it->dna[j];
|
|
|
}
|
|
|
- auto opt = updateOutputs();
|
|
|
+ opt_state opt = updateOutputs();
|
|
|
callback_evaluate_opt(opt, *it);
|
|
|
if (opt.module_state == state::STATE_ERROR) {
|
|
|
_children.erase(it);
|
|
@@ -22,6 +53,8 @@ namespace mdd {
|
|
|
}
|
|
|
//find fitest
|
|
|
double min = _children[0].fitness;
|
|
|
+ _bests.clear();
|
|
|
+ _bests.push_back(_children[0]);
|
|
|
for (size_t i = 1; i < _children.size(); i++)
|
|
|
{
|
|
|
if (round(min/_precision)*_precision > round(_children[i].fitness / _precision) * _precision) {
|