语法
x = intlinprog(f,intcon,A,b,Aeq,beq,lb,ub)
参数详解
f - 系数向量
intcon- 整数约束组成的向量,就说收到约束的整数个数
A-线性不等式约束矩阵
b-线性不等式约束向量
A * x ≤ b
Aeq - 线性等式约束矩阵
beq - 线性等式约束向量
Aeq * x = beq
lb - 下界
ub - 上界
lb ≤ x ≤ ub
案例一
由题可以理解为:z = 8x1 + x2;受到关于x1和x2的限制
目标函数
f = [8;1];%确定目标函数系统
编写目标函数向量和由整数变量组成的向量
intcon = 2;%理解为两个受到x受到整数限制
将所有的不等式转化为A*x ≤b的形式,然后编写代码
A = [-1 -2; -4 -1; 2 1];%构造不等式左边系数矩阵
b = [14; -33;20];%构造不等式右边矩阵
调用intlinprog
x = intlinprog(f,intcon,A,b)
matlab上运行
>> f = [8,1];
>> intcon = 2;
>> A = [-1 -2; -4 -1; 2 1];
>> b = [14 -33 20];
>> x = intlinprog(f,intcon,A,b)
LP: Optimal objective value is 59.000000.
Optimal solution found.
Intlinprog stopped at the root node because the objective value is within a gap tolerance of the optimal
value, options.AbsoluteGapTolerance = 0 (the default value). The intcon variables are
integer within tolerance, options.IntegerTolerance = 1e-05 (the default value).
x =
6.5000
7.0000
案例二
matlab运行
>> f = [-3 -2 -1];
intcon = 3;
A = [1 1 1];
b = [7];
Aeq = [4 2 1];
beq = [12];
lb = [0 0 0];
ub = [inf inf 1];
[x fval] = intlinprog(f,intcon, A ,b,Aeq ,beq,lb,ub)
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.AbsoluteGapTolerance = 0 (the default value). The intcon variables are
integer within tolerance, options.IntegerTolerance = 1e-05 (the default value).
x =
0
5.5000
1.0000
fval =
-12