- added the #define for eo_verbose (true) and eo_no_verbose (false)

- added the eoNormMutation, simple normal mutation for simple real variables
Modified Files:
 	src/eo src/es/eoRealOp.h tutorial/Lesson2/FirstRealEA.cpp
 	tutorial/Lesson3/SecondBitEA.cpp
This commit is contained in:
evomarc 2000-12-04 14:53:59 +00:00
commit 4944881d7c
4 changed files with 57 additions and 6 deletions

View file

@ -28,6 +28,10 @@
#ifndef _eo_
#define _eo_
// some defines to make things easier to get at first sight
#define eo_verbose true
#define eo_no_verbose false
//-----------------------------------------------------------------------------
#include <utils/eoData.h>

View file

@ -61,14 +61,17 @@ template<class Chrom> class eoUniformMutation: public eoMonOp<Chrom>
*/
void operator()(Chrom& chrom)
{
chrom.invalidate();
bool hasChanged=false;
for (unsigned lieu=0; lieu<chrom.size(); lieu++)
{
if (rng.flip(p_change))
{
chrom[lieu] += 2*epsilon*rng.uniform()-epsilon;
hasChanged = true;
}
}
if (hasChanged)
chrom.invalidate();
}
private:
@ -117,6 +120,45 @@ private:
};
template<class Chrom> class eoNormalMutation: public eoMonOp<Chrom>
{
public:
/**
* (Default) Constructor.
* @param _epsilon the range for uniform nutation
* @param _p_change the probability to change a given coordinate
*/
eoNormalMutation(const double& _epsilon, const double& _p_change = 1.0):
epsilon(_epsilon), p_change(_p_change) {}
/// The class name.
string className() const { return "eoNormalMutation"; }
/**
* Do it!
* @param chrom The cromosome undergoing the mutation
*/
void operator()(Chrom& chrom)
{
bool hasChanged=false;
for (unsigned lieu=0; lieu<chrom.size(); lieu++)
{
if (rng.flip(p_change))
{
chrom[lieu] += epsilon*rng.normal();
hasChanged = true;
}
}
if (hasChanged)
chrom.invalidate();
}
private:
double epsilon;
double p_change;
};
// two arithmetical crossovers
/** eoSegmentCrossover --> uniform choice in segment