package jcgp.population; import java.util.Iterator; import jcgp.Parameters; public class Population implements Iterable { private Chromosome[] population; public Population(Chromosome chromosome) { population = new Chromosome[Parameters.getPopulationSize()]; for (int c = 0; c < population.length; c++) { population[c] = new Chromosome(chromosome); } } public Population() { population = new Chromosome[Parameters.getPopulationSize()]; for (int c = 0; c < population.length; c++) { population[c] = new Chromosome(); } } @Override public Iterator iterator() { return new Iterator() { private int index = 0; @Override public boolean hasNext() { if (index < population.length) { return true; } else { return false; } } @Override public Chromosome next() { Chromosome next = population[index]; index++; return next; } @Override public void remove() { // not allowed throw new UnsupportedOperationException("Removing chromosomes from the population is not allowed. Instead, re-instantiate the chromosome."); } }; } }