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

Mert Tas mert_tas at yahoo.com
Tue Nov 9 02:37:41 EST 2004


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 ...


Today's Topics:

1. Obtain "bestIndividual()" value (Luca Moscatelli)
2. Obtain "bestIndividual()" value (Luca Moscatelli)


> ATTACHMENT part 3.1 message/rfc822 
Date: Tue, 2 Nov 2004 18:36:29 +0100
From: Luca Moscatelli 
To: galib at mit.edu
Subject: [galib] Obtain "bestIndividual()" value

Hi to all.

I'm new with this library and I have a simple problem (I hope it's
simple... However, it is quite stupid :D).

I tried the first examples and they are all clear, but 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 with some values 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 the cout
print it?
And, how can I put this value(s) in a float variable(s)?

I hope that my problem is quite clear to you... :)

Thanks in advance to all of you!
Bye,
Luca



			
---------------------------------
Do you Yahoo!?
 Check out the new Yahoo! Front Page. www.yahoo.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.mit.edu/pipermail/galib/attachments/20041108/524f9318/attachment.htm


More information about the galib mailing list