linprog CANNOT be used with integer (binary) variables.
However, there is intlinprog, which is explicitly designed to handle exactly that problem.
help intlinprog
INTLINPROG Mixed integer linear programming.
X = INTLINPROG(f,intcon,A,b) attempts to solve problems of the form
min f'*x subject to: A*x <= b
x Aeq*x = beq
lb <= x <= ub
x(i) integer, where i is in the index
vector intcon (integer constraints)
X = INTLINPROG(f,intcon,A,b) solves the problem with integer variables
in the intcon vector and linear inequality constraints A*x <= b. intcon
is a vector of positive integers indicating components of the solution
X that must be integers. For example, if you want to constrain X(2) and
X(10) to be integers, set intcon to [2,10].
X = INTLINPROG(f,intcon,A,b,Aeq,beq) solves the problem above while
additionally satisfying the equality constraints Aeq*x = beq. (Set A=[]
and b=[] if no inequalities exist.)
X = INTLINPROG(f,intcon,A,b,Aeq,beq,LB,UB) defines a set of lower and
upper bounds on the design variables, X, so that the solution is in the
range LB <= X <= UB. Use empty matrices for LB and UB if no bounds
exist. Set LB(i) = -Inf if X(i) is unbounded below; set UB(i) = Inf if
X(i) is unbounded above.
X = INTLINPROG(f,intcon,A,b,Aeq,beq,LB,UB,X0) sets the initial point
to X0.
X = INTLINPROG(f,intcon,A,b,Aeq,beq,LB,UB,X0,OPTIONS) minimizes with
the default optimization parameters replaced by values in OPTIONS, an
argument created with the OPTIMOPTIONS function. See OPTIMOPTIONS for
details.
X = INTLINPROG(PROBLEM) finds the minimum for PROBLEM. PROBLEM is a
structure with the vector 'f' in PROBLEM.f, the integer constraints in
PROBLEM.intcon, the linear inequality constraints in PROBLEM.Aineq and
PROBLEM.bineq, the linear equality constraints in PROBLEM.Aeq and
PROBLEM.beq, the lower bounds in PROBLEM.lb, the upper bounds in
PROBLEM.ub, the initial point in PROBLEM.x0, the options structure in
PROBLEM.options, and solver name 'intlinprog' in PROBLEM.solver.
[X,FVAL] = INTLINPROG(f,intcon,A,b,...) returns the value of the
objective function at X: FVAL = f'*X.
[X,FVAL,EXITFLAG] = INTLINPROG(f,intcon,A,b,...) returns an EXITFLAG
that describes the exit condition. Possible values of EXITFLAG and the
corresponding exit conditions are
3 Optimal solution found with poor constraint feasibility.
2 Solver stopped prematurely. Integer feasible point found.
1 Optimal solution found.
0 Solver stopped prematurely. No integer feasible point found.
-1 Solver stopped by an output function or plot function.
-2 No feasible point found.
-3 Root LP problem is unbounded.
-9 Solver lost feasibility probably due to ill-conditioned matrix.
[X,FVAL,EXITFLAG,OUTPUT] = INTLINPROG(f,A,b,...) returns a structure
OUTPUT containing information about the optimization process. OUTPUT
includes the number of integer feasible points found and the final gap
between internally calculated bounds on the solution. See the
documentation for a complete description.
See also LINPROG.
Documentation for intlinprog
doc intlinprog
A binary variable is just an integer variable, where the lower and upper bounds are 0 and 1.
