Find minimum of function using genetic algorithm
x = ga(fitnessfcn,nvars)
x = ga(fitnessfcn,nvars,A,b)
x = ga(fitnessfcn,nvars,A,b,Aeq,beq)
x = ga(fitnessfcn,nvars,A,b,Aeq,beq,LB,UB)
x = ga(fitnessfcn,nvars,A,b,Aeq,beq,LB,UB,nonlcon)
x = ga(fitnessfcn,nvars,A,b,Aeq,beq,LB,UB,nonlcon,options)
x = ga(fitnessfcn,nvars,A,b,[],[],LB,UB,nonlcon,IntCon)
x = ga(fitnessfcn,nvars,A,b,[],[],LB,UB,nonlcon,IntCon,options)
x = ga(problem)
[x,fval]
= ga(fitnessfcn,nvars,...)
[x,fval,exitflag]
= ga(fitnessfcn,nvars,...)
[x,fval,exitflag,output]
= ga(fitnessfcn,nvars,...)
[x,fval,exitflag,output,population]
= ga(fitnessfcn,nvars,...)
[x,fval,exitflag,output,population,scores]
= ga(fitnessfcn,nvars,...)
finds
a local unconstrained minimum, x
= ga(fitnessfcn
,nvars
)x
, to the objective
function, fitnessfcn
. nvars
is
the dimension (number of design variables) of fitnessfcn
.
finds
a local minimum x
= ga(fitnessfcn
,nvars
,A
,b
)x
to fitnessfcn
,
subject to the linear inequalities A*x
≤ b
. ga
evaluates
the matrix product A*x
as if x
is
transposed (A*x'
).
finds
a local minimum x
= ga(fitnessfcn
,nvars
,A
,b
,Aeq
,beq
)x
to fitnessfcn
,
subject to the linear equalities Aeq*x
= beq
as well as A*x
≤ b
. (Set A=[]
and b=[]
if
no linear inequalities exist.) ga
evaluates the
matrix product Aeq*x
as if x
is
transposed (Aeq*x'
).
defines
a set of lower and upper bounds on the design variables, x
= ga(fitnessfcn
,nvars
,A
,b
,Aeq
,beq
,LB
,UB
)x
,
so that a solution is found in the range LB
≤ x
≤ UB
.
(Set Aeq=[]
and beq=[]
if no
linear equalities exist.)
subjects
the minimization to the constraints defined in x
= ga(fitnessfcn
,nvars
,A
,b
,Aeq
,beq
,LB
,UB
,nonlcon
)nonlcon
.
The function nonlcon
accepts x
and
returns vectors C
and Ceq
, representing
the nonlinear inequalities and equalities respectively. ga
minimizes
the fitnessfcn
such that C(x)
≤ 0
and Ceq(x) = 0
. (Set LB=[]
and UB=[]
if
no bounds exist.)
minimizes
with the default optimization parameters replaced by values in the
structure x
= ga(fitnessfcn
,nvars
,A
,b
,Aeq
,beq
,LB
,UB
,nonlcon
,options
)options
, which can be created using the gaoptimset
function. (Set nonlcon=[]
if
no nonlinear constraints exist.)
requires
that the variables listed in x
= ga(fitnessfcn
,nvars
,A
,b
,[],[],LB
,UB
,nonlcon
,IntCon
)IntCon
take integer
values.
Note:
When there are integer constraints, 
minimizes
with integer constraints and with the default optimization parameters
replaced by values in the x
= ga(fitnessfcn
,nvars
,A
,b
,[],[],LB
,UB
,nonlcon
,IntCon
,options
)options
structure.
finds
the minimum for x
= ga(problem
)problem
, where problem
is
a structure.
[
returns x
,fval
]
= ga(fitnessfcn
,nvars
,...)fval
,
the value of the fitness function at x
.
[
returns x
,fval
,exitflag
]
= ga(fitnessfcn
,nvars
,...)exitflag
,
an integer identifying the reason the algorithm terminated.
[
returns x
,fval
,exitflag
,output
]
= ga(fitnessfcn
,nvars
,...)output
,
a structure that contains output from each generation and other information
about the performance of the algorithm.
[
returns
the matrix, x
,fval
,exitflag
,output
,population
]
= ga(fitnessfcn
,nvars
,...)population
, whose rows are the final
population.
[
returns x
,fval
,exitflag
,output
,population
,scores
]
= ga(fitnessfcn
,nvars
,...)scores
the
scores of the final population.

Handle to the fitness function. The fitness function should
accept a row vector of length When the  

Positive integer representing the number of variables in the problem.  

Matrix for linear inequality constraints of the form
If the problem has
 

Vector for linear inequality constraints of the form
If the problem has
 

Matrix for linear equality constraints of the form
If the problem has
 

Vector for linear equality constraints of the form
If the problem has
 

Vector of lower bounds.
 

Vector of upper bounds.  

Function handle that returns two outputs: [c,ceq] = nonlcon(x)
You can write nonlcon = @constraintfile where To learn how to use vectorized constraints, see Vectorized Constraints.
 

Structure containing optimization options. Create
 

Vector of positive integers taking values from
 

Structure containing the following fields:
Create 

Best point that  

Fitness function evaluated at  

Integer giving the reason
When there are integer constraints,  

Structure containing output from each generation and other information
about algorithm performance. The
 

Matrix whose rows contain the members of the final population.  

Column vector of the fitness values (scores for 
Given the following inequality constraints and lower bounds
$$\begin{array}{l}\left[\begin{array}{cc}1& 1\\ 1& 2\\ 2& 1\end{array}\right]\left[\begin{array}{c}{x}_{1}\\ {x}_{2}\end{array}\right]\le \left[\begin{array}{c}2\\ 2\\ 3\end{array}\right],\\ {x}_{1}\ge 0,\text{}{x}_{2}\ge 0,\end{array}$$
use this code to find the minimum of the lincontest6
function,
which is provided in your software:
A = [1 1; 1 2; 2 1]; b = [2; 2; 3]; lb = zeros(2,1); [x,fval,exitflag] = ga(@lincontest6,... 2,A,b,[],[],lb) Optimization terminated: average change in the fitness value less than options.TolFun. x = 0.6700 1.3310 fval = 8.2218 exitflag = 1
Optimize a function where some variables must be integers:
fun = @(x) (x(1)  0.2)^2 + ... (x(2)  1.7)^2 + (x(3)  5.1)^2; x = ga(fun,3,[],[],[],[],[],[],[], ... [2 3]) % variables 2 and 3 are integers Optimization terminated: average change in the penalty fitness value less than options.TolFun and constraint violation is less than options.TolCon. x = 0.2000 2.0000 5.0000
For problems without integer constraints, consider using patternsearch
instead of ga
.
[1] Goldberg, David E., Genetic Algorithms in Search, Optimization & Machine Learning, AddisonWesley, 1989.
[2] A. R. Conn, N. I. M. Gould, and Ph. L. Toint. "A Globally Convergent Augmented Lagrangian Algorithm for Optimization with General Constraints and Simple Bounds", SIAM Journal on Numerical Analysis, Volume 28, Number 2, pages 545–572, 1991.
[3] A. R. Conn, N. I. M. Gould, and Ph. L. Toint. "A Globally Convergent Augmented Lagrangian Barrier Algorithm for Optimization with General Inequality Constraints and Simple Bounds", Mathematics of Computation, Volume 66, Number 217, pages 261–288, 1997.