www.gusucode.com > optim 案例源码 matlab代码程序 > optim/UseaMILPProblemStructureExample.m

    %% Use a Problem Structure  
% Solve the problem
%
% $$ \mathop {\min }\limits_x \left( { - 3{x_1} - 2{x_2} - {x_3}} \right)
% {\rm{\ subject\ to }}\left\{ {\begin{array}{*{20}{l}}
% {{x_3}{\rm{\ binary}}}\\
% {{x_1},{x_2} \ge 0}\\
% {{x_1} + {x_2} + {x_3} \le 7}\\
% {4{x_1} + 2{x_2} + {x_3} = 12}
% \end{array}} \right. $$
%
% using iterative display. Use a |problem| structure as the |intlinprog| input.   

%% 
% Specify the solver 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
options = optimoptions('intlinprog','Display','off');  

%% 
% Insert the inputs into a problem structure. Include the solver name. 
problem = struct('f',f,'intcon',intcon,...
    'Aineq',A,'bineq',b,'Aeq',Aeq,'beq',beq,...
    'lb',lb,'ub',ub,'options',options,...
    'solver','intlinprog');  

%% 
% Run the solver. 
x = intlinprog(problem)