Change domain feature

This commit is contained in:
danielwilczak101
2020-09-25 15:12:02 -04:00
parent 7409ffb8ba
commit 9d9d0b750c
3 changed files with 33 additions and 16 deletions

View File

@ -1,14 +1,22 @@
import EasyGA
import random
# Create the Genetic algorithm
ga = EasyGA.GA()
# input domain
#ga.domain = range(3, 10)
ga.domain = ['left', 'right']
def user_gene_domain(gene_index):
"""Each gene index is assosiated to its index in the chromosome"""
domain = [
random.randrange(1,100),
random.uniform(10,5),
random.choice(["up","down"])
]
return domain[gene_index]
# If the user wants to use a domain
ga.domain = user_gene_domain
# If the user wants to use a custom range
#ga.new_range = [random.randrange,1,100]
# initialize random population
ga.initialize()
# Print population
ga.population.print_all()