This vignette demonstrates how to use the
genetic.algo.optimizeR
package to optimize the function
\(f(x) = x^2 - 4x + 4\) using a genetic
algorithm.
Optimize the function \(f(x) = x^2 - 4x + 4\) to find the value of \(x\) that minimizes the function.
We start with a population of three individuals: \(x_1 = 1\), \(x_2 = 3\), and \(x_3 = 0\).
We evaluate the fitness of each individual by calculating \(f(x)\) for each \(x\) value:
We select individuals \(x_1\) and \(x_2\) as parents for crossover because they have higher fitness.
We perform crossover and mutation on the selected parents to generate offspring: \(x_1' = 1\), \(x_2' = 3\).
This vignette demonstrates the usage of the
genetic.algo.optimizeR
package to optimize the given
function using a genetic algorithm. Users can follow similar steps to
optimize other functions or customize the parameters as needed.