eoLottery finished

This commit is contained in:
gustavo 1999-02-05 16:34:00 +00:00
commit 5247c976ce
3 changed files with 11 additions and 11 deletions

View file

@ -11,9 +11,9 @@
//-----------------------------------------------------------------------------
#include <stdexcept> // runtime_error
#include <eoObject.h>
#include <eoPersistent.h>
#include <eoObject.h>
#include <eoPersistent.h>
//-----------------------------------------------------------------------------
/** 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;
}

View file

@ -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

View file

@ -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 Chrom> class eoLottery: public eoSelect<Chrom>
@ -28,11 +27,11 @@ template<class Chrom> class eoLottery: public eoSelect<Chrom>
{
// scores of chromosomes
vector<float> 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<float>(pop[i].fitness());
float sum = accumulate(score.begin(), score.end(), MINFLOAT);
transform(score.begin(), score.end(), score.begin(),
bind2nd(divides<float>(), sum));