from toolz import pipe from leap_ec import Individual, context, test_env_var from leap_ec import ops, probe, util from leap_ec.decoder import IdentityDecoder from leap_ec.binary_rep.problems import MaxOnes from leap_ec.binary_rep.initializers import create_binary_sequence from leap_ec.binary_rep.ops import mutate_bitflip ############################## # Entry point ############################## if __name__ == '__main__': parents = Individual.create_population( 5, initialize=create_binary_sequence(4), decoder=IdentityDecoder(), problem=MaxOnes()) # Evaluate initial population parents = Individual.evaluate_population(parents) # print initial, random population util.print_population(parents, generation=0) # When running the test harness, just run for two generations # (we use this to quickly ensure our examples don't get bitrot) if os.environ.get(test_env_var, False) == 'True': max_generation = 2 else: max_generation = 6
# this was in the context of the 1/5 success rule, which we've not # implemented here. # Handbook of EC, B1.3:2 context['leap']['std'] *= .85 if __name__ == '__main__': # Define the real value bounds for initializing the population. In this case, # we define a genome of four bounds. # the (-5.12,5.12) was what was originally used for this problem in # Ken De Jong's 1975 dissertation, so was used for historical reasons. bounds = [(-5.12, 5.12), (-5.12, 5.12), (-5.12, 5.12), (-5.12, 5.12)] parents = Individual.create_population( 5, initialize=create_real_vector(bounds), decoder=IdentityDecoder(), problem=SpheroidProblem(maximize=False)) # Evaluate initial population parents = Individual.evaluate_population(parents) context['leap']['std'] = 2 # We use the provided context, but we could roll our own if we # wanted to keep separate contexts. E.g., island models may want to have # their own contexts. generation_counter = util.inc_generation(context=context, callbacks=(anneal_std, )) # print initial, random population