problems with `nBestGenomes'

Thomas Binder binder at iue.tuwien.ac.at
Tue Mar 28 04:20:31 EST 2000


Thomas Binder wrote:
> 
> Hi!
> 
> The behaviour is that the objective function seems to be called with a
> non-initialized (or not properly initialized) genome. This, in turn, results 
> in a request for a parameter set which is NOT within the bounds specified in 
> the allele set.
> 

I further tracked down the problem and found that it is also reproducable with
a value of `1' for nBestGenomes.

The problem occurrs ONLY with a derived genome class. 

In the attached example, I derived a class MyRealGenome which inherits from 
GARealGenome.

When the program is started it will print the requests of the genetic algorithm
to stdout. Occasionally you will see requests containing a lot of 0's, which is
definitely a violation of the boundaries specified in the allele set.

If I use GARealGenome erverything works correct!

Is it psooible that I made a mistake in deriving my genome class?
Is any important part (constructor, operator, ...) missing?


Thx for any help,
Tom

----------------------- test program ---------------------

#include <ga/ga.h>
#include <ga/GASimpleGA.h>
#include <ga/GASStateGA.h>
#include <ga/GAIncGA.h>
#include <ga/GADemeGA.h>

#include <ga/GARealGenome.h>
#include <ga/GARealGenome.C>


struct MyRealGenome: public GARealGenome
{
	MyRealGenome(GARealAlleleSetArray& arr_, float(*obj_)(GAGenome&))
		:GARealGenome(arr_, obj_)
	{}
     
     
	MyRealGenome(const MyRealGenome& cp): GARealGenome(cp)
	{}
     
	virtual GAGenome* clone(CloneMethod) const 
	{
		return new MyRealGenome(*this);
	}
     
	virtual void copy(const GAGenome& orig)
	{
		if ((GAGenome*)this == &orig)	return;

		GAGenome::copy(orig);
	}
	
	virtual ~MyRealGenome()
	{}
};


typedef MyRealGenome	UseGenome;
// typedef GARealGenome	UseGenome;


static float objfuncy(GAGenome&);


int main()
{
	GARealAlleleSetArray	mybounds;
	
	mybounds.add(-0.62,  -0.4);
	mybounds.add(0.0028,  0.004);
	mybounds.add(17.4,   17.9);
	mybounds.add(0.1,     0.3);
	mybounds.add(0.01,    0.2);
	mybounds.add(17,     17.5);
	mybounds.add(0.5,     1.);

	GAPopulation	pop(UseGenome(mybounds, objfuncy), 15);
	
	GASteadyStateGA		ssga(pop);
	ssga.pReplacement(0.8);
	GAGeneticAlgorithm&	ga(ssga);
	
	ga.minimize();

	ga.nGenerations (200);
	ga.pCrossover   (0.8);
	ga.pMutation    (0.2);
	
	ga.evolve();
}



static float objfuncy(GAGenome& gen)
{
	UseGenome&	rg((UseGenome&) gen);

	cout << "GA requests: ";
	for (unsigned int i(0); i < (unsigned int) rg.length(); ++i)
	{
		cout << rg[i] << " ";
	}
	cout << endl;

	return drand48();
}

------------------- test program -------------------
-- 
"Computers are like air conditioners - they stop working properly when you open
 Windows"
                            \\\|///
                          \\  ~ ~  //
                           (  @ @  )
/------------------------oOOo-(_)-oOOo-----------------------------------------\
| Thomas Binder                        |                                       |
| Institute for  Microelectronics      | phone: ++43/1/58801-36036             |
| Technical University Vienna          |                                       |
| Gusshausstrasse  27-29 / E360        | fax  : ++43/1/58801-36099             |
| A-1040  Vienna                       |                                       |
| A U S T R I A                        | email: binder at iue.tuwien.ac.at        |
\---------------------------------Oooo.----------------------------------------/
                        .oooO     (   )
                        (   )      ) /
                         \ (      (_/
                          \_)





More information about the galib mailing list