数学建模——非线性规划

非线性规划

目标函数中含有非线性函数的规划问题称为非线性规划问题
非线性规划问题数学标准模型:
min ⁡ f ( x ) , s . t . { h j ( x ) ⩽ 0 , j = 1 , 2 , 3 , . . . , q , g i ( x ) = 0 , i = 1 , 2 , 3 , . . . , p . \min f(\textbf{x}),\\ s.t.\begin{cases} h_j(\textbf{x})\leqslant0,j=1,2,3,...,q,\\ g_i(\textbf{x})=0,i=1,2,3,...,p. \end{cases} minf(x),s.t.{hj(x)0,j=1,2,3,...,q,gi(x)=0,i=1,2,3,...,p.
其中x=[x1, …, xn]T为决策变量;f为目标函数,gi与fi为约束函数,gi(x)=0为等式约束;hj(x)≤0为不等式约束。

非线性规划的matlab标注模型为:
min ⁡ f ( x ) , s . t . { A ⋅ x ⩽ b , A e q ⋅ x = b e q , c ( x ) ⩽ 0 , c e q ( x ) = 0 , l b ⩽ x ⩽ u b . \min f(\textbf{x}),\\ s.t.\begin{cases} \textbf{A}\cdot\textbf{x}\leqslant\textbf{b},\\ Aeq\cdot\textbf{x}=beq,\\ c(\textbf{x})\leqslant0,\\ ceq(\textbf{x})=0,\\ lb\leqslant\textbf{x}\leqslant ub. \end{cases} minf(x),s.t.Axb,Aeqx=beq,c(x)0,ceq(x)=0,lbxub.
matlab中求解非线性规划问题的函数为fmincon
其命令为[x, fval]=fmincon(fun, x0, A, b, Aeq, beq, lb, ub, nonlcon, options)
fun是目标函数f(x)
x0是x的初始值
A, b, Aeq, beq为线性约束条件
lb,ub是变量x的上、下界
nonlcon是非线性向量函数c(x),ceq(x)
options定义了优化参数,可以使用matlab的默认参数设置。

例:

求下列问题的解:
max ⁡ f ( x ) = 2 x 1 + 3 x 1 2 + 3 x 2 + x 2 2 + x 3 s . t . { x 1 + 2 x 1 2 + x 2 + 2 x 2 2 + x 3 ⩽ 10 x 1 + x 1 2 + x 2 + x 2 2 − x 3 ⩽ 50 2 x 1 + x 1 2 + 2 x 2 + x 3 ⩽ 40 x 1 + 2 x 2 ⩾ 1 x 1 2 + 2 x 3 = 2 x 1 ⩾ 0 , x 2 , x 3 无 约 束 . \max f(\textbf{x})=2x_1+3x_1^2+3x_2+x_2^2+x_3\\ s.t.\begin{cases} x_1+2x_1^2+x_2+2x_2^2+x_3\leqslant10\\ x_1+x_1^2+x_2+x_2^2-x_3\leqslant50\\ 2x_1+x_1^2+2x_2+x_3\leqslant40\\ x_1+2x_2\geqslant1\\ x_1^2+2x_3=2\\ x_1\geqslant0,x_2,x_3无约束. \end{cases} maxf(x)=2x1+3x12+3x2+x22+x3s.t.x1+2x12+x2+2x22+x310x1+x12+x2+x22x3502x1+x12+2x2+x340x1+2x21x12+2x3=2x10,x2,x3.
matlab代码实现:

编写fun1目标函数:

function f=fun1(x)
f=-2*x(1)-3*x(1)^2-3*x(2)-x(2)^2-x(3);
end

编写fun2非线性约束条件:

function [g,h]=fun2(x)
g=[x(1)+2*x(1)^2+x(2)+2*x(2)^2+x(3)-10
    x(1)+x(1)^2+x(2)+x(2)^2-x(3)-50
    2*x(1)+x(1)^2+2*x(2)+x(3)-40]; %非线性不等式约束条件
h=[x(1)^2+x(3)-2]; %非线性等式约束条件
end

编写主函数:

function main
clc,clear;
a=[-1,-2,0];
b=[-1];
lb=[0;-inf;-inf];
[x,y]=fmincon('fun1',rand(3,1),a,b,[],[],lb,[],'fun2');
x,-y

输出结果:


Local minimum found that satisfies the constraints.

Optimization completed because the objective function is non-decreasing in 
feasible directions, to within the value of the optimality tolerance,
and constraints are satisfied to within the value of the constraint tolerance.

<stopping criteria details>

x =

    2.3333
    0.1667
   -3.4444


ans =

   18.0833

>> 

无约束极值问题的数值解

matlab中用于求解该问题的两个函数为fminunc和fminsearch
fminunc的基本命令为[x, fval]=fminunc(fun, x0,options)
fminsearch的基本命令为fminsearch(fun,x0,options)
fminsearch只能求一给定的初始值附近的一个极小值点
问题常为求一函数的的极值,且有时利用函数的梯度与导数求解,提供的信息越多,计算越快,精度越高。
求多元函数f(x,y)=x3-y3+3x2+3y2-9x的极值

matlab代码:

clc,clear
f=@(x)x(1)^3-x(2)^3+3*x(1)^2+3*x(2)^2-9*x(1);
g=@(x)-f(x);
[xy10,z10]=fminunc(f,rand(2,1));
[xy11,z11]=fminsearch(f,rand(2,1));
[xy20,z20]=fminunc(g,rand(2,1));
[xy21,z21]=fminsearch(g,rand(2,1));
xy10,z10,xy11,z11
xy20,-z20,xy21,-z21

输出结果:



Local minimum found.

Optimization completed because the size of the gradient is less than
the value of the optimality tolerance.

<stopping criteria details>

Local minimum found.

Optimization completed because the size of the gradient is less than
the value of the optimality tolerance.

<stopping criteria details>

xy10 =

    1.0000
   -0.0000


z10 =

   -5.0000


xy11 =

    1.0000
   -0.0001


z11 =

   -5.0000


xy20 =

   -3.0000
    2.0000


ans =

   31.0000


xy21 =

   -3.0000
    2.0000


ans =

   31.0000

>>  

当问题需要利用梯度或海森矩阵时,利用optimset函数改变fminunc和fminsearch的options变量。
options=optimset(‘GradObj’,‘On’);
options=optimset(‘GradObj’,‘On’,‘Hessian’,‘On’);

罚函数法

罚函数法是有约束最优化问题转化为求解无约束最优化问题
数学建模多用外罚函数法。

外罚函数法

有一优化问题:
min ⁡ f ( x ) s . t . { g i ( x ) ⩽ 0 , i = 1 , 2 , 3 , . . . , r h j ( x ) ⩾ 0 , j = 1 , 2 , 3 , . . . , s k m ( x ) = 0 , m = 1 , 2 , 3 , . . . , t \min f(x)\\ s.t.\begin{cases} g_i(x)\leqslant0, i=1,2,3,...,r\\ h_j(x)\geqslant0,j=1,2,3,...,s\\ k_m(x)=0,m=1,2,3,...,t \end{cases} minf(x)s.t.gi(x)0,i=1,2,3,...,rhj(x)0,j=1,2,3,...,skm(x)=0,m=1,2,3,...,t
取一足够大的数M>0,构造函数:
P ( x , M ) = f ( x ) + M ∑ i = 1 r m a x ( g i ( x ) , 0 ) − M ∑ j = 1 s m i n ( h j ( x ) , 0 ) + M ∑ m = 1 t ∣ k m ( x ) ∣ P(x,M)=f(x)+M\displaystyle\sum_{i=1}^rmax(g_i(x),0)-M\displaystyle\sum_{j=1}^smin(h_j(x),0)+M\displaystyle\sum_{m=1}^t|k_m(x)| P(x,M)=f(x)+Mi=1rmax(gi(x),0)Mj=1smin(hj(x),0)+Mm=1tkm(x)

P ( x , M ) = f ( x ) + M s u m ( max ⁡ ( G ( x ) 0 ) ) − M s u m ( m i n ( H ( x ) 0 ) ) + M ∣ ∣ K ( x ) ∣ ∣ G ( x ) = [ g 1 ( x ) , g 2 ( x ) , . . . , g r ( x ) ] H ( x ) = [ h 1 ( x ) , h 2 ( x ) , . . . , h s ( x ) ] K ( x ) = [ k 1 ( x ) , k 2 ( x ) , . . . , k t ( x ) ] P(x,M)=f(x)+Msum(\max\begin{pmatrix}G(x)\\0\end{pmatrix})-Msum(min\begin{pmatrix}H(x)\\0\end{pmatrix})+M||K(x)||\\ G(x)=[g_1(x),g_2(x),...,g_r(x)]\\ H(x)=[h_1(x),h_2(x),...,h_s(x)]\\ K(x)=[k_1(x),k_2(x),...,k_t(x)]\\ P(x,M)=f(x)+Msum(max(G(x)0))Msum(min(H(x)0))+MK(x)G(x)=[g1(x),g2(x),...,gr(x)]H(x)=[h1(x),h2(x),...,hs(x)]K(x)=[k1(x),k2(x),...,kt(x)]
则以增广函数P(x,M)为目标函数的无约束极值问题minP(x,M)的最优解就是原问题的最优解。
在matlab中利用max,min,sum,fminunc和fminsearch函数可以轻易构造上述函数并求解。

当非线性规划问题要求实时算法时,要用罚函数法计算,但精度较低
当非线性规划问题不需要实施算法时,可以用fmincon函数进行计算,且精度较高

matlab优化工具箱函数

  1. fminbnd函数:
    求单变量非线性函数在区间上的极小值
    min ⁡ x f ( x ) , x ∈ [ x 1 , x 2 ] \min_xf(x),x\in[x_1,x_2] xminf(x),x[x1,x2]
    函数命令为
    [x,fval]=fminbnd(fun,x1,x2,options) \textrm{[x,fval]=fminbnd(fun,x1,x2,options)} [x,fval]=fminbnd(fun,x1,x2,options)
  2. fesminf函数:
    求解
    min ⁡ f ( x ) , s . t . { A ⋅ x ⩽ b , A e q ⋅ x = b e q , c ( x ) ⩽ 0 , c e q ( x ) = 0 , l b ⩽ x ⩽ u b , K i ( x , ω i ) ⩽ 0 , 1 ⩽ i ⩽ n . \min f(\textbf{x}),\\ s.t.\begin{cases} \textbf{A}\cdot\textbf{x}\leqslant\textbf{b},\\ Aeq\cdot\textbf{x}=beq,\\ c(\textbf{x})\leqslant0,\\ ceq(\textbf{x})=0,\\ lb\leqslant\textbf{x}\leqslant ub,\\ K_i(\textbf{x},\omega_i)\leqslant0,1\leqslant i\leqslant n. \end{cases} minf(x),s.t.Axb,Aeqx=beq,c(x)0,ceq(x)=0,lbxub,Ki(x,ωi)0,1in.
    Ki(xi)为标量函数,ω1,ω2,…,ωn为附加变量
    matlab命令为:
    [x,fval]=fseminf(fun,x0,ntheta,seminfcon,A,b,Aeq,beq,lb,ub) \textrm{[x,fval]=fseminf(fun,x0,ntheta,seminfcon,A,b,Aeq,beq,lb,ub)} [x,fval]=fseminf(fun,x0,ntheta,seminfcon,A,b,Aeq,beq,lb,ub)
    ntheta是半无穷约束Ki(xi)的个数,函数seminfcon用于定义非线性不等式约束c(x)、非线性等式约束ceq(x)和半无穷约束Ki(xi)的函数,函数seminfcon有两个输入参量x,和s,s是推荐的取样步长,也可不使用。
  3. fminimax函数:
    求解
    min ⁡ x max ⁡ i F i ( x ) , s . t . { A ⋅ x ⩽ b , A e q ⋅ x = b e q , c ( x ) ⩽ 0 , c e q ( x ) = 0 , l b ⩽ x ⩽ u b , \min_x \max_i F_i(\textbf{x}),\\ s.t.\begin{cases} \textbf{A}\cdot\textbf{x}\leqslant\textbf{b},\\ Aeq\cdot\textbf{x}=beq,\\ c(\textbf{x})\leqslant0,\\ ceq(\textbf{x})=0,\\ lb\leqslant\textbf{x}\leqslant ub,\\ \end{cases} xminimaxFi(x),s.t.Axb,Aeqx=beq,c(x)0,ceq(x)=0,lbxub,
    matlab命令为:
    [x,fval]=fminimax(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options) \textrm{[x,fval]=fminimax(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options)} [x,fval]=fminimax(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options)

参考文献:
[1]司守奎,孙兆亮.数学建模算法与应用[M].第二版.北京:国防工业出版社,2018.
[2]部分资料来源于互联网

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值