%% Solve an MILP with All Types of Constraints
% 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.
% Write the objective function vector and vector of integer variables.

f = [-3;-2;-1];
intcon = 3;

%
% Write the linear inequality constraints.

A = [1,1,1];
b = 7;

%
% Write the linear equality constraints.

Aeq = [4,2,1];
beq = 12;

%
% Write the bound constraints.

lb = zeros(3,1);
ub = [Inf;Inf;1]; % Enforces x(3) is binary

%
% Call intlinprog.

x = intlinprog(f,intcon,A,b,Aeq,beq,lb,ub)

% Copyright 2012 The MathWorks, Inc.