/**
 * Executes the operation
 * @param object An object containing a solution
 * @return An object containing the mutated solution
 * @throws JMException
 */
void * PolynomialMutation::execute(void *object) {
    Solution *solution = (Solution *)object;
    // TODO: VALID_TYPES?
    //double probability = *(double *)getParameter("probability");
    doMutation(mutationProbability_,solution);
    return solution;
} // execute
Example #2
0
void doReproduce(){
	struct Chromosome XoverPop[4]; // Small population of 4 individuals
	XoverPop[0] = Population[selectParent()]; // Select parent 1
	XoverPop[1] = Population[selectParent()]; // Select parent 2
	/*** Crossover ***/
	int GeneNr;
	for(GeneNr = 0; GeneNr < GENETIC_PURSUERS;GeneNr++){ // Take one gene from each parent
		XoverPop[2].gene[GeneNr  ] = XoverPop[0].gene[GeneNr];
		XoverPop[3].gene[GeneNr  ] = XoverPop[1].gene[GeneNr];
		XoverPop[2].gene[GeneNr+1] = XoverPop[1].gene[GeneNr+1];
		XoverPop[3].gene[GeneNr+1] = XoverPop[0].gene[GeneNr+1];
		GeneNr++;
	}
	/*** Mutation ***/
	doMutation(&XoverPop[2]); // Mutate the generated individual
	doMutation(&XoverPop[3]); // Mutate the generated individual
	/*** sort to add best individes ***/
	int i = 0;
	for(i=2;i<4;i++)
		calculateFitness(&XoverPop[i]); // Calculate fitness for children
	sortPopulation(XoverPop, 4); // Sort after fitness
	addToNewPopulation(XoverPop[0]); // Add best individual to new population
	addToNewPopulation(XoverPop[1]); // Add second best individual to new population
}