diff -Naur galib245-orig/ga/GARealGenome.C galib245/ga/GARealGenome.C --- galib245-orig/ga/GARealGenome.C 2004-05-23 16:07:40.400422232 +0200 +++ galib245/ga/GARealGenome.C 2004-05-23 16:12:00.173930656 +0200 @@ -77,69 +77,6 @@ -// 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::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::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 ---------------------------------------------------------------------------- */ @@ -314,3 +251,4 @@ template class GA1DArrayAlleleGenome; #endif #endif + diff -Naur galib245-orig/ga/GARealGenome.h galib245/ga/GARealGenome.h --- galib245-orig/ga/GARealGenome.h 2004-05-23 16:07:40.400422232 +0200 +++ galib245/ga/GARealGenome.h 2004-05-23 16:12:21.258725280 +0200 @@ -20,6 +20,63 @@ typedef GA1DArrayAlleleGenome 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::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::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){ GA1DArrayAlleleGenome::UniformInitializer(g); }