[galib] Initializing a GASimpleGA and allele genomes

Peter Jay Salzman p at dirac.org
Wed Nov 21 13:24:08 EST 2007

Hi all,

Two questions.

First, I'm a little confused about how to initialize an IC on the
population.  Consider this snippet:

   GABin2DecPhenotype map;
   for( int i=0; i<nVars; ++i )
      map.add(31, -4.0, 100.0);

   GABin2DecGenome genome(map, objective);

   GASimpleGA ga(genome);

There are nVars genes in the genome and popsize genomes in the population.
I'd like to initialize the population so that the 1st gene is 0^2, the 2nd
gene is 1^2, the 3rd gene is 2^2, and so on.

Is this the correct way to do it?

   int main( void )
      ga.initializer( myInitializer );

   void myInitializer( GAGenome &c )
      GASimpleGenome &genome = (GASimpleGenome &) c;

      for( int i = 0; i < genome.size(); ++i )
         genome.gene(i, i*i);

In other words, I've just set the IC for one genome - does the initializer
iterate this over all genomes in the population?

Secondly, I'm not sure I understand the concept of a genome with alleles.
>From the documentation, it sounds like an allele is another term for "gene".
Is the whole point of these genomes that we can do operations on one gene,
but not the other?  So, for example, if I had a GA1DArrayGenome<float>, and
I wanted mutation to occur only on the first gene but no others, I would use
a GA1DArrayAlleleGenome<float>?

Or do I have the concept completely wrong?

Many thanks!

More information about the galib mailing list