Skip to content

Commit

Permalink
Change class name: GAPopulation -> Population.
Browse files Browse the repository at this point in the history
  • Loading branch information
PytLab committed Dec 12, 2017
1 parent e4c15d3 commit d3b1064
Show file tree
Hide file tree
Showing 16 changed files with 38 additions and 38 deletions.
4 changes: 2 additions & 2 deletions examples/ex01/ex01.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from gaft import GAEngine
from gaft.components import BinaryIndividual
from gaft.components import GAPopulation
from gaft.components import Population
from gaft.operators import TournamentSelection
from gaft.operators import UniformCrossover
from gaft.operators import FlipBitMutation
Expand All @@ -22,7 +22,7 @@

# Define population.
indv_template = BinaryIndividual(ranges=[(0, 10)], eps=0.001)
population = GAPopulation(indv_template=indv_template, size=50).init()
population = Population(indv_template=indv_template, size=50).init()

# Create genetic operators.
selection = TournamentSelection()
Expand Down
4 changes: 2 additions & 2 deletions examples/ex02/ex02.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from gaft import GAEngine
from gaft.components import BinaryIndividual
from gaft.components import GAPopulation
from gaft.components import Population
from gaft.operators import TournamentSelection
from gaft.operators import UniformCrossover
from gaft.operators import FlipBitBigMutation
Expand All @@ -20,7 +20,7 @@

# Define population.
indv_template = BinaryIndividual(ranges=[(-2, 2), (-2, 2)], eps=0.001)
population = GAPopulation(indv_template=indv_template, size=50).init()
population = Population(indv_template=indv_template, size=50).init()

# Create genetic operators.
#selection = RouletteWheelSelection()
Expand Down
2 changes: 1 addition & 1 deletion gaft/components/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .individual import IndividualBase
from .binary_individual import BinaryIndividual
from .population import GAPopulation
from .population import Population

6 changes: 3 additions & 3 deletions gaft/components/population.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __call__(self, fitness):
return self.result


class GAIndividuals(object):
class Individuals(object):
'''
Descriptor for all individuals in population.
'''
Expand All @@ -49,10 +49,10 @@ def __set__(self, instance, value):
instance.update_flag()


class GAPopulation(object):
class Population(object):

# All individuals.
individuals = GAIndividuals('individuals')
individuals = Individuals('individuals')

