没有合适的资源?快使用搜索试试~ 我知道了~
首页matlab中cplex和yalmip新手指南
matlab中cplex和yalmip新手指南
需积分: 50 6.7k 浏览量
更新于2023-05-27
评论 28
收藏 825KB PDF 举报
内容包括了cplex工具箱多个函数的使用方法及例子,此外还有yalmip的使用方法,方便初学者使用。
资源详情
资源评论
资源推荐

目录
cplexbilp 二进制整数规划问题 ......................................................................................... 2
cplexlp 线性规划问题 ........................................................................................................ 4
cplexlsqbilp 有约束二进制整数最小二乘问题................................................................. 6
cplexlsqlin 有约束的最小二乘问题 ................................................................................... 8
cplexlsqmilp 有约束的混合整数最小二乘问题 ............................................................. 10
cplexlsqmiqcp 含二次约束的混合整数最小二乘问题 ................................................... 13
cplexlsqnonneglin 非负最小二乘问题 ............................................................................ 16
cplexlsqnonnegmilp 非负混合整数最小二乘问题 ......................................................... 18
cplexlsqnonnegmiqcp 非负有二次约束的混合整数最小二乘问题 .............................. 20
cplexlsqnonnegqcp 非负有二次约束的最小二乘问题 .................................................. 23
cplexlsqqcp 有二次约束的最小二乘问题 ....................................................................... 25
cplexmilp 混合整数的线性规划问题 .............................................................................. 27
cplexmiqcp 含二次约束线性或者二次整数规划问题 ................................................... 30
cplexmiqp 混合整数的二次规划问题 ............................................................................. 32
cplexoptimget 检索优化设置值 ...................................................................................... 34
cplexoptimset 创建或编辑一个最优化选项结构体 ....................................................... 35
cplexqcp 有二次约束线性或二次规划问题 ................................................................... 37
cplexqp 二次的规划问题 ................................................................................................. 38
Yalmip 建模常用语法 ....................................................................................................... 40
变量设置 ............................................................................................................ 40
约束条件 ............................................................................................................ 40
目标函数 ............................................................................................................ 40
查看变量或表达式的值 .................................................................................... 40
设置 Yalmip 和求解器的 options .................................................................... 40
常用求解函数 optimize ..................................................................................... 41
输出 Yalmip 模型 .............................................................................................. 41
利用 yalmip 求解后,获取求解的拉格朗日乘子 .......................................... 42
获取求解器的求解时间和 Yalmip 的建模时间 .............................................. 42
设置初值 ............................................................................................................ 43

cplexbilp 二进制整数规划问题
function [x, fval, exitflag, output] = cplexbilp(f, Aineq, bineq, Aeq, beq,
x0, options)
%%
% cplexbilp
% Solve binary integer programming problems.
解决二进制整数规划问题
%
% x = cplexbilp(f) solves the binary integer programming problem min f*x.
解决fx最小值得二进制整数规划问题
%
% x = cplexbilp(f, Aineq, bineq) solves the binary integer programming
% problem min f*x such that Aineq*x <= bineq
解决fx最小值,同时满足不等式条件的二进制整数规划问题
%
% x = cplexbilp(f, Aineq, bineq, Aeq, beq) solves the preceding problem
% with the additional equality constraints Aeq*x = beq. If no inequalities
% exist, set Aineq=[] and bineq=[].
解决增加额外的等式约束的上述问题,如果没有不等式存在,设置Aineq=[],bineq=[]
%
% x = cplexbilp(f, Aineq, bineq, Aeq, beq, x0) sets the starting point for
% the algorithm to x0. If no equalities exist, set Aeq=[] and beq=[].
设置这个算法的起始点为x0,如果没有等式存在,设置Aeq=[],beq=[]
%
% x = cplexbilp(f, Aineq, bineq, Aeq, beq, x0, options) minimizes with the
% default optimization options replaced by values in the structure options,
% which can be created using the function cplexoptimset. If you do not want
% to give an initial point, set x0=[].
通过结构设置的值来替换默认优化设置去最小化问题,也可以通过函数cplexoptimset来设定。
如果不想给定初始值,设置x0=[]
%
% x = cplexbilp(problem) where problem is a structure.
其中Problem是一个结构体
%
% [x,fval] = cplexbilp(...) returns the value of the objective function at
% the solution x: fval = f*x.
返回解为x时目标函数的值fval=fx
%
% [x,fval,exitflag] = cplexbilp(...) returns a value exitflag that
% describes the exit condition of cplexbilp.
返回一个描述cplexbilp退出状态的退出标志值
%
% [x,fval,exitflag,output] = cplexbilp(...) returns a structure output that
% contains information about the optimization.
返回一个包含优化信息的输出结构体。
%
% See also cplexoptimset

