[galib] Custom initializer

Michele Conconi michele.conconi at unibo.it
Wed Apr 15 08:52:54 EDT 2009


Hi everybody.

I' trying to define my own initializer for a GARealGenome genome. 
Basically I can obtain my initial value, but the progran than does not 
run, giving me many times this error message:

GAAlleleSet::allele<unsigned int>:
this method has not been defined.
c:\galib27\ga\GAAllele.C : 219

Here  is my code
--------------------------------
#include <stdio.h>
#include <math.h>

#include "GASimpleGA.h"
#include "GARealGenome.h"
#include "std_stream.h"

#define cout STD_COUT

float Objective(GAGenome &);
void MyInitializer(GAGenome& g);

int
main(int argc, char **argv)
{

  unsigned int seed = 0;

  int popsize  = 5;
  int ngen     = 10;
  float pmut   = 0.001;
  float pcross = 0.9;

  unsigned int n=3;
  float *target = new float[n];
  float min[] = {-5, -5,  -5};
  float max[] = {5, 10,  15};
  unsigned int i;

 for(i=0; i<n; i++)
{
target[i] = GARandomFloat(min[i], max[i]);
cout<<target[i]<<"  ";
}
    
cout << "\n\n";

GARealAlleleSetArray alleles;
alleles.add(min[0],max[0]);
alleles.add(min[1],max[1]);
alleles.add(min[2],max[2]);

GARealGenome genome(alleles, Objective, (void *)target);

GASimpleGA ga(genome);
ga.populationSize(popsize);
ga.nGenerations(ngen);
ga.pMutation(pmut);
ga.pCrossover(pcross);

ga.scoreFilename("bog.dat");
ga.flushFrequency(50);

cout<<genome<<"\n\n";
genome.initializer(MyInitializer);
genome.initialize();
cout<<genome<<"\n\n";

ga.evolve(seed);

genome = ga.statistics().bestIndividual();
cout<<genome<<"\n\n";

delete [] target;

return 0;
}


float
Objective(GAGenome& g)
{
  GARealGenome & genome = (GARealGenome &)g;
  float *sequence = (float *)g.userData();
  float value=0;
  for(int i=0; i<3; i++)
    value += 1.0 / (1.0 + fabs(genome.gene(i) - sequence[i]));
  return value;
}

void
MyInitializer(GAGenome& g)
{
    GARealGenome & genome = (GARealGenome &)g;
    for(int i=0; i<3; i++)
        genome.gene(i,2);
}
---------------------------------------------------------

What's the problem? I really do not understand and, still worst, I do 
not know how to find more galib example or other information to solve 
this problem. I reed the galibdoc.pdf, looking for answere in the 
mailinglist, studied the examples. What's the next step to improve my 
(poor) ability? Thanks in advance for your help

Michele

-- 
* Eng. Michele Conconi*
Ph.D. student
DIEM - Dept. of Mechanical Engineering
Alma Mater Studiorum - University of Bologna
Viale Risorgimento 2, 40136, Bologna, Italy
Email: michele.conconi at unibo.it
Website: http://www.diem.ing.unibo.it/grab
Office: (+39) 051 20 93451
Mobile: (+39) 329 0287996



* INFORMAZIONE RISERVATA E CONFIDENZIALE *
Questo messaggio contiene informazioni riservate e confidenziali.
Se il lettore non fosse il destinatario del messaggio, inoltrato e 
ricevuto per errore,
il testo dovrà essere immediatamente cancellato dal computer del ricevente.
E' assolutamente proibita qualunque circolazione, disseminazione o
copia del messaggio spedito e/o ricevuto per errore.

* CONFIDENTIALITY and WARNING NOTICE *
This message may contain legally privileged or confidential information.
If the reader is not the intended recipient, you received this message 
in error
and it should therefore be deleted from your computer at once.
Any dissemination, distribution and copying of a message
mistakenly sent or received is strictly forbidden.



More information about the galib mailing list