[galib] replacement of best individual

Kupfer, Michael (ARC-AFA)[UC SANTA CRUZ] Michael.Kupfer at nasa.gov
Fri Aug 29 17:57:29 EDT 2008


Hello!


Unfortunately I still have some issue with replacing the best individual
with some improved solution.
What I did is: when a new current best is found, I generate an improved
solution using my heuristic and then, replace it with the original best.
I check with screen output if the right things are done.

However, the problem I am having is that the best of the next iteration
is not the improved solution from the previous step. Somehow it does not
get updated.

I did the following:
 
...

class MyGA : public GASimpleGA {
public:
	virtual void step(GARealAlleleSetArray alleles);
	MyGA(GARealGenome & garg) : GASimpleGA(garg){}
	~MyGA() {}
};

void
MyGA::step(GARealAlleleSetArray alleles)
{
	//GARealGenome& genome = (GARealGenome&)g;
	GASimpleGA::step();

	GARealGenome genome_tmp(alleles, Objective);
	genome_tmp.copy(pop->individual(0));
	
	if(SOME CONDITION)
	{
		cout << "best:       " << "";
		cout << pop->best(0) << "\n";		//The current
best
								//gets
printed correctly
		
		int sep_value = 0;
		for(int i = 0; i < (int) ac; i++)
		{
			if(i > 0)
			{
				IMPROVEMENTHEURISTIC
			}
		}
	cout << "genome_tmp: " << "";
	for(int i = 0; i < (int) ac; i++)
	{
		cout << genome_tmp.gene(i) << " ";	// The improved
solution
								// gets
printed correctly
	}
	cout << endl;			
		
	pop->individual(0).copy(genome_tmp);

	cout << "best after: " << pop->best(0) << "\n";	//After Copy,
the new
	
//best is the improved
	
//solution from the 
	
//heuristic which is
//correct

	pop->evaluate(gaTrue);
	}
}

int main(int argc, char* argv [])
{
	...
	GARealAlleleSetArray alleles;	
    	for (int i = 0; i < (int) ac; i++)
	{
		alleles.add(aircraft[i].arrival_fast,
aircraft[i].arrival_slow, 		10);
	}
	
	GARealGenome genome(alleles, Objective); 
	genome.initializer(MyArrayInitializer);
	genome.crossover(GARealGenome::OnePointCrossover);
	
	GAStatistics stats;

	GAParameterList params;
	GASimpleGA::registerDefaultParameters(params);
	params.set(gaNnGenerations, 30000);
	params.set(gaNpopulationSize, 30); 
	params.set(gaNpMutation, 0.01);
	params.set(gaNpCrossover, 0.4);

	params.set(gaNscoreFrequency, 10);
params.set(gaNflushFrequency, 10);
params.set(gaNnBestGenomes,1);	
	params.set(gaNselectScores, (int)GAStatistics::AllScores);	
	params.parse(argc, argv, gaFalse);

	MyGA ga(genome);	
	ga.minimize();            
	ga.parameters(params);	
	GAPopulation pop(genome, ga.populationSize());
	ga.initialize(seed);

	while(!ga.done())
	{
		ga.step(alleles);
		...
	}
}

float Objective(GAGenome& g )
{
	...
}
 

Everything gets computed and shown on the screen correctly.
BUT in the next iteration the current best is not the improved solution
found with the heuristic from the previous iteration what I would
expect; in other words, the improved solution which is even shown as
current best does not get transferred into the next iteration.

Did I forget something like an update-population-step?

Thanks!

 

Best,
Michael.


-----Original Message-----
From: galib-bounces at mit.edu [mailto:galib-bounces at mit.edu] On Behalf Of
matthew wall
Sent: Wednesday, August 20, 2008 5:51 AM
To: galib at mit.edu
Subject: Re: [galib] replacement of best individual


On 18 Aug 2008, at 20:02, Kupfer, Michael (ARC-AFA)[UC SANTA CRUZ]  
wrote:
> Dear all,
>
> Under certain conditions, I would like to replace the current best  
> individual with another one:
>
> Each time a new best individual is found I want to run a local  
> search heuristic to improve this current best.
> If this improvement routine was successful, I would like to replace  
> the current best with the result of the local search.
> How can I do the replacement? How can I replace pop.best() with the  
> gene-values found in the improvement routine?
>

hi michael,

one approach is to create your own genetic algorithm object, since it  
has access to and complete control over the population.  for example,  
this is a derivative of a simple ga that does repair

class MyGA : public GASimpleGA {
public:
   virtual void step();
}

void
MyGA::step() {
   // let the simple ga do its logic for a single step of evolution
   GASimpleGA::step();

   // this is the genome into which you stick the repairs
   MyGenome genome;
   genome.copy(pop->individual(x));

   // do your heuristic to improve the best here
   genome.setSomeValue();
   genome.modifySomeAttribute();

   // insert the genome into the population at the appropriate location
   pop->individual(x).copy(genome);
}

_______________________________________________
galib mailing list
galib at mit.edu
http://mailman.mit.edu/mailman/listinfo/galib




More information about the galib mailing list