matlab整数规划程序

谁能够给一个完整的matlab整数规划的解题程序,感激不尽!

第1个回答  2011-08-05
可以用YALMIP工具箱解整数规划

定义变量:
sqdvar()实型
intvar()整型
binvar()0-1型
设定目标函数 :
f=目标函数
设定限定条件:
F=set(限定条件)
多个限定条件用加号相连:
F=set(限定条件)+set(限定条件1)+set(限定条件2)……
求解: solvesdp(F,f)
这里解得是F条件下目标函数f的最小值,要求最大值f前面加个负号
求解之后查看数值 :
double(f) double(变量)

intvar(m,n):生成整数型变量;

sdpvar(m,n):生产变量;

solvesdp(F,f):求解最优解(最小值),其中F为约束条件(用set连接),f为目标函数

double:显示求解的答案

有个例子:
已知非线性整数规划为:
Max z=x1^2+x2^2+3*x3^2+4*x4^2+2*x5^2-8*x1-2*x2-3*x3-x4-2*x5
s.t.
0<=xi<=99(i=1,2,...,5)
x1+x2+x3+x4+x5<=400
x1+2*x2+2*x3+x4+6*x5<=800
2*x1+x2+6*x3<=800
x3+x4+5*x5<=200
matlab中输入
>> x=intvar(1,5);
f=[1 1 3 4 2]*(x'.^2)-[8 2 3 1 2]*x';F=set(0<=x<=99);
F=F+set([1 1 1 1 1]*x'<=400)+set([1 2 2 1 6]*x'<=800)+set(2*x(1)+x(2)+6*x(3)<=800);
F=F+set(x(3)+x(4)+5*x(5)<=200);solvesdp(F,-f);
max=double(f)
sx=double(x)
* Starting YALMIP integer branch & bound.
* Lower solver : fmincon-standard
* Upper solver : rounder
* Max iterations : 300

Warning : The relaxed problem may be nonconvex. This means
that the branching process not is guaranteed to find a
globally optimal solution, since the lower bound can be
invalid. Hence, do not trust the bound or the gap...
Node Upper Gap(%) Lower Open
1 : -8.020E+004 0.03 -8.025E+004 2
2 : -8.020E+004 0.03 -8.025E+004 1
3 : -8.020E+004 0.00 -8.020E+004 2
+ 3 Finishing. Cost: -80199

max =

80199

sx =

53 99 99 99 0
相似回答