Hi Fransis,<div><br></div><div>Genome that can hold some integers and some real numbers is very nicely explain bye Mr. Pete</div><div>just pasting the old post very much thanks to Pete</div><div><br></div><div><br></div><div>

Sandy</div><div><br></div><div><br></div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; ">Message: 1<br>Date: Mon, 26 Nov 2007 17:25:59 -0500<br>From: Peter Jay Salzman &lt;<a href="mailto:p@dirac.org" style="color: rgb(0, 0, 204); ">p@dirac.org</a>&gt;<br>

Subject: Re: [galib] Similar to Example 9 with discrete variable<br>To: GALib Mailing List &lt;<a href="mailto:galib@mit.edu" style="color: rgb(0, 0, 204); ">galib@mit.edu</a>&gt;<br>Message-ID: &lt;<a href="mailto:20071126222559.GA7474@dirac.org" style="color: rgb(0, 0, 204); ">20071126222559.GA7474@dirac.org</a>&gt;<br>

Content-Type: text/plain; charset=iso-8859-1<br><br>On Mon 26 Nov 07,  6:57 PM, Sandip Karale &lt;<a href="mailto:sandipkarale@gmail.com" style="color: rgb(0, 0, 204); ">sandipkarale@gmail.com</a>&gt; said:<br>&gt;    Hi All,<br>

&gt;<br>&gt;    I want to find maximum value in the function.<br>&gt;       y =  - ( x1^2 / x3 ) - ( x3 / x2^2 )<br>&gt;<br>&gt;    with the constraints<br>&gt;                  -5 &lt;= x1 &lt;= 5<br>&gt;                  -5 &lt;= x2 &lt;= 5<br>

&gt;    and         x3  =  { 4, 6, 7, 13}<br>&gt;<br>&gt;    I am not getting how to add the phenotype for the discrete variable x3.<br>&gt;<br>&gt;    Thanks,<br>&gt;<br>&gt;    Sandy<br><br><br><br>Hi Sandy,<br><br>I&#39;m very new to GALib, but here&#39;s my understanding:<br>

<br>One genome you can use for this problem is the GA1DArrayAlleleGenome&lt;T&gt;,<br>which can represent allels on a whole bunch of different types of genes<br>(floats, chars, ints, unsigned, coins/booleans, etc).<br><br>

Since you&#39;re only interested in floats, you should use GARealGenome, which<br>is a GA1DArrayAlleleGenome specifically for floats only.<br><br>A GARealGenome can be made one of two ways:<br><br>  1) # of genes &quot;n&quot;, an allele set &quot;aSet&quot;, ptr to ObjF<br>

<br>     In this case, you tell GALib explicitly how many genes you want (you<br>     want n of them) and a single allele set, aSet.  The allele set will<br>     be applied to all n genes.<br><br>  2) an array of allele sets &quot;aArr&quot;, ptr to ObjF<br>

<br>     In this case, you don&#39;t tell GALib explicitly how many genes you want.<br>     Instead, GALib takes your array of alleles and counts the number of<br>     elements.  If there are 3 elements of the array, then there will be<br>

     3 genes in your genome.  The first array element will hold the<br>     allele set for the 1st gene, the 2nd array element will hold the<br>     allele set for the 2nd gene, and so on.<br><br>Given the above, you&#39;re forced into wanting to use a GARealGenome, created<br>

with an array of allele sets, rather than a set of alleles.<br><br><br>Note that if x3&#39;s bounds were also [-5,5], you WOULD create your genome with:<br><br>  GAAlleleSet&lt;float&gt; aSet( -5.0F, -5.0F );<br>  GARealGenome genome( 3, aSet, objective );<br>

<br>But since x3&#39;s bounds are not the same as x1 and x2, you need to create an<br>allele array and pass the allele array to GARealGenome.  Here&#39;s how you&#39;d do<br>that (the default is &quot;inclusive&quot;, not &quot;exclusive&quot;):<br>

<br>  // Create the x3 allele<br>  GAAlleleSet&lt;float&gt; zA;<br>  zA.add(4.0);<br>  zA.add(6.0);<br>  zA.add(7.0);<br>  zA.add(13.0);<br><br>  // Create the allele array with 3 genes<br>  GARealAlleleSetArray alleles;<br>

  alleles.add(-5.0, 5.0);<br>  alleles.add(-5.0, 5.0);<br>  alleles.add(zA);<br><br><br>and that&#39;s pretty much it, to my knowledge.  Note that I&#39;m new to GALib, so<br>all this can be wrong, but I think it at least approximates the truth to<br>

