[galib] put bestIndividual into a variable

Alin Ionascu alin1x at live.com
Wed Aug 1 05:59:20 EDT 2012


Hello Lukasz,

Thanks for your advice. I have tried both suggestions.

1. float test = ga.statistic().bestIndividual().score(); - this gives me the score of the best individual but not the value. This works.

2. ga.statistics().bestIndividual().gene(0) - throws the following error:
control0406.cpp:537: error: ˜const class GAGenome" has no member named ˜gene"

As far as I understood it the GAStatistics class a member function named bestIndividual which is declared in this way:
const GAGenome& bestIndividual(unsigned int n=0) const
which further refers to the class GAGenome which has no member named "gene"   - hence the error

Maybe I've missed something.

If you have other suggestions please let me know.



Thank you for your effort,
Alin




On 07/31/2012 10:16 AM, "Łukasz Kuczkowski" wrote:
> Hi Alin,
> you have to use a score method. You simply write:
>
> float test = ga.statistic().bestIndividual().score();
>
> If you want to use a value of gene then:
> ga.statistic().bestIndividual().gene(0);
>
> All the answers are in documentation and examples (in this case in ex 21 &
> 23 where the GARealGenome was used).
> I hope that my answer helped. Wish a fun with GALib!
> Regards
>
> Lukasz Kuczkowski, PhD. student
> Gdansk University of Technology
> Faculty of Electrical and Control Engineering
> G.Narutowicza 11/12 street
> 80-233 Gdansk, Poland
>> Hello everyone,
>> I am fairly new to GAlib and I was wondering if you could help me with
>> something.
>> I created a GARealGenome:
>>          GARealAlleleSet alleles(MIN_VALUE, MAX_VALUE);        GARealGenome
>> genome(1, alleles, Objective);        GASimpleGA ga(genome);
>> After the GA has finished I would like to further work with the best
>> individual.I can print it out with the following command:    cout <<
>> ga.statistics().bestIndividual();
>>
>> My question is the following :      How can I assign the value to a
>> variable for example a double (each individual has just a value which is a
>> real).     I tried to do something like this:    double test =
>> ga.statistics().bestIndividual();     (this obviously doesn't work since
>> the type ga.statistics().bestIndividual() is const GAGenome&
>> bestIndividual(unsigned int n=0) const  )
>>
>> Can you please tell me how I can get the value from
>> ga.statistics().bestIndividual() into a double variable.
>> Thanks,Alin
>>   		 	   		  _______________________________________________
>> galib mailing list
>> galib at mit.edu
>> http://mailman.mit.edu/mailman/listinfo/galib
>>
> _______________________________________________
> galib mailing list
> galib at mit.edu
> http://mailman.mit.edu/mailman/listinfo/galib
>
>



More information about the galib mailing list