integer

integer is used to constrain a variable to be integer.

Syntax

F = integer(x)

Examples

Setting up a integer linear program can be done as

x = intvar(n,1);
optimize([A*x<=b],c'*x)

or

x = sdpvar(n,1);
optimize([A*x<=b, integer(x)],c'*x)

The integrality constraint is imposed on the involved variables, not the actual expression. Hence, the following two constraints are equivalent.

F = integer(x);
F = integer(pi+sqrt(2)*x);

Comments

If possible, use intvar instead as there are some parts in YALMIP where it can exploit integrality on an earlier stage if the varaibles have been defined as such.