# Define optimization problems by LaTeX

First of all, this issue has bothered me A LOT for such a long time. But every time I just leave it away because the final version of my manuscript looks acceptable in its formatting of optimization problems, well, at least fits ok with the journal template. After these years, I do have a few alternative solutions but, to the best of my knowledge, it doesn’t exist a simple way to be the best solution which dominates the others in all aspects. Please kindly let me know If I am wrong.

So, this is a note for a few different ways to define optimization problems in your tex file.

## 1. Optidef

A co-author recommended Optidef to me. This is a library provides a standard set of environments for writing optimization problems. Before we start, you should import it first.

\usepackage{optidef}

If this library isn’t included in your environment, visit its website (https://www.ctan.org/pkg/optidef) and directly download. Unzip and put the whole folder into where your environment place $\LaTeX$ library, for example, for those MiKTeX users, it would be C:\Program Files\MiKTeX 2.9\tex\latex

The follows is an example of applying Optidef.


\begin{mini}{x_1,x_2}{3x_1+8x_2} {\label{eq1}}{}

\end{mini}



See its documentation for more detail.

## 2. eqnarray

\begin{eqnarray} \min &\sum_{i}\sum_{s}\sum_{f}\sum_{r} (C_{isfr}^+ + C_{isfr}^-)+\textbf{M}\sum_s D_s^-\nonumber \\
\end{eqnarray}
\begin{eqnarray} \textrm{s.t.}&\sum_i\sum_s(PQ_{isfr}+ C_{isfr}^+ - C_{isfr}^-)\times PT_{isfr}\nonumber\\
\end{eqnarray}
\begin{eqnarray} & \sum_{i}\sum_{s}\sum_{f}\sum_{r} (\frac{C_{isfr}^+ + C_{isfr}^-}{PT_{isfr}}) \leq CF
\end{eqnarray}
\begin{eqnarray} & \sum_{i}\sum_{s}\sum_{f}(C_{isfr}^- - C_{isfr}^+)\leq 0 \quad \forall r
\end{eqnarray}
\begin{eqnarray} & \sum_{f}PQ_{isfr}+D_s^- = WSPM_i \quad \forall i,r,s
\end{eqnarray}
\begin{eqnarray} & C_{isfr}^+ \geq 0 \quad \forall i,s,f,r
\end{eqnarray}
\begin{eqnarray} & C_{isfr}^- \geq 0 \quad \forall i,s,f,r
\end{eqnarray}
\begin{eqnarray} & D_s^- \geq 0 \quad \forall s
\end{eqnarray}


I was writing a manuscript for an IEEE transactions, and the paper format is always two-column. Obviously, a breaking equation may be necessary for your optimization problem, and this is one of my compromise solutions for this situation.

## 3. Array

For most of one-column paper, this might be my priority one. But please note that you would better  add “\displaystyle” every time you use a summation symbol, and a comparison is made for your reference. Please note the \displaybreak[d], see row 2, is an option setting about controlling the break between pages. About the parameter d is described as follows:

d=0 means breaking between pages is strictly forbidden, and d=4 means breaking the model is enforced. If you would like to let the break occurs conveniently in between equations, try d=1~3


$$%\displaybreak[d] \begin{array}{rrclcl} \displaystyle\min_{y} & \multicolumn{3}{l}{z=y^2_1+y^2_2+\ldots+y^2_n} \\ \textrm{s.t.} & y_1y_2\ldots y_n & = & c \\ &\displaystyle \sum_{i=1}^5 y_i & \leq & 5 \\ &\sum_{i=1}^5 y_i & \leq & 5 \\ & y_i & \geq & 0 & & i=1,2,\ldots,5 \\ \end{array}$$



## 4. Align

Basically, this will make a align-right style


\begin{align}
\textrm{s.t.}\quad y_1y_2\ldots y_n & = c \\
\sum_{i=1}^5 y_i & \leq 5\\
\end{align}



## 5. Aligned

This one is interesting because it generates align-left style. So, no matter what, your optimization problem will not look too bad at all.


\begin{aligned} & \min_{y} && z=y^2_1+y^2_2+\ldots+y^2_n \\ & \textrm{s.t.} && y_1y_2\ldots y_n=c \\ &&& \sum_{i=1}^5 y_i \leq 5\\ &&& y_i \geq 0 \quad i=1,2,\ldots,5 \\ \end{aligned}



## 6. Matrix

I only used this method for typing a statistics handout for students. My understanding is, this is appropriate for the length of each equation is similar.

\begin{matrix}
\min_{y} & \displaystyle z=\sum_{i=1}^5 y_i^2 \\
\textrm{s.t.} & y_1y_2\ldots y_n & = & c \\
& \displaystyle \sum_{i=1}^5 y_i & \leq & 5\\
& y_i & \geq & 0 && \quad i=1,2,\ldots,5 \\
\end{matrix}