Question: IN PYTHON Programming Language 1. randomly generatea LGP individual withno more than[max_prog_length] instructions(4marks); 2. remove structurally ineffective instructions of the LGP program(4 marks); 3. print

IN PYTHON Programming Language

1. randomly generatea LGP individual withno more than[max_prog_length] instructions(4marks);

2. remove structurally ineffective instructions of the LGP program(4 marks);

3. print the original and structural-intron-free LGP programs(2marks)

GIVE BELOW is the main.py file where the answer is to be coded.

*************************************************************************************************

# Assignment 5 - LGP program generation and structural intron removal

def main():

# setting parameters max_prog_length = 6 # 6 instructions in total is the upper limit n_calculation_reg = 3 # {r0, r1, r2} and r0 is designated as the output register n_input_reg = 2 # {r3, r4} are the input registers n_operators = 4 # {+, -, *, /} are the operators n_constant = 5 # {1, 2, 3, 4, 5} are the constants constant_rate = 0.4 # An operand can be a constant with a 40% chance, however, both operands cannot be constants at the same time

##### 1. randomly generate a LGP program with no more than [max_prog_length] instructions # Hint: an instruction can be represented by a list of 4 elements, # i.e., its return register, operator, first and second operands # a LGP program is thus a list of instructions program = []

# student code begins

# student code ends

##### 2. print the LGP program as a list of instructions # An instruction should be printed as, for instance r3 = r1 + r0 or r2 = r0 * 5 print("The randomly generated LGP program is:")

# student code begins

# student code ends

##### 3. remove a program's structural intron program_intron_free = program.copy() effective_registers = ['r0'] effective_instruction_indices = []

# student code begins

# student code ends

##### 4. print the effective registers and the structual-intron free LGP program print("The effective registers are:") print(effective_registers) print("The LGP program withou any structual intron is:") # student code begins

# student code ends

# end of main

main()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!