<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 solve the Quadratic equation y= x*x+5*x+6. According to manual calculation the result will be two roots ( -3 and -2 , for these values of x the function value will be ZERO ). 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 it is right or not. I'm beginner in GA so your suggestion will be benchmark for me.</STRONG><STRONG></DIV>
<DIV></STRONG> </DIV>
<DIV>I want a result like -2.9986 and -1.9878 (which is nearly the roots bot not exactly -3,-2).</DIV>
<DIV> </DIV>
<DIV> I'm sending the total program.</DIV>
<DIV> </DIV>
<DIV>
<DIV>Regards</DIV>
<DIV>Somnath</DIV></DIV>
<DIV><BR>#include <stdio.h><BR>#include <ga/ga.h><BR>#include <ga/std_stream.h></DIV>
<DIV>#define cout STD_COUT</DIV>
<DIV>float objective(GAGenome &);</DIV>
<DIV>int<BR>main(int argc, char **argv)<BR>{<BR> cout << "This program finds the roots value in the function\n";<BR> cout << " y=x*x + 5*x + 6 ";<BR> cout << "with the constraints\n";<BR> cout << " -3 <= x <= -2\n";<BR> cout << "\n\n"; cout.flush();</DIV>
<DIV> unsigned int seed = 0;<BR> for(int i=1; i<argc; i++) {<BR> if(strcmp(argv[i++],"seed") == 0) {<BR> seed = atoi(argv[i]);<BR> }<BR> }</DIV>
<DIV> int popsize = 30;<BR> int ngen = 100;<BR> float pmut = 0.01;<BR> float pcross = 0.6;</DIV>
<DIV> GABin2DecPhenotype map;<BR> map.add(16, -3, -2);<BR> map.add(16, -3, -2);</DIV>
<DIV> <BR> GABin2DecGenome genome(map, objective);</DIV>
<DIV> GASimpleGA ga(genome);<BR> GASigmaTruncationScaling scaling;<BR> ga.minimize();<BR> ga.populationSize(popsize);<BR> ga.nGenerations(ngen);<BR> ga.pMutation(pmut);<BR> ga.pCrossover(pcross);<BR> ga.scaling(scaling);<BR> ga.scoreFilename("bog.dat");<BR> ga.scoreFrequency(10);<BR> ga.flushFrequency(50);<BR> ga.evolve(seed);</DIV>
<DIV> genome = ga.statistics().bestIndividual();<BR> cout << "the ga found an optimum at the point (";<BR> cout << genome.phenotype(0) << ", " << genome.phenotype(1) << ")\n\n";<BR> cout << "best of generation data are in '" << ga.scoreFilename() << "'\n";</DIV>
<DIV> return 0;<BR>}<BR> </DIV>
<DIV>float<BR>objective(GAGenome & c)<BR>{<BR> GABin2DecGenome & genome = (GABin2DecGenome &)c;</DIV>
<DIV> float y=6.0;<BR> y += genome.phenotype(0) * genome.phenotype(0);</DIV>
<DIV> y += 5 * genome.phenotype(0);<BR> return y;<BR>}<BR></DIV>
<DIV> </DIV>
<DIV> </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>