# Genetic Algorithm

Genetic algorithm solver for mixed-integer or continuous-variable
optimization, constrained or unconstrained

Genetic algorithm solves smooth or nonsmooth optimization problems with any types of constraints, including integer constraints. It is a stochastic, population-based algorithm that searches randomly by mutation and crossover among population members.

## Functions

## Live Editor Tasks

Optimize | Optimize or solve equations in the Live Editor (Since R2020b) |

## Topics

### Problem-Based Genetic Algorithm

**Minimize Rastrigins' Function Using ga, Problem-Based**

Basic example minimizing a function with multiple minima in the problem-based approach.**Constrained Minimization Using ga, Problem-Based**

Solve a nonlinear problem with nonlinear constraints and bounds using`ga`

in the problem-based approach.**Solve a Mixed-Integer Engineering Design Problem Using the Genetic Algorithm, Problem-Based**

Example showing how to use problem-based mixed-integer programming in ga, including how to choose from a finite list of values.**Feasibility Using Problem-Based Optimize Live Editor Task**

Solve a nonlinear feasibility problem using the problem-based Optimize Live Editor task and several solvers.**Set Options in Problem-Based Approach Using varindex**

To set options in some contexts, map problem-based variables to solver-based using`varindex`

.

### Genetic Algorithm Optimization Basics

**Minimize Rastrigin's Function**

Presents an example of solving an optimization problem using the genetic algorithm.**Coding and Minimizing a Fitness Function Using the Genetic Algorithm**

Shows how to write a fitness function including extra parameters or vectorization.**Constrained Minimization Using the Genetic Algorithm**

Shows how to include constraints in your problem.**Options and Outputs**

Shows how to choose input options and output arguments.**Effects of Genetic Algorithm Options**

Example showing the effect of several options.**Global vs. Local Optimization Using ga**

This example shows how setting the initial range can lead to a better solution.

### Common Tuning Options

**Set Maximum Number of Generations and Stall Generations**

Examine the effects of setting the`MaxGenerations`

and`MaxStallGenerations`

options.**Population Diversity**

Shows the importance of population diversity, and how to set it.**Fitness Scaling**

Describes fitness scaling, and how it affects the progress of`ga`

.**Vary Mutation and Crossover**

Shows the effect of the mutation and crossover parameters in`ga`

.**Hybrid Scheme in the Genetic Algorithm**

Shows the use of a hybrid function for improving a solution.**When to Use a Hybrid Function**

Describes cases where hybrid functions are likely to provide greater accuracy or speed.

### Mixed Integer Optimization

**Mixed Integer ga Optimization**

Solve mixed integer programming problems, where some variables must be integer-valued.**Solve a Mixed-Integer Engineering Design Problem Using the Genetic Algorithm**

Example showing how to use mixed-integer programming in ga, including how to choose from a finite list of values.

### Specialized Tasks

**Resume ga**

Shows how to continue optimizing`ga`

from the final population.**Reproduce Results**

Shows how to reproduce results by resetting the random seed.**Run ga from a File**

Provides an example of running`ga`

using a set of parameters to search for the most effective setting.**Vectorize the Fitness Function**

How to gain speed using vectorized function evaluations.**Create Custom Plot Function**

Shows how to create and use a custom plot function in`ga`

.**Custom Output Function for Genetic Algorithm**

This example shows the use of a custom output function in`ga`

.**Custom Data Type Optimization Using the Genetic Algorithm**

Solve a traveling salesman problem using a custom data type.**Optimize ODEs in Parallel**

Save time by calling an expensive subroutine just once and computing an ODE solution in parallel using`patternsearch`

or`ga`

.**Optimize Simulink Model in Parallel**

This example shows how to optimize a Simulink^{®}model in parallel using several Global Optimization Toolbox solvers.

### Genetic Algorithm Background

**What Is the Genetic Algorithm?**

Introduces the genetic algorithm.**Genetic Algorithm Terminology**

Explains some basic terminology for the genetic algorithm.**How the Genetic Algorithm Works**

Presents an overview of how the genetic algorithm works.**Nonlinear Constraint Solver Algorithms for Genetic Algorithm**

Explains the Augmented Lagrangian Genetic Algorithm (ALGA) and penalty algorithm.**Genetic Algorithm Options**

Explore the options for the genetic algorithm.