Added doc strings to EasyGA ga class and attributes class.
This commit is contained in:
@ -20,8 +20,14 @@ from attributes import attributes
|
|||||||
|
|
||||||
|
|
||||||
class GA(attributes):
|
class GA(attributes):
|
||||||
|
"""GA is the main class in EasyGA. Everything is run through the ga
|
||||||
|
class. The GA class inherites all the default ga attributes from the
|
||||||
|
attributes class.
|
||||||
|
|
||||||
|
An extensive wiki going over all major functions can be found at
|
||||||
|
https://github.com/danielwilczak101/EasyGA/wiki
|
||||||
|
"""
|
||||||
|
|
||||||
# Inhert all the ga attributes from the attributes class.
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
chromosome_length = None,
|
chromosome_length = None,
|
||||||
population_size = None,
|
population_size = None,
|
||||||
@ -51,7 +57,7 @@ class GA(attributes):
|
|||||||
mutation_individual_impl = None,
|
mutation_individual_impl = None,
|
||||||
mutation_population_impl = None,
|
mutation_population_impl = None,
|
||||||
termination_impl = None
|
termination_impl = None
|
||||||
):
|
):
|
||||||
super(GA, self).__init__(
|
super(GA, self).__init__(
|
||||||
chromosome_length,
|
chromosome_length,
|
||||||
population_size,
|
population_size,
|
||||||
|
|||||||
@ -19,7 +19,7 @@ from mutation import Mutation_Methods
|
|||||||
from crossover import Crossover_Methods
|
from crossover import Crossover_Methods
|
||||||
|
|
||||||
class attributes:
|
class attributes:
|
||||||
"""SAMPLE TEXT"""
|
"""Default GA attributes can be found here"""
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
chromosome_length,
|
chromosome_length,
|
||||||
@ -51,7 +51,10 @@ class attributes:
|
|||||||
mutation_population_impl,
|
mutation_population_impl,
|
||||||
termination_impl
|
termination_impl
|
||||||
):
|
):
|
||||||
"""Initialize the GA."""
|
|
||||||
|
"""Default GA attributes can be found here. If any attributes have not
|
||||||
|
been set then they will fall back onto the default attribute. All
|
||||||
|
attributes have been catigorized to explain sections in the ga process."""
|
||||||
|
|
||||||
# Initilization variables
|
# Initilization variables
|
||||||
self.chromosome_length = 10 if chromosome_length is None else chromosome_length
|
self.chromosome_length = 10 if chromosome_length is None else chromosome_length
|
||||||
@ -96,14 +99,18 @@ class attributes:
|
|||||||
self.termination_impl = Termination_Methods.fitness_and_generation_based if termination_impl is None else termination_impl
|
self.termination_impl = Termination_Methods.fitness_and_generation_based if termination_impl is None else termination_impl
|
||||||
|
|
||||||
|
|
||||||
# Getter and setters for all varibles
|
# Getter and setters for all required varibles
|
||||||
@property
|
@property
|
||||||
def chromosome_length(self):
|
def chromosome_length(self):
|
||||||
"""SAMPLE TEXT"""
|
"""Getter function for chromosome length"""
|
||||||
|
|
||||||
return self._chromosome_length
|
return self._chromosome_length
|
||||||
|
|
||||||
@chromosome_length.setter
|
@chromosome_length.setter
|
||||||
def chromosome_length(self, value_input):
|
def chromosome_length(self, value_input):
|
||||||
|
"""Setter function with error checking for chromosome length"""
|
||||||
|
|
||||||
|
# If the chromosome length is less then or equal 0 throw error
|
||||||
if(not isinstance(value_input, int) or value_input <= 0):
|
if(not isinstance(value_input, int) or value_input <= 0):
|
||||||
raise ValueError("Chromosome length must be integer greater then 0")
|
raise ValueError("Chromosome length must be integer greater then 0")
|
||||||
self._chromosome_length = value_input
|
self._chromosome_length = value_input
|
||||||
@ -111,10 +118,15 @@ class attributes:
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def population_size(self):
|
def population_size(self):
|
||||||
|
"""Getter function for population size"""
|
||||||
|
|
||||||
return self._population_size
|
return self._population_size
|
||||||
|
|
||||||
@population_size.setter
|
@population_size.setter
|
||||||
def population_size(self, value_input):
|
def population_size(self, value_input):
|
||||||
|
"""Setter function with error checking for population size"""
|
||||||
|
|
||||||
|
# If the population size is less then or equal 0 throw error
|
||||||
if(not isinstance(value_input, int) or value_input <= 0):
|
if(not isinstance(value_input, int) or value_input <= 0):
|
||||||
raise ValueError("Population length must be integer greater then 0")
|
raise ValueError("Population length must be integer greater then 0")
|
||||||
self._population_size = value_input
|
self._population_size = value_input
|
||||||
|
|||||||
Reference in New Issue
Block a user