[galib] Help: still about initializer?

yi.zong@risoe.dk yi.zong at risoe.dk
Thu Oct 2 06:03:56 EDT 2008


Dear all,

   Thank you for your help for my  question.

   I write my initializer. But the first generation's individuals are always zeros and they are not the real number, Like 19.2.

   Could you tell me why?

   Please, see my code snippet from my application as follows. 

   Looking forward to your answer.

   

   Yi

 

float Objective(GAGenome &);

void Myinitializer(GAGenome &);

 

int

main(int argc, char** argv)

{

 

/*

// See if we've been given a seed to use (for testing purposes).  When you

// specify a random seed, the evolution will be exactly the same each time

// you use that seed number.

 

  for(int jj=1; jj<argc; jj++) {

    if(strcmp(argv[jj++],"seed") == 0) {

      GARandomSeed((unsigned int)atoi(argv[jj]));

    }

  }*/

  int length=36;

 

  GARealAlleleSetArray alleles;

  alleles.add(-21,-18);

  alleles.add(-21,-18);

  alleles.add(-21,-18);

  alleles.add(-21,-18);

  alleles.add(-21,-18);

  alleles.add(-21,-18);

  alleles.add(-21,-18);

  alleles.add(-21,-18);

  alleles.add(-21,-18);

  alleles.add(-21,-18);

  alleles.add(-21,-18);

  alleles.add(-21,-18);

  alleles.add(-21,-18);

  alleles.add(-21,-18);

  alleles.add(-21,-18);

  alleles.add(-21,-18);

  alleles.add(-21,-18);

  alleles.add(-21,-18);

  alleles.add(-21,-18);

  alleles.add(-21,-18);

  alleles.add(-21,-18);

  alleles.add(-21,-18);

  alleles.add(-21,-18);

  alleles.add(-21,-18);

  alleles.add(-21,-18);

  alleles.add(-21,-18);

  alleles.add(-21,-18);

  alleles.add(-21,-18);

  alleles.add(-21,-18);

  alleles.add(-21,-18);

  alleles.add(-21,-18);

  alleles.add(-21,-18);

  alleles.add(-21,-18);

  alleles.add(-21,-18);

  alleles.add(-21,-18);

  alleles.add(-21,-18);

  GARealGenome genome(alleles, Objective);

 

 

 GANoScaling scale;//GAScalingScheme::GANoScaling--the fitness scores = the objectivescores

 

  genome.crossover(GARealTwoPointCrossover);

  

  genome.initializer(Myinitializer); // Initial with given by manual, but all with values as 0 ??  

  

  GASimpleGA ga(genome);

  ga.minimize();             // by default we want to minimize the objective

  ga.scaling(scale);                    // set the scaling method to our sharing

  ga.populationSize(73); // how many individuals in the population

  ga.nGenerations(100); // number of generations to evolve

  ga.nBestGenomes(1);           // Specify how many 'best' genomes to record, the default is 1

  ga.pMutation(0.05);                  // likelihood of mutating new offspring

  ga.pCrossover(0.6);                 // likelihood of crossing over parents

  ga.scoreFilename("yinw13.dat"); // name of file for scores

  ga.scoreFrequency(1);                        // keep the scores of every generation

  ga.flushFrequency(1);          // specify how often to write the score to disk, if generation<10, then it only records once

  ga.selectScores(GAStatistics::AllScores);

  ga.parameters(argc, argv, gaTrue); // parse commands, complain if bogus args

   ...

 

}

 

 

void Myinitializer( GAGenome &g )

   {

      GARealGenome &genome = (GARealGenome &)g;

      double IC[]={-19.2,-19.2,-19.2,-19.2,-19.2,-19.2,-19.2,-19.2,-19.2,-19.2,-19.2,-19.2,-19.2,-19.2,-19.2,-19.2,-19.2,-19.2,-19.2,-19.2,-19.2,-19.2,-19.2,-19.2,-19.2,-19.2,-19.2,-19.2,-19.2,-19.2,-19.2,-19.2,-19.2,-19.2,-19.2,-19.2};

   

      for( int i = 0; i < 36; ++i )

        {

             genome.gene(i, IC[i]);

        }    

   }

 

 

Yi Zong
Post doc
Phone direct +45 4677 5045
Mobile 
yi.zong at risoe.dk
 

Wind Energy Department
Risø National Laboratory for Sustainable Energy
Technical University of Denmark - DTU
Building 118, P.O. Box 49
DK-4000 Roskilde, Denmark
Tel +45 4677 4677
Fax +45 4677 5083
www.risoe.dtu.dk 







 

Yi Zong
Post doc
Phone direct +45 4677 5045
Mobile 
yi.zong at risoe.dk
 

Wind Energy Department
Risø National Laboratory for Sustainable Energy
Technical University of Denmark - DTU
Building 118, P.O. Box 49
DK-4000 Roskilde, Denmark
Tel +45 4677 4677
Fax +45 4677 5083
www.risoe.dtu.dk 













 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.mit.edu/pipermail/galib/attachments/20081002/d1e90e18/attachment.htm


More information about the galib mailing list