EvolvingObjects
eoHowMany Class Reference

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>

Inheritance diagram for eoHowMany:
eoPersistent eoPrintable

List of all members.

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

Detailed Description

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:

  • an absolute POSITIVE integer --> return it (regardless of popsize)
  • a POSITIVE rate --> return rate*popSize
  • an absolute NEGATIVE integer --> return popsize-rate (if positive)
  • a NEGATIVE rate in [-1,0] --> store and use 1-|rate| (positive) Note that a negative rate should be have been necessary because a rate is relative, but it is there for consistency reasons - and because it is needed in eoG3Replacement

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>

Examples:
t-eoSharing.cpp.

Definition at line 76 of file eoHowMany.h.


Constructor & Destructor Documentation

eoHowMany::eoHowMany ( double  _rate = 0.0,
bool  _interpret_as_rate = true 
) [inline]

Original Ctor from direct rate + bool.

Parameters:
_ratethe rate, OR the integer to store, depending on 2nd arg.
_interpret_as_rateto tell whether the rate actually is a rate

Definition at line 83 of file eoHowMany.h.


Member Function Documentation

unsigned int eoHowMany::operator() ( unsigned int  _size) [inline]

Does what it was designed for.

  • count==0 : return rate*_size
  • else
    • count>0 : return count (regardless of _size)
    • count<0 : return _size-|count|

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.

Parameters:
_osA std::ostream.

Implements eoPrintable.

Definition at line 143 of file eoHowMany.h.

virtual void eoHowMany::readFrom ( std::istream &  _is) [inline, virtual]

Read object.

Parameters:
_isA std::istream.
Exceptions:
runtime_std::exceptionIf a valid object can't be read.

Implements eoPersistent.

Definition at line 153 of file eoHowMany.h.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Friends