diff options
Diffstat (limited to 'src/jcgp/JCGP.java')
-rw-r--r-- | src/jcgp/JCGP.java | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/src/jcgp/JCGP.java b/src/jcgp/JCGP.java index ee42792..538f677 100644 --- a/src/jcgp/JCGP.java +++ b/src/jcgp/JCGP.java @@ -169,25 +169,25 @@ public class JCGP { problem.evaluate(population, (Resources) resources); report(); - if (resources.getInt("currentGen") < resources.getInt("generations")) { + if (resources.currentGeneration() < resources.generations()) { // we still have generations left to go if (problem.isPerfectSolution(population.getChromosome(evolutionaryStrategy.getFittestChromosome()))) { // solution has been found, start next run - resources.println("[CGP] Solution found on generation " + resources.getInt("currentGen") + ", chromosome: " + evolutionaryStrategy.getFittestChromosome()); + resources.println("[CGP] Solution found, generation " + resources.currentGeneration() + ", chromosome " + evolutionaryStrategy.getFittestChromosome()); - if (resources.getInt("currentRun") < resources.getInt("runs")) { + if (resources.currentRun() < resources.runs()) { // there are still runs left - resources.set("currentRun", resources.getInt("currentRun") + 1); - resources.set("currentGen", 0); + resources.setCurrentRun(resources.currentRun() + 1); + resources.setCurrentGeneration(0); // start a new population - population = new Population((Resources) resources); + population.reinitialise(); } else { // no more generations and no more runs, we're done finished = true; } } else { - resources.set("currentGen", resources.getInt("currentGen") + 1); + resources.setCurrentGeneration(resources.currentGeneration() + 1); } } else { // the run has ended, check if any more runs must be done @@ -195,13 +195,13 @@ public class JCGP { + population.getChromosome(evolutionaryStrategy.getFittestChromosome()).getFitness() + " by chromosome " + evolutionaryStrategy.getFittestChromosome()); - if (resources.getInt("currentRun") < resources.getInt("runs")) { + if (resources.currentRun() < resources.runs()) { // the run has ended but there are still runs left - resources.set("currentRun", resources.getInt("currentRun") + 1); - resources.set("currentGen", 0); + resources.setCurrentRun(resources.currentRun() + 1); + resources.setCurrentGeneration(0); // start a new population - population = new Population(resources); + population.reinitialise();; } else { // no more generations and no more runs, we're done finished = true; @@ -214,16 +214,16 @@ public class JCGP { } private void report() { - if (resources.getInt("report") > 0) { - if (resources.getInt("currentGen") % resources.getInt("report") == 0) { - resources.println("[CGP] Generation: " + resources.getInt("currentGen") + ", fitness: " + population.getChromosome(evolutionaryStrategy.getFittestChromosome()).getFitness()); + if (resources.report() > 0) { + if (resources.currentGeneration() % resources.report() == 0) { + resources.println("[CGP] Generation: " + resources.currentGeneration() + ", fitness: " + population.getChromosome(evolutionaryStrategy.getFittestChromosome()).getFitness()); } } } public void start() { if (!finished) { - while (resources.getInt("currentGen") <= resources.getInt("generations")) { + while (resources.currentGeneration() <= resources.generations()) { nextGeneration(); if (finished) { break; @@ -236,8 +236,8 @@ public class JCGP { public void reset() { finished = false; population = new Population(resources); - resources.set("currentGen", 1); - resources.set("currentRun", 1); + resources.setCurrentGeneration(1); + resources.setCurrentRun(1); resources.println("-----------------------------"); resources.println("New experiment: " + problem.toString()); } |