<div><font color="#333399">Hi Perone ,</font></div>
<div><font color="#333399"> Thanks for your reply. But I think that is an genome based objective function.</font></div>
<div><font color="#333399">Anyhow I got the solution for population based objective function. Posting my solution here. </font></div>
<div><font color="#333399">Hope this will help others. Hope I am correct!!</font></div>
<div> </div>
<div>
<p>#include <iostream><br>#include<ga/GAPopulation.h><br>#include <ga/GASStateGA.h><br>#include <ga/GA2DBinStrGenome.h></p>
<p>using namespace std;<br>void popEvaluator(GAPopulation & p);</p>
<p>int main()<br>{<br> <br> int width=32;<br> int height=9; <br> GARandomBit();<br> GA2DBinaryStringGenome genome(width, height); //Note: No objective function here<br> GAPopulation pop(genome,15); // Create a population object
<br> pop.evaluator(popEvaluator); // Population evaluator<br> GASteadyStateGA ga(pop); // Attach population object to ga<br> ga.populationSize(10);<br> ga.initialize
(); <br> return 0;</p>
<p>} </p>
<p>void popEvaluator(GAPopulation & p)<br>{<br> int value=0; <br> for(int i=0; i<p.size(); i++) <br> {<br> GA2DBinaryStringGenome &genome=(GA2DBinaryStringGenome &)p.individual(i);<br> for(int j=0;j<
genome.height();j++)<br> {<br> for(int k=0;k<genome.width();k++)<br> {<br> if(genome.gene(j,k)==0)<br> {<br> value--; // Evaluate objective score
</p>
<p> }<br> else<br> {<br> value++;<br> }</p>
<p> }</p>
<p> }<br> p.individual(i).score(value); // Set objective score to the individual<br> cout<<"Fitness :"<<p.individual(i).score()<<endl;<br> cout<<
p.individual(i)<<endl;<br> }<br>}<br></p><br><font color="#333399">Thanks N Regards</font></div>
<div><font color="#333399">Raghavendra Prasad NL</font></div>
<div><font color="#333399">India</font></div>
<div> </div>
<div><span class="gmail_quote">On 9/29/05, <b class="gmail_sendername"><a href="mailto:galib-request@mit.edu">galib-request@mit.edu</a></b> <<a href="mailto:galib-request@mit.edu">galib-request@mit.edu</a>> wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Send galib mailing list submissions to<br> <a href="mailto:galib@mit.edu">galib@mit.edu</a><br><br>To subscribe or unsubscribe via the World Wide Web, visit
<br> <a href="http://mailman.mit.edu/mailman/listinfo/galib">http://mailman.mit.edu/mailman/listinfo/galib</a><br>or, via email, send a message with subject or body 'help' to<br> <a href="mailto:galib-request@mit.edu">
galib-request@mit.edu</a><br><br>You can reach the person managing the list at<br> <a href="mailto:galib-owner@mit.edu">galib-owner@mit.edu</a><br><br>When replying, please edit your Subject line so it is more specific
<br>than "Re: Contents of galib digest..."<br><br><br>Today's Topics:<br><br> 1. How to define a population based objective function? (RPrasad)<br> 2. Re: How to define a population based objective function?<br>
(Christian Samuel Perone)<br><br><br>----------------------------------------------------------------------<br><br>Date: Wed, 28 Sep 2005 11:05:49 +0530<br>From: RPrasad <<a href="mailto:raghavendraprasad.nl@gmail.com">
raghavendraprasad.nl@gmail.com</a>><br>To: <a href="mailto:galib@mit.edu">galib@mit.edu</a><br>Subject: [galib] How to define a population based objective function?<br>Message-ID: <<a href="mailto:602605e105092722356a3b15b6@mail.gmail.com">
602605e105092722356a3b15b6@mail.gmail.com</a>><br>Content-Type: multipart/alternative;<br> boundary="----=_Part_1590_21226373.1127885749295"<br>MIME-Version: 1.0<br>Precedence: list<br>Reply-To: RPrasad <
<a href="mailto:raghavendraprasad.nl@gmail.com">raghavendraprasad.nl@gmail.com</a>><br>Message: 1<br><br>------=_Part_1590_21226373.1127885749295<br>Content-Type: text/plain; charset=ISO-8859-1<br>Content-Transfer-Encoding: quoted-printable
<br>Content-Disposition: inline<br><br>Hello friends,<br>I am working on a research project.<br>I have a genome type GA2DBinaryStringGenome genome(1, n); //Specific reaso=<br>n<br>to use this kind of genome<br>For n=3D5, each genome will look like this
<br>1<br>0<br>0<br>1<br>1<br>GASteadyStateGA ga(genome); // creating genetic algorithm object<br>ga.populationSize(5); // I want to invoke the population based objective<br>function at this point<br>Now the population will look something like this
<br>10101<br>01101<br>01001<br>10110<br>00110<br>Now I want to define a objective function for this population. How to<br>create a population-based objective function?<br>Please send me any code that might give a insight into this.
<br>Thanks N Regards<br>Raghavendra Prasad NL<br><a href="mailto:RaghavendraPrasad.NL@gmail.com">RaghavendraPrasad.NL@gmail.com</a><br><br>------=_Part_1590_21226373.1127885749295<br>Content-Type: text/html; charset=ISO-8859-1
<br>Content-Transfer-Encoding: quoted-printable<br>Content-Disposition: inline<br><br><br clear=3D"all"><br><div>Hello friends,</div><br><div>I am working on a research project.</div>
<br><div>&nbsp;</div><br><div>I have a genome type&nbsp; GA2DBinaryStringGenome genome(1, n);&nbsp; =<br>//Specific reason to use this kind of genome</div><br><div>For n=3D5, each genome will look like this </div>
<br><div>1</div><br><div>0</div><br><div>0</div><br><div>1</div><br><div>1</div><br><div>GASteadyStateGA ga(genome);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // creating =
<br>genetic algorithm object</div><br><div>ga.populationSize(5);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=<br>nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
<br>p; // I want to invoke the population based objective function at this poin=<br>t</div><br><div>&nbsp;</div><br><div>Now the population will look something like this</div><br><div>&nbsp;</div>
<br><div><br><div>10101</div><br><div>01101</div><br><div>01001</div><br><div>10110</div><br><div>00110</div><br><div>&nbsp;</div><br><div>Now&nbsp;I want to define a objective function for this population.&nb=
<br>sp;&nbsp;How to create a population-based objective function? </div><br><div>Please send me any code that might give a insight into this.</div><br><div>&nbsp;</div><br><div>&nbsp;</div>
<br><div>Thanks&nbsp;N Regards</div><br><div>Raghavendra Prasad NL</div><br><div><a onclick=3D"return top.js.OpenExtLink(window,event,this)" href=3D"ma=<br>ilto:<a href="mailto:RaghavendraPrasad.NL@gmail.com">
RaghavendraPrasad.NL@gmail.com</a>" target=3D"_blank">RaghavendraPrasad.NL=<br>@<a href="http://gmail.com">gmail.com</a></a></div></div><br><br>------=_Part_1590_21226373.1127885749295--
<br>------------------------------<br><br>Date: Wed, 28 Sep 2005 10:49:40 -0300 (ART)<br>From: Christian Samuel Perone <<a href="mailto:christian_perone@yahoo.com.br">christian_perone@yahoo.com.br</a>><br>To: <a href="mailto:galib@mit.edu">
galib@mit.edu</a><br>Subject: Re: [galib] How to define a population based objective function?<br>Message-ID: <<a href="mailto:20050928134940.95927.qmail@web31905.mail.mud.yahoo.com">20050928134940.95927.qmail@web31905.mail.mud.yahoo.com
</a>><br>In-Reply-To: <<a href="mailto:602605e105092722356a3b15b6@mail.gmail.com">602605e105092722356a3b15b6@mail.gmail.com</a>><br>Content-Type: text/plain; charset=iso-8859-1<br>MIME-Version: 1.0<br>Content-Transfer-Encoding: 8bit
<br>Precedence: list<br>Message: 2<br><br>Hello,<br>You can define the Objective function first<br>declaring the function like this:<br><br>float Objective(GAGenome& g) {<br>GA2DBinaryStringGenome & genome =<br>(GA2DBinaryStringGenome &)g;
<br>float score=0.0;<br>int count=0;<br>for(int i=0; i<genome.width(); i++){<br> for(int j=0; j<genome.height(); j++){<br> if(genome.gene(i,j) == 0 && count%2 == 0)<br> score += 1.0;<br> if(genome.gene
(i,j) == 1 && count%2 != 0)<br> score += 1.0;<br> count++;<br> }<br>}<br>return score;<br>}<br><br>then in the declaration of the genome you<br>define like this:<br><br>GA2DBinaryStringGenome genome(width, height,
<br>objective);<br><br>Read the ex1.C in the examples directory of default<br>galib package.<br><br>I hope this help you.<br><br>- Christian S. Perone<br><br>--- RPrasad <<a href="mailto:raghavendraprasad.nl@gmail.com">
raghavendraprasad.nl@gmail.com</a>> escreveu:<br><br>> Hello friends,<br>> I am working on a research project.<br>> I have a genome type GA2DBinaryStringGenome<br>> genome(1, n); //Specific reason<br>> to use this kind of genome
<br>> For n=5, each genome will look like this<br>> 1<br>> 0<br>> 0<br>> 1<br>> 1<br>> GASteadyStateGA ga(genome); // creating genetic<br>> algorithm object<br>> ga.populationSize(5); // I want to invoke the
<br>> population based objective<br>> function at this point<br>> Now the population will look something like this<br>> 10101<br>> 01101<br>> 01001<br>> 10110<br>> 00110<br>> Now I want to define a objective function for this
<br>> population. How to<br>> create a population-based objective function?<br>> Please send me any code that might give a insight<br>> into this.<br>> Thanks N Regards<br>> Raghavendra Prasad NL<br>>
<a href="mailto:RaghavendraPrasad.NL@gmail.com">RaghavendraPrasad.NL@gmail.com</a><br>> > _______________________________________________<br>> galib mailing list<br>> <a href="mailto:galib@mit.edu">galib@mit.edu
</a><br>> <a href="http://mailman.mit.edu/mailman/listinfo/galib">http://mailman.mit.edu/mailman/listinfo/galib</a><br>><br><br><br><br><br><br><br><br><br><br>_______________________________________________________
<br>Novo Yahoo! Messenger com voz: ligações, Yahoo! Avatars, novos emoticons e muito mais. Instale agora!<br><a href="http://www.yahoo.com.br/messenger/">www.yahoo.com.br/messenger/</a><br>------------------------------<br>
<br>_______________________________________________<br>galib mailing list<br><a href="mailto:galib@mit.edu">galib@mit.edu</a><br><a href="http://mailman.mit.edu/mailman/listinfo/galib">http://mailman.mit.edu/mailman/listinfo/galib
</a><br><br><br>End of galib Digest, Vol 27, Issue 5<br>************************************<br></blockquote></div><br><br clear="all"><br>-- <br>Regards<br>Raghavendra Prasad NL<br>