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 "eoAlgoFoundryFastGA.h"
|
||||
#include "eoEvalFoundryEA.h"
|
||||
#include "eoEvalFoundryFastGA.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// to be continued ...
|
||||
|
|
|
|||
|
|
@ -82,7 +82,12 @@ class eoAlgoFoundryFastGA : public eoAlgoFoundry<EOT>
|
|||
/** The constructon only take an eval, because all other operators
|
||||
* 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),
|
||||
continuators(0, true), // Always re-instantiate continuators, because they hold a state.
|
||||
crossover_rates(1, false),
|
||||
|
|
@ -115,14 +120,14 @@ class eoAlgoFoundryFastGA : public eoAlgoFoundry<EOT>
|
|||
*/
|
||||
void operator()(eoPop<EOT>& pop)
|
||||
{
|
||||
assert(continuators.size() > 0); assert(this->at(continuators.index()) < continuators.size());
|
||||
assert( crossover_rates.size() > 0); assert(this->at( crossover_rates.index()) < crossover_rates.size());
|
||||
assert( crossovers.size() > 0); assert(this->at( crossovers.index()) < crossovers.size());
|
||||
assert( mutation_rates.size() > 0); assert(this->at( mutation_rates.index()) < mutation_rates.size());
|
||||
assert( mutations.size() > 0); assert(this->at( mutations.index()) < mutations.size());
|
||||
assert( selectors.size() > 0); assert(this->at( selectors.index()) < selectors.size());
|
||||
assert( pop_sizes.size() > 0); assert(this->at( pop_sizes.index()) < pop_sizes.size());
|
||||
assert(replacements.size() > 0); assert(this->at(replacements.index()) < replacements.size());
|
||||
assert( continuators.size() > 0); assert(this->at( continuators.index()) < continuators.size());
|
||||
assert(crossover_rates.size() > 0); assert(this->at(crossover_rates.index()) < crossover_rates.size());
|
||||
assert( crossovers.size() > 0); assert(this->at( crossovers.index()) < crossovers.size());
|
||||
assert( mutation_rates.size() > 0); assert(this->at( mutation_rates.index()) < mutation_rates.size());
|
||||
assert( mutations.size() > 0); assert(this->at( mutations.index()) < mutations.size());
|
||||
assert( selectors.size() > 0); assert(this->at( selectors.index()) < selectors.size());
|
||||
assert( pop_sizes.size() > 0); assert(this->at( pop_sizes.index()) < pop_sizes.size());
|
||||
assert( replacements.size() > 0); assert(this->at( replacements.index()) < replacements.size());
|
||||
|
||||
// Crossover or clone
|
||||
double cross_rate = this->crossover_rate();
|
||||
|
|
@ -180,14 +185,14 @@ class eoAlgoFoundryFastGA : public eoAlgoFoundry<EOT>
|
|||
std::string name()
|
||||
{
|
||||
std::ostringstream name;
|
||||
name << this->at(continuators.index()) << " (" << this->continuator().className() << ") + ";
|
||||
name << this->at(crossover_rates.index()) << " (" << this->crossover_rate().className() << ") + ";
|
||||
name << this->at(crossovers.index()) << " (" << this->crossover().className() << ") + ";
|
||||
name << this->at(mutation_rates.index()) << " (" << this->mutation_rate().className() << ") + ";
|
||||
name << this->at(mutations.index()) << " (" << this->mutation().className() << ") + ";
|
||||
name << this->at(selectors.index()) << " (" << this->selector().className() << ") + ";
|
||||
name << this->at(pop_sizes.index()) << " (" << this->pop_size().className() << ")";
|
||||
name << this->at(replacements.index()) << " (" << this->replacement().className() << ")";
|
||||
name << this->at( continuators.index()) << " (" << this-> continuator().className() << ") + ";
|
||||
name << this->at(crossover_rates.index()) << " (" << this->crossover_rate() << ") + ";
|
||||
name << this->at( crossovers.index()) << " (" << this-> crossover().className() << ") + ";
|
||||
name << this->at( mutation_rates.index()) << " (" << this-> mutation_rate() << ") + ";
|
||||
name << this->at( mutations.index()) << " (" << this-> mutation().className() << ") + ";
|
||||
name << this->at( selectors.index()) << " (" << this-> selector().className() << ") + ";
|
||||
name << this->at( pop_sizes.index()) << " (" << this-> pop_size() << ")";
|
||||
name << this->at( replacements.index()) << " (" << this-> replacement().className() << ")";
|
||||
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
|
||||
|
||||
std::cout << _pop << std::endl;
|
||||
// std::cout << _pop << std::endl;
|
||||
|
||||
if (pSize > _pop.size())
|
||||
throw eoException("Population shrinking!");
|
||||
|
|
|
|||
|
|
@ -92,12 +92,19 @@ public:
|
|||
*/
|
||||
std::vector<size_t> decode( const EOT& sol ) const
|
||||
{
|
||||
// Denormalize
|
||||
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 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 repl = static_cast<size_t>(std::ceil( sol[i_repl] * _foundry.replacements.size() ));
|
||||
// // Denormalize
|
||||
// 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 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 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};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue