<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2900.3314" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>Hi,</FONT></DIV>
<DIV><FONT face=Arial size=2>I'm a beginner with Galib and i try to solve a
simple problem before using Galib for more complex problems.</FONT></DIV>
<DIV><FONT face=Arial size=2>I have a genome which each gene takes different
<int> values (ArrayAlleleGenome) and I want Galib give one of the
solutions that verify :</FONT></DIV>
<DIV><FONT face=Arial size=2>Sum(gene(i))=31 and
product(gene(i))=26460.</FONT></DIV>
<DIV><FONT face=Arial size=2>When I launch this small program Galib give me 1 3
2 19 1 1 (with NoInitializer) or 1 1 1 1 1 1 (with
UniformInitializer)!</FONT></DIV>
<DIV><FONT face=Arial size=2>What's wrong?</FONT></DIV>
<DIV><FONT face=Arial size=2>Thanks for your help. Best regards</FONT></DIV>
<DIV><FONT face=Arial size=2>Francois</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>float objective(GAGenome &);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>int main(int argc, char *argv[])<BR>{<BR> int
i;<BR> GAAlleleSetArray<int> allelesp;<BR>
allelesp.add(1,10,1);<BR> allelesp.add(1,7,1);<BR>
allelesp.add(1,5,1);<BR> allelesp.add(1,20,1);<BR>
allelesp.add(1,3,1);<BR> allelesp.add(1,3,1);<BR>
GA1DArrayAlleleGenome<int> genomep(allelesp,objective);<BR> int
param[6]={1,3,2,19,1,1};
//initialziation of genome with determined
values<BR>
for(i=0;i<genomep.length();i++)<BR> genomep.gene(i,param[i]);<BR>
genomep.initializer(GAGenome::NoInitializer); //or
GA1DArrayAlleleGenome<int>::UniformInitializer<BR>
genomep.mutator(GA1DArrayAlleleGenome<int>::FlipMutator);<BR>
genomep.crossover(GA1DArrayGenome<int>::OnePointCrossover);<BR>
GASteadyStateGA ga(genomep);<BR> GASigmaTruncationScaling trunc;<BR>
ga.scaling(trunc);<BR> ga.set(gaNpopulationSize, 40);<BR>
ga.set(gaNpCrossover, 0.6); <BR> ga.set(gaNpMutation, 0.8);<BR>
ga.set(gaNnGenerations, 10000);<BR> ga.set(gaNpReplacement,
0.25);<BR>
ga.evolve(1);<BR> genomep=ga.statistics().bestIndividual();
//Print result<BR> for(i=0;
i<genomep.length(); i++)<BR> {<BR>
cout<<" ";<BR> cout <<
genomep.gene(i);<BR> }<BR> cout << "\n";<BR>
return 0;<BR>}</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>float objective(GAGenome & c)<BR>{<BR>
GA1DArrayAlleleGenome<int> & genome =
(GA1DArrayAlleleGenome<int> &)c;<BR> float
value=0.0,prof;<BR> int sum=0,prod=1,g;<BR> for(int
i=0;i<genome.length();i++)<BR> {<BR> g=genome.gene(i);<BR> sum+=genome.gene(i);<BR> prod*=genome.gene(i);<BR> }<BR> prof=prod/26460;<BR> if(prof>1)<BR> prof=1/prof;<BR> value=1/fabs(sum-31)+prof;
//value range from 0 to
2<BR> return(value);<BR>}</FONT></DIV></BODY></HTML>