iff

iff is used to create equivalence constraints between logic cases

Syntax

F = iff(A,B)

Examples

iff is used to define logic equivalence. As an example, the following code will ensure that a variable x satisfies a set of inequalities if and only if a binary variable d is true (value 1), and vice versa.

d = binvar(1);
F = iff(d,A*x <= b);

iff is mainly intended for (BINARY <-> BINARY), although it can be used also for more general constructions as above (bearing in mind that these models typically are numerically sensitive and may require a lot of binary variables to be modeled).

The following code constrains a variable y if and only if a set of constraints on x hold.

F = iff(A*x <= b, A*y <=y);

The following code is equivalent

d = binvar(1,1);
F = iff(A*x <= b, d);
F = iff(A*y <= b, d);

iff is overloaded as == on constraints, hence the following code gives the same model.

F = [(A*x <= b) == (A*y <= b)];

and so does the following model

binvar d
F = [d == (A*x <= b), d == (A*y <= b)];

Comments

Since iff is implemented using a big-M approach, it is crucial that all involved variables have explicit bound constraints.

iff is very sensitive to modeling choices (is \(10^{-5}\) really a positive number in practice?), so it should be avoided as much as possible. If you can rewrite your model to simple (BINARY-> Linear) using implies, do so! See for instance the logic programming example