Skip to content

Commit

Permalink
Change name: variants -> solution.
Browse files Browse the repository at this point in the history
  • Loading branch information
PytLab committed Dec 12, 2017
1 parent 50f0934 commit a42e4c8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions examples/ex01/ex01.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion gaft/analysis/console_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions gaft/analysis/fitness_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ 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.
best_indv = population.best_indv(engine.fitness)
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')

Expand Down

0 comments on commit a42e4c8

Please sign in to comment.