How can I to evolve the entire popolation
Ramon Diaz-Uriarte
ramon-diaz at teleline.es
Mon Jan 15 14:27:35 EST 2001
On Mon, 15 Jan 2001, Signoretto Mirko wrote:
> Hi,
>
> I have a very slow objective function and so I need to calculate it for the entire population.
>
> I've tried to use the population evaluator:
>
> ga.population().evaluator(popEvaluator);
>
> defining a popEvaluator function.
>
> The problem is that my "popEvaluator" is called only once... but I need that it is called
> for every generation.
>
> Thanks.
I am attaching a little dumb program that I wrote a while ago where popEvaluator
is definitely called every generation. I know the program is stupid, but I
wanted to convince myself that things would work with more complicaated
poEvaluator functions.
I hope this helps,
Ramón
************************** little program
#include<stdio.h>
#include<iostream.h>
#include<math.h>
#include<ga/ga.h>
using namespace std;
void popEvaluator(GAPopulation & p);
void Initializer(GAGenome& g);
int main(){
int length_genome = 3;
GA1DArrayGenome<float> genome(length_genome);
genome.initializer(::Initializer);
GAPopulation pop(genome);
pop.evaluator(popEvaluator);
GASimpleGA ga(pop);
ga.nGenerations(20);
ga.populationSize(10);
ga.initialize();
cout <<" evolving\n "; cout.flush();
while(!ga.done()){
cout <<"\n ************* A new generation *************** \n";
ga.step();
}
cout << ga.statistics() << endl;
return 0;
}
void popEvaluator(GAPopulation & p) {
cout <<"\npopEvaluator being called here\n";
for (int i=0; i<p.size(); i++) {
GA1DArrayGenome<float> & gx = (GA1DArrayGenome<float>&)p.individual(i);
cout<<"\n popEvaluator being called on each individual \n";
p.individual(i).score(gx.gene(1)+2*gx.gene(2));
}
}
void Initializer(GAGenome& g) {
GA1DArrayGenome<float>& genome = (GA1DArrayGenome<float>&)g;
genome.gene(0, GARandomFloat(0, 20));
genome.gene(1, GARandomFloat(0, 20));
genome.gene(2, GARandomFloat(0, 20));
}
**************** end little program
>
>
> --
> -------------------------------------------------------------------------
> Mirko Signoretto mat. IN 308
>
> Facolta` di Scienze MM.FF.NN. Corso di Laurea in Informatica (Verona)
>
> E-mail: msigno at arena.sci.univr.it
> msigno at libero.it
>
> Phone: +39 045/890.23.64 WWW: http://arena.sci.univr.it/~msigno
> -------------------------------------------------------------------------
--
Ramón Díaz-Uriarte
Triana 47
28016 Madrid
Spain
email:ramon-diaz at teleline.es
Phone: +-34-918-513-966
+-34-657-186-407
More information about the galib
mailing list