/** GPPopulation.java * J Scott Cameron * This class controls a population * of Genetic Programs * and controls their regeneration */ import GPNode; import GPTerminalNode; import GPBinaryNode; import GPUnaryNode; import GPVariableNode; import GPPair; import GPFunctionTemplate; import java.io.*; import java.util.*; import java.lang.reflect.*; public class GPPopulation{ private GPNodeContainer population[];/* The population of GP's */ private boolean mutation;/* controls whether or not mutation occurs */ private boolean crossover;/* controls whether or not crossover occurs */ private double mutationRate;/* the rate at which mutation occurs */ private int popSize;/* size of the population */ private static Random random; /* class which implements GPFunctionTemplate * so that GP can retreive all the possible methods */ private GPFunctionTemplate gpft; private Vector binaryFunctions;/* possible binary Functions*/ private Vector unaryFunctions;/* possible unary functions*/ private Vector variables;/* possible variables */ private double sumFitness;/* sum of all the fitness ratings */ private double lowestFitness;/* lowest fitness in the population */ public GPPopulation() { } /* parameterized contructor */ public GPPopulation(GPFunctionTemplate gpft,int popSize,boolean crossover, boolean mutation, double mutationRate) { this.gpft = gpft; this.popSize = popSize; this.crossover = crossover; this.mutation = mutation; this.mutationRate = mutationRate; random = new Random(); binaryFunctions = gpft.getBinaryFunctions(); unaryFunctions = gpft.getUnaryFunctions(); variables = gpft.getVariables(); population = new GPNodeContainer[popSize]; GPNode gpn; /* fill the population with random function trees */ for(int i=0;i= x) { return population[i].getNode(); } } return population[popSize-1].getNode(); } /* prints the functions strings for every GP in the * population */ public String toString() { StringWriter sw = new StringWriter(); for(int i=0;i