EvolvingObjects
|
A helper class, to determine a number of individuals from another one Typically, is used in selection / replacement procedures, e.g. More...
#include <eoHowMany.h>
Public Member Functions | |
eoHowMany (double _rate=0.0, bool _interpret_as_rate=true) | |
Original Ctor from direct rate + bool. | |
eoHowMany (int _count) | |
Ctor from an int - both from int and unsigned int are needed to avoid ambiguity with the Ctor from a double. | |
eoHowMany (unsigned int _count) | |
Ctor from an unsigned int - both from int and unsigned int are needed to avoid ambiguity with the Ctor from a double. | |
virtual | ~eoHowMany () |
Virtual dtor. They are needed in virtual class hierarchies. | |
unsigned int | operator() (unsigned int _size) |
Does what it was designed for. | |
virtual void | printOn (std::ostream &_os) const |
Write object. | |
virtual void | readFrom (std::istream &_is) |
Read object. | |
void | readFrom (std::string _value) |
eoHowMany | operator- () |
The unary - operator: reverses the computation. | |
Private Attributes | |
double | rate |
int | count |
A helper class, to determine a number of individuals from another one Typically, is used in selection / replacement procedures, e.g.
the number of offspring from the number of parents, or the number of survivors for an eoReduce functor, ...
Such construct is very useful because in some cases you might not know the population size that will enter the replacement. For instance, you cannot simply have a pre-computed (double) rate of 1/popSize if you want to select or kill just 1 guy. Using an eoHowMany allows one to modify the population size without touching anything else.
There are 4 possible way to compute the return value from the argument:
It has 2 private members, a double and an integer to cover all cases
Example use: in eoGeneralBreeder.h Example reading from parser: in do/make_algo_scalar.h line 141
MS 10/04/2002: Added the possibility to have a negative number - when treated as a number: returns then (size - count) 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>
Definition at line 76 of file eoHowMany.h.
eoHowMany::eoHowMany | ( | double | _rate = 0.0 , |
bool | _interpret_as_rate = true |
||
) | [inline] |
Original Ctor from direct rate + bool.
_rate | the rate, OR the integer to store, depending on 2nd arg. |
_interpret_as_rate | to tell whether the rate actually is a rate |
Definition at line 83 of file eoHowMany.h.
unsigned int eoHowMany::operator() | ( | unsigned int | _size | ) | [inline] |
Does what it was designed for.
Definition at line 121 of file eoHowMany.h.
virtual void eoHowMany::printOn | ( | std::ostream & | _os | ) | const [inline, virtual] |
Write object.
It's called printOn since it prints the object on a stream.
_os | A std::ostream. |
Implements eoPrintable.
Definition at line 143 of file eoHowMany.h.
virtual void eoHowMany::readFrom | ( | std::istream & | _is | ) | [inline, virtual] |
Read object.
_is | A std::istream. |
runtime_std::exception | If a valid object can't be read. |
Implements eoPersistent.
Definition at line 153 of file eoHowMany.h.