I am stuck in a constraint formulation of a discrete optimization problem. Consider a board of Cartesian grids (M rows by N columns). We are going to color some grids among them. There is a geometric constraint that the colored grids must form a rectangle (and its interior, no holes).
My question is: How to algebraically formulate this geometric constraint (so that it can be handled by computer)?
The decision variables can be written as $x_i, i\in \{1,2,\ldots,M\cdot N\}$. $x_i=1$ if the $i$th grid is colored; $x_i=0$ if the $i$th grid is not colored. (Or since the board is 2D, for convenience, you can use a two-digit index to denote a decision variable, for example, $x_{ij}=1$ if the grid located at $i$th row and $j$th column is colored, now $i\in \{1,2,\ldots,M\}$ and $j\in \{1,2,\ldots,N\}$)
A sketch to help you understand the question: sketch