<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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I want to solve the Quadratic equation y= x*x+5*x+6. According&nbsp;to manual calculation the result will be two roots ( -3 and -2 , for&nbsp;these values of x the&nbsp;function value will be ZERO&nbsp;). Now by GA the results (means the roots) should be nearly -3 and -2 (not exactly -3,-2).
<DIV><STRONG>I'm not sure that&nbsp; it is right or not. I'm beginner in GA so your suggestion will be benchmark for me.</STRONG><STRONG></DIV>
<DIV></STRONG>&nbsp;&nbsp;&nbsp;&nbsp;</DIV>
<DIV>I want a result like -2.9986 and -1.9878 (which is nearly the roots bot not exactly -3,-2).</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;I'm sending the total program.</DIV>
<DIV>&nbsp;</DIV>
<DIV>
<DIV>Regards</DIV>
<DIV>Somnath</DIV></DIV>
<DIV><BR>#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 roots&nbsp;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";<BR>&nbsp; cout &lt;&lt; "best of generation data are in '" &lt;&lt; ga.scoreFilename() &lt;&lt; "'\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=6.0;<BR>&nbsp; y&nbsp; += genome.phenotype(0) * genome.phenotype(0);</DIV>
<DIV>&nbsp;&nbsp; y += 5 * genome.phenotype(0);<BR>&nbsp;&nbsp;&nbsp; return y;<BR>}<BR></DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV></DIV></div><br>


      <!--1--><hr size=1></hr> Bollywood, fun, friendship, sports and more. You name it, <a href="http://in.rd.yahoo.com/tagline_groups_1/*http://in.promos.yahoo.com/groups"> we have it.</a></body></html>