Esempio n. 1
0
/******************************************************************************
	Function createChildren - controls the process of creating children
	Takes parameters:
		@geneticArray - pointer to a vector of whole population
		@geneticP - pointer to a struct of all CGP params
		@functions - pointer to an array of available functions
******************************************************************************/
void createChildren(vector<TIndividual>* geneticArray, TCgpProperties* geneticP, TFuncAvailable* functions){
	for(int i = 1; i < geneticP->individCount; i++){
		//copy parent
		copyGenotype(&geneticArray->at(0), &geneticArray->at(i), geneticP);
		//change 3-10% of genes
		changeGenes(&geneticArray->at(i), geneticP, functions);
	}
}
Esempio n. 2
0
Individual *copyIndividual(Individual *individual) {
  Individual *newIndividual = malloc(sizeof(Individual));
  newIndividual->valid = individual->valid;
  newIndividual->fitness = individual->fitness;
  newIndividual->genotype = copyGenotype(individual->genotype);
  /* TODO copy phenotype and tree */
  newIndividual->phenotype = NULL;
  newIndividual->derivationTree = NULL;

  return newIndividual;
}
Esempio n. 3
0
/******************************************************************************
	Function getParents - selects the best individual in the generation compared
		by fitness. Secondary parameters - the one which was not parent is better
		and the one with shorter equation is better.
	Takes parameters:
		@geneticArray - pointer to a vector of whole population
		@geneticP - pointer to a struct of all CGP params
******************************************************************************/
void getParents(vector<TIndividual>* geneticArray, TCgpProperties* geneticP){
	int max = -1;
	TIndividual* parent;

	for(int i = 0; i < geneticP->individCount; i++){
		if(geneticArray->at(i).fitness > max){
			max = geneticArray->at(i).fitness;
			parent = &(geneticArray->at(i));
		}
		else if(geneticArray->at(i).fitness == max){
			if(geneticArray->at(i).activeNodesCount < parent->activeNodesCount){
				parent = &(geneticArray->at(i));
			}
			else if((i > 0) && (parent == &(geneticArray->at(i)))){
				parent = &(geneticArray->at(i));
			}
		}
	}

	copyGenotype(parent, &geneticArray->at(0), geneticP);
}