* indentations + whitespace cleanup
This commit is contained in:
parent
8457e39efe
commit
56c6edab04
285 changed files with 6068 additions and 6223 deletions
|
|
@ -1,11 +1,11 @@
|
|||
This directory contains:
|
||||
|
||||
- some standard EO source files, named eoXXXXX, that define objects
|
||||
- some standard EO source files, named eoXXXXX, that define objects
|
||||
for the eoBit<FitT> representation (bitstrings).
|
||||
|
||||
- some make_XXX.cpp files that are instanciations for EO bitstrings
|
||||
(eoBit<double> AND eoBit<eoMinimizingFitness>) of the tempatized code
|
||||
that is defined in the EO src/do dir.
|
||||
(eoBit<double> AND eoBit<eoMinimizingFitness>) of the tempatized code
|
||||
that is defined in the EO src/do dir.
|
||||
This MK's trick allows to actually compile all these bits in a library
|
||||
(eolibga.a) and to only recompile the bits you need for your own
|
||||
(bitstring!) application.
|
||||
|
|
@ -18,4 +18,3 @@ that constructs the EOType initializer (make_genotype.h) and the one
|
|||
that buils up the operators (make_op.h).
|
||||
|
||||
MS, April 23, 2001CVS
|
||||
|
||||
|
|
|
|||
|
|
@ -106,11 +106,11 @@ public:
|
|||
std::string bits;
|
||||
is >> bits;
|
||||
if (is)
|
||||
{
|
||||
resize(bits.size());
|
||||
std::transform(bits.begin(), bits.end(), begin(),
|
||||
{
|
||||
resize(bits.size());
|
||||
std::transform(bits.begin(), bits.end(), begin(),
|
||||
std::bind2nd(std::equal_to<char>(), '1'));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -87,10 +87,10 @@ template<class Chrom> class eoDetBitFlip: public eoMonOp<Chrom>
|
|||
{
|
||||
// does not check for duplicate: if someone volunteers ....
|
||||
for (unsigned k=0; k<num_bit; k++)
|
||||
{
|
||||
unsigned i = eo::rng.random(chrom.size());
|
||||
chrom[i] = (chrom[i]) ? false : true;
|
||||
}
|
||||
{
|
||||
unsigned i = eo::rng.random(chrom.size());
|
||||
chrom[i] = (chrom[i]) ? false : true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
|
|
@ -126,9 +126,9 @@ template<class Chrom> class eoBitMutation: public eoMonOp<Chrom>
|
|||
double actualRate = (normalize ? rate/chrom.size() : rate);
|
||||
bool changed_something = false;
|
||||
for (unsigned i = 0; i < chrom.size(); i++)
|
||||
if (eo::rng.flip(actualRate))
|
||||
if (eo::rng.flip(actualRate))
|
||||
{
|
||||
chrom[i] = !chrom[i];
|
||||
chrom[i] = !chrom[i];
|
||||
changed_something = true;
|
||||
}
|
||||
|
||||
|
|
@ -137,7 +137,7 @@ template<class Chrom> class eoBitMutation: public eoMonOp<Chrom>
|
|||
|
||||
private:
|
||||
double rate;
|
||||
bool normalize; // divide rate by chromSize
|
||||
bool normalize; // divide rate by chromSize
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -187,16 +187,16 @@ template<class Chrom> class eoBitNext: public eoMonOp<Chrom>
|
|||
bool operator()(Chrom& chrom)
|
||||
{
|
||||
for (int i = chrom.size() - 1; i >= 0; i--)
|
||||
if (chrom[i])
|
||||
{
|
||||
chrom[i] = 0;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
chrom[i] = 1;
|
||||
break;
|
||||
}
|
||||
if (chrom[i])
|
||||
{
|
||||
chrom[i] = 0;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
chrom[i] = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -221,16 +221,16 @@ template<class Chrom> class eoBitPrev: public eoMonOp<Chrom>
|
|||
bool operator()(Chrom& chrom)
|
||||
{
|
||||
for (int i = chrom.size() - 1; i >= 0; i--)
|
||||
if (chrom[i])
|
||||
{
|
||||
chrom[i] = 0;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
chrom[i] = 1;
|
||||
continue;
|
||||
}
|
||||
if (chrom[i])
|
||||
{
|
||||
chrom[i] = 0;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
chrom[i] = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -281,7 +281,7 @@ template<class Chrom> class eoUBitXover: public eoQuadOp<Chrom>
|
|||
eoUBitXover(const float& _preference = 0.5): preference(_preference)
|
||||
{
|
||||
if ( (_preference <= 0.0) || (_preference >= 1.0) )
|
||||
std::runtime_error("UxOver --> invalid preference");
|
||||
std::runtime_error("UxOver --> invalid preference");
|
||||
}
|
||||
/// The class name.
|
||||
virtual std::string className() const { return "eoUBitXover"; }
|
||||
|
|
@ -295,18 +295,18 @@ template<class Chrom> class eoUBitXover: public eoQuadOp<Chrom>
|
|||
bool operator()(Chrom& chrom1, Chrom& chrom2)
|
||||
{
|
||||
if ( chrom1.size() != chrom2.size())
|
||||
std::runtime_error("UxOver --> chromosomes sizes don't match" );
|
||||
std::runtime_error("UxOver --> chromosomes sizes don't match" );
|
||||
bool changed = false;
|
||||
for (unsigned int i=0; i<chrom1.size(); i++)
|
||||
{
|
||||
if (chrom1[i] != chrom2[i] && eo::rng.flip(preference))
|
||||
{
|
||||
bool tmp = chrom1[i];
|
||||
chrom1[i]=chrom2[i];
|
||||
chrom2[i] = tmp;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
{
|
||||
if (chrom1[i] != chrom2[i] && eo::rng.flip(preference))
|
||||
{
|
||||
bool tmp = chrom1[i];
|
||||
chrom1[i]=chrom2[i];
|
||||
chrom2[i] = tmp;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
private:
|
||||
|
|
@ -390,9 +390,9 @@ template<class Chrom> class eoBitGxOver: public eoQuadOp<Chrom>
|
|||
gene_size(_gene_size), num_points(_num_points)
|
||||
{
|
||||
if (gene_size < 1)
|
||||
std::runtime_error("GxOver --> invalid gene size");
|
||||
std::runtime_error("GxOver --> invalid gene size");
|
||||
if (num_points < 1)
|
||||
std::runtime_error("GxOver --> invalid number of points");
|
||||
std::runtime_error("GxOver --> invalid number of points");
|
||||
}
|
||||
|
||||
/// The class name
|
||||
|
|
@ -412,22 +412,22 @@ template<class Chrom> class eoBitGxOver: public eoQuadOp<Chrom>
|
|||
|
||||
// selects genes to swap
|
||||
do {
|
||||
unsigned bit = eo::rng.random(max_genes);
|
||||
if (points[bit])
|
||||
continue;
|
||||
else
|
||||
{
|
||||
points[bit] = true;
|
||||
cut_genes--;
|
||||
}
|
||||
unsigned bit = eo::rng.random(max_genes);
|
||||
if (points[bit])
|
||||
continue;
|
||||
else
|
||||
{
|
||||
points[bit] = true;
|
||||
cut_genes--;
|
||||
}
|
||||
} while (cut_genes);
|
||||
|
||||
// swaps genes
|
||||
for (unsigned i = 0; i < points.size(); i++)
|
||||
if (points[i])
|
||||
std::swap_ranges(chrom1.begin() + i * gene_size,
|
||||
chrom1.begin() + i * gene_size + gene_size,
|
||||
chrom2.begin() + i * gene_size);
|
||||
if (points[i])
|
||||
std::swap_ranges(chrom1.begin() + i * gene_size,
|
||||
chrom1.begin() + i * gene_size + gene_size,
|
||||
chrom2.begin() + i * gene_size);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -442,4 +442,3 @@ template<class Chrom> class eoBitGxOver: public eoQuadOp<Chrom>
|
|||
//-----------------------------------------------------------------------------
|
||||
//@}
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// eoOpFactory.h
|
||||
// (c) GeNeura Team, 1998
|
||||
/*
|
||||
/*
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
|
|
@ -39,135 +39,134 @@ that are created here
|
|||
@ingroup Variators
|
||||
*/
|
||||
template< class EOT>
|
||||
class eoBitOpFactory: public eoFactory<EOT>
|
||||
class eoBitOpFactory: public eoFactory<EOT>
|
||||
{
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/// @name ctors and dtors
|
||||
//{@
|
||||
/// constructor
|
||||
eoBitOpFactory( ) {};
|
||||
|
||||
/// destructor
|
||||
virtual ~eoBitOpFactory() {};
|
||||
//@}
|
||||
|
||||
/** Another factory method: creates an object from an std::istream, reading from
|
||||
it whatever is needed to create the object. Usually, the format for the std::istream will be\\
|
||||
objectType parameter1 parameter2 ... parametern\\
|
||||
If there are problems, an std::exception is raised; it should be caught at the
|
||||
upper level, because it might be something for that level\\
|
||||
At the same time, it catches std::exceptions thrown at a lower level, which will
|
||||
indicate that whatever is in the stream is for this method to process
|
||||
@param _is an stream from where a single line will be read
|
||||
@throw runtime_std::exception if the object type is not known
|
||||
*/
|
||||
virtual eoOp<EOT>* make(std::istream& _is)
|
||||
/// @name ctors and dtors
|
||||
//{@
|
||||
/// constructor
|
||||
eoBitOpFactory( ) {};
|
||||
|
||||
/// destructor
|
||||
virtual ~eoBitOpFactory() {};
|
||||
//@}
|
||||
|
||||
/** Another factory method: creates an object from an std::istream, reading from
|
||||
it whatever is needed to create the object. Usually, the format for the std::istream will be\\
|
||||
objectType parameter1 parameter2 ... parametern\\
|
||||
If there are problems, an std::exception is raised; it should be caught at the
|
||||
upper level, because it might be something for that level\\
|
||||
At the same time, it catches std::exceptions thrown at a lower level, which will
|
||||
indicate that whatever is in the stream is for this method to process
|
||||
@param _is an stream from where a single line will be read
|
||||
@throw runtime_std::exception if the object type is not known
|
||||
*/
|
||||
virtual eoOp<EOT>* make(std::istream& _is)
|
||||
{
|
||||
eoOp<EOT> * opPtr = NULL;
|
||||
try {
|
||||
opPtr = eoFactory<EOT>::make( _is );
|
||||
} catch ( const std::string& objectTypeStr ) {
|
||||
if ( objectTypeStr == "eoBinBitFlip" ) {
|
||||
opPtr = new eoOneBitFlip<EOT>( );
|
||||
}
|
||||
// handles old operator names as well as new ones
|
||||
if ( objectTypeStr == "eoOneBitFlip" ) {
|
||||
opPtr = new eoOneBitFlip<EOT>( );
|
||||
}
|
||||
eoOp<EOT> * opPtr = NULL;
|
||||
try {
|
||||
opPtr = eoFactory<EOT>::make( _is );
|
||||
} catch ( const std::string& objectTypeStr ) {
|
||||
if ( objectTypeStr == "eoBinBitFlip" ) {
|
||||
opPtr = new eoOneBitFlip<EOT>( );
|
||||
}
|
||||
// handles old operator names as well as new ones
|
||||
if ( objectTypeStr == "eoOneBitFlip" ) {
|
||||
opPtr = new eoOneBitFlip<EOT>( );
|
||||
}
|
||||
|
||||
// Standard BitFilp Mutation
|
||||
if ( objectTypeStr == "eoBinMutation" ) {
|
||||
float rate;
|
||||
_is >> rate;
|
||||
opPtr = new eoBitMutation<EOT>( rate );
|
||||
}
|
||||
if ( objectTypeStr == "eoBitMutation" ) {
|
||||
float rate;
|
||||
_is >> rate;
|
||||
opPtr = new eoBitMutation<EOT>( rate );
|
||||
}
|
||||
// Standard BitFilp Mutation
|
||||
if ( objectTypeStr == "eoBinMutation" ) {
|
||||
float rate;
|
||||
_is >> rate;
|
||||
opPtr = new eoBitMutation<EOT>( rate );
|
||||
}
|
||||
if ( objectTypeStr == "eoBitMutation" ) {
|
||||
float rate;
|
||||
_is >> rate;
|
||||
opPtr = new eoBitMutation<EOT>( rate );
|
||||
}
|
||||
|
||||
// Bit inversion
|
||||
if ( objectTypeStr == "eoBinInversion" ) {
|
||||
opPtr = new eoBitInversion<EOT>( );
|
||||
}
|
||||
if ( objectTypeStr == "eoBitInversion" ) {
|
||||
opPtr = new eoBitInversion<EOT>( );
|
||||
}
|
||||
// Bit inversion
|
||||
if ( objectTypeStr == "eoBinInversion" ) {
|
||||
opPtr = new eoBitInversion<EOT>( );
|
||||
}
|
||||
if ( objectTypeStr == "eoBitInversion" ) {
|
||||
opPtr = new eoBitInversion<EOT>( );
|
||||
}
|
||||
|
||||
// Next binary value
|
||||
if ( objectTypeStr == "eoBinNext" ) {
|
||||
opPtr = new eoBitNext<EOT>( );
|
||||
}
|
||||
if ( objectTypeStr == "eoBitNext" ) {
|
||||
opPtr = new eoBitNext<EOT>( );
|
||||
}
|
||||
// Next binary value
|
||||
if ( objectTypeStr == "eoBinNext" ) {
|
||||
opPtr = new eoBitNext<EOT>( );
|
||||
}
|
||||
if ( objectTypeStr == "eoBitNext" ) {
|
||||
opPtr = new eoBitNext<EOT>( );
|
||||
}
|
||||
|
||||
// Previous binary value
|
||||
if ( objectTypeStr == "eoBinPrev" ) {
|
||||
opPtr = new eoBitPrev<EOT>( );
|
||||
}
|
||||
if ( objectTypeStr == "eoBitPrev" ) {
|
||||
opPtr = new eoBitPrev<EOT>( );
|
||||
}
|
||||
// Previous binary value
|
||||
if ( objectTypeStr == "eoBinPrev" ) {
|
||||
opPtr = new eoBitPrev<EOT>( );
|
||||
}
|
||||
if ( objectTypeStr == "eoBitPrev" ) {
|
||||
opPtr = new eoBitPrev<EOT>( );
|
||||
}
|
||||
|
||||
// 1 point Xover
|
||||
if ( objectTypeStr == "eoBinCrossover" ) {
|
||||
opPtr = new eo1PtBitXover<EOT>( );
|
||||
}
|
||||
if ( objectTypeStr == "eo1PtBitXover" ) {
|
||||
opPtr = new eo1PtBitXover<EOT>( );
|
||||
}
|
||||
// 1 point Xover
|
||||
if ( objectTypeStr == "eoBinCrossover" ) {
|
||||
opPtr = new eo1PtBitXover<EOT>( );
|
||||
}
|
||||
if ( objectTypeStr == "eo1PtBitXover" ) {
|
||||
opPtr = new eo1PtBitXover<EOT>( );
|
||||
}
|
||||
|
||||
// Npts Xover
|
||||
if ( objectTypeStr == "eoBinNxOver" ) {
|
||||
unsigned nPoints;
|
||||
_is >> nPoints;
|
||||
opPtr = new eoNPtsBitXover<EOT>( nPoints );
|
||||
}
|
||||
if ( objectTypeStr == "eoNPtsBitXover" ) {
|
||||
unsigned nPoints;
|
||||
_is >> nPoints;
|
||||
opPtr = new eoNPtsBitXover<EOT>( nPoints );
|
||||
}
|
||||
// Npts Xover
|
||||
if ( objectTypeStr == "eoBinNxOver" ) {
|
||||
unsigned nPoints;
|
||||
_is >> nPoints;
|
||||
opPtr = new eoNPtsBitXover<EOT>( nPoints );
|
||||
}
|
||||
if ( objectTypeStr == "eoNPtsBitXover" ) {
|
||||
unsigned nPoints;
|
||||
_is >> nPoints;
|
||||
opPtr = new eoNPtsBitXover<EOT>( nPoints );
|
||||
}
|
||||
|
||||
// Gene Xover (obsolete)
|
||||
if ( objectTypeStr == "eoBinGxOver" ) {
|
||||
unsigned geneSize, nPoints;
|
||||
_is >> geneSize >> nPoints;
|
||||
opPtr = new eoBitGxOver<EOT>( geneSize, nPoints );
|
||||
}
|
||||
if ( objectTypeStr == "eoBitGxOver" ) {
|
||||
unsigned geneSize, nPoints;
|
||||
_is >> geneSize >> nPoints;
|
||||
opPtr = new eoBitGxOver<EOT>( geneSize, nPoints );
|
||||
}
|
||||
// Gene Xover (obsolete)
|
||||
if ( objectTypeStr == "eoBinGxOver" ) {
|
||||
unsigned geneSize, nPoints;
|
||||
_is >> geneSize >> nPoints;
|
||||
opPtr = new eoBitGxOver<EOT>( geneSize, nPoints );
|
||||
}
|
||||
if ( objectTypeStr == "eoBitGxOver" ) {
|
||||
unsigned geneSize, nPoints;
|
||||
_is >> geneSize >> nPoints;
|
||||
opPtr = new eoBitGxOver<EOT>( geneSize, nPoints );
|
||||
}
|
||||
|
||||
// Uniform Xover
|
||||
if ( objectTypeStr == "eoBinUxOver" ) {
|
||||
float rate;
|
||||
_is >> rate;
|
||||
opPtr = new eoUBitXover<EOT>( rate );
|
||||
}
|
||||
if ( objectTypeStr == "eoUBitXover" ) {
|
||||
float rate;
|
||||
_is >> rate;
|
||||
opPtr = new eoUBitXover<EOT>( rate );
|
||||
}
|
||||
// Uniform Xover
|
||||
if ( objectTypeStr == "eoBinUxOver" ) {
|
||||
float rate;
|
||||
_is >> rate;
|
||||
opPtr = new eoUBitXover<EOT>( rate );
|
||||
}
|
||||
if ( objectTypeStr == "eoUBitXover" ) {
|
||||
float rate;
|
||||
_is >> rate;
|
||||
opPtr = new eoUBitXover<EOT>( rate );
|
||||
}
|
||||
|
||||
// nothing read!
|
||||
if ( !opPtr ) { // to be caught by the upper level
|
||||
throw objectTypeStr;
|
||||
}
|
||||
}
|
||||
return opPtr;
|
||||
};
|
||||
// nothing read!
|
||||
if ( !opPtr ) { // to be caught by the upper level
|
||||
throw objectTypeStr;
|
||||
}
|
||||
}
|
||||
return opPtr;
|
||||
};
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// eoBoolFlip.h
|
||||
// (c) Marc Schoenauer, 2003
|
||||
/*
|
||||
/*
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
|
|
@ -33,7 +33,7 @@
|
|||
@ingroup Variators
|
||||
*/
|
||||
class eoBoolFlip : public eoMonOp<bool> {
|
||||
public:
|
||||
public:
|
||||
/** simply flips the boolean argument */
|
||||
bool operator()(bool & _b)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -49,8 +49,8 @@ public:
|
|||
* using the default values is equivalent to using eoPBILOrg
|
||||
*/
|
||||
eoPBILAdditive(double _LRBest, unsigned _nbBest = 1,
|
||||
double _tolerance=0.0,
|
||||
double _LRWorst = 0.0, unsigned _nbWorst = 0 ) :
|
||||
double _tolerance=0.0,
|
||||
double _LRWorst = 0.0, unsigned _nbWorst = 0 ) :
|
||||
maxBound(1.0-_tolerance), minBound(_tolerance),
|
||||
LR(0.0), nbBest(_nbBest), nbWorst(_nbWorst)
|
||||
{
|
||||
|
|
@ -59,18 +59,18 @@ public:
|
|||
|
||||
if (_nbBest)
|
||||
{
|
||||
lrb = _LRBest/_nbBest;
|
||||
LR += _LRBest;
|
||||
lrb = _LRBest/_nbBest;
|
||||
LR += _LRBest;
|
||||
}
|
||||
else
|
||||
lrb=0.0; // just in case
|
||||
lrb=0.0; // just in case
|
||||
if (_nbWorst)
|
||||
{
|
||||
lrw = _LRWorst/_nbWorst;
|
||||
LR += _LRWorst;
|
||||
lrw = _LRWorst/_nbWorst;
|
||||
LR += _LRWorst;
|
||||
}
|
||||
else
|
||||
lrw=0.0; // just in case
|
||||
lrw=0.0; // just in case
|
||||
}
|
||||
|
||||
/** Update the distribution from the current population */
|
||||
|
|
@ -82,29 +82,29 @@ public:
|
|||
|
||||
unsigned i, popSize=_pop.size();
|
||||
std::vector<const EOT*> result;
|
||||
_pop.sort(result); // is it necessary to sort the whole population?
|
||||
// but I'm soooooooo lazy !!!
|
||||
_pop.sort(result); // is it necessary to sort the whole population?
|
||||
// but I'm soooooooo lazy !!!
|
||||
|
||||
for (unsigned g=0; g<distrib.size(); g++)
|
||||
{
|
||||
p[g] *= (1-LR); // relaxation
|
||||
if (nbBest) // update from some of the best
|
||||
for (i=0; i<nbBest; i++)
|
||||
{
|
||||
const EOT & best = (*result[i]);
|
||||
if ( best[g] ) // if 1, increase proba
|
||||
p[g] += lrb;
|
||||
}
|
||||
if (nbWorst)
|
||||
for (i=popSize-1; i>=popSize-nbWorst; i--)
|
||||
{
|
||||
const EOT & best = (*result[i]);
|
||||
if ( !best[g] ) // if 0, increase proba
|
||||
p[g] += lrw;
|
||||
}
|
||||
// stay in [0,1] (possibly strictly due to tolerance)
|
||||
p[g] = std::min(maxBound, p[g]);
|
||||
p[g] = std::max(minBound, p[g]);
|
||||
p[g] *= (1-LR); // relaxation
|
||||
if (nbBest) // update from some of the best
|
||||
for (i=0; i<nbBest; i++)
|
||||
{
|
||||
const EOT & best = (*result[i]);
|
||||
if ( best[g] ) // if 1, increase proba
|
||||
p[g] += lrb;
|
||||
}
|
||||
if (nbWorst)
|
||||
for (i=popSize-1; i>=popSize-nbWorst; i--)
|
||||
{
|
||||
const EOT & best = (*result[i]);
|
||||
if ( !best[g] ) // if 0, increase proba
|
||||
p[g] += lrw;
|
||||
}
|
||||
// stay in [0,1] (possibly strictly due to tolerance)
|
||||
p[g] = std::min(maxBound, p[g]);
|
||||
p[g] = std::max(minBound, p[g]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,26 +28,26 @@
|
|||
#include <eoDistribution.h>
|
||||
|
||||
/**
|
||||
* Distribution Class for PBIL algorithm
|
||||
* Distribution Class for PBIL algorithm
|
||||
* (Population-Based Incremental Learning, Baluja and Caruana 96)
|
||||
*
|
||||
* It encodes a univariate distribution on the space of bitstrings,
|
||||
* i.e. one probability for each bit to be one
|
||||
*
|
||||
* It is an eoValueParam<std::vector<double> > :
|
||||
* It is an eoValueParam<std::vector<double> > :
|
||||
* the std::vector<double> stores the probabilities that each bit is 1
|
||||
*
|
||||
* It is still pure virtual, as the update method needs to be specified
|
||||
*/
|
||||
|
||||
template <class EOT>
|
||||
class eoPBILDistrib : public eoDistribution<EOT>,
|
||||
public eoValueParam<std::vector<double> >
|
||||
class eoPBILDistrib : public eoDistribution<EOT>,
|
||||
public eoValueParam<std::vector<double> >
|
||||
{
|
||||
public:
|
||||
/** Ctor with size of genomes, and update parameters */
|
||||
eoPBILDistrib(unsigned _genomeSize) :
|
||||
eoDistribution<EOT>(),
|
||||
eoDistribution<EOT>(),
|
||||
eoValueParam<std::vector<double> >(std::vector<double>(_genomeSize, 0.5), "Distribution"),
|
||||
genomeSize(_genomeSize)
|
||||
{}
|
||||
|
|
@ -55,10 +55,10 @@ public:
|
|||
/** the randomizer of indis */
|
||||
virtual void operator()(EOT & _eo)
|
||||
{
|
||||
_eo.resize(genomeSize); // just in case
|
||||
_eo.resize(genomeSize); // just in case
|
||||
for (unsigned i=0; i<genomeSize; i++)
|
||||
_eo[i] = eo::rng.flip(value()[i]);
|
||||
_eo.invalidate(); // DO NOT FORGET!!!
|
||||
_eo.invalidate(); // DO NOT FORGET!!!
|
||||
}
|
||||
|
||||
/** Accessor to the genome size */
|
||||
|
|
@ -70,22 +70,22 @@ public:
|
|||
os << value().size() << ' ';
|
||||
for (unsigned i=0; i<value().size(); i++)
|
||||
os << value()[i] << ' ';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** reading...*/
|
||||
virtual void readFrom(std::istream& is)
|
||||
{
|
||||
unsigned sz;
|
||||
is >> sz;
|
||||
|
||||
|
||||
value().resize(sz);
|
||||
unsigned i;
|
||||
|
||||
|
||||
for (i = 0; i < sz; ++i)
|
||||
{
|
||||
double atom;
|
||||
is >> atom;
|
||||
value()[i] = atom;
|
||||
double atom;
|
||||
is >> atom;
|
||||
value()[i] = atom;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -58,15 +58,15 @@ public:
|
|||
|
||||
for (unsigned g=0; g<distrib.size(); g++)
|
||||
{
|
||||
// double & r = value()[g];
|
||||
p[g] *= (1-LR);
|
||||
if ( best[g] )
|
||||
p[g] += LR;
|
||||
// else nothing
|
||||
// double & r = value()[g];
|
||||
p[g] *= (1-LR);
|
||||
if ( best[g] )
|
||||
p[g] += LR;
|
||||
// else nothing
|
||||
|
||||
// stay away from 0 and 1
|
||||
p[g] = std::min(maxBound, p[g]);
|
||||
p[g] = std::max(minBound, p[g]);
|
||||
// stay away from 0 and 1
|
||||
p[g] = std::min(maxBound, p[g]);
|
||||
p[g] = std::max(minBound, p[g]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
#ifndef _make_PBILdistrib_h
|
||||
#define _make_PBILdistrib_h
|
||||
|
||||
#include <ctime> // for time(0) for random seeding
|
||||
#include <ctime> // for time(0) for random seeding
|
||||
#include <ga/eoPBILOrg.h>
|
||||
#include <utils/eoRNG.h>
|
||||
#include <utils/eoParser.h>
|
||||
|
|
@ -51,21 +51,21 @@ eoPBILDistrib<EOT> & do_make_PBILdistrib(eoParser & _parser, eoState& _state, E
|
|||
// First the random seed
|
||||
eoValueParam<uint32_t>& seedParam = _parser.createParam(uint32_t(0), "seed", "Random number seed", 'S');
|
||||
if (seedParam.value() == 0)
|
||||
seedParam.value() = time(0);
|
||||
seedParam.value() = time(0);
|
||||
|
||||
// chromosome size:
|
||||
unsigned theSize;
|
||||
// but it might have been already read in the definition fo the performance
|
||||
eoParam* ptParam = _parser.getParamWithLongName(std::string("chromSize"));
|
||||
|
||||
if (!ptParam) // not already defined: read it here
|
||||
if (!ptParam) // not already defined: read it here
|
||||
{
|
||||
theSize = _parser.createParam(unsigned(10), "chromSize", "The length of the bitstrings", 'n',"Problem").value();
|
||||
theSize = _parser.createParam(unsigned(10), "chromSize", "The length of the bitstrings", 'n',"Problem").value();
|
||||
}
|
||||
else // it was read before, get its value
|
||||
else // it was read before, get its value
|
||||
{
|
||||
eoValueParam<unsigned>* ptChromSize = dynamic_cast<eoValueParam<unsigned>*>(ptParam);
|
||||
theSize = ptChromSize->value();
|
||||
eoValueParam<unsigned>* ptChromSize = dynamic_cast<eoValueParam<unsigned>*>(ptParam);
|
||||
theSize = ptChromSize->value();
|
||||
}
|
||||
|
||||
eoPBILDistrib<EOT> * ptDistrib = new eoPBILDistrib<EOT>(theSize);
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// make_PBILupdate.h
|
||||
// (c) Marc Schoenauer, Maarten Keijzer, 2001
|
||||
/*
|
||||
/*
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
|
|
@ -47,7 +47,7 @@
|
|||
template <class EOT>
|
||||
eoDistribUpdater<EOT> & do_make_PBILupdate(eoParser & _parser, eoState& _state, EOT)
|
||||
{
|
||||
// ast the moment, a single update rule is available
|
||||
// ast the moment, a single update rule is available
|
||||
// but at some point we'll have to choose among different rules
|
||||
|
||||
std::string UType = _parser.createParam(std::string("PBIL"), "updateRule", "Type of update rule (only PBIL additive at the moment)", 'U', "Algorithm").value();
|
||||
|
|
@ -59,7 +59,7 @@ eoDistribUpdater<EOT> & do_make_PBILupdate(eoParser & _parser, eoState& _state,
|
|||
double tolerance = _parser.createParam(0.0, "tolerance", "Keeping away from 0 and 1", 't', "Algorithm").value();
|
||||
|
||||
// a pointer to choose among several possible types
|
||||
eoDistribUpdater<EOT> * ptUpdate;
|
||||
eoDistribUpdater<EOT> * ptUpdate;
|
||||
|
||||
if (UType == std::string("PBIL"))
|
||||
{
|
||||
|
|
@ -72,7 +72,7 @@ eoDistribUpdater<EOT> & do_make_PBILupdate(eoParser & _parser, eoState& _state,
|
|||
throw std::runtime_error("Only PBIL additive update rule available at the moment");
|
||||
|
||||
// done: don't forget to store the allocated pointers
|
||||
_state.storeFunctor(ptUpdate);
|
||||
_state.storeFunctor(ptUpdate);
|
||||
return *ptUpdate;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// make_algo_scalar_ga.cpp
|
||||
// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2001
|
||||
/*
|
||||
/*
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
|
|
@ -27,7 +27,7 @@
|
|||
#ifdef _MSC_VER
|
||||
// to avoid long name warnings
|
||||
#pragma warning(disable:4786)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/** This file contains all ***INSTANCIATED DEFINITIONS*** of pop. init.
|
||||
* of the library for ***BISTRING*** evolution inside EO.
|
||||
|
|
@ -35,11 +35,11 @@
|
|||
* Compiling this file allows one to generate part of the library (i.e. object
|
||||
* files that you just need to link with your own main and fitness code).
|
||||
*
|
||||
* The corresponding ***INSTANCIATED DECLARATIONS*** are contained
|
||||
* The corresponding ***INSTANCIATED DECLARATIONS*** are contained
|
||||
* in src/ga/ga.h
|
||||
* while the TEMPLATIZED code is define in make_algo_scalar.h in the src/do dir
|
||||
*
|
||||
* Unlike most EO .h files, it does not (and should not) contain any code,
|
||||
* Unlike most EO .h files, it does not (and should not) contain any code,
|
||||
* just declarations
|
||||
*/
|
||||
|
||||
|
|
@ -61,4 +61,3 @@ eoAlgo<eoBit<eoMinimizingFitness> >& make_algo_scalar(eoParser& _parser, eoStat
|
|||
{
|
||||
return do_make_algo_scalar(_parser, _state, _eval, _continue, _op, _dist);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// make_checkpoint_ga.cpp
|
||||
// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2001
|
||||
/*
|
||||
/*
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
|
|
@ -27,7 +27,7 @@
|
|||
#ifdef _MSC_VER
|
||||
// to avoid long name warnings
|
||||
#pragma warning(disable:4786)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/** This file contains all ***INSTANCIATED DEFINITIONS*** of operators
|
||||
* of the library for ***BISTRING*** evolution inside EO.
|
||||
|
|
@ -35,11 +35,11 @@
|
|||
* Compiling this file allows one to generate part of the library (i.e. object
|
||||
* files that you just need to link with your own main and fitness code).
|
||||
*
|
||||
* The corresponding ***INSTANCIATED DECLARATIONS*** are contained
|
||||
* The corresponding ***INSTANCIATED DECLARATIONS*** are contained
|
||||
* in make_checkpoint_ga.h
|
||||
* while the TEMPLATIZED code is define in make_checkpoint.h in the do dir
|
||||
*
|
||||
* Unlike most EO .h files, it does not (and should not) contain any code,
|
||||
* Unlike most EO .h files, it does not (and should not) contain any code,
|
||||
* just declarations
|
||||
*/
|
||||
|
||||
|
|
@ -48,7 +48,7 @@
|
|||
// the instanciating EOType
|
||||
#include <ga/eoBit.h>
|
||||
|
||||
/// The following function merely call the templatized do_* functions
|
||||
/// The following function merely call the templatized do_* functions
|
||||
|
||||
// checkpoint
|
||||
/////////////
|
||||
|
|
@ -56,9 +56,7 @@ eoCheckPoint<eoBit<double> >& make_checkpoint(eoParser& _parser, eoState& _state
|
|||
{
|
||||
return do_make_checkpoint(_parser, _state, _eval, _continue);
|
||||
}
|
||||
eoCheckPoint<eoBit<eoMinimizingFitness> >& make_checkpoint(eoParser& _parser, eoState& _state, eoEvalFuncCounter<eoBit<eoMinimizingFitness> >& _eval, eoContinue<eoBit<eoMinimizingFitness> >& _continue)
|
||||
eoCheckPoint<eoBit<eoMinimizingFitness> >& make_checkpoint(eoParser& _parser, eoState& _state, eoEvalFuncCounter<eoBit<eoMinimizingFitness> >& _eval, eoContinue<eoBit<eoMinimizingFitness> >& _continue)
|
||||
{
|
||||
return do_make_checkpoint(_parser, _state, _eval, _continue);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// make_continue_ga.cpp
|
||||
// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2001
|
||||
/*
|
||||
/*
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
|
|
@ -27,7 +27,7 @@
|
|||
#ifdef _MSC_VER
|
||||
// to avoid long name warnings
|
||||
#pragma warning(disable:4786)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/** This file contains all ***INSTANCIATED DEFINITIONS*** of operators
|
||||
* of the library for ***BISTRING*** evolution inside EO.
|
||||
|
|
@ -35,11 +35,11 @@
|
|||
* Compiling this file allows one to generate part of the library (i.e. object
|
||||
* files that you just need to link with your own main and fitness code).
|
||||
*
|
||||
* The corresponding ***INSTANCIATED DECLARATIONS*** are contained
|
||||
* The corresponding ***INSTANCIATED DECLARATIONS*** are contained
|
||||
* in ga.h
|
||||
* while the TEMPLATIZED code is define in make_contninue.h in the src/do dir
|
||||
*
|
||||
* Unlike most EO .h files, it does not (and should not) contain any code,
|
||||
* Unlike most EO .h files, it does not (and should not) contain any code,
|
||||
* just declarations
|
||||
*/
|
||||
|
||||
|
|
@ -60,5 +60,3 @@ eoContinue<eoBit<eoMinimizingFitness> >& make_continue(eoParser& _parser, eoStat
|
|||
{
|
||||
return do_make_continue(_parser, _state, _eval);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// ga.h
|
||||
// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2001
|
||||
/*
|
||||
/*
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
|
|
@ -24,14 +24,14 @@
|
|||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/** This file contains all ***INSTANCIATED*** declarations of all components
|
||||
/** This file contains all ***INSTANCIATED*** declarations of all components
|
||||
* of the library for ***BISTRING*** evolution inside EO.
|
||||
* It should be included in the file that calls any of the corresponding fns
|
||||
*
|
||||
* The corresponding ***INSTANCIATED*** definitions are contained in ga.cpp
|
||||
* while the TEMPLATIZED code is define in the different makeXXX.h files
|
||||
*
|
||||
* Unlike most EO .h files, it does not (and should not) contain any code,
|
||||
* Unlike most EO .h files, it does not (and should not) contain any code,
|
||||
* just declarations
|
||||
*/
|
||||
|
||||
|
|
@ -56,7 +56,7 @@
|
|||
* @{
|
||||
*/
|
||||
|
||||
// the genotypes
|
||||
// the genotypes
|
||||
eoInit<eoBit<double> > & make_genotype(eoParser& _parser, eoState& _state, eoBit<double> _eo);
|
||||
eoInit<eoBit<eoMinimizingFitness> > & make_genotype(eoParser& _parser, eoState& _state, eoBit<eoMinimizingFitness> _eo);
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// make_genotype_ga.cpp
|
||||
// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2001
|
||||
/*
|
||||
/*
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
|
|
@ -27,7 +27,7 @@
|
|||
#ifdef _MSC_VER
|
||||
// to avoid long name warnings
|
||||
#pragma warning(disable:4786)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/** This file contains all ***INSTANCIATED DEFINITIONS*** of operators
|
||||
* of the library for ***BISTRING*** evolution inside EO.
|
||||
|
|
@ -35,8 +35,8 @@
|
|||
* Compiling this file allows one to generate part of the library (i.e. object
|
||||
* files that you just need to link with your own main and fitness code).
|
||||
*
|
||||
* The corresponding ***INSTANCIATED DECLARATIONS*** are contained
|
||||
* in ga.h in src/ga dir
|
||||
* The corresponding ***INSTANCIATED DECLARATIONS*** are contained
|
||||
* in ga.h in src/ga dir
|
||||
* while the TEMPLATIZED code is define in make_genotype_ga.h
|
||||
*/
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// make_genotype.h
|
||||
// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2001
|
||||
/*
|
||||
/*
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
|
|
@ -36,24 +36,24 @@
|
|||
|
||||
/////////////////// the bitstring ////////////////
|
||||
/*
|
||||
* This fuction does the initialization of what's needed for a particular
|
||||
* This fuction does the initialization of what's needed for a particular
|
||||
* genotype (here, bitstrings).
|
||||
* It could be here tempatied only on the fitness, as it can be used to evolve
|
||||
* It could be here tempatied only on the fitness, as it can be used to evolve
|
||||
* bitstrings with any fitness.
|
||||
* However, for consistency reasons, it was finally chosen, as in
|
||||
* the rest of EO, to templatize by the full EOT, as this eventually
|
||||
* However, for consistency reasons, it was finally chosen, as in
|
||||
* the rest of EO, to templatize by the full EOT, as this eventually
|
||||
* allows to choose the type of genotype at run time (see in es dir)
|
||||
*
|
||||
* It is instanciated in ga/ga.cpp - and incorporated in the ga/libga.a
|
||||
*
|
||||
* It returns an eoInit<eoBit<FitT> > tha can later be used to initialize
|
||||
* It returns an eoInit<eoBit<FitT> > tha can later be used to initialize
|
||||
* the population (see make_pop.h).
|
||||
*
|
||||
* It uses a parser (to get user parameters) and a state (to store the memory)
|
||||
* the last argument is to disambiguate the call upon different instanciations.
|
||||
*
|
||||
* WARNING: that last argument will generally be the result of calling
|
||||
* the default ctor of EOT, resulting in most cases in an EOT
|
||||
* WARNING: that last argument will generally be the result of calling
|
||||
* the default ctor of EOT, resulting in most cases in an EOT
|
||||
* that is ***not properly initialized***
|
||||
*
|
||||
* @ingroup bitstring
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// make_op.h
|
||||
// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2001
|
||||
/*
|
||||
/*
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
|
|
@ -57,9 +57,9 @@
|
|||
* This is why the template is the complete EOT even though only the fitness
|
||||
* is actually templatized here: the following only applies to bitstrings
|
||||
*
|
||||
* Note : the last parameter is an eoInit: if some operator needs some info
|
||||
* Note : the last parameter is an eoInit: if some operator needs some info
|
||||
* about the gneotypes, the init has it all (e.g. bounds, ...)
|
||||
* Simply do
|
||||
* Simply do
|
||||
* EOT myEO;
|
||||
* _init(myEO);
|
||||
* and myEO is then an ACTUAL object
|
||||
|
|
@ -78,12 +78,12 @@ eoGenOp<EOT> & do_make_op(eoParser& _parser, eoState& _state, eoInit<EOT>& _init
|
|||
eoValueParam<std::string>& operatorParam = _parser.createParam(std::string("SGA"), "operator", "Description of the operator (SGA only now)", 'o', "Variation Operators");
|
||||
|
||||
if (operatorParam.value() != std::string("SGA"))
|
||||
throw std::runtime_error("Only SGA-like operator available right now\n");
|
||||
throw std::runtime_error("Only SGA-like operator available right now\n");
|
||||
|
||||
// now we read Pcross and Pmut,
|
||||
// now we read Pcross and Pmut,
|
||||
// the relative weights for all crossovers -> proportional choice
|
||||
// the relative weights for all mutations -> proportional choice
|
||||
// and create the eoGenOp that is exactly
|
||||
// and create the eoGenOp that is exactly
|
||||
// crossover with pcross + mutation with pmut
|
||||
|
||||
eoValueParam<double>& pCrossParam = _parser.createParam(0.6, "pCross", "Probability of Crossover", 'C', "Variation Operators" );
|
||||
|
|
@ -118,10 +118,10 @@ eoGenOp<EOT> & do_make_op(eoParser& _parser, eoState& _state, eoInit<EOT>& _init
|
|||
bool bCross = true;
|
||||
if (onePointRateParam.value()+twoPointsRateParam.value()+uRateParam.value()==0)
|
||||
{
|
||||
std::cerr << "Warning: no crossover" << std::endl;
|
||||
bCross = false;
|
||||
std::cerr << "Warning: no crossover" << std::endl;
|
||||
bCross = false;
|
||||
}
|
||||
|
||||
|
||||
// Create the CombinedQuadOp
|
||||
eoPropCombinedQuadOp<EOT> *ptCombinedQuadOp = NULL;
|
||||
eoQuadOp<EOT> *ptQuad = NULL;
|
||||
|
|
@ -129,12 +129,12 @@ eoGenOp<EOT> & do_make_op(eoParser& _parser, eoState& _state, eoInit<EOT>& _init
|
|||
ptQuad = new eo1PtBitXover<EOT>;
|
||||
_state.storeFunctor(ptQuad);
|
||||
ptCombinedQuadOp = new eoPropCombinedQuadOp<EOT>(*ptQuad, onePointRateParam.value());
|
||||
|
||||
|
||||
// uniform crossover for bitstring
|
||||
ptQuad = new eoUBitXover<EOT>;
|
||||
_state.storeFunctor(ptQuad);
|
||||
ptCombinedQuadOp->add(*ptQuad, uRateParam.value());
|
||||
|
||||
|
||||
// 2-points xover
|
||||
ptQuad = new eoNPtsBitXover<EOT>;
|
||||
_state.storeFunctor(ptQuad);
|
||||
|
|
@ -155,7 +155,7 @@ eoGenOp<EOT> & do_make_op(eoParser& _parser, eoState& _state, eoInit<EOT>& _init
|
|||
// minimum check
|
||||
if ( (bitFlipRateParam.value() < 0) )
|
||||
throw std::runtime_error("Invalid bitFlipRate");
|
||||
|
||||
|
||||
eoValueParam<double> & oneBitRateParam = _parser.createParam(0.01, "oneBitRate", "Relative rate for deterministic bit-flip mutation", 'd', "Variation Operators" );
|
||||
// minimum check
|
||||
if ( (oneBitRateParam.value() < 0) )
|
||||
|
|
@ -165,10 +165,10 @@ eoGenOp<EOT> & do_make_op(eoParser& _parser, eoState& _state, eoInit<EOT>& _init
|
|||
bool bMut = true;
|
||||
if (bitFlipRateParam.value()+oneBitRateParam.value()==0)
|
||||
{
|
||||
std::cerr << "Warning: no mutation" << std::endl;
|
||||
bMut = false;
|
||||
std::cerr << "Warning: no mutation" << std::endl;
|
||||
bMut = false;
|
||||
}
|
||||
|
||||
|
||||
// Create the CombinedMonOp
|
||||
eoPropCombinedMonOp<EOT> *ptCombinedMonOp = NULL;
|
||||
eoMonOp<EOT> *ptMon = NULL;
|
||||
|
|
@ -180,7 +180,7 @@ eoGenOp<EOT> & do_make_op(eoParser& _parser, eoState& _state, eoInit<EOT>& _init
|
|||
ptCombinedMonOp = new eoPropCombinedMonOp<EOT>(*ptMon, bitFlipRateParam.value());
|
||||
|
||||
// mutate exactly 1 bit per individual
|
||||
ptMon = new eoDetBitFlip<EOT>;
|
||||
ptMon = new eoDetBitFlip<EOT>;
|
||||
_state.storeFunctor(ptMon);
|
||||
ptCombinedMonOp->add(*ptMon, oneBitRateParam.value());
|
||||
|
||||
|
|
@ -190,7 +190,7 @@ eoGenOp<EOT> & do_make_op(eoParser& _parser, eoState& _state, eoInit<EOT>& _init
|
|||
// to simulate SGA (crossover with proba pCross + mutation with proba pMut
|
||||
// we must construct
|
||||
// a sequential combination of
|
||||
// with proba 1, a proportional combination of
|
||||
// with proba 1, a proportional combination of
|
||||
// a QuadCopy and our crossover
|
||||
// with proba pMut, our mutation
|
||||
|
||||
|
|
@ -205,7 +205,7 @@ eoGenOp<EOT> & do_make_op(eoParser& _parser, eoState& _state, eoInit<EOT>& _init
|
|||
// now the sequential
|
||||
eoSequentialOp<EOT> *op = new eoSequentialOp<EOT>;
|
||||
_state.storeFunctor(op);
|
||||
op->add(*cross, 1.0); // always crossover (but clone with prob 1-pCross
|
||||
op->add(*cross, 1.0); // always crossover (but clone with prob 1-pCross
|
||||
op->add(*ptCombinedMonOp, pMutParam.value());
|
||||
|
||||
// that's it!
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// make_op_ga.cpp
|
||||
// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2001
|
||||
/*
|
||||
/*
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
|
|
@ -27,7 +27,7 @@
|
|||
#ifdef _MSC_VER
|
||||
// to avoid long name warnings
|
||||
#pragma warning(disable:4786)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/** This file contains all ***INSTANCIATED DEFINITIONS*** of operators
|
||||
* of the library for ***BISTRING*** evolution inside EO.
|
||||
|
|
@ -35,11 +35,11 @@
|
|||
* Compiling this file allows one to generate part of the library (i.e. object
|
||||
* files that you just need to link with your own main and fitness code).
|
||||
*
|
||||
* The corresponding ***INSTANCIATED DECLARATIONS*** are contained
|
||||
* The corresponding ***INSTANCIATED DECLARATIONS*** are contained
|
||||
* in make_op_ga.h
|
||||
* while the TEMPLATIZED code is define in make_op.h in the ga dir
|
||||
*
|
||||
* Unlike most EO .h files, it does not (and should not) contain any code,
|
||||
* Unlike most EO .h files, it does not (and should not) contain any code,
|
||||
* just declarations
|
||||
*/
|
||||
|
||||
|
|
@ -59,4 +59,3 @@ eoGenOp<eoBit<eoMinimizingFitness> >& make_op(eoParser& _parser, eoState& _stat
|
|||
{
|
||||
return do_make_op(_parser, _state, _init);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// make_pop_ga.cpp
|
||||
// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2001
|
||||
/*
|
||||
/*
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
|
|
@ -27,7 +27,7 @@
|
|||
#ifdef _MSC_VER
|
||||
// to avoid long name warnings
|
||||
#pragma warning(disable:4786)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/** This file contains all ***INSTANCIATED DEFINITIONS*** of population init
|
||||
* of the library for ***BISTRING*** evolution inside EO.
|
||||
|
|
@ -35,7 +35,7 @@
|
|||
* Compiling this file allows one to generate part of the library (i.e. object
|
||||
* files that you just need to link with your own main and fitness code).
|
||||
*
|
||||
* The corresponding ***INSTANCIATED DECLARATIONS*** are contained
|
||||
* The corresponding ***INSTANCIATED DECLARATIONS*** are contained
|
||||
* in ga/make_ga.h
|
||||
* while the TEMPLATIZED code is define in make_pop.h in the src/do dir
|
||||
*
|
||||
|
|
@ -59,5 +59,3 @@ eoPop<eoBit<eoMinimizingFitness> >& make_pop(eoParser& _parser, eoState& _state
|
|||
{
|
||||
return do_make_pop(_parser, _state, _init);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// make_run_ga.cpp
|
||||
// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2001
|
||||
/*
|
||||
/*
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
|
|
@ -27,7 +27,7 @@
|
|||
#ifdef _MSC_VER
|
||||
// to avoid long name warnings
|
||||
#pragma warning(disable:4786)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/** This file contains all ***INSTANCIATED DEFINITIONS*** of operators
|
||||
* of the library for ***BISTRING*** evolution inside EO.
|
||||
|
|
@ -35,11 +35,11 @@
|
|||
* Compiling this file allows one to generate part of the library (i.e. object
|
||||
* files that you just need to link with your own main and fitness code).
|
||||
*
|
||||
* The corresponding ***INSTANCIATED DECLARATIONS*** are contained
|
||||
* The corresponding ***INSTANCIATED DECLARATIONS*** are contained
|
||||
* in make_run_ga.h
|
||||
* while the TEMPLATIZED code is define in make_run.h in the do dir
|
||||
*
|
||||
* Unlike most EO .h files, it does not (and should not) contain any code,
|
||||
* Unlike most EO .h files, it does not (and should not) contain any code,
|
||||
* just declarations
|
||||
*/
|
||||
|
||||
|
|
@ -63,4 +63,3 @@ void run_ea(eoAlgo<eoBit<eoMinimizingFitness> >& _ga, eoPop<eoBit<eoMinimizingFi
|
|||
{
|
||||
do_run(_ga, _pop);
|
||||
}
|
||||
|
||||
|
|
|
|||
Reference in a new issue