How to model a modulo with linear constraints?

2.4k Views Asked by At

How is it possible to implement the following constraint linearly :

$x_i=0 \Rightarrow \sum_{j=0}^{i-1} q_j \ \mathrm{mod} Q = 0$

I have written the following thing :

$\sum_{j=0}^{i-1} q_j \ \mathrm{mod} Q \leq M \cdot x_i$ with $M=Q-1$

However, I don't know if there is a way to implement the modulo function (remainder of the division) linearly or if it is necessary to model the constraint in a different way.

Thanks in advance

1

There are 1 best solutions below

0
On BEST ANSWER

In a MIP model, the constraint $$ y = x \text{ mod } a$$ can be written as $$\begin{align} &x = k \cdot a + y\\ &k \text{ integer }\\ & 0 \le y \le a-0.001 \end{align}$$ Here $k$ is an extra integer variable. I assume $a$ is a constant.