View | Details | Raw Unified
Collapse All | Expand All

(-) galib245-orig/ga/GARealGenome.C (-63 / +1 lines)
 Lines 77-145    Link Here 
// 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;
}
/* ----------------------------------------------------------------------------
/* ----------------------------------------------------------------------------
   Operator specializations
   Operator specializations
---------------------------------------------------------------------------- */
---------------------------------------------------------------------------- */
 Lines 314-316    Link Here 
template class GA1DArrayAlleleGenome<float>;
template class GA1DArrayAlleleGenome<float>;
#endif
#endif
#endif
#endif
(-) galib245-orig/ga/GARealGenome.h (+56 lines)
 Lines 20-25    Link Here 
typedef GA1DArrayAlleleGenome<float> GARealGenome;
typedef GA1DArrayAlleleGenome<float> GARealGenome;
// 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;
}
inline void GARealUniformInitializer(GAGenome& g){
inline void GARealUniformInitializer(GAGenome& g){
  GA1DArrayAlleleGenome<float>::UniformInitializer(g);
  GA1DArrayAlleleGenome<float>::UniformInitializer(g);
}
}