def __init__(self, indv_template, size=100):
'''
Expand Down
8 changes: 4 additions & 4 deletions gaft/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import pstats
import os

from .components import IndividualBase, GAPopulation
from .components import IndividualBase, Population
from .plugin_interfaces.operators import GASelection, GACrossover, GAMutation
from .plugin_interfaces.analysis import OnTheFlyAnalysis
from .mpiutil import mpi
Expand Down Expand Up @@ -106,7 +106,7 @@ def __init__(self, population, selection, crossover, mutation,
the engine object unites these informations and provide means for running
a genetic algorthm optimization.
:param population: The GAPopulation to be reproduced in evolution iteration.
:param population: The Population to be reproduced in evolution iteration.
:param selection: The GASelection to be used for individual seleciton.
:param crossover: The GACrossover to be used for individual crossover.
:param mutation: The GAMutation to be used for individual mutation.
Expand Down Expand Up @@ -231,8 +231,8 @@ def _check_parameters(self):
'''
Helper function to check parameters of engine.
'''
if not isinstance(self.population, GAPopulation):
raise TypeError('population must be a GAPopulation object')
if not isinstance(self.population, Population):
raise TypeError('population must be a Population object')
if not isinstance(self.selection, GASelection):
raise TypeError('selection operator must be a GASelection instance')
if not isinstance(self.crossover, GACrossover):
Expand Down
4 changes: 2 additions & 2 deletions gaft/plugin_interfaces/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def register_step(self, g, population, engine):
:type g: int
:param population: The up to date population of the iteration.
:type population: GAPopulation
:type population: Population
:param engine: The current GAEngine where the analysis is running.
:type engine: GAEngine
Expand All @@ -49,7 +49,7 @@ def finalize(self, population, engine):
post-processing of the collected data.
:param population: The up to date population of the iteration.
:type population: GAPopulation
:type population: Population
:param engine: The current GAEngine where the analysis is running.
:type engine: GAEngine
Expand Down
6 changes: 3 additions & 3 deletions gaft/plugin_interfaces/metaclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from functools import wraps

from ..components.individual import IndividualBase
from ..components.population import GAPopulation
from ..components.population import Population
from ..mpiutil import master_only


Expand Down Expand Up @@ -153,8 +153,8 @@ def _wrapped_select(self, population, fitness):
''' Wrapper to add parameters type checking.
'''
# Check parameter types.
if not isinstance(population, GAPopulation):
raise TypeError('population must be GAPopulation object')
if not isinstance(population, Population):
raise TypeError('population must be Population object')
if not callable(fitness):
raise TypeError('fitness must be a callable object')

Expand Down
4 changes: 2 additions & 2 deletions tests/dynamic_linear_scaling_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from gaft import GAEngine
from gaft.components import BinaryIndividual
from gaft.components import GAPopulation
from gaft.components import Population
from gaft.operators import RouletteWheelSelection
from gaft.operators import UniformCrossover
from gaft.operators import FlipBitMutation
Expand All @@ -25,7 +25,7 @@ def test_run(self):
Make sure GA engine can run correctly.
'''
indv_template = BinaryIndividual(ranges=[(0, 10)], eps=0.001, verbosity=0)
population = GAPopulation(indv_template=indv_template, size=50).init()
population = Population(indv_template=indv_template, size=50).init()

# Create genetic operators.
selection = RouletteWheelSelection()
Expand Down
4 changes: 2 additions & 2 deletions tests/engine_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from gaft import GAEngine
from gaft.components import BinaryIndividual
from gaft.components import GAPopulation
from gaft.components import Population
from gaft.operators import RouletteWheelSelection
from gaft.operators import UniformCrossover
from gaft.operators import FlipBitMutation
Expand All @@ -25,7 +25,7 @@ def test_run(self):
Make sure GA engine can run correctly.
'''
indv_template = BinaryIndividual(ranges=[(0, 10)], eps=0.001, verbosity=0)
population = GAPopulation(indv_template=indv_template, size=50).init()
population = Population(indv_template=indv_template, size=50).init()

# Create genetic operators.
selection = RouletteWheelSelection()
Expand Down
4 changes: 2 additions & 2 deletions tests/exponential_ranking_selection_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import unittest

from gaft.components import GAPopulation, BinaryIndividual
from gaft.components import Population, BinaryIndividual
from gaft.operators import ExponentialRankingSelection

class ExponentialRankingSelectionTest(unittest.TestCase):
Expand All @@ -20,7 +20,7 @@ def fitness(indv):

def test_selection(self):
indv = BinaryIndividual(ranges=[(0, 30)], verbosity=0)
p = GAPopulation(indv)
p = Population(indv)
p.init()

selection = ExponentialRankingSelection()
Expand Down
4 changes: 2 additions & 2 deletions tests/flip_bit_big_mutation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from gaft import GAEngine
from gaft.components import BinaryIndividual
from gaft.components import GAPopulation
from gaft.components import Population
from gaft.operators import RouletteWheelSelection
from gaft.operators import UniformCrossover
from gaft.operators.mutation.flip_bit_mutation import FlipBitBigMutation
Expand All @@ -23,7 +23,7 @@ def test_mutate(self):
''' Make sure the individual can be mutated correctly.
'''
indv_template = BinaryIndividual(ranges=[(0, 10)], eps=0.001, verbosity=0)
population = GAPopulation(indv_template=indv_template, size=50).init()
population = Population(indv_template=indv_template, size=50).init()

# Create genetic operators.
selection = RouletteWheelSelection()
Expand Down
4 changes: 2 additions & 2 deletions tests/linear_ranking_selection_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import unittest

from gaft.components import GAPopulation, BinaryIndividual
from gaft.components import Population, BinaryIndividual
from gaft.operators import LinearRankingSelection

class LinearRankingSelectionTest(unittest.TestCase):
Expand All @@ -20,7 +20,7 @@ def fitness(indv):

def test_selection(self):
indv = BinaryIndividual(ranges=[(0, 30)], verbosity=0)
p = GAPopulation(indv)
p = Population(indv)
p.init()

selection = LinearRankingSelection()
Expand Down
4 changes: 2 additions & 2 deletions tests/linear_scaling_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from gaft import GAEngine
from gaft.components import BinaryIndividual
from gaft.components import GAPopulation
from gaft.components import Population
from gaft.operators import RouletteWheelSelection
from gaft.operators import UniformCrossover
from gaft.operators import FlipBitMutation
Expand All @@ -25,7 +25,7 @@ def test_run(self):
Make sure GA engine can run correctly.
'''
indv_template = BinaryIndividual(ranges=[(0, 10)], eps=0.001, verbosity=0)
population = GAPopulation(indv_template=indv_template, size=50).init()
population = Population(indv_template=indv_template, size=50).init()

