fix FastGA mutation invalidation
This commit is contained in:
parent
0f4dbf3a13
commit
6d465c6c2f
1 changed files with 10 additions and 1 deletions
|
|
@ -82,6 +82,7 @@ public:
|
||||||
// Set lambda to the pop size
|
// Set lambda to the pop size
|
||||||
// if it was not set up at construction.
|
// if it was not set up at construction.
|
||||||
if(_offsprings_size == 0) {
|
if(_offsprings_size == 0) {
|
||||||
|
// eo::log << eo::debug << "Set offspring size to: " << pop.size() << std::endl;
|
||||||
_offsprings_size = pop.size();
|
_offsprings_size = pop.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -89,8 +90,10 @@ public:
|
||||||
eoPop<EOT> offsprings;
|
eoPop<EOT> offsprings;
|
||||||
|
|
||||||
for(size_t i=0; i < _offsprings_size; ++i) {
|
for(size_t i=0; i < _offsprings_size; ++i) {
|
||||||
|
// eo::log << eo::xdebug << "\tOffspring #" << i << std::endl;
|
||||||
|
|
||||||
if(eo::rng.flip(_rate_crossover)) {
|
if(eo::rng.flip(_rate_crossover)) {
|
||||||
|
// eo::log << eo::xdebug << "\t\tDo crossover" << std::endl;
|
||||||
// Manual setup of eoSelectOne
|
// Manual setup of eoSelectOne
|
||||||
// (usually they are setup in a
|
// (usually they are setup in a
|
||||||
// wrapping eoSelect).
|
// wrapping eoSelect).
|
||||||
|
|
@ -118,6 +121,7 @@ public:
|
||||||
|
|
||||||
// Additional mutation (X)OR the crossed/cloned solution.
|
// Additional mutation (X)OR the crossed/cloned solution.
|
||||||
if(eo::rng.flip(_rate_mutation)) {
|
if(eo::rng.flip(_rate_mutation)) {
|
||||||
|
// eo::log << eo::xdebug << "\t\tDo mutation" << std::endl;
|
||||||
if(_mutation(sol3)) {
|
if(_mutation(sol3)) {
|
||||||
sol3.invalidate();
|
sol3.invalidate();
|
||||||
}
|
}
|
||||||
|
|
@ -125,9 +129,12 @@ public:
|
||||||
offsprings.push_back(sol3);
|
offsprings.push_back(sol3);
|
||||||
|
|
||||||
} else { // If not crossing, always mutate.
|
} else { // If not crossing, always mutate.
|
||||||
|
// eo::log << eo::xdebug << "\t\tNo crossover, do mutation" << std::endl;
|
||||||
_select_mut.setup(pop);
|
_select_mut.setup(pop);
|
||||||
EOT sol3 = _select_mut(pop);
|
EOT sol3 = _select_mut(pop);
|
||||||
_mutation(sol3);
|
if(_mutation(sol3)) {
|
||||||
|
sol3.invalidate();
|
||||||
|
}
|
||||||
offsprings.push_back(sol3);
|
offsprings.push_back(sol3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -136,6 +143,8 @@ public:
|
||||||
_pop_eval(pop, offsprings);
|
_pop_eval(pop, offsprings);
|
||||||
_replace(pop, offsprings);
|
_replace(pop, offsprings);
|
||||||
|
|
||||||
|
// eo::log << eo::xdebug << "\tEnd of generation" << std::endl;
|
||||||
|
|
||||||
} while(_continuator(pop));
|
} while(_continuator(pop));
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
assert(pop.size() > 0);
|
assert(pop.size() > 0);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue