<DIV>Hi,</DIV>
<DIV>Well your solution seems to work fine in GARealGenome case. But I suppose you can not use the same approach on other genome types. I am using GABinaryStringGenome</DIV>
<DIV>and you cannot assign the bestIndividual() value that easily since it has no &nbsp;gene() operator. What I did here is, as stated before, I used the file stream operators to get its value. Anyone has a better idea?&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>Greetings,</DIV>
<DIV>Mert<BR><BR><B><I>galib-request@mit.edu</I></B> wrote:</DIV>
<BLOCKQUOTE class=replbq style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #1010ff 2px solid">Send galib mailing list submissions to<BR>galib@mit.edu<BR><BR>To subscribe or unsubscribe via the World Wide Web, visit<BR>http://mailman.mit.edu/mailman/listinfo/galib<BR>or, via email, send a message with subject or body 'help' to<BR>galib-request@mit.edu<BR><BR>You can reach the person managing the list at<BR>galib-owner@mit.edu<BR><BR>When replying, please edit your Subject line so it is more specific<BR>than "Re: Contents of galib digest..."<BR>Today's Topics:<BR><BR>1. Re: Obtain "bestIndividual()" value (Mert Tas)<BR>2. Re: Re: Obtain "bestIndividual()" value (Luca Moscatelli)<BR>3. Re: Obtain "bestIndividual()" value (gio sarto)<BR>4. Re: Obtain "bestIndividual()" value (gio sarto)<BR><BR><BR>&gt; ATTACHMENT part 3.1 message/rfc822 <BR>Date: Mon, 8 Nov 2004 23:37:41 -0800 (PST)<BR>From: Mert Tas <MERT_TAS@YAHOO.COM><BR>To: galib@mit.edu<BR>Subject: [galib] Re: Obtain
 "bestIndividual()" value <BR><BR>
<DIV>
<BLOCKQUOTE class=replbq style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #1010ff 2px solid">
<P>Unfortunately, it is not a quite simple problem. Since bestIndividual is of type GaGenome&amp; 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.</P>
<P>One way is to use file stream operators as follows:</P>
<P>ofstream fout;</P>
<P>fout.open("bestInd.txt", ios::in);</P>
<P>if (!fout.fail()){</P>
<P>fout &lt;&lt; ga.statistics().bestIndividual() ;</P>
<P>fout.close();</P>
<P>}</P>
<P>ifstream fin;</P>
<P>fin.open("bestInd.txt", ios::out);</P>
<P>if (!fin.fail()){</P>
<P>float bestInd,</P>
<P>fin &gt;&gt; bestInd; // read the value from file and write it to bestInd</P>
<P>fin.close();</P>
<P>}</P>
<P>Hope this helps ...</P>
<P><BR>Today's Topics:<BR><BR>1. Obtain "bestIndividual()" value (Luca Moscatelli)<BR>2. Obtain "bestIndividual()" value (Luca Moscatelli)<BR><BR><BR>&gt; ATTACHMENT part 3.1 message/rfc822 <BR>Date: Tue, 2 Nov 2004 18:36:29 +0100<BR>From: Luca Moscatelli <LUCASTER@GMAIL.COM><BR>To: galib@mit.edu<BR>Subject: [galib] Obtain "bestIndividual()" value<BR><BR>Hi to all.<BR><BR>I'm new with this library and I have a simple problem (I hope it's<BR>simple... However, it is quite stupid :D).<BR><BR>I tried the first examples and they are all clear, but I saw that the<BR>best individual is only printed at the end of each program, but what<BR>have I to do if I want to use it?<BR><BR>I'll try to be more clear:<BR>I created a GARealAlleleSet, filled with some values and inserted into<BR>the GARealGenome, then I evolved it.<BR>If I print the best individual like in the examples with "cout &lt;&lt;<BR>ga.statistics().bestIndividual() I see the right value, but now I<BR>want, for example, t!
 ! o add 1
 to this value...<BR><BR>Now, I looked the documentation and I saw that the<BR>ga.statistics().bestIndividual() returns a GaGenome&amp;, how can the cout<BR>print it?<BR>And, how can I put this value(s) in a float variable(s)?<BR><BR>I hope that my problem is quite clear to you... :)<BR><BR>Thanks in advance to all of you!<BR>Bye,<BR>Luca<BR></P></BLOCKQUOTE></DIV>
