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 _combien)
 Ctor from an int - both from int and unsigned int are needed to avoid ambiguity with the Ctor from a double.
 eoHowMany (unsigned int _combien)
 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
  • combien==0 : return rate*_size
  • else
    • combien>0 : return combien (regardless of _size)
    • combien<0 : return _size-|combien|.

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 combien


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:

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 - combien) 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 69 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:
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 76 of file eoHowMany.h.


Member Function Documentation

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:
_os A std::ostream.

Implements eoPrintable.

Definition at line 130 of file eoHowMany.h.

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

Read object.

Parameters:
_is A std::istream.
Exceptions:
runtime_std::exception If a valid object can't be read.

Implements eoPersistent.

Definition at line 140 of file eoHowMany.h.


The documentation for this class was generated from the following file:

Generated on Thu Jan 1 23:19:47 2009 for EvolvingObjects by  doxygen 1.5.5