package jcgp.population; import java.util.ArrayList; import java.util.Iterator; import jcgp.CGP.Parameters; public final class Population implements Iterable { private ArrayList population; public Population() { population = new ArrayList(Parameters.getPopulationSize()); for (int c = 0; c < Parameters.getPopulationSize(); c++) { population.add(new Chromosome(Parameters.getInputs(), Parameters.getRows(), Parameters.getColumns(), Parameters.getOutputs())); } } @Override public Iterator iterator() { return new Iterator() { private int index = 0; @Override public boolean hasNext() { if (index < population.size()) { return true; } else { return false; } } @Override public Chromosome next() { Chromosome next = population.get(index); index++; return next; } @Override public void remove() { // not allowed } }; } }