%
for example:
function cplexbilpex
% Use the function cplexbilp to solve a binary integer programming problem
%
% The bilp problem solved in this example is
% Maximize x1 + 2 x2 + 3 x3 + x4
% Subject to
% - x1 + x2 + x3 + 10 x4 <= 20
% x1 - 3 x2 + x3 <= 30
% x2 - 3.5x4 = 0
% Binary Integer
% x1 x2 x3 x4
%
-----------------------------------------------------------------------
----
% File: cplexbilpex.m
% Version 12.5
%
-----------------------------------------------------------------------
----
% Licensed Materials - Property of IBM
% 5725-A06 5725-A29 5724-Y48 5724-Y49 5724-Y54 5724-Y55 5655-Y21
% Copyright IBM Corporation 2008, 2012. All Rights Reserved.
%
% US Government Users Restricted Rights - Use, duplication or
% disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
%
-----------------------------------------------------------------------
----
try
% Since cplexbilp solves minimization problems and the problem
% is a maximization problem, negate the objective
f = [-1 -2 -3 -1]';
Aineq = [-1 1 1 10;
1 -3 1 0];
bineq = [20 30]';
Aeq = [0 1 0 -3.5];
beq = 0;
options = cplexoptimset;
options.Diagnostics = 'on';
[x, fval, exitflag, output] = cplexbilp (f, Aineq, bineq, Aeq, beq, ...
[ ], options);
fprintf ('\nSolution status = %s\n', output.cplexstatusstring);
fprintf ('Solution value = %d\n', fval);
disp ('Values = ');
disp (x');
catch m
disp(m.message);
end

end
cplexlp 线性规划问题
function [x, fval, exitflag, output, lambda] = cplexlp (f, Aineq, bineq,
Aeq, beq, lb, ub, x0, options)
%%
% cplexlp
% Solve linear programming problems.
解决线性规划问题
%
% x = cplexlp(f,Aineq,bineq) solves the linear programming problem min f*x
% such that Aineq*x <= bineq.
解决fx最小值的线性规划问题,有不等式条件Aineq*x<=bineq
%
% x = cplexlp(f,Aineq,bineq,Aeq,beq) solves the preceding problem with the
% additional equality constraints Aeq*x = beq. If no inequalities exist,
% set Aineq=[] and bineq=[].
加上额外的等式约束解决上述问题,如果没有不等式存在,设置Aineq=[],bineq=[]
%
% x = cplexlp(f,Aineq,bineq,Aeq,beq,lb,ub) defines a set of lower and upper
% bounds on the design variables, x, so that the solution is always in the
% range lb <= x <= ub. If no equalities exist, set Aeq=[] and beq=[].
定义一组设计变量x的上下界,因此解总是在lb~ub的范围内,如果没有等式存在,设置
Aeq=[],beq=[].
%
% x = cplexlp(f,Aineq,bineq,Aeq,beq,lb,ub,x0) sets the starting point for
% the algorithm to x0. If no bounds exist, set lb=[] and ub=[].
设置算法的初始点位x0,如果没有界限存在,设置lb=[],ub=[]
%
% x = cplexlp(f,Aineq,bineq,Aeq,beq,lb,ub,x0,options) minimizes with the
% default optimization options replaced by values in the structure options,
% which can be created using the function cplexoptimset. If you do not want
% to give an initial point, set x0=[].
通过结构设置的值替换默认优化设置来最小化,也可以通过cplexoptimset来设置。如果没有给
初始点,设置x0=[];
%
% x = cplexlp(problem) where problem is a structure.
其中problem是一个结构体
%
% [x,fval] = cplexlp(...) returns the value of the objective function at
% the solution x: fval = f*x.
返回解为x的目标函数的值,fval=fx
%
% [x,fval,exitflag] = cplexlp(...) returns a value exitflag that describes
% the exit condition of cplexlp.

返回描述cplexlp退出状态的退出标志值
%
% [x,fval,exitflag,output] = cplexlp(...) returns a structure output that
% contains information about the optimization.
返回一个包含优化信息的结构体输出
%
% [x,fval,exitflag,output,lambda] = cplexlp(...) returns a structure lambda
% whose fields contain the Lagrange multipliers at the solution x.
返回结构体lamda,内容包括解为x时的拉格朗日乘子。
%
% See also cplexoptimset
%
for example:
function cplexlpex
% Use the function cplexlp to solve a linear programming problem
%
% The LP problem solved in this example is
% Maximize x1 + 2 x2 + 3 x3
% Subject to
% - x1 + x2 + x3 <= 20
% x1 - 3 x2 + x3 <= 30
% Bounds
% 0 <= x1 <= 40
% 0 <= x2
% 0 <= x3
%
-----------------------------------------------------------------------
----
% File: cplexlpex.m
% Version 12.5
%
-----------------------------------------------------------------------
----
% Licensed Materials - Property of IBM
% 5725-A06 5725-A29 5724-Y48 5724-Y49 5724-Y54 5724-Y55 5655-Y21
% Copyright IBM Corporation 2008, 2012. All Rights Reserved.
%
% US Government Users Restricted Rights - Use, duplication or
% disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
%
-----------------------------------------------------------------------
----
try
% Since cplexlp solves minimization problems and the problem
% is a maximization problem, negate the objective
f = [-1 -2 -3]';
Aineq = [-1 1 1; 1 -3 1];
bineq = [20 30]';
lb = [0 0 0]';
ub = [40 inf inf]';
options = cplexoptimset;
剩余42页未读,继续阅读



















安全验证
文档复制为VIP权益,开通VIP直接复制

评论0