package jcgp.population; import jcgp.JCGP.Resources; public class Population { private Chromosome[] chromosomes; private int fittest; public Population(Resources resources) { chromosomes = new Chromosome[(resources.getInt("popSize"))]; for (int c = 0; c < chromosomes.length; c++) { chromosomes[c] = new Chromosome(resources); } } public Population(Chromosome parent, Resources resources) { chromosomes = new Chromosome[(resources.getInt("popSize"))]; // make a clone for safety this.chromosomes[0] = new Chromosome(parent); // generate the rest of the individuals for (int c = 1; c < chromosomes.length; c++) { chromosomes[c] = new Chromosome(chromosomes[0]); } } /** * Returns all chromosomes, parents first, then offspring. * * @param index * @return */ public Chromosome getChromosome(int index) { return chromosomes[index]; } public void setBestIndividual(int index) { fittest = index; } public Chromosome getBestIndividual() { return chromosomes[fittest]; } }