[galib] galib Digest, Vol 63, Issue 5
yi.zong@risoe.dk
yi.zong at risoe.dk
Thu Oct 9 08:25:27 EDT 2008
Dear all,
Thanks a lot.
Specially, many thanks to Patrick.
I have solved the problem.
1. We need to use:
ga.initialize() in
int main(int argc, char** argv)
{
}
2. Addition: put Myinitializer
Before Objective
Like this:
void Myinitializer(GAGenome &);
float Objective(GAGenome &);
int
main(int argc, char** argv)
{
for(int jj=1; jj<argc; jj++) {
if(strcmp(argv[jj++],"seed") == 0) {
GARandomSeed((unsigned int)atoi(argv[jj]));
}
}
ofstream outfile;
GARealGenome genome(length, alleles, Objective);
// GASharing scale;//using GAScalingScheme::GASharing-default
GANoScaling scale;//GAScalingScheme::GANoScaling--the fitness scores = the objectivescores
genome.crossover(GARealTwoPointCrossover);
genome.initializer(Myinitializer); // Initial with Myinitializer
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("yinw25.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
//unsigned int seed=0;
//ga.initialize(seed)
ga.initialize();
....
}
void Myinitializer( GAGenome &g )
{
GARealGenome &genome = (GARealGenome &)g;
float 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
________________________________
From: Patrick Coquillard [mailto:patrick.coquillard at unice.fr]
Sent: Wednesday, October 08, 2008 6:51 PM
To: yi.zong at risoe.dk
Subject: Re: [galib] galib Digest, Vol 63, Issue 5
Hi Yi,
I embedded your code in a simple source...that did nothing. Compilation and execution. Really, I do not understand why your initializer is never called. May be you found a bug of galib. I suggest you could try to use an other kind of genome ? I don't know.
I attach the stupid example I build from your code.
Sorry,
regards, P.
________________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.mit.edu/pipermail/galib/attachments/20081009/bdb8df33/attachment.htm
More information about the galib
mailing list