From 74f6c8957be27b4d743f9e411ba62e3138615ae4 Mon Sep 17 00:00:00 2001 From: danielwilczak101 <44122838+danielwilczak101@users.noreply.github.com> Date: Thu, 22 Oct 2020 00:03:51 -0400 Subject: [PATCH] Added some error checking --- src/attributes.py | 19 +++++++++++++++++-- src/run_testing.py | 6 +++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/attributes.py b/src/attributes.py index 5430926..757d69e 100644 --- a/src/attributes.py +++ b/src/attributes.py @@ -64,7 +64,7 @@ class attributes: self.termination_impl = Termination_Methods.generation_based - # Example of how the setter error checking will look like + # Getter and setters for all varibles @property def chromosome_length(self): return self._chromosome_length @@ -72,5 +72,20 @@ class attributes: @chromosome_length.setter def chromosome_length(self, value_input): 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 + + + @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 diff --git a/src/run_testing.py b/src/run_testing.py index 56b8260..44050b8 100644 --- a/src/run_testing.py +++ b/src/run_testing.py @@ -3,10 +3,10 @@ import EasyGA # Create the Genetic algorithm ga = EasyGA.GA() -ga.target_fitness_type = 'min' +ga.target_fitness_type = 'max' ga.chromosome_length = 10 -ga.population_size = 25 -ga.generation_goal = 50 +ga.population_size = 10 +ga.generation_goal = 200 ga.gene_impl = lambda: random.randint(0, 10) def fitness_function(chromosome):