Exemplo n.º 1
0
def test_attributes_gene_impl():
    # Create the Genetic algorithm
    ga = GA()

    # Set necessary attributes
    ga.population_size = 3
    ga.chromosome_length = 5
    ga.generation_goal =  1
    # Set gene_impl
    ga.gene_impl = lambda: random.randint(1, 10)

    # Evolve the genetic algorithm
    ga.evolve()
Exemplo n.º 2
0
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()