Main Content

转换非线性约束代理形式和其他求解器形式

为什么把Constraint Forms?

To try various solvers including代理在具有非线性不平等约束的问题上,您必须在要求的形式之间转换代理and the form required by other solvers.

转换代理结构形式to Other Solvers

目标函数objconstr(x)为了代理返回结构。这FVALfield contains the objective function value, a scalar. Theineq字段包含约束函数值的向量。求解器试图在ineq场小于或等于零。正值表明违反限制。

其他求解器期望目标函数返回标量值,而不是结构。其他求解器还期望非线性约束函数返回两个输出,c(x)andCEQ(X),不是包含的结构c(x)

To convert the代理functionobjconstr(x)为了use in other solvers:

  • Set the objective function to@(x)objconstr(x).Fval

  • 将非线性约束功能设置为@(x)deal(objconstr(x).ineq,[])

For example,

functionff = objconstr(x) ff.Fval = norm(x)^2; ff.Ineq = norm(x - [5,8])^2 - 25;结尾

解决约束最小化问题objconstr, 称呼代理

lb = [-10,-20];ub = [20,10];sol = promogateOpt(@objconstr,lb,ub)
Surrogateopt stopped because it exceeded the function evaluation limit set by 'options.MaxFunctionEvaluations'. sol = 2.3325 3.7711

使用相同的问题使用Fmincon, split the objective and constraint into separate functions. Include the nonlinear equality constraint as[]通过使用交易功能。

objfcn = @(x)objconstr(x).fval;nlcon = @(x)deal(objconstr(x).ineq,[]);

称呼Fmincon具有目标功能objfcn和非线性约束功能NLCON

[solf,fvalf,eflag,output] =...Fmincon(objfcn,[0,0],[],[],[],[],lb,ub,nlcon)
当地最低限度发现满足约束。之所以完成优化,是因为目标函数在可行的方向,最优性公差值之内不折叠,并且在约束公差的值之内满足了约束。solf = 2.3500 3.7600 fvalf = 19.6602 eflag = 1 output = struct with fields: iterations: 7 funcCount: 24 constrviolation: 0 stepsize: 2.0395e-05 algorithm: 'interior-point' firstorderopt: 4.9651e-06 cgiterations: 0 message: '发现满足约束的最低限量最小。循↵Optimization完成,因为目标函数在最佳公差的值之内,在约束公差的值之内满足了最佳公差的值。↵<停止标准详细信息>↵Optimization完成:相对一阶最优度度量,6.602486E-07,麦小于选项。OptimalityTolerance= 1.000000E-06和最大约束,0.000000E+00+00,少于选项。

您也可以使用patternsearchorGA使用相同的转换解决问题。

从其他求解器转换为代理结构形式

如果您有其他求解器的形式写的问题,请使用packfcnfunction to convert the objective and nonlinear constraints to the structure form for代理。If the objective function is a function handle@OBJ非线性约束功能是@nlconst, then use the objective functionobjconstr为了代理

objconstr = packfcn(@obj,@nlconst);

在此示例中,目标函数是Rosenbrock的功能。

ros = @(x)100*(x(2)-x(1)^2)^2 +(1 -x(1))^2;

Specify the constraint function to restrict the solution to lie inside a disk of radius 1/3 centered at the point [1/3,1/3].

function[C,CEQ] = CircleCon(x)C =(x(1)-1/3)^2 +(x(2)-1/3)^2  - (1/3)^2;ceq = [];

Set bounds of –2 and 2 on each component.

lb = [-2,-2];ub = [2,2];

使用patternsearch从[0,0]开始。

x0 = [0,0];X = patternsearch(ROS,X0,[],[],[],[],[LB,UB,@CircleCon)
Optimization terminated: mesh size less than options.MeshTolerance and constraint violation is less than options.ConstraintTolerance. x = 0.6523 0.4258

Convert the problem for solution by代理

objconstr = packfcn(ros,@circlecon);xs = surnogateOpt(objconstr,lb,ub)
Surrogateopt stopped because it exceeded the function evaluation limit set by 'options.MaxFunctionEvaluations'. xs = 0.6543 0.4284

也可以看看

|

Related Topics