Definition of Genetic Operators

Bodsch, Norbert Norbert.Bodsch at volkswagen.de
Thu Aug 24 06:04:52 EDT 2000


Hi all,

I recently started using galib. My question is about the definition of the
Genetic operators.

On page 11 of the galib documentation I find:

   template<class T> int
   OnePointCrossover(const GAGenome& p1, const GAGenome& p1, GAGenome* c1,
GAGenome* c1) 
   {
      GAListGenome<T> &mom = (GAListGenome<T> &) p1;
      ...

What's the reason for this cast? My interpretation is: The parameter list
contains two references to objects of class GAGenome which are the parents.
These two references are then casted to GAListGenome<T> &. But in my
opinion, this makes sense only if the casting is possible at all. So the
caller has to hand over references to objects of class GAListGenome<T> or
subclasses of it. So why is this global function not defined this way?:

   template<class T> int
   OnePointCrossover(
      const GAListGenome<T>& p1, const GAListGenome<T>& p1, 
      GAListGenome<T>* c1, GAListGenome<T>* c1) 
   {
      ...

Regards
Norbert Bodsch





More information about the galib mailing list