<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:times new roman, new york, times, serif;font-size:12pt"><DIV>I want to make an optimization problem to solve a quadratic equation (y=X*X+5*X+6).</DIV>
<DIV>I designed a program but it's showing some non desired result. I'm beginner in GA please tell me what I have to do. Is the following progam is right?</DIV>
<DIV>&nbsp;</DIV>
<DIV>Somnath.</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>#include &lt;stdio.h&gt;<BR>#include &lt;ga/ga.h&gt;<BR>#include &lt;ga/std_stream.h&gt;</DIV>
<DIV>#define cout STD_COUT</DIV>
<DIV>float objective(GAGenome &amp;);</DIV>
<DIV>int<BR>main(int argc, char **argv)<BR>{<BR>&nbsp; cout &lt;&lt; "This program finds the minimum value in the function\n";<BR>&nbsp; cout &lt;&lt; "&nbsp; y=x*x + 5*x + 6 ";<BR>&nbsp; cout &lt;&lt; "with the constraints\n";<BR>&nbsp; cout &lt;&lt; "&nbsp;&nbsp;&nbsp;&nbsp; -3 &lt;= x &lt;= -2\n";<BR>&nbsp; cout &lt;&lt; "\n\n"; cout.flush();</DIV>
<DIV>&nbsp; unsigned int seed = 0;<BR>&nbsp; for(int i=1; i&lt;argc; i++) {<BR>&nbsp;&nbsp;&nbsp; if(strcmp(argv[i++],"seed") == 0) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; seed = atoi(argv[i]);<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp; }</DIV>
<DIV>&nbsp; int popsize&nbsp; = 30;<BR>&nbsp; int ngen&nbsp;&nbsp;&nbsp;&nbsp; = 100;<BR>&nbsp; float pmut&nbsp;&nbsp; = 0.01;<BR>&nbsp; float pcross = 0.6;</DIV>
<DIV>&nbsp; GABin2DecPhenotype map;<BR>&nbsp; map.add(16, -3, -2);<BR>&nbsp; map.add(16, -3, -2);</DIV>
<DIV>&nbsp; <BR>&nbsp; GABin2DecGenome genome(map, objective);</DIV>
<DIV>&nbsp; GASimpleGA ga(genome);<BR>&nbsp; GASigmaTruncationScaling scaling;<BR>&nbsp; ga.minimize();<BR>&nbsp; ga.populationSize(popsize);<BR>&nbsp; ga.nGenerations(ngen);<BR>&nbsp; ga.pMutation(pmut);<BR>&nbsp; ga.pCrossover(pcross);<BR>&nbsp; ga.scaling(scaling);<BR>&nbsp; ga.scoreFilename("bog.dat");<BR>&nbsp; ga.scoreFrequency(10);<BR>&nbsp; ga.flushFrequency(50);<BR>&nbsp; ga.evolve(seed);</DIV>
<DIV>&nbsp; genome = ga.statistics().bestIndividual();<BR>&nbsp; cout &lt;&lt; "the ga found an optimum at the point (";<BR>&nbsp; cout &lt;&lt; genome.phenotype(0) &lt;&lt; ", " &lt;&lt; genome.phenotype(1) &lt;&lt; ")\n\n";</DIV>
<DIV>&nbsp; return 0;<BR>}<BR>&nbsp;</DIV>
<DIV>float<BR>objective(GAGenome &amp; c)<BR>{<BR>&nbsp; GABin2DecGenome &amp; genome = (GABin2DecGenome &amp;)c;</DIV>
<DIV>&nbsp; float y;<BR>&nbsp; y = genome.phenotype(0) * genome.phenotype(0) + 5 * genome.phenotype(0) + 6;<BR>&nbsp;&nbsp;&nbsp; return y;<BR>}<BR></DIV></div><br>



      <!--1--><hr size=1></hr> Why delete messages? Unlimited storage is <a href="http://in.rd.yahoo.com/tagline_mail_1/*http://help.yahoo.com/l/in/yahoo/mail/yahoomail/tools/tools-08.html/">just a click away.</a></body></html>