主要内容

ga

使用遗传算法查找最小功能

Description

example

x= ga(乐趣,nvars)找到当地的不受约束,x, to the objective function,乐趣nvarsis the dimension (number of design variables) of乐趣

Note

Passing Extra Parameters如有必要,如何将额外参数传递给客观函数和非线性约束函数。

example

x= ga(乐趣,nvars,A,b)找到当地的最低限度x乐趣, subject to the linear inequalitiesA*xbga评估矩阵产品A*x仿佛xis transposed (A*x').

example

x= ga(乐趣,nvars,A,b,Aeq,beq)找到当地的最低限度x乐趣, subject to the linear equalitiesAeq*x=beqandA*xb。(SetA=[]andb=[]if no linear inequalities exist.)ga评估矩阵产品Aeq*x仿佛xis transposed (Aeq*x').

example

x= ga(乐趣,nvars,A,b,Aeq,beq,,UB.)defines a set of lower and upper bounds on the design variables,x, so that a solution is found in the rangexUB.。(SetAeq=[]andbeq = []if no linear equalities exist.)

example

x= ga(乐趣,nvars,A,b,Aeq,beq,,UB.,nonlcon.)对所定义的约束最小化nonlcon.。The functionnonlcon.接受xand returns vectorsCandCeq, representing the nonlinear inequalities and equalities respectively.gaminimizes the乐趣such thatC(x)0andCeq(x) = 0。(Set磅=[]andUB.=[]if no bounds exist.)

example

x= ga(乐趣,nvars,A,b,Aeq,beq,,UB.,nonlcon.,选择)最小化默认优化参数替换为值选择。(Setnonlcon.=[]if no nonlinear constraints exist.) Create选择usingoptimoptions

example

x= ga(乐趣,nvars,A,b,[],[],,UB.,nonlcon.,IntCon)要么x= ga(乐趣,nvars,A,b,[],[],,UB.,nonlcon.,IntCon,选择)requires that the variables listed inIntContake integer values.

Note

当。。。的时候re are integer constraints,gadoes not accept linear or nonlinear equality constraints, only inequality constraints.

x= ga(problem)finds the minimum forproblem,描述的结构problem

example

[x,fval] = ga(___),对于任何先前的输入参数,也会返回fval, the value of the fitness function atx

example

[x,fval,exitflag,output] = ga(___)also returnsexitflag, an integer identifying the reason the algorithm terminated, andoutput, a structure that contains output from each generation and other information about the performance of the algorithm.

example

[x,fval,exitflag,output,population,得分] = ga(___)也返回一个矩阵population, whose rows are the final population, and a vector得分, the scores of the final population.

Examples

collapse all

Theps_example.m.file ships with your software. Plot the function.

ξ= linspace (2300);易= linspace (4 4300); [X,Y] = meshgrid(xi,yi); Z = ps_example([X(:),Y(:)]); Z = reshape(Z,size(X)); surf(X,Y,Z,'MeshStyle','none') colormap'jet'view(-26,43) xlabel('x(1)')ylabel('x(2)')标题('ps\_example(x)')

Find the minimum of this function usingga

rngdefault重复性的%X = GA(@ PS_EXAMPLE,2)
优化终止:FITHS值的平均变化小于选项。功能化。
X =1×2-4。6793 -0.0860

使用遗传算法最小化ps_example.乐趣ction on the regionx(1) + x(2) >= 1andx(2)<= 5 + x(1)

First, convert the two inequality constraints to the matrix forma * x <= b。In other words, get thex在不等式的左侧的变量,并使不等式少于或等于:

-x(1) -x(2) <= -1

-x(1) + x(2) <= 5

A = [-1,-1; -1,1]; b = [-1;5];

Solve the constrained problem usingga

rngdefault重复性的%有趣= @ps_example;X =ga(fun,2,A,b)
优化终止:FITHS值的平均变化小于选项。功能化。
X =1×20.9991 0.0000

约束对约束公差的默认值满意,1e-3。To see this, computeA*x' - b, which should have negative components.

disp(A*x' - b)
0.0009 -5.9991

使用遗传算法最小化ps_example.乐趣ction on the regionx(1) + x(2) >= 1andx(2)== 5 + x(1)

First, convert the two constraints to the matrix forma * x <= bandAeq*x = beq。In other words, get thex变量on the left-hand side of the expressions, and make the inequality into less than or equal form:

-x(1) -x(2) <= -1

-x(1) + x(2) == 5

A = [-1 -1]; b = -1; Aeq = [-1 1]; beq = 5;

Solve the constrained problem usingga

rngdefault重复性的%有趣= @ps_example;X = GA(有趣,2,A,B,AEQ,BEQ)
优化终止:FITHS值的平均变化小于选项。功能化。
X =1×2-2。0000 2.9990

检查约束是否满足于默认值ConstraintTolerance,1e-3

disp(A*x' - b)
9.9998e-04
disp(Aeq*x' - beq)
-9.9937E-04.

使用遗传算法最小化ps_example.乐趣ction on the regionx(1) + x(2) >= 1andx(2)== 5 + x(1)。In addition, set bounds1 <= x(1) <= 6and-3 <= x(2) <= 8

First, convert the two linear constraints to the matrix forma * x <= bandAeq*x = beq。In other words, get thex变量on the left-hand side of the expressions, and make the inequality into less than or equal form:

-x(1) -x(2) <= -1

-x(1) + x(2) == 5

A = [-1 -1]; b = -1; Aeq = [-1 1]; beq = 5;

设定界限andUB.

磅= [1 -3]; ub = [6 8];

Solve the constrained problem usingga

rngdefault重复性的%有趣= @ps_example;X =ga(fun,2,A,b,Aeq,beq,lb,ub)
优化终止:FITHS值的平均变化小于选项。功能化。
X =1×21.0000 5.9991

Check that the linear constraints are satisfied to within the default value ofConstraintTolerance,1e-3

disp(A*x' - b)
-5.9991.
disp(Aeq*x' - beq)
-9.0713E-04.

使用遗传算法最小化ps_example.乐趣ction on the region 2 x 1 2 + x 2 2 3 and ( x 1 + 1 ) 2 = ( x 2 / 2 ) 4

To do so, first write a function省号.m.that returns the inequality constraint in the first output,c,以及第二个输出中的平等约束,ceq。Save the file省号.m.至a folder on your MATLAB® path.

typeellipsecons
乐趣ction [c,ceq] = ellipsecons(x) c = 2*x(1)^2 + x(2)^2 - 3; ceq = (x(1)+1)^2 - (x(2)/2)^4;

包括功能句柄ellipseconsas thenonlcon.argument.

nonlcon.= @ellipsecons; fun = @ps_example; rngdefault重复性的%X =ga(fun,2,[],[],[],[],[],[],nonlcon)
Optimization terminated: average change in the fitness value less than options.FunctionTolerance and constraint violation is less than options.ConstraintTolerance.
X =1×2-0.9766 0。0362

Check that the nonlinear constraints are satisfied atx。The constraints are satisfied whenc≤0且ceq= 0到默认值ConstraintTolerance,1e-3

[c,ceq] = nonlcon(x)
c = -1.0911.
ceq = 5.4645e-04

使用遗传算法最小化ps_example.乐趣ction on the regionx(1) + x(2) >= 1andx(2)== 5 + x(1)using a constraint tolerance that is smaller than the default.

First, convert the two constraints to the matrix forma * x <= bandAeq*x = beq。In other words, get thex变量on the left-hand side of the expressions, and make the inequality into less than or equal form:

-x(1) -x(2) <= -1

-x(1) + x(2) == 5

A = [-1 -1]; b = -1; Aeq = [-1 1]; beq = 5;

To obtain a more accurate solution, set a constraint tolerance of1e-6。And to monitor the solver progress, set a plot function.

选择= optimoptions('ga','ConstraintTolerance',1e-6,'plotfcn', @gaplotbestf);

解决最小化问题。

rngdefault重复性的%有趣= @ps_example;X =ga(fun,2,A,b,Aeq,beq,[],[],[],options)
优化终止:FITHS值的平均变化小于选项。功能化。

X =1×2-2。0000 3.0000

Check that the linear constraints are satisfied to within1e-6

disp(A*x' - b)
9.9999E-07.
disp(Aeq*x' - beq)
-9.9503E-07.

使用遗传算法最小化ps_example.函数受约束的影响x(1)是一个整数。

IntCon = 1; rngdefault重复性的%有趣= @ps_example;a = [];b = [];AEQ = [];beq = [];lb = [];UB = [];nonlcon = [];X = GA(乐趣,2,A,B,AEQ,BEQ,LB,UB,NONLCCON,INTCON)
Optimization terminated: average change in the penalty fitness value less than options.FunctionTolerance and constraint violation is less than options.ConstraintTolerance.
X =1×2-5.0000 -0.0000

Use to genetic algorithm to minimize an integer-constrained nonlinear problem. Obtain both the location of the minimum and the minimum function value.

IntCon = 1; rngdefault重复性的%有趣= @ps_example;a = [];b = [];AEQ = [];beq = [];lb = [];UB = [];nonlcon = [];[,fval] = ga(fun,2,a,b,AEQ,Beq,LB,UB,Nonlcon,Intcon)
Optimization terminated: average change in the penalty fitness value less than options.FunctionTolerance and constraint violation is less than options.ConstraintTolerance.
X =1×2-5.0000 -0.0000
fval = -1.9178

Compare this result to the solution of the problem with no constraints.

[x,fval] = ga(乐趣,2)
Optimization terminated: maximum number of generations exceeded.
X =1×2-4。7121 0.0051
fval = -1.9949.

使用遗传算法最小化ps_example.乐趣ction constrained to havex(1)整数值。To understand the reason the solver stopped and howgasearched for a minimum, obtain theexitflagandoutputresults. Also, plot the minimum observed objective function value as the solver progresses.

IntCon = 1; rngdefault重复性的%有趣= @ps_example;a = [];b = [];AEQ = [];beq = [];lb = [];UB = [];nonlcon = [];选择= optimoptions('ga','plotfcn', @gaplotbestf); [x,fval,exitflag,output] = ga(fun,2,A,b,Aeq,beq,lb,ub,nonlcon,IntCon,options)

Optimization terminated: average change in the penalty fitness value less than options.FunctionTolerance and constraint violation is less than options.ConstraintTolerance.
X =1×2-5.0000 -0.0000
fval = -1.9178
exitflag = 1
output =struct with fields:问题型:'Integercontraints'rngstate:[1x1 struct]代:96 Funccount:3691消息:'优化终止:惩罚健身值的平均变化低于选项.FunctionTolecta ...'MaxConstraint:0 HybridFlag:[]

使用遗传算法最小化ps_example.乐趣ction constrained to havex(1)整数值。获取所有输出,包括最终种群和分数矢量。

IntCon = 1; rngdefault重复性的%有趣= @ps_example;a = [];b = [];AEQ = [];beq = [];lb = [];UB = [];nonlcon = [];[x,fval,exitflag,output,population,scores] = ga(fun,2,A,b,Aeq,beq,lb,ub,nonlcon,IntCon);
Optimization terminated: average change in the penalty fitness value less than options.FunctionTolerance and constraint violation is less than options.ConstraintTolerance.

Examine the first 10 members of the final population and their corresponding scores. Notice thatx(1)对所有这些人口成员都是整数的重视。整数ga算法仅生成整数可行的群体。

DISP(人口(1:10,:))
-5.0000 -0.0000-5.0000 -0.0000-5。0000 0.0014 -6.0000 0.0008 -13.0000 -0.0124 -10.0000 0.0011 -4.0000 -0.0010 0 0.0072 -4.0000 0.0010 -5.0000 -0.0000
DISP(分数(1:10))
-1.9178 -1.9178 -1.9165 1.0008 64.0124 25.0011 -1.5126 2.5072 -1.5126 -1.9178

Input Arguments

collapse all

目标职能, specified as a function handle or function name. Write the objective function to accept a row vector of lengthnvarsand return a scalar value.

当。。。的时候'undervectorized'option is真正,写乐趣至accept apop-通过-nvars矩阵,其中popis the current population size. In this case,乐趣returns a vector the same length aspop包含健身功能值。确保这件事乐趣does not assume any particular size forpop,自从ga即使在矢量化计算中也可以通过人口的单个成员。

Example:Fun = @(x)(x-[4,2])。^ 2

数据类型:char|乐趣ction_handle|string

Number of variables, specified as a positive integer. The solver passes row vectors of lengthnvars乐趣

Example:4

数据类型:

线性不平等约束, specified as a real matrix.A是一个M-通过-nvars矩阵,其中Mis the number of inequalities.

Aencodes theMlinear inequalities

a * x <= b,

wherex是栏矢量nvars变量x(:),和bis a column vector withM元素。

例如,至specify

x1+ 2x2≤ 10
3x1+ 4x2≤ 20
5x1+ 6x2≤ 30,

give these constraints:

a = [1,2; 3,4; 5,6];B = [10; 20; 30];

Example:要指定控制变量总和1或更少,请给出约束A = ones(1,N)andb = 1

数据类型:

线性不平等约束, specified as a real vector.b是一个M- 与...相关的矢量A矩阵。If you passbas a row vector, solvers internally convertb至the column vectorb(:)

bencodes theMlinear inequalities

a * x <= b,

wherex是栏矢量N变量x(:),和A是大小的矩阵M-通过-N

例如,至specify

x1+ 2x2≤ 10
3x1+ 4x2≤ 20
5x1+ 6x2≤ 30,

give these constraints:

a = [1,2; 3,4; 5,6];B = [10; 20; 30];

Example:要指定控制变量总和1或更少,请给出约束A = ones(1,N)andb = 1

数据类型:

线性平等约束,指定为真实矩阵。Aeq是一个Me-通过-nvars矩阵,其中Me是平等的数量。

Aeqencodes theMe线性平等

Aeq*x = beq,

wherex是栏矢量N变量x(:),和beqis a column vector withMe元素。

例如,至specify

x1+ 2x2+ 3x3= 10
2x1+ 4x2+x3= 20,

give these constraints:

Aeq = [1,2,3;2,4,1]; beq = [10;20];

Example:To specify that the control variables sum to 1, give the constraintsAeq = ones(1,N)andbeq = 1

数据类型:

Linear equality constraints, specified as a real vector.beq是一个Me- 与...相关的矢量Aeq矩阵。If you passbeqas a row vector, solvers internally convertbeq至the column vectorBeq(:)

beqencodes theMe线性平等

Aeq*x = beq,

wherex是栏矢量N变量x(:),和Aeq是大小的矩阵MEQ.-通过-N

例如,至specify

x1+ 2x2+ 3x3= 10
2x1+ 4x2+x3= 20,

give these constraints:

Aeq = [1,2,3;2,4,1]; beq = [10;20];

Example:To specify that the control variables sum to 1, give the constraintsAeq = ones(1,N)andbeq = 1

数据类型:

下限,指定为真正的矢量或双打数组。表示下限元素明智xUB.

Internally,gaconverts an array至the vector磅(:)

Example:lb = [0; -inf; 4]手段x(1) ≥ 0,x(3) ≥ 4

数据类型:

上限, specified as a real vector or array of doubles.UB.represents the upper bounds element-wise inxUB.

Internally,gaconverts an arrayUB.至the vectorUB.(:)

Example:UB.= [Inf;4;10]手段X(2)≤4,x(3) ≤ 10

数据类型:

Nonlinear constraints, specified as a function handle or function name.nonlcon.is a function that accepts a vector or arrayx并返回两个数组,C(x)andceq(x)

  • C(x)is the array of nonlinear inequality constraints atxga试图满足

    C(x)<= 0

    对于所有参赛作品c

  • ceq(x)is the array of nonlinear equality constraints atxga试图满足

    ceq(x) = 0

    对于所有参赛作品ceq

例如,

X =ga(@myfun,4,A,b,Aeq,beq,lb,ub,@mycon)

wheremyconis a MATLAB®乐趣ction such as

乐趣ction [c,ceq] = mycon(x) c = ... % Compute nonlinear inequalities at x. ceq = ... % Compute nonlinear equalities at x.
有关更多信息,请参阅非线性约束

要了解如何使用矢量化约束,请参阅Vectorized Constraints

Note

gadoes not enforce nonlinear constraints to be satisfied when the人民型option is set to'bitString'要么'习俗'

IfIntConis not empty, the second output ofnonlcon.(ceq) must be an empty entry ([]).

对于information on howga用途nonlcon., see非线性约束求解器算法

数据类型:char|乐趣ction_handle|string

Optimization options, specified as the output ofoptimoptions要么a structure.

optimoptionshides the options listed initalics。看到Optimoptions隐藏的选项

  • Values in{}denote the default value.

  • {}*represents the default when there are linear constraints, and forMutationFcn还有界限。

  • I*indicates thatgahandles options for integer constraints differently; this notation does not apply togamultiobj.

  • NM表示该选项不适用于gamultiobj.

Options forga, Integerga,和gamultiobj.

Option Description Values
ConstraintTolerance

Determines the feasibility with respect to nonlinear constraints. Also,max(sqrt(eps),约束特定)确定线性约束的可行性。

对于an options structure, usetolcon.

Positive scalar |{1e-3}

Creationfcn.

I*Function that creates the initial population. Specify as a name of a built-in creation function or a function handle. SeePopulation Options

{'gacreationuniform'}|{'gacreationlinearfeasible'}*|Custom creation function

CrossoverFcn

I*Function that the algorithm uses to create crossover children. Specify as a name of a built-in crossover function or a function handle. SeeCrossover Options

{'crossoverscattered'}forga,{'crossoverintermediate'}*forgamultiobj.|'交叉过电'|'sortropsinglepoint'|'crossovertwopoint'|'crossoverarithmetic'|自定义交叉功能

交叉零件

交叉函数的下一代,不包括精英儿童的人口的一小部分。

Positive scalar |{0.8}

显示

Level of display.

'off'|'iter'|'诊断'|{'final'}

DistanceMeasureFcn

函数,计算距离衡量个体所uals. Specify as a name of a built-in distance measure function or a function handle. The value applies to decision variable or design space (genotype) or to function space (phenotype). The default'distancecrowding'处于功能空间(表型)。对于gamultiobj.只要。看到多目标选项

对于an options structure, use a function handle, not a name.

{'distancercowding'}手段the same as{@ distancerwated,'表型'}|{@ distancrovding,'genotype'}|Custom distance function

EliteCount

NMPositive integer specifying how many individuals in the current generation are guaranteed to survive to the next generation. Not used ingamultiobj.

Positive integer |{CEIL(0.05 *人群化)}|{0.05*(default PopulationSize)}对于混合整数问题

FitnessLimit

NM如果健身功能达到价值FitnessLimit,算法停止。

标量|{-Inf}

FitnessScalingFcn

尺寸缩放健身功能值的功能。指定为内置缩放功能或函数句柄的名称。选项不可用gamultiobj.

{'fitscalingrank'}|'fitscalingshiftlinear'|'fitscalingprop'|'fitscalingtop'|Custom fitness scaling function

FunctionTolerance

如果最佳健身功能值的平均相对变化,则该算法停止MaxStallGenerations几代人数小于要么equal toFunctionTolerance。IfStallTestis'几何不一致',那么算法停止了weightedaverage relative change is less than or equal toFunctionTolerance

对于gamultiobj.,算法停止,当传播值的相对变化的几何平均值时停止选择。MaxStallGenerations几代人数小于选择。FunctionTolerance,和the final spread is less than the mean spread over the past选择。MaxStallGenerations几代人。看到gamultiobj算法

对于an options structure, useTolFun

Positive scalar |{1e-6}forga,{1e-4}forgamultiobj.

HybridFcn

I*Function that continues the optimization aftergaterminates. Specify as a name or a function handle.

Alternatively, a cell array specifying the hybrid function and its options. Seega Hybrid Function

对于gamultiobj., the only hybrid function is@fgoalattain。看到gamultiobj.Hybrid Function

看到When to Use a Hybrid Function

Function name or handle |'fminsearch'|'patternsearch'|'fminunc'|'fmincon'|{[]}

要么

1-by-2 cell array |{@solver, hybridoptions},在哪里solver = fminsearch,patternsearch,fminunc, 要么粉刺{[]}

InitialPenalty

NMI*Initial value of penalty parameter

Positive scalar |{10}

InitialPopulationMatrix

Initial population used to seed the genetic algorithm. Has up toPopulationSizerows andN列,其中N是变量的数量。你可以通过部分人口,意思是一个少于PopulationSizerows. In that case, the genetic algorithm usesCreationfcn.至generate the remaining population members. SeePopulation Options

对于an options structure, useInitialPopulation

矩阵|{[]}

InitialPopulationRange

Matrix or vector specifying the range of the individuals in the initial population. Applies togacreationuniformcreation function.gashifts and scales the default initial range to match any finite bounds.

对于an options structure, usePopInitRange

Matrix or vector |{[-10; 10]}for unbounded components,{[-1e4+1;1e4+1]}for unbounded components of integer-constrained problems,{[lb;ub]}for bounded components, with the default range modified to match one-sided bounds.

InitialScoresMatrix

I*Initial scores used to determine fitness. Has up toPopulationSizerows and hasNf列,其中Nfis the number of fitness functions (1forga, greater than1forgamultiobj.). You can pass a partial scores matrix, meaning one with fewer thanPopulationSizerows. In that case, the solver fills in the scores when it evaluates the fitness functions.

对于an options structure, useInitialScores

单个目标的列向量|多目标矩阵|{[]}

MaxGenerations

算法停止之前的最大迭代次数。

对于an options structure, useGenerations

Positive integer |{100 * numberofvariables}forga,{200 * numberofvariables}forgamultiobj.

MaxStallGenerations

如果最佳健身功能值的平均相对变化,则该算法停止MaxStallGenerations几代人数小于要么equal toFunctionTolerance。IfStallTestis'几何不一致',那么算法停止了weighted average relative change is less than or equal toFunctionTolerance

对于gamultiobj.,算法停止,当传播值的相对变化的几何平均值时停止选择。MaxStallGenerations几代人数小于选择。FunctionTolerance,和the final spread is less than the mean spread over the past选择。MaxStallGenerations几代人。看到gamultiobj算法

对于an options structure, useStallGenLimit

Positive integer |{50}forga,{100}forgamultiobj.

maxstalltime.

NM如果目标函数没有改善,则算法停止maxstalltime.秒,测量ticand至c

对于an options structure, useStalltimelimit.

Positive scalar|{inf}

MaxTime

算法在运行后停止MaxTime秒,测量ticand至c。This limit is enforced after each iteration, soga当迭代需要大量时间时,可以超出限制。

对于an options structure, useTimeLimit

Positive scalar |{inf}

MigrationDirection

Direction of migration. SeeMigration Options

'both'|{'forward'}

MigrationFraction

标量从0到1指定每个亚父群中的个体的分数,该群体迁移到不同的子群。看到Migration Options

标量|{0.2}

MigrationInterval

Positive integer specifying the number of generations that take place between migrations of individuals between subpopulations. SeeMigration Options

Positive integer |{20}

MutationFcn

I*产生突变儿童的功能。指定为内置突变函数或函数句柄的名称。看到突变选择

{'mutationgaussian'}forga,{' mutationadaptfeasible} *forgamultiobj.|'mutationuniform'|自定义突变函数

非线性扩展算法

非线性约束算法。看到非线性约束求解器算法。Option unchangeable forgamultiobj.

对于an options structure, useNonlinConAlgorithm

{'auglag'}forga,{'penalty'}forgamultiobj.

OutputFcn

Functions thatgacalls at each iteration. Specify as a function handle or a cell array of function handles. See输出函数选项

对于an options structure, useoutputfcns.

Function handle or cell array of function handles |{[]}

ParetoFraction

从0到1标量,指定个人的一部分,以保持第一帕捕前线,而求解器选择来自较高前部的个体gamultiobj.只要。看到多目标选项

标量|{0.35}

罚款

NMI*惩罚更新参数。

Positive scalar |{100}

PlotFcn

函数绘制由算法计算的数据。指定为内置绘图函数,函数句柄或内置名称或功能句柄的单元格数组的名称。看到情节选项

对于an options structure, usePlotFcns

ga要么gamultiobj.:{[]}|'gaplotdistance' | 'gaplotgenealogy' | 'gaplotselection' | 'gaplotscorediversity' |'gaplotscores' | 'gaplotstopping' | 'gaplotmaxconstr' |自定义绘图功能

gaonly:'gaplotbestf' | 'gaplotbestindiv' | 'gaplotexpectation' | 'gaplotrange'

gamultiobj.only:'gaplotpareto' | 'gaplotparetodistance' | 'gaplotrankhist' | 'gaplotspread'

PlotInterval

正整数指定与绘制函数的连续调用之间的几代数量。

Positive integer |{1}

PopulationSize

Size of the population.

Positive integer |{50}什么时候numberOfVariables <= 5,{200}otherwise |{min(max(10*nvars,40),100)}对于混合整数问题

人民型

Data type of the population. Must be'doubleVector'for mixed integer problems.

'bitstring'|'习俗'|{'doublevector'}

ga忽略所有约束人民型is set to'bitString'要么'习俗'。看到Population Options

选择汇总

I*选择交叉和变异儿童的父母的功能。指定为内置选择功能或函数句柄的名称。

gamultiobj.用途only'selectiontournament'

{'selectionstochunif'}forga,{'selectiontournament'}forgamultiobj.|'selectionremainder'|'selectionuniform'|'selectionroulette'|Custom selection function

StallTest

NMStopping test type.

'几何不一致'|{''averagechange'}

UseParallel

Compute fitness and nonlinear constraint functions in parallel. See矢量化和并行选项(用户功能评估)andHow to Use Parallel Processing in Global Optimization Toolbox

真正|{假}

UseVectorized

Specifies whether functions are vectorized. See矢量化和并行选项(用户功能评估)andVectorize the Fitness Function

对于an options structure, useVectorizedwith the values'on'要么'off'

真正|{假}

Example:optimoptions('ga','PlotFcn',@gaplotbestf)

整数变量, specified as a vector of positive integers taking values from1nvars。Each value inIntConrepresents anxcomponent that is integer-valued.

Note

WhenIntConis nonempty,Aeqandbeqmust be an empty entry ([]), andnonlcon.必须返回空ceq。对于more information on integer programming, see混合整数GA优化

Example:指定偶数条目xare integer-valued, setIntCon2:2:NVARS

数据类型:

问题描述,指定为包含这些字段的结构。

fitnessfcn

Fitness functions

nvars

Number of design variables

Aineq

A线性不等式约束的矩阵

Bineq

bvector for linear inequality constraints

Aeq

Aeqmatrix for linear equality constraints

Beq

beqvector for linear equality constraints

下限x

UB.

Upper bound onx

nonlcon.

非线性约束函数

rngstate.

Optional field to reset the state of the random number generator

solver

'ga'

选择

使用创建的选项optimoptions要么an options structure

数据类型:struct

输出参数s

collapse all

解决方案,作为真正的矢量返回。x是最好的一点galocated during its iterations.

目标职能value at the solution, returned as a real number. Generally,fval=有趣(x)

Reason thatga停了下来, returned as an integer.

Exit Flag 含义
1

没有非线性约束— Average cumulative change in value of the fitness function overMaxStallGenerations几代人数小于FunctionTolerance,约束违规小于ConstraintTolerance

With nonlinear constraints— Magnitude of the complementarity measure (seeComplementarity Measure) is less thansqrt(ConstraintTolerance), the subproblem is solved using a tolerance less thanFunctionTolerance,约束违规小于ConstraintTolerance

3

Value of the fitness function did not change inMaxStallGenerations几代人和约束违规小于ConstraintTolerance

4

Magnitude of step smaller than machine precision and the constraint violation is less thanConstraintTolerance

5

最小健身限制FitnessLimit达到,约束违规小于ConstraintTolerance

0

Maximum number of generationsMaxGenerationsexceeded.

-1

优化由输出函数或绘图函数终止。

-2

No feasible point found.

-4

Stall time limitmaxstalltime.exceeded.

-5

时限MaxTimeexceeded.

当。。。的时候re are integer constraints,ga用途the penalty fitness value instead of the fitness value for stopping criteria.

Information about the optimization process, returned as a structure with these fields:

  • 问题型— Problem type, one of:

    • 'unconstrained'

    • '绑定'

    • 'linearconstraints'

    • 'nonlinearconstr'

    • 'integerconstraints'

  • rngstate.— State of the MATLAB random number generator, just before the algorithm started. You can use the values inrngstate.重现产出ga。看到再现结果

  • 几代人— Number of generations computed.

  • Funccount.— Number of evaluations of the fitness function.

  • message- 理由the algorithm terminated.

  • maxconstraint- 最大约束违规,如果有的话。

  • hybridflag.— Exit flag from the hybrid function. Relates to theHybridFcn选择。不适合gamultiobj.

Final population, returned as aPopulationSize-通过-nvars矩阵。行的行population是个人。

Final scores, returned as a column vector.

  • 对于non-integer problems, the final scores are the fitness function values of the rows ofpopulation

  • 对于整数问题,最终分数是人口成员的惩罚适应价值。看到Integer ga Algorithm

More About

collapse all

Complementarity Measure

In the Augmented Lagrangian nonlinear constraint solver, thecomplementarity measureis the norm of the vector whose elements areciλ.i,在哪里ciis the nonlinear inequality constraint violation, andλ.iis the corresponding Lagrange multiplier. SeeAugmented Lagrangian Genetic Algorithm

Tips

  • 将函数与其他可以调用的独立变量写入函数ga, seePassing Extra Parameters

  • 对于problems that use the population type双载体(the default),gadoes not accept functions whose inputs are of typecomplex。To solve problems involving complex data, write your functions so that they accept real vectors, by separating the real and imaginary parts.

Algorithms

对于a description of the genetic algorithm, seeHow the Genetic Algorithm Works

对于a description of the mixed integer programming algorithm, seeInteger ga Algorithm

对于a description of the nonlinear constraint algorithms, see非线性约束求解器算法

Alternative Functionality

App

TheOptimizeLive Editor task provides a visual interface forga

Compatibility Considerations

expand all

Behavior changed in R2019b

References

[1]戈德伯格,大卫E.,Genetic Algorithms in Search, Optimization & Machine Learning, Addison-Wesley, 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”,暹罗杂志数值分析, Volume 28, Number 2, pages 545–572, 1991.

[3] A. R. Conn,N. I. M. Gould和pH。L. Toint。“全球会聚增强拉格朗日屏障算法,用于优化一般不等式约束和简单边界”,计算数学,第66卷,217页,第211页,第261-288页,1997。

扩展能力

在R2006A之前介绍