fix foundry encoding
- remove normalization, use direct encoding in foundries - add fastGA in <eo>
This commit is contained in:
parent
a6c68f324a
commit
3f4d9bf728
4 changed files with 37 additions and 24 deletions
|
|
@ -164,6 +164,7 @@
|
||||||
#include "eoAlgoFoundryEA.h"
|
#include "eoAlgoFoundryEA.h"
|
||||||
#include "eoAlgoFoundryFastGA.h"
|
#include "eoAlgoFoundryFastGA.h"
|
||||||
#include "eoEvalFoundryEA.h"
|
#include "eoEvalFoundryEA.h"
|
||||||
|
#include "eoEvalFoundryFastGA.h"
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// to be continued ...
|
// to be continued ...
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,12 @@ class eoAlgoFoundryFastGA : public eoAlgoFoundry<EOT>
|
||||||
/** The constructon only take an eval, because all other operators
|
/** The constructon only take an eval, because all other operators
|
||||||
* are stored in the public containers.
|
* are stored in the public containers.
|
||||||
*/
|
*/
|
||||||
eoAlgoFoundryFastGA( eoInit<EOT> & init, eoEvalFunc<EOT>& eval, size_t max_evals = 10000, size_t max_restarts = std::numeric_limits<size_t>::max() ) :
|
eoAlgoFoundryFastGA(
|
||||||
|
eoInit<EOT> & init,
|
||||||
|
eoEvalFunc<EOT>& eval,
|
||||||
|
size_t max_evals = 10000,
|
||||||
|
size_t max_restarts = std::numeric_limits<size_t>::max()
|
||||||
|
) :
|
||||||
eoAlgoFoundry<EOT>(8),
|
eoAlgoFoundry<EOT>(8),
|
||||||
continuators(0, true), // Always re-instantiate continuators, because they hold a state.
|
continuators(0, true), // Always re-instantiate continuators, because they hold a state.
|
||||||
crossover_rates(1, false),
|
crossover_rates(1, false),
|
||||||
|
|
@ -181,12 +186,12 @@ class eoAlgoFoundryFastGA : public eoAlgoFoundry<EOT>
|
||||||
{
|
{
|
||||||
std::ostringstream name;
|
std::ostringstream name;
|
||||||
name << this->at( continuators.index()) << " (" << this-> continuator().className() << ") + ";
|
name << this->at( continuators.index()) << " (" << this-> continuator().className() << ") + ";
|
||||||
name << this->at(crossover_rates.index()) << " (" << this->crossover_rate().className() << ") + ";
|
name << this->at(crossover_rates.index()) << " (" << this->crossover_rate() << ") + ";
|
||||||
name << this->at( crossovers.index()) << " (" << this-> crossover().className() << ") + ";
|
name << this->at( crossovers.index()) << " (" << this-> crossover().className() << ") + ";
|
||||||
name << this->at(mutation_rates.index()) << " (" << this->mutation_rate().className() << ") + ";
|
name << this->at( mutation_rates.index()) << " (" << this-> mutation_rate() << ") + ";
|
||||||
name << this->at( mutations.index()) << " (" << this-> mutation().className() << ") + ";
|
name << this->at( mutations.index()) << " (" << this-> mutation().className() << ") + ";
|
||||||
name << this->at( selectors.index()) << " (" << this-> selector().className() << ") + ";
|
name << this->at( selectors.index()) << " (" << this-> selector().className() << ") + ";
|
||||||
name << this->at(pop_sizes.index()) << " (" << this->pop_size().className() << ")";
|
name << this->at( pop_sizes.index()) << " (" << this-> pop_size() << ")";
|
||||||
name << this->at( replacements.index()) << " (" << this-> replacement().className() << ")";
|
name << this->at( replacements.index()) << " (" << this-> replacement().className() << ")";
|
||||||
return name.str();
|
return name.str();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -272,7 +272,7 @@ template<class EOT> class eoEasyEA: public eoAlgo<EOT>
|
||||||
|
|
||||||
replace(_pop, offspring); // after replace, the new pop. is in _pop
|
replace(_pop, offspring); // after replace, the new pop. is in _pop
|
||||||
|
|
||||||
std::cout << _pop << std::endl;
|
// std::cout << _pop << std::endl;
|
||||||
|
|
||||||
if (pSize > _pop.size())
|
if (pSize > _pop.size())
|
||||||
throw eoException("Population shrinking!");
|
throw eoException("Population shrinking!");
|
||||||
|
|
|
||||||
|
|
@ -92,12 +92,19 @@ public:
|
||||||
*/
|
*/
|
||||||
std::vector<size_t> decode( const EOT& sol ) const
|
std::vector<size_t> decode( const EOT& sol ) const
|
||||||
{
|
{
|
||||||
// Denormalize
|
// // Denormalize
|
||||||
size_t cont = static_cast<size_t>(std::ceil( sol[i_cont] * _foundry.continuators.size() ));
|
// size_t cont = static_cast<size_t>(std::ceil( sol[i_cont] * _foundry.continuators.size() ));
|
||||||
size_t cros = static_cast<size_t>(std::ceil( sol[i_cros] * _foundry.crossovers .size() ));
|
// size_t cros = static_cast<size_t>(std::ceil( sol[i_cros] * _foundry.crossovers .size() ));
|
||||||
size_t muta = static_cast<size_t>(std::ceil( sol[i_muta] * _foundry.mutations .size() ));
|
// size_t muta = static_cast<size_t>(std::ceil( sol[i_muta] * _foundry.mutations .size() ));
|
||||||
size_t sele = static_cast<size_t>(std::ceil( sol[i_sele] * _foundry.selectors .size() ));
|
// size_t sele = static_cast<size_t>(std::ceil( sol[i_sele] * _foundry.selectors .size() ));
|
||||||
size_t repl = static_cast<size_t>(std::ceil( sol[i_repl] * _foundry.replacements.size() ));
|
// size_t repl = static_cast<size_t>(std::ceil( sol[i_repl] * _foundry.replacements.size() ));
|
||||||
|
|
||||||
|
// Direct encoding
|
||||||
|
size_t cont = static_cast<size_t>(std::ceil( sol[i_cont] ));
|
||||||
|
size_t cros = static_cast<size_t>(std::ceil( sol[i_cros] ));
|
||||||
|
size_t muta = static_cast<size_t>(std::ceil( sol[i_muta] ));
|
||||||
|
size_t sele = static_cast<size_t>(std::ceil( sol[i_sele] ));
|
||||||
|
size_t repl = static_cast<size_t>(std::ceil( sol[i_repl] ));
|
||||||
|
|
||||||
return {cont, cros, muta, sele, repl};
|
return {cont, cros, muta, sele, repl};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue