// Genetic Algorithm maxA testing method public static void main( String[] args ) { // Initializing the population (we chose 500 genes for the population, // but you can play with the population size to try different approaches) GeneticAlgorithm population = new GeneticAlgorithm(POPULATION_SIZE); int generationCount = 0; // For the sake of this sample, evolution goes on forever. // If you wish the evolution to halt (for instance, after a number of // generations is reached or the maximum fitness has been achieved), // this is the place to make any such checks while(true){ // --- evaluate current generation: population.evaluateGeneration(); // --- print results here: // we choose to print the average fitness, // as well as the maximum and minimum fitness // as part of our progress monitoring float avgFitness=0f; float minFitness=float.PositiveInfinity; float maxFitness=float.NegativeInfinity; string bestIndividual=""; string worstIndividual=""; for(int i = 0; i < population.size(); i++){ float currFitness = population.getGene(i).getFitness(); avgFitness += currFitness; if(currFitness < minFitness){ minFitness = currFitness; worstIndividual = population.getGene(i).getPhenotype(); } if(currFitness > maxFitness){ maxFitness = currFitness; bestIndividual = population.getGene(i).getPhenotype(); } } if(population.size()>0){ avgFitness = avgFitness/population.size(); } string output = "Generation: " + generationCount; output += "\t AvgFitness: " + avgFitness; output += "\t MinFitness: " + minFitness + " (" + worstIndividual +")"; output += "\t MaxFitness: " + maxFitness + " (" + bestIndividual +")"; Debug.Log(output); // produce next generation: population.produceNextGeneration(); generationCount++; } }