[galib] Optimization Program

Peter Jay Salzman p at dirac.org
Fri Nov 16 12:55:00 EST 2007


On Thu 15 Nov 07,  3:44 PM, Somnath Bhattacharjee <sn.bhattacharjee at yahoo.co.in> said:
>    I want to make an optimization problem to solve a quadratic equation
>    (y=X*X+5*X+6).
>    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?
>     
>    Somnath.
>     
>     
>    #include <stdio.h>
>    #include <ga/ga.h>
>    #include <ga/std_stream.h>
>    #define cout STD_COUT
>    float objective(GAGenome &);
>    int
>    main(int argc, char **argv)
>    {
>      cout << "This program finds the minimum value in the function\n";
>      cout << "  y=x*x + 5*x + 6 ";
>      cout << "with the constraints\n";
>      cout << "     -3 <= x <= -2\n";
>      cout << "\n\n"; cout.flush();
>      unsigned int seed = 0;
>      for(int i=1; i<argc; i++) {
>        if(strcmp(argv[i++],"seed") == 0) {
>          seed = atoi(argv[i]);
>        }
>      }
>      int popsize  = 30;
>      int ngen     = 100;
>      float pmut   = 0.01;
>      float pcross = 0.6;
>      GABin2DecPhenotype map;
>      map.add(16, -3, -2);
>      map.add(16, -3, -2);
>     
>      GABin2DecGenome genome(map, objective);
>      GASimpleGA ga(genome);
>      GASigmaTruncationScaling scaling;
>      ga.minimize();
>      ga.populationSize(popsize);
>      ga.nGenerations(ngen);
>      ga.pMutation(pmut);
>      ga.pCrossover(pcross);
>      ga.scaling(scaling);
>      ga.scoreFilename("bog.dat");
>      ga.scoreFrequency(10);
>      ga.flushFrequency(50);
>      ga.evolve(seed);
>      genome = ga.statistics().bestIndividual();
>      cout << "the ga found an optimum at the point (";
>      cout << genome.phenotype(0) << ", " << genome.phenotype(1) << ")\n\n";
>      return 0;
>    }
>     
>    float
>    objective(GAGenome & c)
>    {
>      GABin2DecGenome & genome = (GABin2DecGenome &)c;
>      float y;
>      y = genome.phenotype(0) * genome.phenotype(0) + 5 * genome.phenotype(0)
>    + 6;
>        return y;
>    }



Hi Somnath,

Please state, clearly and precisely, the problem you want to solve.  For
example:

   "I want to find the 1st root of Bessel's function of 2nd order."
   "I want to find the 3 cubic roots of unity."
   "I want to minimize the gudermanian function."
   "I want to find the intersection of tan(x) and tanh(x)."

If you can state your problem very clearly, I will try to help.

Pete

-- 
GPG Fingerprint: B9F1 6CF3 47C4 7CD8 D33E  70A9 A3B9 1945 67EA 951D
Last night I dreamt of 09-f9-11-02-9d-74-e3-5b-d8-41-56-c5-63-56-88-c0

"A mathematician is a machine for converting coffee    p at dirac.org
 into theorems."     -- Paul Erdös                     http://www.dirac.org



More information about the galib mailing list