<!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 
&lt;int&gt; 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>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>float objective(GAGenome &amp;);</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>int main(int argc, char *argv[])<BR>{<BR>&nbsp; int 
i;<BR>&nbsp; GAAlleleSetArray&lt;int&gt; allelesp;<BR>&nbsp; 
allelesp.add(1,10,1);<BR>&nbsp; allelesp.add(1,7,1);<BR>&nbsp; 
allelesp.add(1,5,1);<BR>&nbsp; allelesp.add(1,20,1);<BR>&nbsp; 
allelesp.add(1,3,1);<BR>&nbsp; allelesp.add(1,3,1);<BR>&nbsp; 
GA1DArrayAlleleGenome&lt;int&gt; genomep(allelesp,objective);<BR>&nbsp; int 
param[6]={1,3,2,19,1,1}; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //initialziation of genome with determined 
values<BR>&nbsp; 
for(i=0;i&lt;genomep.length();i++)<BR>&nbsp;&nbsp;genomep.gene(i,param[i]);<BR>&nbsp; 
genomep.initializer(GAGenome::NoInitializer);&nbsp; //or 
GA1DArrayAlleleGenome&lt;int&gt;::UniformInitializer<BR>&nbsp; 
genomep.mutator(GA1DArrayAlleleGenome&lt;int&gt;::FlipMutator);<BR>&nbsp; 
genomep.crossover(GA1DArrayGenome&lt;int&gt;::OnePointCrossover);<BR>&nbsp; 
GASteadyStateGA ga(genomep);<BR>&nbsp; GASigmaTruncationScaling trunc;<BR>&nbsp; 
ga.scaling(trunc);<BR>&nbsp; ga.set(gaNpopulationSize, 40);<BR>&nbsp; 
ga.set(gaNpCrossover, 0.6); <BR>&nbsp; ga.set(gaNpMutation, 0.8);<BR>&nbsp; 
ga.set(gaNnGenerations, 10000);<BR>&nbsp; ga.set(gaNpReplacement, 
0.25);<BR>&nbsp; 
ga.evolve(1);<BR>&nbsp;genomep=ga.statistics().bestIndividual();&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //Print result<BR>&nbsp;for(i=0; 
i&lt;genomep.length(); i++)<BR>&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
cout&lt;&lt;"&nbsp; ";<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cout &lt;&lt; 
genomep.gene(i);<BR>&nbsp; }<BR>&nbsp;&nbsp;&nbsp; cout &lt;&lt; "\n";<BR>&nbsp; 
return 0;<BR>}</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>float objective(GAGenome &amp; c)<BR>{<BR>&nbsp; 
GA1DArrayAlleleGenome&lt;int&gt; &amp; genome = 
(GA1DArrayAlleleGenome&lt;int&gt; &amp;)c;<BR>&nbsp; float 
value=0.0,prof;<BR>&nbsp; int sum=0,prod=1,g;<BR>&nbsp;for(int 
i=0;i&lt;genome.length();i++)<BR>&nbsp;{<BR>&nbsp;&nbsp;g=genome.gene(i);<BR>&nbsp;&nbsp;sum+=genome.gene(i);<BR>&nbsp;&nbsp;prod*=genome.gene(i);<BR>&nbsp;}<BR>&nbsp;prof=prod/26460;<BR>&nbsp;if(prof&gt;1)<BR>&nbsp;&nbsp;prof=1/prof;<BR>&nbsp;value=1/fabs(sum-31)+prof;&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; //value range from 0 to 
2<BR>&nbsp; return(value);<BR>}</FONT></DIV></BODY></HTML>