From a42e4c86fa42a8c5bb5a1697cdae0108ffea8b64 Mon Sep 17 00:00:00 2001 From: pytlab Date: Tue, 12 Dec 2017 22:05:14 +0800 Subject: [PATCH] Change name: variants -> solution. --- examples/ex01/ex01.py | 8 ++++---- gaft/analysis/console_output.py | 2 +- gaft/analysis/fitness_store.py | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/ex01/ex01.py b/examples/ex01/ex01.py index ba6cb18..db4cb50 100644 --- a/examples/ex01/ex01.py +++ b/examples/ex01/ex01.py @@ -8,7 +8,7 @@ from math import sin, cos from gaft import GAEngine -from gaft.components import GAIndividual +from gaft.components import BinaryIndividual from gaft.components import GAPopulation from gaft.operators import TournamentSelection from gaft.operators import UniformCrossover @@ -21,7 +21,7 @@ from gaft.analysis.fitness_store import FitnessStore # Define population. -indv_template = GAIndividual(ranges=[(0, 10)], encoding='binary', eps=0.001) +indv_template = BinaryIndividual(ranges=[(0, 10)], eps=0.001) population = GAPopulation(indv_template=indv_template, size=50).init() # Create genetic operators. @@ -37,7 +37,7 @@ # Define fitness function. @engine.fitness_register def fitness(indv): - x, = indv.variants + x, = indv.solution return x + 10*sin(5*x) + 7*cos(4*x) # Define on-the-fly analysis. @@ -53,7 +53,7 @@ def register_step(self, g, population, engine): def finalize(self, population, engine): best_indv = population.best_indv(engine.fitness) - x = best_indv.variants + x = best_indv.solution y = engine.fitness(best_indv) msg = 'Optimal solution: ({}, {})'.format(x, y) self.logger.info(msg) diff --git a/gaft/analysis/console_output.py b/gaft/analysis/console_output.py index c30fa25..9183f10 100644 --- a/gaft/analysis/console_output.py +++ b/gaft/analysis/console_output.py @@ -27,7 +27,7 @@ def register_step(self, g, population, engine): def finalize(self, population, engine): best_indv = population.best_indv(engine.fitness) - x = best_indv.variants + x = best_indv.solution y = engine.fitness(best_indv) msg = 'Optimal solution: ({}, {})'.format(x, y) self.logger.info(msg) diff --git a/gaft/analysis/fitness_store.py b/gaft/analysis/fitness_store.py index c604858..b7fff00 100644 --- a/gaft/analysis/fitness_store.py +++ b/gaft/analysis/fitness_store.py @@ -18,8 +18,8 @@ def setup(self, ng, engine): # Best fitness in each generation. self.fitness_values = [] - # Best variants. - self.variants = [] + # Best solution. + self.solution = [] def register_step(self, g, population, engine): # Collect data. @@ -27,13 +27,13 @@ def register_step(self, g, population, engine): best_fit = engine.ori_fitness(best_indv) self.ngs.append(g) - self.variants.append(best_indv.variants) + self.solution.append(best_indv.solution) self.fitness_values.append(best_fit) def finalize(self, population, engine): with open('best_fit.py', 'w', encoding='utf-8') as f: f.write('best_fit = [\n') - for ng, x, y in zip(self.ngs, self.variants, self.fitness_values): + for ng, x, y in zip(self.ngs, self.solution, self.fitness_values): f.write(' ({}, {}, {}),\n'.format(ng, x, y)) f.write(']\n\n')