zeroth order.<br><br>For my own education, I tried to implement your problem.<br><br>The first thing I did was throw it onto Excel.  Unfortunately, I trust Excel<br>a bit more than GALib at the moment.  I couldn&#39;t find a way of making solver<br>

constrain a problem to discrete values, so I set z=k for each run:<br><br>x = -8.1E-10<br>y = 5<br>z = 4<br>F  -.16<br><br>x = -8.1E-10<br>y = 5<br>z = 6<br>F  -.24<br><br>x = -8.1E-10<br>y = 5<br>z = 7<br>F  -.28<br><br>

x = -8.1E-10<br>y = 5<br>z = 13<br>F  -.52<br><br>So clearly, Excel thinks the answer to your problem is:<br><br>x = -8.1E-10<br>y = 5<br>z = 4<br>F  -.16<br><br>Since that maximizes F (-.16 is the least negative value for your objective<br>

function).<br><br>Next I tried to find an answer by hand.  By taking partial derivatives, the<br>function is maximized when:<br><br>  x = 0<br>  y = infinity<br>  z = xy<br><br>Given the constraint on y, the answer Solver should&#39;ve given me was:<br>

<br>  x = 0<br>  y = 5<br>  z = xy<br><br>I&#39;m not sure what to do with z since it&#39;s indeterminant (x*y = 5*0), but if<br>I had to take a guess, this would indicate that z=0, or given your<br>constraint on z, that z would be as small as possible.  Your smallest<br>

constraint on z is 4, so I think the analytic answer would be:<br><br>  x = 0<br>  y = 5<br>  z = 4<br><br>which is pretty much what Excel&#39;s Solver said.<br><br><br>Next I coded something up with GALib.  Here are the results with the<br>

&quot;standard&quot; GALib:<br><br>  p@satan$ time 03main<br><br>  9.88578e-05 5 4<br><br>  real    0m26.531s<br>  user    0m26.421s<br>  sys     0m0.009s<br><br>It took about 26 seconds to run, and got an answer of {0,5,4}, which is<br>

exactly what I found using both Excel&#39;s solver and calculus.<br><br>When I ran your problem through my GALibDbl version of the GALib library,<br>the returned answer was:<br><br>  p@satan$ time ./03maindbl<br><br>  1.56162e-06 5 4<br>

<br>  real    0m26.848s<br>  user    0m26.809s<br>  sys     0m0.009s<br><br>Took just as long, but the numerical &quot;zero&quot; is an order of magnitude closer<br>to actual zero.   :)<br><br>At this point, you&#39;d play with population, generation, crossover, and<br>

mutation probabilities to determine whehter x1 is really &quot;zero zero&quot; or<br>simply just something close to zero.  Basically, you&#39;d look at covergence.<br><br>The code I wrote to implement your problem is below (make sure to change<br>

TYPE to float if you&#39;re going to use the default GALib library).<br><br>Shameless Plug Alert -- Shameless Plug Alert -- Shameless Plug Alert:<br><br>  If anyone finds this answer remotely useful, please consider answering my<br>

  or other peoples&#39; questions in the future.  I still have many questions<br>  about GALib, but would be more than happy to share what I know with other<br>  people.  I could really really use some GALib using friends to converse<br>

  and share knowledge with.<br><br>Thanks,<br>Pete<br><br><br>// Compile with:<br>//    g++ -Wall -I galibdbl/ -g3 03main.cc -L galibdbl/ -lga -o 03maindbl<br>// or:<br>//    g++ -Wall -I galib/ -g3    03main.cc  -L galib/ -lga -o 03main<br>

#include &lt;cstdio&gt;<br>#include &lt;cmath&gt;<br>#include &lt;ctime&gt;<br>#include &lt;cfloat&gt;<br>#include &quot;ga/ga.h&quot;<br>#include &quot;ga/std_stream.h&quot;<br>#define TYPE double<br><br>#define INSTANTIATE_REAL_GENOME<br>

