Added the negative rate (-> 1-rate) and the unary operator- (useful

in eoG3Replacement)
This commit is contained in:
evomarc 2002-06-21 13:30:17 +00:00
commit 427ed0f5bf

View file

@ -37,14 +37,16 @@
* if you want to select or kill just 1 guy. Using an eoHowMany * if you want to select or kill just 1 guy. Using an eoHowMany
* allows one to modify the population size without touching anything else. * allows one to modify the population size without touching anything else.
* *
* There are 3 possible way to compute the return value from the argument: * There are 4 possible way to compute the return value from the argument:
* - a rate -> return rate*popSize
* - an absolute POSITIVE integer --> return rate (regardless of popsize) * - an absolute POSITIVE integer --> return rate (regardless of popsize)
* - a POSITIVE rate -> return rate*popSize
* - an absolute NEGATIVE integer --> return popsize-rate * - an absolute NEGATIVE integer --> return popsize-rate
* Note that a negative rate is unnecessary because a rate is relative anyway. * - a NEGATIVE rate -> return (1-rate)*popSize
* Note that a negative rate should be unnecessary because a rate is
* relative, but it is there for consistency reasons - and because it
* is needed in <a href="classeo_g3_replacement_h-source.html">eoG3Replacement</a>
* *
* It has 2 private members, a double for case 1, * It has 2 private members, a double and an integer to cover all cases
* and an integer for cases 2 and 3 above
* *
* Example use: in <a href="class_eogeneralbreeder.html">eoGeneralBreeder.h</a> * Example use: in <a href="class_eogeneralbreeder.html">eoGeneralBreeder.h</a>
* Example reading from parser: in * Example reading from parser: in
@ -55,6 +57,10 @@
* when treated as a number: returns then (size - combien) * when treated as a number: returns then (size - combien)
* Should not modify anything when a positive number is passed in the ctor * Should not modify anything when a positive number is passed in the ctor
* *
* MS 20/06/2002:
* Added the negative rate and the operator-() (for
* eoG3Repalcement)
*
* It is an eoPersistent because we need to be able to use eoParamValue<eoHowMany> * It is an eoPersistent because we need to be able to use eoParamValue<eoHowMany>
*/ */
@ -71,14 +77,16 @@ public:
if (_interpret_as_rate) if (_interpret_as_rate)
{ {
if (_rate<0) if (_rate<0)
throw std::logic_error("Negative rate in eoHowMany!"); rate = 1.0-rate;
if (rate > 1.0)
throw std::logic_error("rate>1 in eoHowMany!");
} }
else else
{ {
rate = 0.0; // just in case, but shoud be unused rate = 0.0; // just in case, but shoud be unused
combien = int(_rate); // negative values are allowed here combien = int(_rate); // negative values are allowed here
if (combien != _rate) if (combien != _rate)
cout << "Warning: Number was rounded in eoHowMany"; cerr << "Warning: Number was rounded in eoHowMany";
} }
} }
@ -158,6 +166,16 @@ public:
throw runtime_error("Negative rate read in eoHowMany::readFrom"); throw runtime_error("Negative rate read in eoHowMany::readFrom");
} }
/** The unary - operator: reverses the computation */
eoHowMany operator-()
{
if (!combien) // only rate is used
rate = 1.0-rate;
else
combien = -combien;
return (*this);
}
private : private :
double rate; double rate;
int combien; int combien;