diff --git a/eo/src/EO.h b/eo/src/EO.h index e9ff84e75..16b332131 100644 --- a/eo/src/EO.h +++ b/eo/src/EO.h @@ -11,9 +11,9 @@ //----------------------------------------------------------------------------- #include // runtime_error - -#include -#include + +#include +#include //----------------------------------------------------------------------------- /** EO is a base class for evolvable objects, that is, the subjects of evolution. @@ -40,7 +40,7 @@ public: */ EO( istream& _is ) { _is >> repFitness; - validFitness = true; + invalidFitness = false; }; /// Copy ctor @@ -53,7 +53,8 @@ public: Fitness fitness() const { if (invalid()) - throw runtime_error("invalid fitness"); + //throw runtime_error("invalid fitness"); + cout << "invalid fitness" << endl; return repFitness; } diff --git a/eo/src/Makefile.am b/eo/src/Makefile.am index 89b02cc0e..0bd70623b 100644 --- a/eo/src/Makefile.am +++ b/eo/src/Makefile.am @@ -7,4 +7,4 @@ lib_LTLIBRARIES = libeo.la libeo_la_SOURCES = eoPrintable.cpp eoPersistent.cpp libeoincdir = $(includedir)/eo -libeoinc_HEADERS = eo EO.h eoDup.h eoMultiMonOp.h eoPop.h eoUniform.h eoESChrom.h eoNegExp.h eoProblem.h eoVector.h eoFitness.h eoNormal.h eoRnd.h eoXOver2.h eo1d.h eoID.h eoObject.h eoString.h eoAged.h eoKill.h eoOp.h eoTranspose.h eoBin.h +libeoinc_HEADERS = eo EO.h eoDup.h eoMultiMonOp.h eoPop.h eoUniform.h eoESChrom.h eoNegExp.h eoProblem.h eoVector.h eoFitness.h eoNormal.h eoRnd.h eoXOver2.h eo1d.h eoID.h eoObject.h eoString.h eoAged.h eoKill.h eoOp.h eoTranspose.h eoBin.h eoPrintable.h eoPersistent.h eoLottery.h eoMutation.h eoPopOps.h eoUniform.h diff --git a/eo/src/eoLottery.h b/eo/src/eoLottery.h index 28b988b26..acd8d60f4 100644 --- a/eo/src/eoLottery.h +++ b/eo/src/eoLottery.h @@ -13,8 +13,7 @@ //----------------------------------------------------------------------------- /// eoLottery: a selection method. -/// requires that the fitness type of the chromosome inherits from eoFitness -/// or have a cast to float implemented +/// requires Chrom::Fitness to be float castable //----------------------------------------------------------------------------- template class eoLottery: public eoSelect @@ -28,11 +27,11 @@ template class eoLottery: public eoSelect { // scores of chromosomes vector score(pop.size()); - + // calculates accumulated scores for chromosomes for (unsigned i = 0; i < pop.size(); i++) - score[i] = pop[i].fitness(); - + score[i] = static_cast(pop[i].fitness()); + float sum = accumulate(score.begin(), score.end(), MINFLOAT); transform(score.begin(), score.end(), score.begin(), bind2nd(divides(), sum));