HyperMath

GA

GA

Previous topic Next topic No expanding text in this topic  

GA

Previous topic Next topic JavaScript is required for expanding text JavaScript is required for the print function  

Minimizes a multivariate function f(x), subject to arbitrary constraints, using genetic algorithm.

Syntax

x, f, c, dh, oh, ch, genseed = GA(objFunc, conFunc, lb, ub, con_ub, init, seed, numIters, popSize, globalSearch, gmax, userdata)

Arguments

Name

Description

 

objFunc

Name of the user defined objective function. It must return a real number. It must return a real number or one element vector. See Comments.

 

conFunc (optional)

Name of the user defined constraint function. If the vector has one element, then a real number may be returned instead.  See Comments.

 

lb

The vector of lower bounds of the design variables. The length is the number of variables.

 

ub

The vector of upper bounds of the design variables.

 

con_ub (optional)

The vector of upper bounds of the constraint function output variables.

 

init (optional)

The vector of initial estimates for the design variables. The length is the number of variables. If it is empty or omitted, the midpoints of the bounding intervals are used.

 

seed (optional)

A one element vector containing an integer seed for the random number generator. If it is zero or the vector is empty, then an unrepeatable random seed is selected.

 

numIters (optional)

A one-element vector containing the maximum number of iterations allowed, or a two-element vector containing the minimum and maximum number of iterations allowed. It may be empty or omitted. The default values are 25 for the minimum and 200 for the maximum. The maximum can be set to Inf to specify the greatest number of iterations (1000) that the algorithm allows.

 

popSize (optional)

A one element vector containing the population size. If it is empty or omitted, it defaults to 0, which allows the algorithm to determine what size to use

 

globalSearch (optional)

A one element vector containing the global search option. If it is empty or omitted, it defaults to 2.

 

cons_tol

A one element vector containing the constraint violation margin. If it is empty or omitted, it defaults to 0.5.

 

userdata (optional)

Data matrix that is passed to the user defined function at each iteration. This can be used to supply data that are defined outside the function. It can be omitted or empty.

Output

Name

Description

 

x

The location of the function minimum. It may only be a local minimum.

 

f

The minimum value of the function.

 

c

A vector containing the constraint function values at the function minimum. It will have the same orientation as con_ub. It is omitted from the output if there are no input constraints.

 

dh

A matrix containing the design variable history. Each column of the matrix contains the iteration step values for a design variable.

 

oh

A row vector containing the objective function history at each iteration step.

 

ch

A matrix containing the constraint function history. Each column of the matrix contains the iteration step values for a design variable. It is omitted from the outputs if there are no input constraints.

 

genseed

The random number generator seed. It returns either seed or the internally generated seed, as applicable.

Example 1

Find the minimum of a paraboloid, subject to x + 3y > = 22 and x + 5y > = 32.

f(x,y) = (x-3)^2 - 5(x-3)(y-2) + 4(y-2)^2 + 6.

The problem is defined with a lower bound which must be reformulated as an upper bound.

 

Syntax

// define the objective function

function ObjFunc(x, d)

{

   return (x(1)-d(1))^2 - 5*(x(1)-d(1))*(x(2)-d(2))

          + 4*(x(2)-d(2))^2 + 6

}

 

// define the constraint function

function ConFunc(x)

{

   // note the negation to reformulate as upper bound      

   return [-x(1) - 3*x(2), -x(1) - 5*x(2)]

}

 

// find the minimum

lowerBound = [-10, -10]

upperBound = [10, 10]

conUpBound = [-22, -32]   // note the negation

userData = [3, 2]

 

x,f = GA("ObjFunc", "ConFunc", lowerBound, upperBound,

        conUpBound, [], [2003], [100], [100], [2],

        [], userData)

 

Result

x = 10.0    6.375

f = -21.5625

Comments

The user defined functions get called by the solver until it is no longer decreasing based on the given tolerance.  They accept a vector of the same size as lb for the variable values as the first argument.  Optionally, they can take a data matrix as the second argument.

The output vector x will have the same orientation as the input vector init. If the vector of initial estimates is omitted, the output vector will have the same orientation as the vector of lower bounds. However, the vector for the design variables that is passed to the user functions will be a column vector.

See Also:

FMinBnd

FMinCon

FMinUncon

NLCurveFit

NLSolve