[大谦MATLAB,dqmatlab点com]
【例10】求解下面的混合整数线性规划问题。
\[\left\{ \begin{matrix} \begin{matrix} \mathrm{\mathrm{min}}{z=8{x}_{1}+{x}_{2}} \\ {x}_{1}+2{x}_{2}\geq-14 \\ -4{x}_{1}-{x}_{2}\leq-33 \end{matrix} \\ 2{x}_{1}+{x}_{2}\leq20 \\ {x}_{2}是整数 \end{matrix} \right.\]
在MATLAB命令窗口中输入:
code.matlab
>> f=[8;1];
>> ic=2;
>> A=[-1 -2;-4 -1;2 1];
>> b=[14;-33;20];
>> x=intlinprog(f,ic,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
所以,问题的最优解为x1=6.5,x2=7,此时的最小值为59。
【例11】求解下面的混合整数线性规划问题。
\[\left\{ \begin{matrix} \begin{matrix} \mathrm{\mathrm{min}}{z=-3{x}_{1}-2{x}_{2}-{x}_{3 }} \\ -3{x}_{1}-2{x}_{2}-{x}_{3 } \\ 4{x}_{1}+2{x}_{2}+{x}_{3}=12 \end{matrix} \\ {x}_{1},{x}_{2}\geq0 \\ {x}_{3}=0,1 \end{matrix} \right.\]
在MATLAB命令窗口中输入
code.matlab
>> f=[-3;-2;-1];
>> ic=3;
>> A=[1,1,1];
>> b=7;
>> Aeq=[4,2,1];
>> beq=12;
>> lb=zeros(3,1);
>> ub=[Inf;Inf;1];
>> options=optimoptions('intlinprog', 'Display', 'off');
>> x=intlinprog(f,ic,A,b,Aeq,beq,lb,ub,options)
x =
0
5.5000
1.0000
所以,问题的最优解为x1=0,x2=5.5,x3=1,此时的最小值为-12。因为options关闭了过程显示,所以直接给出结果。