[galib] g++ compilation problems

Bertrand Mesot bertrand.mesot at epfl.ch
Wed Dec 10 16:51:17 EST 2003


Hello,

This message should reply to: Etienne Jodoin, Kofi Deh and Martin Schulze.

In GARealGenome.h, some inline functions use methods from 
GA1DArrayAlleleGenome<float>. This is a problem because 
GA1DArrayAlleleGenome is instantiated with float and later two 
additional methods allele() and allele(unsigned int) are defined, in 
GARealGenome.C.

Actually all definitions must be done before instantiation, thus moving 
the definitions of

float GAAlleleSet<float>::allele() const

and

float GAAlleleSet<float>::allele(unsigned int i) const

before any of the inline function in GARealGenome.h should do the job.

Briefly, remove the following code from GARealGenome.C:
---------------------------------------------------------------------
// We must also specialize the allele set so that the alleles are handled
// properly.  Be sure to handle bounds correctly whether we are discretized
// or continuous.  Handle the case where someone sets stupid bounds that
// might cause an infinite loop for exclusive bounds.
float
GAAlleleSet<float>::allele() const {
  float value = 0.0;
  if(core->type == GAAllele::ENUMERATED)
    value = core->a[GARandomInt(0, core->sz-1)];
  else if(core->type == GAAllele::DISCRETIZED){
    float n = (core->a[1] - core->a[0]) / core->a[2];
    int m = (int)n;
    if(core->lowerb == GAAllele::EXCLUSIVE) m -= 1;
    if(core->upperb == GAAllele::EXCLUSIVE) m -= 1;
    value = core->a[0] + GARandomInt(0,(int)m) * core->a[2];
    if(core->lowerb == GAAllele::EXCLUSIVE) value += core->a[2];
  }
  else{
    if(core->a[0] == core->a[1] &&
       core->lowerb == GAAllele::EXCLUSIVE &&
       core->upperb == GAAllele::EXCLUSIVE) {
      value = core->a[0];
    }
    else {
      do {
    value = GARandomFloat(core->a[0], core->a[1]);
      } while ((core->lowerb == GAAllele::EXCLUSIVE && value == 
core->a[0]) ||
           (core->upperb == GAAllele::EXCLUSIVE && value == core->a[1]));
    }
  }
  return value;
}

// If someone asks for a discretized item that is beyond the bounds, 
give them
// one of the bounds.  If they ask for allele item when there is no
// discretization or enumeration, then error and return lower bound.
float
GAAlleleSet<float>::allele(unsigned int i) const {
  float value = 0.0;
  if(core->type == GAAllele::ENUMERATED)
    value = core->a[i % core->sz];
  else if(core->type == GAAllele::DISCRETIZED){
    float n = (core->a[1] - core->a[0])/core->a[2];
    unsigned int m = (unsigned int)n;            // what about bogus 
limits?
    if(core->lowerb == GAAllele::EXCLUSIVE) m -= 1;
    if(core->upperb == GAAllele::EXCLUSIVE) m -= 1;
    if(i > m) i = (int)m;
    value = core->a[0] + i*core->a[2];
    if(core->lowerb == GAAllele::EXCLUSIVE) value += core->a[2];
  }
  else{
    GAErr(GA_LOC, "GAAlleleSet", "allele", gaErrNoAlleleIndex);
    value = core->a[0];
  }
  return value;
}
---------------------------------------------------------------------
and place it just after:

typedef GA1DArrayAlleleGenome<float> GARealGenome;

in GARealGenome.h.



Bertrand



More information about the galib mailing list