Domain $[-5,5]^2$, global minimum $f(0,0)=0$.
Select a benchmark function and configure population size, mutation rate, and crossover rate. Watch the population converge to the global optimum.
Domain $[-5,5]^2$, global minimum $f(0,0)=0$.
The core of a Genetic Algorithm is the selection process, which determines which solutions survive to reproduce. A common method is "Fitness-Proportionate Selection," where the probability of selecting an individual is proportional to its fitness score relative to the whole population.
$$P(\text{select individual }i) = \frac{f_i}{\sum_{j=1}^{N} f_j}$$Here, $f_i$ is the fitness of individual $i$, and $N$ is the population size. A higher fitness means a better solution (e.g., a lower function value for minimization). This drives the population toward better regions of the search space.
Another key operation is mutation, which introduces random variations to maintain diversity and explore new solutions. For a real-valued parameter $x$, a simple mutation adds Gaussian noise.
$$x' = x + \mathcal{N}(0, \sigma)$$Here, $x'$ is the mutated parameter, and $\mathcal{N}(0, \sigma)$ is a random number from a normal distribution with mean 0 and standard deviation $\sigma$, which is often related to the mutation rate you control in the simulator. This small random jump can help escape local optima.
Aerodynamic Design: Genetic Algorithms are used to optimize the shape of aircraft wings or turbine blades. Engineers define parameters describing the shape, and the GA searches for the configuration that minimizes drag or maximizes lift, evaluating thousands of designs computationally.
Antenna Design: Designing antennas for specific radiation patterns is highly complex. GAs can optimize the layout and dimensions of antenna elements to meet target frequency and gain specifications, a task difficult for traditional methods.
Robotics & Motion Planning: GAs help optimize the gait of walking robots or the trajectory of robotic arms. The algorithm searches for joint angle sequences that minimize energy consumption or complete a task fastest while avoiding obstacles.
Financial Portfolio Optimization: In finance, GAs can search for the optimal mix of assets (stocks, bonds) that maximizes expected return for a given level of risk, navigating a complex landscape of historical data and constraints.
As you become familiar with genetic algorithms (GAs) using this simulator, you might be tempted to see them as a "universal optimization tool." First, GAs do not guarantee finding the "optimal solution." They are a method for finding a "very good solution" with high probability. In practical applications, especially, the computational cost can become enormous. For example, optimizing a vehicle's crash safety might require several hours for a single CAE analysis. With a population of 100 and 50 generations, a simple calculation suggests 5000 analyses would be needed, which is often impractical. In practice, GAs are frequently used for rough exploration to determine an initial design or for generating initial solutions for problems where other methods provide no leads.
Next, avoid relying on magical parameter settings. Discard superstitions like "a mutation rate of 0.01 is the golden rule." The optimal parameters vary greatly depending on the problem. What you should try with this tool is observing how an extremely high mutation rate (e.g., 0.5) causes the population to perform a random walk and fail to converge, while an excessively low rate (e.g., 0.001) causes a loss of initial diversity, trapping the search in the first local optimum it encounters. In practice, you'll need to adjust parameters, starting with default values, then increasing the mutation rate if diversity is lost too quickly, or strengthening the selection pressure if convergence is too slow.
Optimizing the Rastrigin function (global minimum f(0,0)=0) with population=50, mutation=0.15, crossover=0.8, generations=200: initial best fitness ≈ 45.2 at generation 1; after 100 generations, fitness drops to 8.3 with best point near (0.4, −0.2); final generation achieves f=1.7 at (0.08, 0.06). Diversity (std. dev.) decays from 12.4 to 0.3, indicating convergence. Mutation rate 0.15 prevents premature stagnation while crossover 0.8 enables effective recombination.