I have an optimization problem that chooses which location must be opened based on a set of possible locations. And per location we have a certain amount of available spots from which we must buy a number.
I have a constraint in the model which says that if a location is opened, the number of bought spots in this location must be an integer number which is at least 1. But if a location is not opened, you cannot buy any spots there.
It is modelled as follows:
- $P$ = the set of all possible locations to open
- $x_i$ = whether location $i$ is opened or not (0=not opened, 1=opened)
- $p_i$ = amount of places bought at location $i$
\begin{equation} p_i=\begin{cases} p_i \geq 1, \ p_{i} \in \mathbb{Z}, & \text{if $x_i = 1$}\\ p_i = 0, & \text{if $x_i = 0$} \end{cases} \qquad \forall i \in P \label{open+parking} \end{equation}
How can I model this constraint such that I can use MILP or MIQCP to solve this optimization problem?
The following is one possible way:
\begin{align*} (2p_i - 1)(2x_i - 1) &\geq 0, \\ p_i &\geq 0, \\ p_i &\in \mathbb{Z}. \end{align*}
When $x_i = 0$, then $2x_i - 1 < 0$. Hence, we must have $2p_i - 1 < 0$ to satisfy the first constraint. This is equivalent to $p_i < 1/2$. But, because the other two constraints say that $p_i \geq 0$ and $p_i \in \mathbb{Z}$, we only have one possible value for $p_i$, that is, $p_i = 0$.
Similarly, when $x_i = 1$, then $2x_i - 1 > 0$. Hence, we must have $2p_i - 1 > 0$ to satisfy the first constraint. This is equivalent to $p_i > 1/2$. Due to the last constraint, we must have $p_i \geq 1$ and $p_i \in \mathbb{Z}$.
Addendum.
If it is known that there is a constant $M_i$ such that $p_i \leq M_i$, we can model the variable without quadratic terms: \begin{align*} p_i + M_i(1-x_i) &> 0, \\ p_i + M_i(1-x_i) &\leq M_i, \\ p_i &\geq 0, \\ p_i &\in \mathbb{Z}. \end{align*}
When $x_i = 0$, the second constraint gives us $p_i \leq 0$. Together with the third constraint, it forces $p_i$ to be $0$.
When $x_i = 1$, the first constraint becomes $p_i + 0 > 0$. Together with the third and fourth constraints, we have $p_i \geq 1$ and $p_i \in \mathbb{Z}$, as required.