版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、PAGE PAGE - 15 -MATLAB数学规划问题(实验题目及答案在最后)一、线性规划线性规划问题是目标函数和约束条件均为线性函数的问题,MATLAB6.0及更高版本解决的线性规划问题的标准形式为:minsub.to: 其中f、x、b、beq、lb、ub为向量,A、Aeq为矩阵。其它形式的线性规划问题都可经过适当变换化为此标准形式。在MATLAB6.0版中,线性规划问题(Linear Programming)已用函数linprog取代了MATLAB5.x版中的lp函数。在6.0和7.0中依然可以使用lp函数,但在更高版本中,就只能使用linprog函数了。函数 linprog调用格式:x
2、=linprog(f,A,b)x=linprog(f,A,b,Aeq,beq)x=linprog(f,A,b,Aeq,beq,lb,ub)x=linprog(f,A,b,Aeq,beq,lb,ub,x0) x=linprog(f,A,b,Aeq,beq,lb,ub,x0,options)x,fval=linprog()x, fval, exitflag=linprog()x, fval, exitflag, output=linprog()x, fval, exitflag, output, lambda=linprog()说明:x=linprog(f, A, b) %求min f *x, s
3、ub.to 线性规划的最优解。返回值x为最优解向量。x=linprog(f, A, b, Aeq, beq) %含有等式约束,若没有不等式约束,则令A= ,b= 。x = linprog(f, A, b, Aeq, beq, lb, ub) %指定x的范围x=linprog(f, A, b, Aeq, beq, lb, ub, x0) %设置x0为初值点。x=linprog(f, A, b, Aeq, beq, lb, ub, x0, options) % options为指定的优化参数。下面将进行专门描述。x, fval = linprog() % 返回目标函数最优值,即fval= f *x
4、。x, lambda, exitflag = linprog() % lambda为解x的Lagrange乘子。x, lambda, fval, exitflag = linprog() % exitflag为终止迭代的错误条件。x, fval, lambda, exitflag, output = linprog() % output为关于优化的一些信息。若exitflag0表示函数收敛于解x,exitflag=0表示超过函数估值或迭代的最大数字,exitflag lambda.ineqlinans = 0.0000 1.5000 0.5000 lambda.lowerans = 1.000
5、0 0.0000 0.0000表明:不等约束条件2和3以及第1个下界是有效的二、混合整数线性规划及0-1规划Matlab2014中新增了intlinpoog函数,用于求解混合整数规划及0-1规划问题。当把某个变量限定为非负整数且小于等于1时,它只可能取0和1。intlinprog - Mixed-integer linear programming (MILP)混合整数规划,即可设定部分或全部分量必须为整数。 X = intlinprog(f,intcon,A,b) attempts to solve problems of the form min f*x subject to: A*x =
6、 b Aeq*x = beq lb = x = ub x(i) integer, where i is in the index vector intcon (integer constraints) X = intlinprog(f,intcon,A,b) solves the problem with integer variables in the intcon vector and linear inequality constraints A*x = b. intcon is a vector of positive integers indicating components of
7、 the solution X that must be integers. For example, if you want to constrain X(2) and X(10) to be integers, set intcon to 2,10.X = intlinprog(f,intcon,A,b)求解满足约束条件A*x = b且含有整数变量的线性规划问题。其中intcon是一个正整数向量,给出解X的必须取整数的分量的下标,例如,要是X(2)和X(10)为整数,须设置intcon=2,10。 例2 利用intlinprog求解例1中的优化问题,代码如下:f = -5; -4; -6;
8、A = 1 -1 1; 3 2 4; 3 2 0;b = 20; 42; 30;lb = zeros(3,1); %指定x(1),x(2),x(3)非负intcon = 1:3; %指定x(1),x(2),x(3)都是整数x,fval,exitflag,output = intlinprog(f,intcon,A,b,lb)例3 Solve the problem of Mixed-integer linear programming求解下列混合整数规划问题。解 (1) Write the objective function vector and vector of integer vari
9、ables.f = 8;1;intcon = 2; %指定x(2)是整数(2) Convert all inequalities into the formA*x =约束的方程首先要两边同乘以-1后再输入A,b)A = -1,-2; -4,-1; 2,1;b = 14; -33; 20;(3) Callintlinprog.x = intlinprog(f,intcon,A,b)(4) Running results(运行结果):LP: Optimal objective value is 59.000000. Optimal solution found.Intlinprog stopped
10、 at the root node because the objective value is within a gap tolerance of the optimal value;options.TolGapAbs = 0 (the default value). The intcon variables are integer within tolerance,options.TolInteger = 1e-05 (the default value).x = 6.5000 7.0000 X = intlinprog(f,intcon,A,b,Aeq,beq) solves the p
11、roblem above while additionally satisfying the equality constraints Aeq*x = beq. (Set A= and b= if no inequalities exist.) X = intlinprog(f,intcon,A,b,Aeq,beq,LB,UB) defines a set of lower and upper bounds on the design variables, X, so that the solution is in the range LB = X = UB. Use empty matric
12、es for LB and UB if no bounds exist. Set LB(i) = -Inf if X(i) is unbounded below; set UB(i) = Inf if X(i) is unbounded above.例4 Solve an MILP with All Types of Constraints求解下列混合0-1规划问题。解 (1) Write the objective function vector and vector of integer variables.f = -3;-2;-1;intcon = 3;(2) Write the lin
13、ear inequality constraints.A = 1,1,1;b = 7;(3) Write the linear equality constraints.Aeq = 4,2,1;beq = 12;(4) Write the bound constraints.lb = zeros(3,1);ub = Inf;Inf;1; % Enforces x(3) is binary(5) Call intlinprog.x = intlinprog(f,intcon,A,b,Aeq,beq,lb,ub)(6) Running results(运行结果):LP: Optimal objec
14、tive value is -12.000000. Optimal solution found.Intlinprog stopped at the root node because the objective value is within a gap tolerance of the optimal value;options.TolGapAbs = 0 (the default value). The intcon variables are integer within tolerance,options.TolInteger = 1e-05 (the default value).
15、x = 0 5.5000 1.0000 X = intlinprog(f,intcon,A,b,Aeq,beq,LB,UB,OPTIONS) minimizes with the default optimization parameters replaced by values in OPTIONS, an argument created with the OPTIMOPTIONS function. See OPTIMOPTIONS for details.例5 续例4,Solve an MILP with Nondefault Options解 (1) Specify the solv
16、er inputs(指定求解器输入参数):f = -3;-2;-1;intcon = 3;A = 1,1,1;b = 7;Aeq = 4,2,1;beq = 12;lb = zeros(3,1);ub = Inf;Inf;1; % enforces x(3) is binary(2) Specify no display(指定无显示):options = optimoptions(intlinprog,Display,off);(3) Run the solver(运行求解器):x = intlinprog(f,intcon,A,b,Aeq,beq,lb,ub,options)(4) Runn
17、ing results(运行结果):x = 0 5.50001.0000X = intlinprog(PROBLEM) finds the minimum for PROBLEM. PROBLEM is a structure with the vector f in PROBLEM.f, the integer constraints inPROBLEM.intcon, the linear inequality constraints in PROBLEM.Aineq and PROBLEM.bineq, the linear equality constraints in PROBLEM
18、.Aeq and PROBLEM.beq, the lower bounds in PROBLEM.lb, the upper bounds in PROBLEM.ub, the options structure in PROBLEM.options, and solver name intlinprog in PROBLEM.solver.例6 续例4,Use a Problem Structure.using iterative display. Use a problem structure as the intlinprog input.解 (1) Specify the solve
19、r inputs(指定求解器输入参数):f = -3;-2;-1;intcon = 3;A = 1,1,1;b = 7;Aeq = 4,2,1;beq = 12;lb = zeros(3,1);ub = Inf;Inf;1; % enforces x(3) is binaryoptions = optimoptions(intlinprog,Display,off);(2) Insert the inputs into a problem structure. Include the solver name(将输入参数插入到问题结构,包括求解器名称):problem = struct(f,f,
20、intcon,intcon,. Aineq,A,bineq,b,Aeq,Aeq,beq,beq,. lb,lb,ub,ub,options,options,. solver,intlinprog);(3) Run the solver(运行求解器):x = intlinprog(problem)(4) Running results(运行结果):x = 0 5.5000 1.0000 X,FVAL = intlinprog(f,intcon,A,b,.) returns the value of the objective function at X: FVAL = f*X. X,FVAL,E
21、XITFLAG = intlinprog(f,intcon,A,b,.) returns an EXITFLAG that describes the exit condition. Possible values of EXITFLAG and the corresponding exit conditions are 2 Solver stopped prematurely. Integer feasible point found. 1 Optimal solution found. 0 Solver stopped prematurely. No integer feasible po
22、int found. -2 No feasible point found. -3 Root LP problem is unbounded. X,FVAL,EXITFLAG,OUTPUT = intlinprog(f,A,b,.) returns a structure OUTPUT containing information about the optimization process. OUTPUT includes the number of integer feasible points found and the final gap between internally calc
23、ulated bounds on the solution. See the documentation for a complete description.Call intlinprog with all outputs.例7 续例4,Call intlinprog with more outputs to see solution details and process.解 参数输入见例4的(1) - (4)。多输出调用格式:x,fval,exitflag,output = intlinprog(f,intcon,A,b,Aeq,beq,lb,ub)Running results(运行结
24、果):LP: Optimal objective value is -12.000000. Optimal solution found.Intlinprog stopped at the root node because the objective value is within a gap tolerance of the optimal value;options.TolGapAbs = 0 (the default value). The intcon variables are integer within tolerance,options.TolInteger = 1e-05
25、(the default value).x = 0 5.5000 1.0000fval = -12.0000exitflag = 1output = relativegap: 0 absolutegap: 0 numfeaspoints: 1 numnodes: 0 constrviolation: 1.7764e-15 message: Optimal solution found.Intlinprog stopped at the root node because the objective v.关于0-1整数规划的注释:MATLAB7.0提供了 bintprog函数求解0-1规划问题,
26、但Matlab2014中取消了该函数,统一用intlinpoog函数求解混合整数规划及0-1规划问题。 MATLAB 中0-1 规划的标准形式:min f*X s.t. A*X = b, Aeq*X = beq其中X的每个分量为 0 或者1。 (1)X = bintprog(f) 求解问题 min f*X (2)X = bintprog (f,A,b)求解 min f*X s.t. A*X = b (3)X = bintprog (f,A,b,Aeq,beq) 求解 min f*X s.t. Aeq*X = beq, A*X = b三、MATLAB非线性规划(一)二次规划二次规划的标准型为:M
27、in Z=XTHX+cTXs.t. AX=b VLBXVUB用MATLAB的quadprog函数求解,其调用格式如下: (1)x=quadprog(H,C,A,b); (2)x=quadprog(H,C,A,b,Aeq,beq); (3)x=quadprog(H,C,A,b,Aeq,beq,VLB,VUB); (4)x=quadprog(H,C,A,b, Aeq,beq ,VLB,VUB,X0); (5)x=quadprog(H,C,A,b, Aeq,beq ,VLB,VUB,X0,options); (6)x,fval=quadprog(.); (7)x,fval,exitflag=quap
28、rog(.); (8)x,fval,exitflag,output=quaprog(.);例8 解下面二次规划问题 解:先化为标准型:求解程序:H=1 -1; -1 2; c=-2 ;-6;A=1 1; -1 2;b=2;2;Aeq=;beq=; VLB=0;0;VUB=;x,z=quadprog(H,c,A,b,Aeq,beq,VLB,VUB计算结果:x =0.6667 1.3333 z = -8.2222(二)一般非线性规划标准型为:min F(X)s.t AX=b, Aeq X = beq, G(X)=0, Ceq(X)=0, VLBXVUB其中X为n维变元向量,G(X)与Ceq(X)均
29、为非线性函数组成的向量,其它变量的含义与线性规划、二次规划中相同。用Matlab求解上述非线性规划问题,基本步骤分三步:1. 首先建立M文件fun.m,定义目标函数F(X):function f=fun(X);f=F(X);2. 若约束条件中有非线性约束G(X)=0 或Ceq(X)=0,则建立M文件nonlcon.m定义函数G(X)与Ceq(X):function G,Ceq=nonlcon(X)G=.Ceq=.3. 建立主程序.非线性规划求解的函数是fmincon,命令的基本格式如下: (1) x=fmincon(fun,X0,A,b) (2) x=fmincon(fun,X0,A,b,Ae
30、q,beq) (3) x=fmincon(fun,X0,A,b, Aeq,beq,VLB,VUB) (4) x=fmincon(fun,X0,A,b,Aeq,beq,VLB,VUB,nonlcon)(5) x=fmincon(fun,X0,A,b,Aeq,beq,VLB,VUB,nonlcon,options) (6) x,fval= fmincon(.) (7) x,fval,exitflag= fmincon(.)(8) x,fval,exitflag,output= fmincon(.)注意:1 fmincon函数提供了大型优化算法和中型优化算法。默认时,若在fun函数中提供了梯度(op
31、tions参数的GradObj设置为on),并且只有上下界存在或只有等式约束,fmincon函数将选择大型算法。当既有等式约束又有梯度约束时,使用中型算法。2 fmincon函数的中型算法使用的是序列二次规划法。在每一步迭代中求解二次规划子问题,并用BFGS法更新拉格朗日Hessian矩阵。3 fmincon函数可能会给出局部最优解,这与初值X0的选取有关。例9 解下列非线性规划问题。(1) 建立M文件 fun.m,定义目标函数:function f=fun(x); f=exp(x(1)*(4*x(1)2+2*x(2)2+4*x(1)*x(2)+2*x(2)+1);(2) 再建立M文件nonl
32、con.m定义非线性约束:function g,ceq= nonlcon(x)g=x(1)+x(2);1.5+x(1)*x(2)-x(1)-x(2);-x(1)*x(2)-10;(3) 主程序nonlin.m为:x0=-1;1; %初始值A=;b=; %线性不等式约束Aeq=1 1;beq=0; %线性等式约束vlb=;vub=; %上下限约束x,fval=fmincon(fun,x0,A,b,Aeq,beq,vlb,vub,nonlcon)(4) 运算结果:x = -1.2250 1.2250 fval = 1.8951(三)单变量有界非线性函数的极小值fminbnd Single-vari
33、able bounded nonlinear function minimization. fminbnd函数用于计算单变量有界非线性函数的极小值。 X = fminbnd(FUN,x1,x2) attempts to find a local minimizer X of the function FUN in the interval x1 X bx). X,FVAL,EXITFLAG,OUTPUT = fminbnd(.) also returns a structure OUTPUT with the number of iterations taken in OUTPUT.itera
34、tions, the number of function evaluations in OUTPUT.funcCount, the algorithm name in OUTPUT.algorithm, and the exit message in OUTPUT.message. 例 10 FUN can be specified using (使用指定求极值的函数):X = fminbnd(cos,3,4) % Computes pi to a few decimal places and gives a message upon termination.X,FVAL,EXITFLAG
35、= fminbnd(cos,3,4,optimset(TolX,1e-12,Display,off) % Computes pi to about 12 decimal places, suppresses output, returns the % function value at x, and returns an EXITFLAG of 1.X = fminbnd(x) sin(x)+3,2,5) % FUN can be an anonymous function. 例11 FUN can be a parameterized function. Use an anonymous f
36、unction to capture the problem-dependent parameters: f = (x,c) (x-c).2; % The parameterized function. c = 1.5; % The parameter. X = fminbnd(x) f(x,c),0,1)The argument fun can also be a function handle for an anonymous function. For example, to find the minimum of the function f(x) = x3 2x 5 on the i
37、nterval (0,2), create an anonymous function ff = (x)x.3-2*x-5;Then invoke fminbnd withx = fminbnd(f, 0, 2)The result isx = 0.8165四、matlab多目标规划x,fval,attainfactor,exitflag=fgoalattain(fun,x0,goal,.,weight,A,b,Aeq,beq,lb,ub).输入部分: fun是目标函数,x0是初始值,goal是目标函数希望达到的值,weight是目标权重。(1) 当目标权重为正时,指令fgoalattain试
38、图使对象小于目标值。为了使目标函数大于目标值,可使权重设置为负。(2)一般设置为weight=goal或weight=abs(goal)。(3)A,b给出线性不等式约束;Aeq,beq给出线性等式约束;lb,ub为x的上界和下界。如无某类约束,可用代替。它们与线性规划中的含义相同。输出部分:exitflag为输出标记。当exitflag0时解收敛,所给出的x,fval有效;当exitflag0时x称满意解,fval称目标达到值。attainfactor是指目标达到情况。当attainfactor=0时目标达到值fval没有溢出goal;当attainfactor=50 x1*2+x2*1=10
39、0 x1,x2=0建立模型:min f1=x1*2+x2*1min f2=-x1-x2min f3=x1s.t :x1*2+x2*1=200-x1-x2=-100-x1=0matlab程序:fun=2*x(1)+x(2),-x(1)-x(2),-x(1);A=2 1;-1 -1;-1 0;b=200 -100 -50;goal=200,-100,-50;weight=goal;x0=55,55;lb=0,0;x,fval,attainfactor,exitflag=fgoalattain(fun,x0,goal,weight,A,b,lb,)计算结果:x = 50.0000 50.0000fval = 150.0000 -100.0000 -50.0000attainfactor = 3.4101e-10exitflag = 4实习题目: 1. 就要求变量为整数和不要其为整数两种情况解线性
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 《离婚法律程序执行细则协议》版
- 二零二五版保险及期货居间业务委托管理合同3篇
- 二零二五年度智慧社区商业配套租赁协议3篇
- 二零二五年度集成墙板原材料期货交易与风险管理合同2篇
- 二零二五年度高端人才引进与培养合同5篇
- 临时建筑建设合同样本2024年版版B版
- 2025年度智能厨房设备研发、安装与培训服务合同3篇
- 二零二五版公共工程合同担保制度及操作细则3篇
- 二零二五年电子设备采购与技术服务合同2篇
- 2024年简化版资金借用协议范本版B版
- DB-T29-74-2018天津市城市道路工程施工及验收标准
- 小学一年级20以内加减法混合运算3000题(已排版)
- 智慧工厂数字孪生解决方案
- 病机-基本病机 邪正盛衰讲解
- 品管圈知识 课件
- 非诚不找小品台词
- 2024年3月江苏省考公务员面试题(B类)及参考答案
- 患者信息保密法律法规解读
- 老年人护理风险防控PPT
- 充电桩采购安装投标方案(技术方案)
- 医院科室考勤表
评论
0/150
提交评论