Week 5 - Genetic Algorithm
Genetic Algorithm
A Genetic Algorithm is a search heuristic inspired by the process of natural selection and genetics. It is commonly used to find approximate solutions to optimization and search problems. The algorithm operates on a population of potential solutions, encoding them as individuals, and evolves the population over generations.
The ga function in MATLAB is used to perform genetic algorithm optimization. The basic syntax is as follows:
[x, fval] = ga(fun, nvars)
fun: The objective function to be minimized or maximized.
nvars: The number of variables in the optimization problem.
Additional parameters and options can be provided to customize the behavior of the genetic algorithm. For example:
[x, fval] = ga(fun, nvars, A, b, Aeq, beq, lb, ub, nonlcon, options)
A, b: Linear inequality constraints.
Aeq, beq: Linear equality constraints.
lb, ub: Lower and upper bounds for the variables.
nonlcon: Nonlinear constraint function.
options: A structure containing various options for the genetic algorithm.
Matlab code :
Stalagmite function code :
Plots and observations :
Figure 1: Stalagmite Function Surface Plot

- This figure represents the surface plot of the stalagmite function over the given two-dimensional grid.
- The surface plot gives a visual understanding of the function's behavior in the specified input space.
Figure 2: Unbounded Inputs Study

- This figure depicts the results of the genetic algorithm optimization for unbounded inputs.
- The surface plot shows the original function, and the red markers represent the optimal points found by the genetic algorithm.
- The lower subplot illustrates the evolution of the maximum function value over iterations.
Figure 3: Bounded Inputs Study

- This figure shows the results of the genetic algorithm optimization for bounded inputs.
- Similar to Figure 2, the surface plot displays the original function, and the red markers indicate optimal points within the specified bounds.
- The lower subplot depicts the convergence of the maximum function value over iterations.
Figure 4: Bounded Inputs with Increased Population Study

- This figure represents the outcomes of the genetic algorithm optimization for bounded inputs with an increased population size.
- The surface plot visualizes the original function, and the red markers highlight optimal points found by the genetic algorithm.
- The lower subplot shows the progression of the maximum function value with a larger population.
Observations:
- In both studies with bounded inputs (Figure 3 and Figure 4), the genetic algorithm successfully finds optimal solutions within the specified bounds.
- The use of an increased population in Figure 4 appears to contribute to faster convergence and potentially better solutions.
- The convergence behavior and speed can be influenced by various factors, including the choice of optimization algorithm, population size and other algorithm-specific parameters.
- Comparing the results of different studies can provide insights into the trade-offs between solution quality, convergence speed, and computational cost.