Site logoTungTT

Modeling tips & tricks

4 minutes
636 words

1. Binary variables#

This method is used when we can precisely determine the possible values of a variable. For instance, given an integer variable xZx \in \mathbb{Z} with the condition 0x90 \leq x \leq 9, we can decompose the variable xx into 9 binary variables xix_i (0i90 \leq i \leq 9) to satisfy

xi={1 if x is equal to i0 otherwise x_i = \begin{cases} 1 & \text{ if } x\text{ is equal to } i \\ 0 & \text{ otherwise } \end{cases}

Why do we need to decompose a variable into multiple variables? What is the benefit? The answer is, suppose we have not only one variable xx as above but also another variable yZy \in \mathbb{Z} with the condition 0y90 \leq y \leq 9. Then, it would be very difficult to linearize the condition xyx \neq y if we use these two variables. On the other hand, if we decompose both xx and yy into binary variables, this condition can be easily modeled as follows: xi+yi1,0i9x_i + y_i \leq 1, \forall 0 \leq i \leq 9.

2. Modeling nonlinear constraints geometrically#

This method is applicable when we can find a convex hull containing only points that satisfy the desired constraint. For instance, to linearize the condition x=yz=1x = y \Leftrightarrow z = 1 where x,y,zx, y, z are binary variables. We observe that the feasible points are (1,1,1),(0,0,1),(1,0,0),(0,1,0)(1, 1, 1), (0, 0, 1), (1, 0, 0), (0, 1, 0). Geometrically representing these points in three-dimensional space, we obtain the tetrahedron ABCDABCD shown below

modeling_tips_tricks

The points within the tetrahedron ABCDABCD are precisely those that satisfy the given condition. The equations defining this tetrahedron are the exact constraints needed to linearize the original condition, specifically, the following conditions

{x+yz1y+zx1z+xy1x+y=z1\begin{cases} x + y - z \geq 1 \\ y + z - x \geq 1 \\ z + x - y \geq 1 \\ x + y = z \geq 1 \\ \end{cases}

A few notes:

  • Use this method when we can determine all points satisfying the original constraint
  • There must exist a convex set that contains all and only the points satisfying the constraint
  • The above convex set should be easily representable by other linear constraints
  • From this point forward, I will use the term geometric method to describe this technique. (This name is entirely my own creation, and I haven't consulted any references. It might not be the correct terminology. If you know the proper term for this method, please let me know so I can correct it.)

3. Modeling nonlinear “AA or BB” constraints#

The typical form of these constraints is:

[f(x)Ag(x)B\left[ \begin{array}{ll} f(x) & \geq A \\ g(x) & \geq B \end{array} \right .

A common approach to linearize this type of constraint is to introduce an additional binary variable that corresponds to the two cases of the original constraint and then try to reformulate the original condition so that they are not contradictory. For example, consider linearizing the following constraint with x,y0x, y \geq 0

{[2x+y5x+2y5x,y0\begin{cases} \left[ \begin{array}{ll} 2x + y \geq 5 \\ x + 2y \geq 5 \end{array} \right .\\ x, y \geq 0 \end{cases}

Create binary variable zz satisfying

z={1if 2x+y50if x+2y5z = \begin{cases} 1 & \text{if } 2x + y \geq 5 \\ 0 & \text{if } x + 2y \geq 5 \\ \end{cases}

Then the original condition can be reformulated as follows

{2x+yAzx+2yAA(1z)x,y0\begin{cases} 2x + y \geq Az \\ x + 2y \geq A - A(1-z)\\ x, y \geq 0 \end{cases}

Note: This method is quite difficult to apply and requires case-by-case analysis to find an appropriate linearization.

4. Conclusion#

We have discussed 3 common modeling techniques. Additional methods can be found in MOSEK Modeling Cookbook.

Happy modeling!