From 3326c58f4d2d7e8c77738277dcd093aa864ad2a5 Mon Sep 17 00:00:00 2001 From: Eduardo Pedroni Date: Thu, 13 Feb 2014 17:43:59 +0000 Subject: Finished population tests, now thinking about methods to compare chromosomes --- src/jcgp/population/Population.java | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'src/jcgp/population/Population.java') diff --git a/src/jcgp/population/Population.java b/src/jcgp/population/Population.java index 56f1b50..4153e0f 100644 --- a/src/jcgp/population/Population.java +++ b/src/jcgp/population/Population.java @@ -8,14 +8,17 @@ public class Population implements Iterable { private Chromosome[] population; - public Population(Chromosome ... chromosomes) { - if (chromosomes.length > 0) { - population = chromosomes; - } else { - population = new Chromosome[Parameters.getPopulationSize()]; - for (int c = 0; c < population.length; c++) { - population[c] = new Chromosome(); - } + 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(); } } @@ -44,10 +47,8 @@ public class Population implements Iterable { @Override public void remove() { // not allowed - // since this would shift everything back one position, increment index - // index++; + throw new UnsupportedOperationException("Removing chromosomes from the population is not allowed. Instead, re-instantiate the chromosome."); } - }; } } -- cgit v1.2.3