<p>Hello,</p>
<p> </p>
<p>I am new to gelib and when trying to define a genome I get the following error:</p>
<p> </p>
<p>
<p>ex1.c: In function ‘int altermain(task_info)’:</p>
<p>ex1.c:49: error: missing template arguments before ‘genome’</p>
<p>ex1.c:49: error: expected ‘;’ before ‘genome’</p>
<p>ex1.c:57: error: ‘genome’ was not declared in this scope</p>
</p>
<p> </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> </p>
<p>
<p> </p>
<p>#include <ga/GASimpleGA.h><span style="white-space: pre;"> </span>// we're going to use the simple GA</p>
<p>#include <ga/GA2DBinStrGenome.h> // and the 2D binary string genome</p>
<p>#include <ga/std_stream.h></p>
<p>#include <ga/GA1DArrayGenome.h></p>
<p>#define cout STD_COUT</p>
<p>#include "header.h"</p>
<p> </p>
<p>#include <ga/GAArray.h></p>
<p>#include <ga/GAGenome.h></p>
<p>#include <ga/GAAllele.h></p>
<p> </p>
<p> </p>
<p> int NUM_TAR = 29;</p>
<p> int MAX_NUM = 15;</p>
<p> </p>
<p>int altermain(task_info tasklist)</p>
<p>{</p>
<p> cout << "Example 1\n\n";</p>
<p> cout << "This program tries to fill a 2DBinaryStringGenome with\n";</p>
<p> cout << "alternating 1s and 0s using a SimpleGA\n\n"; cout.flush();</p>
<p> </p>
<p>// See if we've been given a seed to use (for testing purposes). 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> </p>
<p> </p>
<p>int argc = 0;</p>
<p>char **argv = NULL;</p>
<p> for(int ii=1; ii<argc; ii++) {</p>
<p> if(strcmp(argv[ii++],"seed") == 0) {</p>
<p> GARandomSeed((unsigned int)atoi(argv[ii]));</p>
<p> }</p>
<p> }</p>
<p> </p>
<p>// Declare variables for the GA parameters and set them to some default values.</p>
<p> </p>
<p> int width = 10;</p>
<p> int height = 5;</p>
<p> int popsize = 30;</p>
<p> int ngen = 400;</p>
<p> float pmut = 0.001;</p>
<p> float pcross = 0.9;</p>
<p> </p>
<p> </p>
<p>// Now create the GA and run it. First we create a genome of the type that</p>
<p>// we want to use in the GA. 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> GA1DArrayGenome genome(NUM_TAR, Objective); </p>
<p> </p>
<p> //GA2DBinaryStringGenome genome(width, height, Objective);</p>
<p> </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. And finally we tell it to evolve itself.</p>
<p> </p>
<p> GASimpleGA ga(genome);</p>
<p> ga.populationSize(popsize);</p>
<p> ga.nGenerations(ngen);</p>
<p> ga.pMutation(pmut);</p>
<p> ga.pCrossover(pcross);</p>
<p> ga.evolve();</p>
<p> </p>
<p>// Now we print out the best genome that the GA found.</p>
<p> </p>
<p> cout << "The GA found:\n" << ga.statistics().bestIndividual() << "\n";</p>
<p> </p>
<p>// That's it!</p>
<p> </p>
<p> </p>
<p> return 0;</p>
<p>}</p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p>// This is the objective function. All it does is check for alternating 0s and</p>
<p>// 1s. 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. No</p>
<p>// penalties are assigned. </p>
<p>// We have to do the cast because a plain, generic GAGenome doesn't have </p>
<p>// the members that a GA2DBinaryStringGenome has. 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> </p>
<p>/*</p>
<p>float</p>
<p>Objective(GAGenome& g) {</p>
<p> GA2DBinaryStringGenome & genome = (GA2DBinaryStringGenome &)g;</p>
<p> float score=0.0;</p>
<p> int count=0;</p>
<p> for(int i=0; i<genome.width(); i++){</p>
<p> for(int j=0; j<genome.height(); j++){</p>
<p> if(genome.gene(i,j) == 0 && count%2 == 0)</p>
<p><span style="white-space: pre;"> </span>score += 1.0;</p>
<p> if(genome.gene(i,j) == 1 && count%2 != 0)</p>
<p><span style="white-space: pre;"> </span>score += 1.0;</p>
<p> count++;</p>
<p> }</p>
<p> }</p>
<p> return score;</p>
<p>}</p>
<p>*/</p>
<p> </p>
<p>float Objective(GAGenome& g) </p>
<p>{</p>
<p> </p>
<p>GA1DArrayGenome & genome = (GA1DArrayGenome &)g;</p>
<p> </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<= 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<genome.length();i++)</p>
<p><span style="white-space: pre;"> </span>{</p>
<p><span style="white-space: pre;"> </span> 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<=MAX_NUM;j++){</p>
<p><span style="white-space: pre;"> </span> if(tiempo_contador[j]>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>