[galib] Re: Obtain "bestIndividual()" value

Luca Moscatelli lucaster at gmail.com
Tue Nov 9 13:27:18 EST 2004


Thanks,
   But, with some help, I used another (and better, I suppose) solution.

Here to you:
First of all, you put the best individual into an appropriate genome
(GARealGenome in my case):

GARealGenome best = (GARealGenome &)ga.statistics().bestIndividual();

Then
float f = best.gene(n);
where 'n' is the value into the gene you are interested in...

I tried this approach and it works!
Bye,
Luca

On Mon, 8 Nov 2004 23:37:41 -0800 (PST), Mert Tas <mert_tas at yahoo.com> wrote:
> 
>  
>  
> 
> Unfortunately, it is not a quite simple problem. Since bestIndividual is of
> type GaGenome& you could not access its value directly. I solved this
> problem by first printing the bestIndividual value to a file, then reading
> its value from that file and assigning it to a new variable. 
> 
> One way is to use file stream operators as follows: 
> 
> ofstream fout; 
> 
> fout.open("bestInd.txt", ios::in); 
> 
> if (!fout.fail()){ 
> 
> fout << ga.statistics().bestIndividual() ; 
> 
> fout.close(); 
> 
> } 
> 
> ifstream fin; 
> 
> fin.open("bestInd.txt", ios::out); 
> 
> if (!fin.fail()){ 
> 
> float bestInd, 
> 
> fin >> bestInd; // read the value from file and write it to bestInd 
> 
> fin.close(); 
> 
> } 
> 
> Hope this helps ...


More information about the galib mailing list