[galib] customization problem

Tomasz Samotyjak t.samotyjak at pwsz.elblag.pl
Thu Jun 9 07:41:22 EDT 2005


there are (at least) two approaches.  the first approach is to use an 
existing genome class and the userData object bound to each genome.  
the second approach is to create your own genome class.

the first approach goes something like this:

class TwoDData : public UserData {
   ...
};

float ObjFunc(GAGenome& g) {
   TwoDData* data = DYN_CAST(TwoDData*, g.userData());
   assert(data);
   ...
}

main() {
   TwoDData data;
   data.readFromDisk();
   GA1DArrayGenome<int> genome(10, ObjFunc);
   genome.userData(&data);
   GASimpleGA ga(genome);
   ga.evolve();
}



the second approach goes something like this:

class TwoDDataGenome : public GA1DArrayGenome<int> {
   static int* arraydata;
   static void ReadData();
   ...
};

float ObjFunc(GAGenome& g) {
   TwoDDataGenome& genome = DYN_CAST(TwoDDataGenome&, g);
   ...
}

main() {
   TwoDDataGenome::ReadData();
   TwoDDataGenome genome(10, ObjFunc);
   GASimpleGA ga(genome);
   ga.evolve();
}


hope that helps...

m

Dnia czwartek, 9 czerwca 2005 09:18, #SAWHNEY ADITI# napisał:
> Supposing these below are the protoptypes for my customized initializer and
> objectiev functions.
>
> float objective(GAGenome &, float);
>
> void RouteInitializer(GAGenome &, float );
>
>
> my question is how now do i pass the float parameter to teh fiunctions.
> normally to make gagenome use my customized function i would just issue:
> GARealGenome genome(numCustomer+numVeh, alleles, objective);
>
> genome.initializer(RouteInitializer);
>
> but how will i pass my float parameter? oor should i make my parameter a
> global variable?
>
> I'm sorry for the amateurish quetsiosn but i am new to galib and c++.
>
> Thanks,
>
> Aditi
>
>
> ________________________________
>
> From: galib-bounces at mit.edu on behalf of Christian S. Perone
> Sent: Tue 6/7/2005 3:30 AM
> To: galib at mit.edu
> Subject: Re: [galib] minimization problem
>
>
>
> Hello,
>
> *GALinearScaling*(float c = /gaDefLinearScalingMultiplier/)
>     The fitness scores are derived from the objective scores using the
>     linear scaling method described in Goldberg's book. You can specify
>     the scaling coefficient. *Negative objective scores are not allowed
>     with this method.* Objective scores are converted to fitness scores
>     using the relation
>
> You can read in http://lancet.mit.edu/galib-2.4/API.html about the
> Linear Scaling that not
> allow negative scores. To minimize the objective function just call
> ga.minimize(), like Anthony said.
> This function is in GABaseGA.h:
>     (...)
>        int minimize() { return minimaxi(MINIMIZE); }
>
> and the minimaxi() is in GABaseGA.c:
>     (...)
>        if(m==MINIMIZE)
>           pop->order(GAPopulation::LOW_IS_BEST);
>
> I hope that this can help.
>
> energenius energenius wrote:
> > Hi,
> >
> > I'm using GALib.2.4.5 with VC6.0. I want to minimize my objective
> > function. Although my program works properly in maximization, when I
> > use ga.minimize(), it stucks and gives no response. How can i solve
> > this problem?
> >
> > May adding a minus sign in front of the objective function be a solution?
> >
> > Thanks in advance.
> >
> > _________________________________________________________________
> > En etkili ve güvenilir PC Korumayi tercih edin, rahat edin!
> > http://www.msn.com.tr/security/
> >
> > _______________________________________________
> > galib mailing list
> > galib at mit.edu
> > http://mailman.mit.edu/mailman/listinfo/galib
>
> ____________________________________________________
> Yahoo! Mail, cada vez melhor: agora com 1GB de espaço grátis!
> http://mail.yahoo.com.br _______________________________________________
> galib mailing list
> galib at mit.edu
> http://mailman.mit.edu/mailman/listinfo/galib
>
>
>
> _______________________________________________
> galib mailing list
> galib at mit.edu
> http://mailman.mit.edu/mailman/listinfo/galib

-- 
Pozdrawiam
Tomasz Samotyjak
http://samotyjak.pwsz.elblag.pl



More information about the galib mailing list