[galib] Obtain "bestIndividual()" value

gio sarto teofilo68 at yahoo.co.uk
Tue Nov 9 15:28:51 EST 2004


My apologies there was an error in my previous reply,
the Id is GAID::FloatGenome and not GAID::ArrayGenome

 When you use GAGenome's that are a derived of
 GAArray (it is the case for GARealGenome),
 all you need to do is to cast it to its actual type:
 
 // before doing this you may want to check
 // that the identity is correct, use
 ga.statistics().bestIndividual().classID() ==
 GAID::FloatGenome;
 // or the C++ dynamic_cast< T > operator
 // then cast 
 GARealGenome& gr = ga.statistics().bestIndividual();
 
 // then you can use either the ::gene(int i) method
 x = gr.gene(i);  // 0<= i <= gr.size()
 // or the indexing operator:
 x = gr[i];
 
 // or you can even cast the genome to a pointer to
 // double, and then index this directly:
 double* pgenome = (double*) gr; 
 x = pgenome[i];
 // this holds in general for any genome calass that
 // is derived from GAArray<T>, not only for
 GARealGenome.
 
 Have a look at the header files:
 GAArray.h and GA1DArrayGenome.h
 
 
 Cheers
 
 Giovanni
 
>  --- Luca Moscatelli <lucaster at gmail.com> wrote: 
> > Hi to all.
> > I tried the first examples and they are all clear,
> > and I saw that the
> > best individual is only printed at the end of each
> > program, but what
> > have I to do if I want to use it?
> > 
> > I'll try to be more clear:
> > I created a GARealAlleleSet, filled and inserted
> > into the
> > GARealGenome, then I evolved it.
> > If I print the best individual like in the
> examples
> > with "cout <<
> > ga.statistics().bestIndividual()" I see the right
> > value, but now I
> > want, for example, to add 1 to this value...
> > 
> > Now, I looked the documentation and I saw that the
> > ga.statistics().bestIndividual() returns a
> > GaGenome&,  how can I put
> > this value(s) in a float variable(s)?
> > 
> > Thanks in advance to all of you!
> > Bye,
> > Luca
> > _______________________________________________
> > galib mailing list
> > galib at mit.edu
> > http://mailman.mit.edu/mailman/listinfo/galib
> >  
> 
> 
> 	
> 	
> 		
>
___________________________________________________________ALL-NEW
> Yahoo! Messenger - all new features - even more fun!
> http://uk.messenger.yahoo.com
>  


	
	
		
___________________________________________________________ALL-NEW Yahoo! Messenger - all new features - even more fun! http://uk.messenger.yahoo.com


More information about the galib mailing list