Problem with GAStatistics::updateBestIndividual

Markku Laukkanen markku at ailabsolutions.com
Mon Mar 25 09:06:26 EST 2002


Hi,

I have the following kind of problem, my fitness function is extremely
sensitive for the values what it gets in & when the GA is initialized, the
GAStatistics::boa seems to be uninitialized to random values, however it
can be fixed e.g. by following code segment -->

Instead

void
GAStatistics::
updateBestIndividual(const GAPopulation & pop, GABoolean flag){
  if(boa == (GAPopulation *)0 || boa->size() == 0) return; // do nothing
  if(pop.order() != boa->order()) boa->order(pop.order());

  if(flag == gaTrue){		// reset the BOA array
    int j=0;
    for(int i=0; i<boa->size(); i++){
	// PKY here the best(i) is going to evaluate the are which has not
been initialized by Initializer function ??
      boa->best(i).copy(pop.best(j));
      if(j < pop.size()-1) j++;
    }
    return;
  }

void
GAStatistics::
updateBestIndividual(const GAPopulation & pop, GABoolean flag){
  if(boa == (GAPopulation *)0 || boa->size() == 0) return; // do nothing
  if(pop.order() != boa->order()) boa->order(pop.order());

  if(flag == gaTrue){		// reset the BOA array
    int j=0;
    int boaSize = boa->size();
	// so remove all existing ones
    for(int i=0; i < boaSize; i++){
      boa->remove(GAPopulation::RANDOM);
    }
	// and add the new ones
    for(int i=0; i < boaSize; i++){
      boa->add(pop.best(j).clone());
      if(j < pop.size()-1) j++;
    }
    return;
  }

Hmm, is there easier solution or am I doing something wrong ?

	PKY




More information about the galib mailing list