Added some error checking
This commit is contained in:
@ -64,7 +64,7 @@ class attributes:
|
|||||||
self.termination_impl = Termination_Methods.generation_based
|
self.termination_impl = Termination_Methods.generation_based
|
||||||
|
|
||||||
|
|
||||||
# Example of how the setter error checking will look like
|
# Getter and setters for all varibles
|
||||||
@property
|
@property
|
||||||
def chromosome_length(self):
|
def chromosome_length(self):
|
||||||
return self._chromosome_length
|
return self._chromosome_length
|
||||||
@ -72,5 +72,20 @@ class attributes:
|
|||||||
@chromosome_length.setter
|
@chromosome_length.setter
|
||||||
def chromosome_length(self, value_input):
|
def chromosome_length(self, value_input):
|
||||||
if(value_input == 0):
|
if(value_input == 0):
|
||||||
raise ValueError("Sorry your chromosome length must be greater then 0")
|
raise ValueError("Chromosome length must be greater then 0")
|
||||||
self._chromosome_length = value_input
|
self._chromosome_length = value_input
|
||||||
|
|
||||||
|
|
||||||
|
@property
|
||||||
|
def population_size(self):
|
||||||
|
return self._population_size
|
||||||
|
|
||||||
|
@population_size.setter
|
||||||
|
def population_size(self, value_input):
|
||||||
|
if(value_input == 0):
|
||||||
|
raise ValueError("Population length must be greater then 0")
|
||||||
|
self._population_size = value_input
|
||||||
|
|
||||||
|
@property
|
||||||
|
def chromosome_impl(self):
|
||||||
|
return self._chromosome_impl
|
||||||
|
|||||||
@ -3,10 +3,10 @@ import EasyGA
|
|||||||
|
|
||||||
# Create the Genetic algorithm
|
# Create the Genetic algorithm
|
||||||
ga = EasyGA.GA()
|
ga = EasyGA.GA()
|
||||||
ga.target_fitness_type = 'min'
|
ga.target_fitness_type = 'max'
|
||||||
ga.chromosome_length = 10
|
ga.chromosome_length = 10
|
||||||
ga.population_size = 25
|
ga.population_size = 10
|
||||||
ga.generation_goal = 50
|
ga.generation_goal = 200
|
||||||
ga.gene_impl = lambda: random.randint(0, 10)
|
ga.gene_impl = lambda: random.randint(0, 10)
|
||||||
|
|
||||||
def fitness_function(chromosome):
|
def fitness_function(chromosome):
|
||||||
|
|||||||
Reference in New Issue
Block a user