<p>Hello,</p>
<p>&nbsp;</p>
<p>I am new to gelib and when trying to define a genome I get the following error:</p>
<p>&nbsp;</p>
<p>
<p>ex1.c: In function &lsquo;int altermain(task_info)&rsquo;:</p>
<p>ex1.c:49: error: missing template arguments before &lsquo;genome&rsquo;</p>
<p>ex1.c:49: error: expected &lsquo;;&rsquo; before &lsquo;genome&rsquo;</p>
<p>ex1.c:57: error: &lsquo;genome&rsquo; was not declared in this scope</p>
</p>
<p>&nbsp;</p>
<p>I am modifying the ex1.c example changing the GA2Dbinary to a GA1DArrayGenome and I have defined a new objetive function.</p>
<p>Thanks in advance.</p>
<p>&nbsp;</p>
<p>
<p>&nbsp;</p>
<p>#include &lt;ga/GASimpleGA.h&gt;<span style="white-space: pre;"> </span>// we're going to use the simple GA</p>
<p>#include &lt;ga/GA2DBinStrGenome.h&gt; // and the 2D binary string genome</p>
<p>#include &lt;ga/std_stream.h&gt;</p>
<p>#include &lt;ga/GA1DArrayGenome.h&gt;</p>
<p>#define cout STD_COUT</p>
<p>#include "header.h"</p>
<p>&nbsp;</p>
<p>#include &lt;ga/GAArray.h&gt;</p>
<p>#include &lt;ga/GAGenome.h&gt;</p>
<p>#include &lt;ga/GAAllele.h&gt;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp; int NUM_TAR = 29;</p>
<p>&nbsp; int MAX_NUM = 15;</p>
<p>&nbsp;</p>
<p>int altermain(task_info tasklist)</p>
<p>{</p>
<p>&nbsp; cout &lt;&lt; "Example 1\n\n";</p>
<p>&nbsp; cout &lt;&lt; "This program tries to fill a 2DBinaryStringGenome with\n";</p>
<p>&nbsp; cout &lt;&lt; "alternating 1s and 0s using a SimpleGA\n\n"; cout.flush();</p>
<p>&nbsp;</p>
<p>// See if we've been given a seed to use (for testing purposes). &nbsp;When you</p>
<p>// specify a random seed, the evolution will be exactly the same each time</p>
<p>// you use that seed number.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>int argc = 0;</p>
<p>char **argv = NULL;</p>
<p>&nbsp; for(int ii=1; ii&lt;argc; ii++) {</p>
<p>&nbsp; &nbsp; if(strcmp(argv[ii++],"seed") == 0) {</p>
<p>&nbsp; &nbsp; &nbsp; GARandomSeed((unsigned int)atoi(argv[ii]));</p>
<p>&nbsp; &nbsp; }</p>
<p>&nbsp; }</p>
<p>&nbsp;</p>
<p>// Declare variables for the GA parameters and set them to some default values.</p>
<p>&nbsp;</p>
<p>&nbsp; int width &nbsp; &nbsp;= 10;</p>
<p>&nbsp; int height &nbsp; = 5;</p>
<p>&nbsp; int popsize &nbsp;= 30;</p>
<p>&nbsp; int ngen &nbsp; &nbsp; = 400;</p>
<p>&nbsp; float pmut &nbsp; = 0.001;</p>
<p>&nbsp; float pcross = 0.9;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>// Now create the GA and run it. &nbsp;First we create a genome of the type that</p>
<p>// we want to use in the GA. &nbsp;The ga doesn't operate on this genome in the</p>
<p>// optimization - it just uses it to clone a population of genomes.</p>
<p>&nbsp; GA1DArrayGenome genome(NUM_TAR, Objective);&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp; //GA2DBinaryStringGenome genome(width, height, Objective);</p>
<p>&nbsp;</p>
<p>// Now that we have the genome, we create the genetic algorithm and set</p>
<p>// its parameters - number of generations, mutation probability, and crossover</p>
<p>// probability. &nbsp;And finally we tell it to evolve itself.</p>
<p>&nbsp;</p>
<p>&nbsp; GASimpleGA ga(genome);</p>
<p>&nbsp; ga.populationSize(popsize);</p>
<p>&nbsp; ga.nGenerations(ngen);</p>
<p>&nbsp; ga.pMutation(pmut);</p>
<p>&nbsp; ga.pCrossover(pcross);</p>
<p>&nbsp; ga.evolve();</p>
<p>&nbsp;</p>
<p>// Now we print out the best genome that the GA found.</p>
<p>&nbsp;</p>
<p>&nbsp; cout &lt;&lt; "The GA found:\n" &lt;&lt; ga.statistics().bestIndividual() &lt;&lt; "\n";</p>
<p>&nbsp;</p>
<p>// That's it!</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp; return 0;</p>
<p>}</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>// This is the objective function. &nbsp;All it does is check for alternating 0s and</p>
<p>// 1s. &nbsp;If the gene is odd and contains a 1, the fitness is incremented by 1.</p>
<p>// If the gene is even and contains a 0, the fitness is incremented by 1. &nbsp;No</p>
<p>// penalties are assigned.&nbsp;</p>
<p>// &nbsp; We have to do the cast because a plain, generic GAGenome doesn't have&nbsp;</p>
<p>// the members that a GA2DBinaryStringGenome has. &nbsp;And it's ok to cast it</p>
<p>// because we know that we will only get GA2DBinaryStringGenomes and</p>
<p>// nothing else.</p>
<p>&nbsp;</p>
<p>/*</p>
<p>float</p>
<p>Objective(GAGenome&amp; g) {</p>
<p>&nbsp; GA2DBinaryStringGenome &amp; genome = (GA2DBinaryStringGenome &amp;)g;</p>
<p>&nbsp; float score=0.0;</p>
<p>&nbsp; int count=0;</p>
<p>&nbsp; for(int i=0; i&lt;genome.width(); i++){</p>
<p>&nbsp; &nbsp; for(int j=0; j&lt;genome.height(); j++){</p>
<p>&nbsp; &nbsp; &nbsp; if(genome.gene(i,j) == 0 &amp;&amp; count%2 == 0)</p>
<p><span style="white-space: pre;"> </span>score += 1.0;</p>
<p>&nbsp; &nbsp; &nbsp; if(genome.gene(i,j) == 1 &amp;&amp; count%2 != 0)</p>
<p><span style="white-space: pre;"> </span>score += 1.0;</p>
<p>&nbsp; &nbsp; &nbsp; count++;</p>
<p>&nbsp; &nbsp; }</p>
<p>&nbsp; }</p>
<p>&nbsp; return score;</p>
<p>}</p>
<p>*/</p>
<p>&nbsp;</p>
<p>float Objective(GAGenome&amp; g)&nbsp;</p>
<p>{</p>
<p>&nbsp;</p>
<p>GA1DArrayGenome &amp; genome = (GA1DArrayGenome &amp;)g;</p>
<p>&nbsp;</p>
<p>float score=0;</p>
<p>int i,j;</p>
<p><span style="white-space: pre;"> </span></p>
<p>int tiempo_contador[1000]; for (j=1; j&lt;= MAX_NUM; j++){tiempo_contador[j]=0;}</p>
<p><span style="white-space: pre;"> </span>//printf(" (%d)evaluacion %d ",es_inicial,contador);</p>
<p><span style="white-space: pre;"> </span>//fflush(stdout);</p>
<p><span style="white-space: pre;"> </span>for(i=0;i&lt;genome.length();i++)</p>
<p><span style="white-space: pre;"> </span>{</p>
<p><span style="white-space: pre;"> </span> &nbsp;tiempo_contador[ genome.gene(i) ]=tiempo_contador[ genome.gene(i) ]+ structarray[i].value;</p>
<p><span style="white-space: pre;"> </span>}</p>
<p><span style="white-space: pre;"> </span></p>
<p><span style="white-space: pre;"> </span>for(j=1;j&lt;=MAX_NUM;j++){</p>
<p><span style="white-space: pre;"> </span> &nbsp;if(tiempo_contador[j]&gt;score) score=tiempo_contador[j];</p>
<p><span style="white-space: pre;"> </span>}</p>
<p><span style="white-space: pre;"> </span></p>
<p><span style="white-space: pre;"> </span>return(score);<span style="white-space: pre;"> </span></p>
<p>}</p>
</p>