package aiproject1; /** * * @author Layan */ public class Population { Gene[] genes = new Gene[5000]; //array of genes int optimal; //what we want to reach public void initializePopulation(int size){ for (int i = 0; i < genes.length; i++) { genes[i] = new Gene(); } } //get optimal gene public Gene getOptimal(){ int lowerFit = Integer.MAX_VALUE; // the worst case int maxOPTindex = 0;// //loop to find lowest value fitness in array genes for(int i=0;i=genes[i].fitness) //anything better than the worst case lowerFit=genes[i].fitness; maxOPTindex = i; } optimal = genes[maxOPTindex].fitness; // new optimal gene return genes[maxOPTindex];// return the optimal gene }//END GET OPTIMAL //get gene with second lowest fitness for selection public Gene getSecondOptimal(){ int lowfit1=0; int lowfit2=0; for(int i=0;i