Files
EasyGA/src/new_initialization_method_testing.py
RyleyGG 6aec9770b6 Further optimizations, error-checking, user-input conversions
1) The initialization now accepts "general" inputs that should apply to each gene. For example, rather than a gene input of [1,100] being interpreted to mean gene 1 hsould be 1 and gene 2 should be 100, it will apply a range of [1,100] to each gene.
2) The initialization now accepts "general" gene_input_types. For example, if the user had a set of index-dependent number values, they could just say ga.gene_input_type = "domain" and the package will propagate that across all genes in the chromosome. The user still has the option of defining the entire array or just defining a specific element if they so choose. For later commits, the general gene_input_type will have to be checked for validity; for example, a string can never be a range.
3) Fixed an issue in the ordering of the initialization function call.
4) Added comments surrounding the signfiicant changes to the initialization.
5) Added example tests to the testing file.
2020-09-25 18:02:45 -04:00

36 lines
1.3 KiB
Python

import EasyGA
import random
#1. GA should take in range for gene input
#2. GA should take in index-dependent range for gene input
#3. GA should take in domain input
#4. GA should take in index-dependent domain for gene input
#5. GA should accept mix of range and domain for gene input
# Create the Genetic algorithm
ga = EasyGA.GA()
test_gene_input = [["left", "right"],[1,100],[5.0,10],[22,"up"]]
ga.gene_input_type[1] = "float-range"
ga.gene_input_type[2] = "domain"
ga.initialize(test_gene_input)
ga.population.print_all()
#Example tests
#Note, the following examples assume a chromosome length of 4.
#if the test_gene_input is longer than the chromosomes, it will get truncated at the length of the chromosome
#for example, for chromosomes with length 2, [["left", "right"],[1,100],[5.0,10],[22,"up"]] becomes [["left", "right"],[1,100]]
#if the test_gene_input is shorter than the chromosomes, the remaining elements will be populated with None
#test_gene_input = [1,100]
#test_gene_input = [["left", "right"],[1,100],[5.0,10],[22,"up"]]
#test_gene_input = ["left", "right", "up", "down"]
#test_gene_input = [[1,100],[0,1],[33,35],[5,6]]
#test_gene_input = [["left", "right"], ["up", "down"], ["left", "down"], ["down", "right"]]
#ga.gene_input_type = "float-range"
#ga.gene_input_type[1] = "domain"
#ga.gene_input_type[1] = "float-range"