[galib] The Genome Constructor and Member Functions

Xavier Chardon xavier.chardon at rennes.inra.fr
Wed Aug 20 08:32:13 EDT 2008


Hi,

You need to derive your own genome and define the Evaluator() method.

Let's say you have a class "Application" with a 
ObjectiveFunction(MyGenome) member.
Then you create your own genome (let's call it MyGenome). You give it as 
attribute a pointer to an instance of Application (name: mpApplication)

Then you must write something like:

float MyGenome::Evaluator(GAGenome& g)
{
MyGenome& genome = (MyGenome&) g;
float score = genome.mpApplication->ObjectiveFunction(g);
return score;
}

To derive your own genome, you will need to read the help of GALib on 
this topic. In your case, there won't be much to do.

Hope this is clear. Not sure it's the best solution, but it works for 
me. I don't have much time right now to elaborate on that, but feel free 
to contact me next week if you need more explanations.

Xavier



Alitis a écrit :
> Hello,
>      I am using GALib as part of a network simulation project on the
> application layer of a simulated node. Due to the way the simulator I
> am using is set up, the application layer must be a C++ class and
> everything in the application layer must be a member of that class.
> The problem I am experiencing is during construction of a genome. The
> constructor requires an pointer to the Objective function of type *
> (GAGenome&). Since the Objective function is now a member function of
> the application layer class, its type changes to something which is
> not recognized by the constructor. I can't simply make it a static
> function, as it needs access to the application layer's data members
> in order to compute a score. A number of FAQs have advised against
> trying to cast a pointer to a member function into a standard function
> pointer, since the size of the former is often greater than that of
> the latter. As such I seem to be able to neither make the function
> static, nor cast it into a form acceptable to the Genome constructor.
> Any suggestions as to how I can get around this difficulty would be
> greatly appreciated.
> _______________________________________________
> galib mailing list
> galib at mit.edu
> http://mailman.mit.edu/mailman/listinfo/galib
>
>   

-- 
Xavier Chardon
Thésard Institut de l'élevage / INRA
Projet ACTA "modélisation environnementale des systèmes bovins et porcins"

xavier.chardon at inst-elevage.asso.fr
xavier.chardon at rennes.inra.fr
02 23 48 50 91




More information about the galib mailing list