Genetic algorithm
Question 2 – Genetic Algorithms Function Optimization Python A very popular application of GAs is in function optimization for multi-variable, complex functions encountered in engineering problems. In this question, we will use a simpler, linear function and optimize it using a GA. Consider the function: f = |a + 2b + 3c + 4d – 50|.Your objective is to find the combination of a, b, c and d that will minimize f. For this, a chromosome could be the combination of values for a-b-c-d. For example, a=20, b = 12, c=15, d = 8 is encoded as 20-12-15-8. The fitness function Is the value of f for the combination of a-b-c-d values in the chromosome.
Write a program to implement a GA that minimizes a linear function. Your program should prompt the user for GA input parameters like in Question 1 above. After that, it should prompt the user to enter the function to be optimized in the form below, or exit the program. The function input format is:
<max OR min> |n_1a + n_2b + n_3c + ….| - K where n_1, n_2, n_3…and K are integer constants. Each of the constants could be positive or negative. Note that the number of function variables, a, b, c, and so on have to be determined from the input. The optimization will be either max or min.
After running the GA, the program should print the same output as in Question 1, that is given again below:
- Values of input parameters used (on a single line, comma-separated, format:- <parameter name: value>)
- Number of iterations or generations of the GA executed
- Final state reached
- Final state’s fitness function value.
After printing the output, the program should go back to the menu for function input and exit.