#include &quot;ga/GARealGenome.h&quot;<br>using namespace std;<br><br><br>TYPE objective(GAGenome &amp;);<br>void initializer(GAGenome &amp;);<br><br><br><br>int main( int argc, char *argv[] )<br>{<br>  GAAlleleSet&lt;TYPE&gt; zA;<br>

  zA.add(4.0);<br>  zA.add(6.0);<br>  zA.add(7.0);<br>  zA.add(13.0);<br><br>  GARealAlleleSetArray alleles;<br>  alleles.add(-5.0, 5.0);<br>  alleles.add(-5.0, 5.0);<br>  alleles.add(zA);<br><br>  GARealGenome genome(alleles, objective);<br>

  genome.initializer(initializer);<br><br><br>  GASteadyStateGA ga(genome);<br><br><br>  GASigmaTruncationScaling trunc;<br>  ga.scaling(trunc);<br><br>  ga.maximize();<br>  ga.populationSize( 800 );<br>  ga.nGenerations( 15000 );<br>

  ga.pMutation( .05 );<br>  ga.pCrossover( .8 );<br>  ga.scoreFilename(&quot;bog.dat&quot;);<br>  ga.selectScores(GAStatistics::AllScores);<br>  ga.scoreFrequency(10);<br>  ga.flushFrequency(50);<br><br>  ga.set(gaNscoreFilename, &quot;bog.dat&quot;);<br>

  ga.evolve( 0 );<br>  cout &lt;&lt; endl &lt;&lt; endl &lt;&lt; ga.statistics().bestIndividual() &lt;&lt; endl &lt;&lt; endl;<br><br>  return 0;<br>}<br><br>TYPE objective( GAGenome &amp;g )<br>{<br>  GARealGenome&amp; genome = ( GARealGenome&amp; )g;<br>

<br>  TYPE x = genome.gene(0);<br>  TYPE y = genome.gene(1);<br>  TYPE z = genome.gene(2);<br><br>  return  - ( x*x / z ) - z /(y*y );<br>}<br><br><br><br>void initializer( GAGenome &amp;g )<br>{<br>  GARealGenome&amp; genome = ( GARealGenome&amp; )g;<br>

  genome.gene(0, 3.1415926);<br>  genome.gene(1, 3.1415926);<br>  genome.gene(2, 13);<br>}<br><br><br>--<br>GPG Fingerprint: B9F1 6CF3 47C4 7CD8 D33E  70A9 A3B9 1945 67EA 951D<br>Last night I dreamt of 09-f9-11-02-9d-74-e3-5b-d8-41-56-c5-63-56-88-c0<br>

<br>&quot;A mathematician is a machine for converting coffee    <a href="mailto:p@dirac.org" style="color: rgb(0, 0, 204); ">p@dirac.org</a><br> into theorems.&quot;     -- Paul Erd?s                     <a href="http://www.dirac.org/" target="_blank" style="color: rgb(0, 0, 204); ">http://www.dirac.org</a><br>

<br><br>------------------------------<br><br>_______________________________________________<br>galib mailing list<br><a href="mailto:galib@mit.edu" style="color: rgb(0, 0, 204); ">galib@mit.edu</a><br><a href="http://mailman.mit.edu/mailman/listinfo/galib" target="_blank" style="color: rgb(0, 0, 204); ">http://mailman.mit.edu/mailman/listinfo/galib</a><br>

<br><br>End of galib Digest, Vol 52, Issue 12<br>*************************************</span></div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;"><br>

</span></font><br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><br><br>
Message: 3<br>
Date: Fri, 16 Apr 2010 18:09:04 -0300<br>
From: francis keyes &lt;<a href="mailto:fkeymo@gmail.com">fkeymo@gmail.com</a>&gt;<br>
Subject: [galib] composite genome example<br>
To: <a href="mailto:galib@mit.edu">galib@mit.edu</a><br>
Message-ID:<br>
        &lt;<a href="mailto:z2md64607cc1004161409heb156fc3q3b7bd589bc466698@mail.gmail.com">z2md64607cc1004161409heb156fc3q3b7bd589bc466698@mail.gmail.com</a>&gt;<br>
Content-Type: text/plain; charset=&quot;iso-8859-1&quot;<br>
<br>
Hey All,<br>
<br>
Does anyone have an example for a composite genome that can hold some<br>
integers and some real numbers?<br>
<br>
Thanks,<br>
Francis<br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <a href="http://mailman.mit.edu/pipermail/galib/attachments/20100416/166875e2/attachment-0001.htm" target="_blank">http://mailman.mit.edu/pipermail/galib/attachments/20100416/166875e2/attachment-0001.htm</a><br>
<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" target="_blank">http://mailman.mit.edu/mailman/listinfo/galib</a><br>
<br>
<br>
End of galib Digest, Vol 79, Issue 3<br>
************************************<br>
</blockquote></div><br><br clear="all"><br>-- <br>I wish to walk alone always...but will be happy, if you with me....<br>
</div>