[galib] how to add my custom arguments to Initializer and Objective?
matthew wall
mbwall at MIT.EDU
Sat Feb 26 18:03:53 EST 2005
On 26 Feb 2005, at 15:13, Jose daVeiga wrote:
> I am using GA lib for a plugin I am writing for MAYA (www.maya.com).
>
> To initialize my genome I need to populate it with the xyz values of
> surfaces. I also need to call MAYA through its specific API to be able
> to evaluate the surfaces I would be updating with the values from the
> genes. I am able to do all the MAYA stuff I need but now I need to get
> the genetic stuff to work. In sum, I would need my initializer and
> objective functions to look like this:
>
> float Objective1( GAGenome& g, MDagPath objectPath, MObject component)
> void DeterministicInitializer (GAGenome&, MDagPath objectPath, MObject
> component)
>
> I could possibly set objectPath and component as global variables, and
> then access them inside my Objective1 and
> DeterministicInitializer...but
> that’s just wrong! ;)
>
> I've been reading the documentation and I can't seem to figure out a
> way
> to do this. Any suggestions would be welcome.
use the userData in the genome to store the MDagPath and MObject parts.
create your own userdata class (derived from the GAGenome::UserData),
then in your initializer instantiate one and attach it to each genome,
or a separate one for each genome (depending on what you are trying to
do) using the userData method of the genome.
alternatively you can use the userData bound to a population, if the
userdata needs to know about more than just a single genome.
> PS- I am also looking to write a progress bar, when the duration is the
> number of generations, and I am wondering how can I get the current
> generation number after evolve() is called/running?
do it like this:
GASteadyStateGA ga(genome);
ga.initialize();
while(!ga.done()) {
ga++;
cout << ga.generation() << endl;
}
some of the example contain this construct, and i think it is shown in
the documentation in the section about creating your own genetic
algorithm class.
m
More information about the galib
mailing list