def test_attributes_chromosome_impl_lambdas(): # Create the Genetic algorithm ga = GA() # Set necessary attributes ga.chromosome_length = 3 ga.generation_goal = 1 # Set gene_impl to None so it won't interfere ga.gene_impl = None # Set chromosome_impl ga.chromosome_impl = lambda: [ random.randrange(1,100), random.uniform(10,5), random.choice(["up","down"]) ] # Evolve the genetic algorithm ga.evolve()
def test_attributes_chromosome_impl_functions(): # Create the Genetic algorithm ga = GA() # Set necessary attributes ga.chromosome_length = 3 ga.generation_goal = 1 # Create chromosome_impl user function def user_chromosome_function(): chromosome_data = [ random.randrange(1,100), random.uniform(10,5), random.choice(["up","down"]) ] return chromosome_data # Set the chromosome_impl ga.chromosome_impl = user_chromosome_function # Evolve the genetic algorithm ga.evolve()