passing multidimensional parameters in objective function

Matthew Wall mbwall at MIT.EDU
Wed Aug 28 20:09:52 EDT 2002


all genomes share a single userData, but each genome gets its own 
copy of evalData.  in order to use evalData, you must define a class 
that derives from GAEvalData so that when the 'clone' method is 
called (to give each genome an instance) everything will work 
properly.

to use eval data (each genome gets its own instance), do something like this:

class MyData : public GAEvalData {
   // data members here

public:
   MyData();
   virtual ~MyData();
   virtual GAEvalData* clone() {
     // copy data members here
   }
   virtual void copy(const GAEvalData& orig) {
     const MyData* d = DYN_CAST(const MyData*, orig);
     // copy data members here
   }
};

int
main() {
   MyData mydata;
   MyGenome genome(blah);
   genome.evalData(mydata);
   GASteadyStateGA ga(genome);
   ga.evolve();
   return 0;
}



to use user data (single instance shared by all genomes), do this:

int
main() {
   int foobar = 0;
   MyGenome genome(blah);
   genome.userData(&foobar);
   GASteadyStateGA ga(genome);
   ga.evolve();
   return 0;
}



hope that helps,

matthew


>Hi,
>I am using GAlib and trying to pass a bunch of multi-dimensional 
>arrays into the objective function. With the user.Data this does not 
>work (might be possible to pass all the parameters as a an array and 
>reorder them...)
>If there is any way to do this, I am more than happy to hear it!
>
>Thanks
>
>Sam



More information about the galib mailing list