openGA icon indicating copy to clipboard operation
openGA copied to clipboard

User specified initial population

Open ababaritECN opened this issue 1 year ago • 0 comments

Hi, I believe that the code does not work properly when providing a used defined initial population. According to my tests, whatever the size of the user defined population, it adds a number of additional random individuals equal to the size of the population. This is because N_add is not modified. Here is quick fix:

void init_population(thisGenerationType &generation0)
	{
		(...)
		// Evaluate and add the user defined population
		for(const GeneType &solution:user_initial_solutions)
		{
			thisChromosomeType X;
			X.genes=solution;
			bool accepted=init_population_try(generation0,X,-1);
			//** Fix
			if (accepted) {N_add-=1;} // User defined individual is accepted, thus we must reduce by 1 the number of random individuals to be added.
			//** End of fix
			(void) accepted; // unused parametre
			if(generation0.chromosomes.size()>=population)
				break;
		}
		(...)
	}

ababaritECN avatar Apr 17 '24 07:04 ababaritECN