Moved the static eoRNG rng to an extern eoRNG
This external object is now defined in eoPersistent.cpp This should change...
This commit is contained in:
parent
c48c1f2c12
commit
2443677f13
12 changed files with 257 additions and 227 deletions
|
|
@ -28,6 +28,14 @@
|
||||||
#ifndef COMPAT_H
|
#ifndef COMPAT_H
|
||||||
#define COMPAT_H
|
#define COMPAT_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#ifdef _1__GNUC__
|
||||||
|
// Specifics for GNUC
|
||||||
|
#define NO_GOOD_ISTREAM_ITERATORS
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
/*
|
/*
|
||||||
Maarten: added this code here because Mirkosoft has the
|
Maarten: added this code here because Mirkosoft has the
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ template <class EOT> class eoDetTournament: public eoSelectOne<EOT>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// (Default) Constructor.
|
/// (Default) Constructor.
|
||||||
eoDetTournament(unsigned _Tsize = 2 ):eoSelectOne(), Tsize(_Tsize) {
|
eoDetTournament(unsigned _Tsize = 2 ):eoSelectOne<EOT>(), Tsize(_Tsize) {
|
||||||
// consistency check
|
// consistency check
|
||||||
if (Tsize < 2) {
|
if (Tsize < 2) {
|
||||||
cout << "Warning, Tournament size should be >= 2\nAdjusted\n";
|
cout << "Warning, Tournament size should be >= 2\nAdjusted\n";
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,8 @@ class eoGOpSelector: public eoOpSelector<EOT>, public vector<eoGeneralOp<EOT>*>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
typedef eoOpSelector<EOT>::ID ID;
|
||||||
|
|
||||||
/// Dtor
|
/// Dtor
|
||||||
virtual ~eoGOpSelector() {
|
virtual ~eoGOpSelector() {
|
||||||
for ( list< eoGeneralOp<EOT>* >::iterator i= ownOpList.begin();
|
for ( list< eoGeneralOp<EOT>* >::iterator i= ownOpList.begin();
|
||||||
|
|
@ -84,12 +86,12 @@ public:
|
||||||
virtual string className() const { return "eoGOpSelector"; };
|
virtual string className() const { return "eoGOpSelector"; };
|
||||||
|
|
||||||
///
|
///
|
||||||
void printOn(ostream& _os) const {
|
void printOn(ostream& _os) const {}
|
||||||
_os << className() << endl;
|
// _os << className().c_str() << endl;
|
||||||
for ( unsigned i=0; i!= rates.size(); i++ ) {
|
// for ( unsigned i=0; i!= rates.size(); i++ ) {
|
||||||
_os << *(operator[](i)) << "\t" << rates[i] << endl;
|
// _os << *(operator[](i)) << "\t" << rates[i] << endl;
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
|
||||||
const vector<float>& getRates(void) const { return rates; }
|
const vector<float>& getRates(void) const { return rates; }
|
||||||
|
|
|
||||||
|
|
@ -30,8 +30,7 @@
|
||||||
#ifndef eoInserter_h
|
#ifndef eoInserter_h
|
||||||
#define eoInserter_h
|
#define eoInserter_h
|
||||||
|
|
||||||
#include "eoObject.h"
|
#include "eoPop.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* eoInserter: Interface class that enables an operator to insert
|
* eoInserter: Interface class that enables an operator to insert
|
||||||
new individuals into the (intermediate) population.
|
new individuals into the (intermediate) population.
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ public:
|
||||||
* @param _os A ostream.
|
* @param _os A ostream.
|
||||||
*/
|
*/
|
||||||
virtual void printOn(ostream& _os) const {
|
virtual void printOn(ostream& _os) const {
|
||||||
_os << className();
|
_os << className().c_str();
|
||||||
// _os << arity;
|
// _os << arity;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,3 +8,7 @@ istream & operator >> ( istream& _is, eoPersistent& _o ) {
|
||||||
_o.readFrom(_is);
|
_o.readFrom(_is);
|
||||||
return _is;
|
return _is;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#include "eoRNG.h"
|
||||||
|
|
||||||
|
eoRng rng;
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@
|
||||||
// EO includes
|
// EO includes
|
||||||
#include <eoRnd.h>
|
#include <eoRnd.h>
|
||||||
#include <eoPersistent.h>
|
#include <eoPersistent.h>
|
||||||
|
#include <eoEvalFunc.h>
|
||||||
|
|
||||||
/** Subpopulation: it is used to move parts of population
|
/** Subpopulation: it is used to move parts of population
|
||||||
from one algorithm to another and one population to another. It is safer
|
from one algorithm to another and one population to another. It is safer
|
||||||
|
|
@ -90,6 +91,21 @@ class eoPop: public vector<EOT>, public eoObject, public eoPersistent {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Ctor for fixed-size chromosomes, with variable content
|
||||||
|
@param _popSize total population size
|
||||||
|
@param _eoSize chromosome size. EOT should accept a fixed-size ctor
|
||||||
|
@param _geneRdn random number generator for each of the genes
|
||||||
|
*/
|
||||||
|
eoPop( unsigned _popSize, unsigned _eoSize, eoRnd<Type> & _geneRnd, eoEvalFunc<EOT>& _eval)
|
||||||
|
:vector<EOT>() {
|
||||||
|
for ( unsigned i = 0; i < _popSize; i ++ ){
|
||||||
|
EOT tmpEOT( _eoSize, _geneRnd);
|
||||||
|
push_back( tmpEOT );
|
||||||
|
_eval(back());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/** Ctor from an istream; reads the population from a stream,
|
/** Ctor from an istream; reads the population from a stream,
|
||||||
each element should be in different lines
|
each element should be in different lines
|
||||||
@param _is the stream
|
@param _is the stream
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,7 @@ public:
|
||||||
modified or whatever
|
modified or whatever
|
||||||
@param _id a previously assigned ID
|
@param _id a previously assigned ID
|
||||||
@throw runtime_error if the ID does not exist*/
|
@throw runtime_error if the ID does not exist*/
|
||||||
|
|
||||||
virtual eoOp<EOT>& getOp( ID _id ) {
|
virtual eoOp<EOT>& getOp( ID _id ) {
|
||||||
MMF::iterator i=begin();
|
MMF::iterator i=begin();
|
||||||
ID j = 1;
|
ID j = 1;
|
||||||
|
|
@ -135,7 +136,7 @@ public:
|
||||||
base classes, so you don´t have to worry about, for instance, fitness.
|
base classes, so you don´t have to worry about, for instance, fitness.
|
||||||
@param _s the ostream in which things are written*/
|
@param _s the ostream in which things are written*/
|
||||||
virtual void printOn( ostream& _s ) const{
|
virtual void printOn( ostream& _s ) const{
|
||||||
_s << className() << endl;
|
_s << className().c_str() << endl;
|
||||||
for ( MMF::const_iterator i=begin(); i!=end(); i++ ) {
|
for ( MMF::const_iterator i=begin(); i!=end(); i++ ) {
|
||||||
_s << i->first << "\t" << *(i->second )<< endl;
|
_s << i->first << "\t" << *(i->second )<< endl;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -197,7 +197,7 @@ public :
|
||||||
{
|
{
|
||||||
if (total == 0)
|
if (total == 0)
|
||||||
{ // count
|
{ // count
|
||||||
for (unsigned i = 0; i < vec.size(); ++i)
|
for (int i = 0; i < vec.size(); ++i)
|
||||||
total += vec[i];
|
total += vec[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -270,7 +270,7 @@ private :
|
||||||
/**
|
/**
|
||||||
The one and only global eoRng object
|
The one and only global eoRng object
|
||||||
*/
|
*/
|
||||||
static eoRng rng;
|
extern eoRng rng;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The class uniform_generator can be used in the STL generate function
|
The class uniform_generator can be used in the STL generate function
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ template<class EOT> class eoSteadyStateEA: public eoAlgo<EOT>
|
||||||
eoGOpSelector<EOT>& _opSelector,
|
eoGOpSelector<EOT>& _opSelector,
|
||||||
eoPopIndiSelector<EOT>& _selector,
|
eoPopIndiSelector<EOT>& _selector,
|
||||||
eoSteadyStateInserter<EOT>& _inserter,
|
eoSteadyStateInserter<EOT>& _inserter,
|
||||||
eoTerm<Chrom>& _terminator,
|
eoTerm<EOT>& _terminator,
|
||||||
unsigned _steps = 0 )
|
unsigned _steps = 0 )
|
||||||
: step(_opSelector, _selector, _inserter),
|
: step(_opSelector, _selector, _inserter),
|
||||||
terminator( _terminator)
|
terminator( _terminator)
|
||||||
|
|
@ -57,7 +57,7 @@ template<class EOT> class eoSteadyStateEA: public eoAlgo<EOT>
|
||||||
terminator( _terminator){};
|
terminator( _terminator){};
|
||||||
|
|
||||||
/// Apply one generation of evolution to the population.
|
/// Apply one generation of evolution to the population.
|
||||||
virtual void operator()(eoPop<Chrom>& pop) {
|
virtual void operator()(eoPop<EOT>& pop) {
|
||||||
do {
|
do {
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
@ -70,6 +70,7 @@ template<class EOT> class eoSteadyStateEA: public eoAlgo<EOT>
|
||||||
throw runtime_error( s );
|
throw runtime_error( s );
|
||||||
}
|
}
|
||||||
} while ( terminator( pop ) );
|
} while ( terminator( pop ) );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Class name.
|
/// Class name.
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ template <class EOT> class eoUniformSelect: public eoSelectOne<EOT>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// (Default) Constructor.
|
/// (Default) Constructor.
|
||||||
eoUniformSelect():eoSelectOne() {}
|
eoUniformSelect():eoSelectOne<EOT>() {}
|
||||||
|
|
||||||
/// not a big deal!!!
|
/// not a big deal!!!
|
||||||
virtual const EOT& operator()(const eoPop<EOT>& pop) {
|
virtual const EOT& operator()(const eoPop<EOT>& pop) {
|
||||||
|
|
|
||||||
|
|
@ -144,7 +144,6 @@ public :
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Helper class to make sure that stuff that is inserted will be used again with the next operator
|
/// Helper class to make sure that stuff that is inserted will be used again with the next operator
|
||||||
template <class EOT>
|
|
||||||
class eoIndiSelectorInserter : public eoIndiSelector<EOT>, public eoInserter<EOT>
|
class eoIndiSelectorInserter : public eoIndiSelector<EOT>, public eoInserter<EOT>
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
|
|
@ -204,7 +203,7 @@ public :
|
||||||
void operator()( eoIndiSelector<EOT>& _in,
|
void operator()( eoIndiSelector<EOT>& _in,
|
||||||
eoInserter<EOT>& _out ) const {
|
eoInserter<EOT>& _out ) const {
|
||||||
|
|
||||||
eoIndiSelectorInserter<EOT> in_out(_in);
|
eoIndiSelectorInserter in_out(_in);
|
||||||
|
|
||||||
for (size_t i = 0; i < ops.size(); ++i)
|
for (size_t i = 0; i < ops.size(); ++i)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Reference in a new issue