<P>
<HR SIZE=1>
Do you Yahoo!?<BR>Check out the new Yahoo! Front Page. <A href="http://www.yahoo.com/">www.yahoo.com</A><BR><BR>&gt; ATTACHMENT part 3.2 message/rfc822 <BR>Date: Tue, 9 Nov 2004 19:27:18 +0100<BR>From: Luca Moscatelli <LUCASTER@GMAIL.COM><BR>To: galib@mit.edu<BR>Subject: Re: [galib] Re: Obtain "bestIndividual()" value<BR><BR>Thanks,<BR>But, with some help, I used another (and better, I suppose) solution.<BR><BR>Here to you:<BR>First of all, you put the best individual into an appropriate genome<BR>(GARealGenome in my case):<BR><BR>GARealGenome best = (GARealGenome &amp;)ga.statistics().bestIndividual();<BR><BR>Then<BR>float f = best.gene(n);<BR>where 'n' is the value into the gene you are interested in...<BR><BR>I tried this approach and it works!<BR>Bye,<BR>Luca<BR><BR>On Mon, 8 Nov 2004 23:37:41 -0800 (PST), Mert Tas <MERT_TAS@YAHOO.COM>wrote:<BR>&gt; <BR>&gt; <BR>&gt; <BR>&gt; <BR>&gt; Unfortunately, it is not a quite simple problem. Since bestIndividual is of<BR>&gt; type
 GaGenome&amp; you could not access its value directly. I solved this<BR>&gt; problem by first printing the bestIndividual value to a file, then reading<BR>&gt; its value from that file and assigning it to a new variable. <BR>&gt; <BR>&gt; One way is to use file stream operators as follows: <BR>&gt; <BR>&gt; ofstream fout; <BR>&gt; <BR>&gt; fout.open("bestInd.txt", ios::in); <BR>&gt; <BR>&gt; if (!fout.fail()){ <BR>&gt; <BR>&gt; fout &lt;&lt; ga.statistics().bestIndividual() ; <BR>&gt; <BR>&gt; fout.close(); <BR>&gt; <BR>&gt; } <BR>&gt; <BR>&gt; ifstream fin; <BR>&gt; <BR>&gt; fin.open("bestInd.txt", ios::out); <BR>&gt; <BR>&gt; if (!fin.fail()){ <BR>&gt; <BR>&gt; float bestInd, <BR>&gt; <BR>&gt; fin &gt;&gt; bestInd; // read the value from file and write it to bestInd <BR>&gt; <BR>&gt; fin.close(); <BR>&gt; <BR>&gt; } <BR>&gt; <BR>&gt; Hope this helps ...<BR><BR><BR>&gt; ATTACHMENT part 3.3 message/rfc822 <BR>Date: Tue, 9 Nov 2004 20:15:34 +0000 (GMT)<BR>From: gio sarto
 <TEOFILO68@YAHOO.CO.UK><BR>To: Luca Moscatelli <LUCASTER@GMAIL.COM>, galib@mit.edu<BR>Subject: Re: [galib] Obtain "bestIndividual()" value<BR><BR>When you use GAGenome's that are a derived of<BR>GAArray (it is the case for GARealGenome),<BR>all you need to do is to cast it to its actual type:<BR><BR>// before doing this you may want to check<BR>// that the identity is correct, use<BR>ga.statistics().bestIndividual().classID() ==<BR>GAID::ArrayGenome;<BR>// or the C++ dynamic_cast&lt; T &gt; operator<BR>// then cast <BR>GARealGenome&amp; gr = ga.statistics().bestIndividual();<BR><BR>// then you can use either the ::gene(int i) method<BR>x = gr.gene(i); // 0&lt;= i &lt;= gr.size()<BR>// or the indexing operator:<BR>x = gr[i];<BR><BR>// or you can even cast the genome to a pointer to<BR>// double, and then index this directly:<BR>double* pgenome = (double*) gr; <BR>x = pgenome[i];<BR>// this holds in general for any genome calass that<BR>// is derived from GAArray<T>, not only
 for<BR>GARealGenome.<BR><BR>Have a look at the header files:<BR>GAArray.h and GA1DArrayGenome.h<BR><BR><BR>Cheers<BR><BR>Giovanni<BR><BR>--- Luca Moscatelli <LUCASTER@GMAIL.COM>wrote: <BR>&gt; Hi to all.<BR>&gt; I tried the first examples and they are all clear,<BR>&gt; and I saw that the<BR>&gt; best individual is only printed at the end of each<BR>&gt; program, but what<BR>&gt; have I to do if I want to use it?<BR>&gt; <BR>&gt; I'll try to be more clear:<BR>&gt; I created a GARealAlleleSet, filled and inserted<BR>&gt; into the<BR>&gt; GARealGenome, then I evolved it.<BR>&gt; If I print the best individual like in the examples<BR>&gt; with "cout &lt;&lt;<BR>&gt; ga.statistics().bestIndividual()" I see the right<BR>&gt; value, but now I<BR>&gt; want, for example, to add 1 to this value...<BR>&gt; <BR>&gt; Now, I looked the documentation and I saw that the<BR>&gt; ga.statistics().bestIndividual() returns a<BR>&gt; GaGenome&amp;, how can I put<BR>&gt; this value(s) in a float
 variable(s)?<BR>&gt; <BR>&gt; Thanks in advance to all of you!<BR>&gt; Bye,<BR>&gt; Luca<BR>&gt; _______________________________________________<BR>&gt; galib mailing list<BR>&gt; galib@mit.edu<BR>&gt; http://mailman.mit.edu/mailman/listinfo/galib<BR>&gt; <BR><BR><BR><BR><BR><BR>___________________________________________________________ALL-NEW Yahoo! Messenger - all new features - even more fun! http://uk.messenger.yahoo.com<BR><BR><BR>&gt; ATTACHMENT part 3.4 message/rfc822 <BR>Date: Tue, 9 Nov 2004 20:28:51 +0000 (GMT)<BR>From: gio sarto <TEOFILO68@YAHOO.CO.UK><BR>To: galib@mit.edu<BR>Subject: Re: [galib] Obtain "bestIndividual()" value<BR><BR>My apologies there was an error in my previous reply,<BR>the Id is GAID::FloatGenome and not GAID::ArrayGenome<BR><BR>When you use GAGenome's that are a derived of<BR>GAArray (it is the case for GARealGenome),<BR>all you need to do is to cast it to its actual type:<BR><BR>// before doing this you may want to check<BR>// that the id!
 entity is
 correct, use<BR>ga.statistics().bestIndividual().classID() ==<BR>GAID::FloatGenome;<BR>// or the C++ dynamic_cast&lt; T &gt; operator<BR>// then cast <BR>GARealGenome&amp; gr = ga.statistics().bestIndividual();<BR><BR>// then you can use either the ::gene(int i) method<BR>x = gr.gene(i); // 0&lt;= i &lt;= gr.size()<BR>// or the indexing operator:<BR>x = gr[i];<BR><BR>// or you can even cast the genome to a pointer to<BR>// double, and then index this directly:<BR>double* pgenome = (double*) gr; <BR>x = pgenome[i];<BR>// this holds in general for any genome calass that<BR>// is derived from GAArray<T>, not only for<BR>GARealGenome.<BR><BR>Have a look at the header files:<BR>GAArray.h and GA1DArrayGenome.h<BR><BR><BR>Cheers<BR><BR>Giovanni<BR><BR>&gt; --- Luca Moscatelli <LUCASTER@GMAIL.COM>wrote: <BR>&gt; &gt; Hi to all.<BR>&gt; &gt; I tried the first examples and they are all clear,<BR>&gt; &gt; and I saw that the<BR>&gt; &gt; best individual is only printed at the end of
 each<BR>&gt; &gt; program, but what<BR>&gt; &gt; have I to do if I want to use it?<BR>&gt; &gt; <BR>&gt; &gt; I'll try to be more clear:<BR>&gt; &gt; I created a GARealAlleleSet, filled and inserted<BR>&gt; &gt; into the<BR>&gt; &gt; GARealGenome, then I evolved it.<BR>&gt; &gt; If I print the best individual like in the<BR>&gt; examples<BR>&gt; &gt; with "cout &lt;&lt;<BR>&gt; &gt; ga.statistics().bestIndividual()" I see the right<BR>&gt; &gt; value, but now I<BR>&gt; &gt; want, for example, to add 1 to this value...<BR>&gt; &gt; <BR>&gt; &gt; Now, I looked the documentation and I saw that the<BR>&gt; &gt; ga.statistics().bestIndividual() returns a<BR>&gt; &gt; GaGenome&amp;, how can I put<BR>&gt; &gt; this value(s) in a float variable(s)?<BR>&gt; &gt; <BR>&gt; &gt; Thanks in advance to all of you!<BR>&gt; &gt; Bye,<BR>&gt; &gt; Luca<BR>&gt; &gt; _______________________________________________<BR>&gt; &gt; galib mailing list<BR>&gt; &gt; galib@mit.edu<BR>&gt; &gt;
 http://mailman.mit.edu/mailman/listinfo/galib<BR>&gt; &gt; <BR>&gt; <BR>&gt; <BR>&gt; <BR>&gt; <BR>&gt; <BR>&gt;<BR>___________________________________________________________ALL-NEW<BR>&gt; Yahoo! Messenger - all new features - even more fun!<BR>&gt; http://uk.messenger.yahoo.com<BR>&gt; <BR><BR><BR><BR><BR><BR>___________________________________________________________ALL-NEW Yahoo! Messenger - all new features - even more fun! http://uk.messenger.yahoo.com<BR>_______________________________________________<BR>galib mailing list<BR>galib@mit.edu<BR>http://mailman.mit.edu/mailman/listinfo/galib<BR></BLOCKQUOTE><p>
        
                <hr size=1>Do you Yahoo!?<br> 
Check out the new Yahoo! Front Page. <a href="http://www.yahoo.com">www.yahoo.com</a>