Skip to content

Initialisation Operators

th5th edited this page Jan 28, 2012 · 7 revisions

There are two types of initialisers provided with libcea. The first carries out random initialisation of a population, while the second initialises a population deterministically.

CeaOpInitRand

This class describes a random population initialiser. It requires a CeaRVar-derived object to provide random gene values as required.

class CeaOpInitRand : public CeaOperator
{
    public:
        // Constructors
        CeaOpInitRand ();
        CeaOpInitRand (CeaRVar * rv);
        
        // Setters
        void set_rv (CeaRVar * rv);

        // Application method override
        void apply_to (CeaPopulation pop);

     // ...
 };

This initialiser simply inserts a value generated by *rv into every gene in the population. The configuration of this class is therefore conducted solely through the random variable provided to it.

CeaOpInitDeterm

The second initialiser provided is deterministic. The class can initialise a population explicitly - by passing it a vector (with length equal to the number of of individuals) of vectors (with lengths equal to the number of genes in each individual). It can also initialise a population according to a linear equation, such that the ith individual's jth gene has value a*i + b*j+ c.

Future note: there is room here potentially to use an user-provided iterator to allow arbitrary gene values to be added to a population as and when, without prior creation and thus without memory use prior to population initialisation.

class CeaOpInitDeterm : public CeaOperator
{
    public:
        // Constructors - second one will be templated sometime...
        CeaOpInitDeterm ();
        CeaOpInitDeterm (vector< vector<int> > gene_data);
        CeaOpInitDeterm (float a, float b, float c);
        
        // After-the-fact setup [...]

        // Application method override
        void apply_to (CeaPopulation pop);

     // ...
 };

Clone this wiki locally