Mutation, Crossover not working on GARealGenome
Alexander Borghgraef
ab at telin.rug.ac.be
Mon Apr 22 09:28:55 EDT 2002
On Thu, 18 Apr 2002, Naveeed Ahmad wrote:
> Here is the code
>
> GARealAlleleSet alleles(-10.0,10.0);
>
></snip>
I looked into the galib245 code, and I think I found the problem. The
constructor for GARealAlleleSet sets type of the alleleset to
GAAlleleSet::BOUNDED. Now, when the genome-constructor uses 'alleles',
it calls the default UniformInitializer in order to fill it's starting
population, and the function GA1DArrayAlleleGenome::UniformInitializer()
asks the function GAAlleleSet::allele() to return a random member of the
alleleset. Only if you watch the code for allele()
template <class T> T
GAAlleleSet<T>::allele() const {
if(core->type == GAAllele::ENUMERATED)
return core->a[GARandomInt(0, core->sz-1)];
else if(core->type == GAAllele::DISCRETIZED){
GAErr(GA_LOC, "GAAlleleSet", "allele(unsigned int)", gaErrOpUndef);
return core->a[0];
}
else{
GAErr(GA_LOC, "GAAlleleSet", "allele(unsigned int)", gaErrOpUndef);
return core->a[0];
}
}
it will give you your error message and return a[0], which I suspect
will contain -10 in the case of your code.
I guess this means galib doesn't allways do what it promises, and you'll
have to write some extensions to the code. Maybe the best thing would be
to derive a class from GAAlleleSet which contains an adapted allele()
member function, which does return a random float between the bounds set
in the constructor. Sorry I can't be of more help than that.
--
Alex Borghgraef
Vakgroep Telecommunicatie en Informatieverwerking Tel: +32-(0)9-264 34 16
Universiteit Gent Fax: +32-(0)9-264 42 95
St-Pietersnieuwstraat 41, B-9000 Gent, Belgium email: ab at telin.rug.ac.b
More information about the galib
mailing list