int256 = ugp4.make_parameter(ugp4.parameter.Integer, min=0, max=256) # define macros assign = ugp4.Macro("{var} := {val}", {'var': variable, 'val': int256}) jmps = ugp4.Macro( "back {back}\nback_loose {back_loose}\ngeneric {generic}\nforward {forward}\nforward_loose {forward_loose}", { 'back': backward_only, 'back_loose': backward_loose, 'generic': generic, 'forward': forward_only, 'forward_loose': forward_loose }) filler = ugp4.make_section({assign}, size=(2, 5), instances=(0, 10)) # library library = ugp4.Constraints() library['main'] = ["\t; BEGIN", filler, jmps, filler, "\t; END"] def f(individual): return 42 library.evaluator = ugp4.fitness.make_evaluator(evaluator=f, fitness_type=ugp4.fitness.Simple) # Create a list of operators with their arities_____________________________________________________________________ operators = ugp4.Operators() operators += ugp4.GenOperator(ugp4.create_random_individual, 0) operators += ugp4.GenOperator(ugp4.macro_pool_uniform_crossover, 2) # Create the object that will manage the evolution__________________________________________________________________ mu = 10 nu = 20
init_macro = ugp4.Macro( " movl ${int_a}, %eax\n" + " movl ${int_b}, %ebx\n" + " movl ${int_c}, %ecx\n" + " movl ${int_d}, %edx\n", { 'int_a': integer, 'int_b': integer, 'int_c': integer, 'int_d': integer }) # Define section sec1 = ugp4.make_section({jmp1, instr_op_macro, shift_op_macro}, size=(1, 50)) # Create the instruction library library = ugp4.Constraints(file_name='solution{node_id}.s') library['main'] = [prologue_macro, init_macro, sec1, epilogue_macro] # Define the evaluator script and the fitness type if sys.platform == "win32": script = "eval.bat" else: script = "./eval.sh" library.evaluator = ugp4.fitness.make_evaluator( evaluator=script, fitness_type=ugp4.fitness.Lexicographic) # Define and set a property. It checks whether the section 'sec1' has or not the same number of 'shr' and 'shl' def shift_count(individual, frame, **kk): shl_count = 0 shr_count = 0 for node in individual.nodes(frame_selector=frame):