# Create genetic operators.
selection = RouletteWheelSelection()
Expand Down
10 changes: 5 additions & 5 deletions tests/population_test.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

''' Test case for GAPopulation
''' Test case for Population
'''

import unittest

from gaft.components import GAPopulation, BinaryIndividual
from gaft.components import Population, BinaryIndividual

class PopulationTest(unittest.TestCase):

Expand All @@ -20,7 +20,7 @@ def fitness(indv):

def test_initialization(self):
''' Make sure a population can be initialized correctly. '''
population = GAPopulation(indv_template=self.indv_template, size=10)
population = Population(indv_template=self.indv_template, size=10)

self.assertListEqual(population.individuals, [])

Expand All @@ -32,14 +32,14 @@ def test_initialization(self):

def test_new_population(self):
''' Make sure population can clone a new population. '''
population = GAPopulation(indv_template=self.indv_template, size=10)
population = Population(indv_template=self.indv_template, size=10)
population.init()
new_population = population.new()
self.assertEqual(new_population.size, 10)
self.assertListEqual(new_population.individuals, [])

def test_all_fits(self):
population = GAPopulation(indv_template=self.indv_template, size=10)
population = Population(indv_template=self.indv_template, size=10)
population.init()
all_fits = population.all_fits(fitness=self.fitness)

Expand Down
4 changes: 2 additions & 2 deletions tests/roulette_wheel_selection_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import unittest

from gaft.components import GAPopulation, BinaryIndividual
from gaft.components import Population, BinaryIndividual
from gaft.operators.selection.roulette_wheel_selection import RouletteWheelSelection

class RouletteWheelSelectionTest(unittest.TestCase):
Expand All @@ -20,7 +20,7 @@ def fitness(indv):

def test_selection(self):
indv = BinaryIndividual(ranges=[(0, 30)], verbosity=0)
p = GAPopulation(indv)
p = Population(indv)
p.init()

selection = RouletteWheelSelection()
Expand Down
4 changes: 2 additions & 2 deletions tests/tournament_selection_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import unittest

from gaft.components import GAPopulation, BinaryIndividual
from gaft.components import Population, BinaryIndividual
from gaft.operators import TournamentSelection

class TournamentSelectionTest(unittest.TestCase):
Expand All @@ -20,7 +20,7 @@ def fitness(indv):

def test_selection(self):
indv = BinaryIndividual(ranges=[(0, 30)], verbosity=0)
p = GAPopulation(indv)
p = Population(indv)
p.init()

selection = TournamentSelection()
Expand Down

0 comments on commit d3b1064

Please sign in to comment.