diff --git a/eo/src/eo b/eo/src/eo index a296c7091..ced1abdcc 100644 --- a/eo/src/eo +++ b/eo/src/eo @@ -164,6 +164,7 @@ #include "eoAlgoFoundryEA.h" #include "eoAlgoFoundryFastGA.h" #include "eoEvalFoundryEA.h" +#include "eoEvalFoundryFastGA.h" //----------------------------------------------------------------------------- // to be continued ... diff --git a/eo/src/eoAlgoFoundryFastGA.h b/eo/src/eoAlgoFoundryFastGA.h index f9ab98f00..ca64f44e8 100644 --- a/eo/src/eoAlgoFoundryFastGA.h +++ b/eo/src/eoAlgoFoundryFastGA.h @@ -82,7 +82,12 @@ class eoAlgoFoundryFastGA : public eoAlgoFoundry /** The constructon only take an eval, because all other operators * are stored in the public containers. */ - eoAlgoFoundryFastGA( eoInit & init, eoEvalFunc& eval, size_t max_evals = 10000, size_t max_restarts = std::numeric_limits::max() ) : + eoAlgoFoundryFastGA( + eoInit & init, + eoEvalFunc& eval, + size_t max_evals = 10000, + size_t max_restarts = std::numeric_limits::max() + ) : eoAlgoFoundry(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 */ void operator()(eoPop& 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 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(); } diff --git a/eo/src/eoEasyEA.h b/eo/src/eoEasyEA.h index fc2ebd6b2..ace02604a 100644 --- a/eo/src/eoEasyEA.h +++ b/eo/src/eoEasyEA.h @@ -272,7 +272,7 @@ template class eoEasyEA: public eoAlgo 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!"); diff --git a/eo/src/eoEvalFoundryEA.h b/eo/src/eoEvalFoundryEA.h index f3b33cba5..76521c9b6 100644 --- a/eo/src/eoEvalFoundryEA.h +++ b/eo/src/eoEvalFoundryEA.h @@ -92,12 +92,19 @@ public: */ std::vector decode( const EOT& sol ) const { - // Denormalize - size_t cont = static_cast(std::ceil( sol[i_cont] * _foundry.continuators.size() )); - size_t cros = static_cast(std::ceil( sol[i_cros] * _foundry.crossovers .size() )); - size_t muta = static_cast(std::ceil( sol[i_muta] * _foundry.mutations .size() )); - size_t sele = static_cast(std::ceil( sol[i_sele] * _foundry.selectors .size() )); - size_t repl = static_cast(std::ceil( sol[i_repl] * _foundry.replacements.size() )); + // // Denormalize + // size_t cont = static_cast(std::ceil( sol[i_cont] * _foundry.continuators.size() )); + // size_t cros = static_cast(std::ceil( sol[i_cros] * _foundry.crossovers .size() )); + // size_t muta = static_cast(std::ceil( sol[i_muta] * _foundry.mutations .size() )); + // size_t sele = static_cast(std::ceil( sol[i_sele] * _foundry.selectors .size() )); + // size_t repl = static_cast(std::ceil( sol[i_repl] * _foundry.replacements.size() )); + + // Direct encoding + size_t cont = static_cast(std::ceil( sol[i_cont] )); + size_t cros = static_cast(std::ceil( sol[i_cros] )); + size_t muta = static_cast(std::ceil( sol[i_muta] )); + size_t sele = static_cast(std::ceil( sol[i_sele] )); + size_t repl = static_cast(std::ceil( sol[i_repl] )); return {cont, cros, muta, sele, repl}; }