Added a new boolean argument to the ctor of eoBitMutation:
you can now specify a rate-per-bit that will be normalized by the chromSize
This commit is contained in:
parent
78f6c6ef3c
commit
e3834441fd
1 changed files with 5 additions and 2 deletions
|
|
@ -132,7 +132,8 @@ template<class Chrom> class eoBitMutation: public eoMonOp<Chrom>
|
||||||
* (Default) Constructor.
|
* (Default) Constructor.
|
||||||
* @param _rate Rate of mutation.
|
* @param _rate Rate of mutation.
|
||||||
*/
|
*/
|
||||||
eoBitMutation(const double& _rate = 0.01): rate(_rate) {}
|
eoBitMutation(const double& _rate = 0.01, bool _normalize=false):
|
||||||
|
rate(_rate), normalize(_normalize) {}
|
||||||
|
|
||||||
/// The class name.
|
/// The class name.
|
||||||
virtual string className() const { return "eoBitMutation"; }
|
virtual string className() const { return "eoBitMutation"; }
|
||||||
|
|
@ -143,9 +144,10 @@ template<class Chrom> class eoBitMutation: public eoMonOp<Chrom>
|
||||||
*/
|
*/
|
||||||
bool operator()(Chrom& chrom)
|
bool operator()(Chrom& chrom)
|
||||||
{
|
{
|
||||||
|
double actualRate = (normalize ? rate/chrom.size() : rate);
|
||||||
bool changed_something = false;
|
bool changed_something = false;
|
||||||
for (unsigned i = 0; i < chrom.size(); i++)
|
for (unsigned i = 0; i < chrom.size(); i++)
|
||||||
if (eo::rng.flip(rate))
|
if (eo::rng.flip(actualRate))
|
||||||
{
|
{
|
||||||
chrom[i] = !chrom[i];
|
chrom[i] = !chrom[i];
|
||||||
changed_something = true;
|
changed_something = true;
|
||||||
|
|
@ -156,6 +158,7 @@ template<class Chrom> class eoBitMutation: public eoMonOp<Chrom>
|
||||||
|
|
||||||
private:
|
private:
|
||||||
double rate;
|
double rate;
|
||||||
|
bool normalize; // divide rate by chromSize
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Reference in a new issue