From e3834441fdd1e02a7f42f6a80e6fc0b654825d87 Mon Sep 17 00:00:00 2001 From: evomarc Date: Thu, 12 Apr 2001 05:29:34 +0000 Subject: [PATCH] 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 --- eo/src/ga/eoBitOp.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/eo/src/ga/eoBitOp.h b/eo/src/ga/eoBitOp.h index 61117a46..951c1c50 100644 --- a/eo/src/ga/eoBitOp.h +++ b/eo/src/ga/eoBitOp.h @@ -132,7 +132,8 @@ template class eoBitMutation: public eoMonOp * (Default) Constructor. * @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. virtual string className() const { return "eoBitMutation"; } @@ -143,9 +144,10 @@ template class eoBitMutation: public eoMonOp */ bool operator()(Chrom& chrom) { + double actualRate = (normalize ? rate/chrom.size() : rate); bool changed_something = false; for (unsigned i = 0; i < chrom.size(); i++) - if (eo::rng.flip(rate)) + if (eo::rng.flip(actualRate)) { chrom[i] = !chrom[i]; changed_something = true; @@ -156,6 +158,7 @@ template class eoBitMutation: public eoMonOp private: double rate; + bool normalize; // divide rate by chromSize };