eoLottery finished
This commit is contained in:
parent
57e734fdf2
commit
5247c976ce
3 changed files with 11 additions and 11 deletions
11
eo/src/EO.h
11
eo/src/EO.h
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue