[Tex/LaTex] package for specifying optimization problems

packages

Is there a package for specifying optimization problems, such as in linear programming, quadratic programming, convex programming, etc.?

Or do I have to write my own code with align, constraints and so on? I thought that there might be a very elegant way to specify a min/max problem with some constraints below it.

I am talking about something like Example 2.2 in http://people.ucsc.edu/~rgil/Optimization.pdf.

EDIT: Following a request below, I add an illustrating example of a problem I had with align.

\begin{alignat}{3}
\min && n \\
\mathrm{s.t.} && xxxxxxx \\
&& yyyyyyyyyyyyyyyyyyy \\
&& zzzzzzzzzzzzzzzzzzz
\end{alignat}

What happens is that n is aligned to the far left. I want all of the left columns to be centered below each other.
This is my way of formulating a constrained optimization problem, if someone has a better idea I will be glad to hear about it.

If I use only two columns, there is almost no space between $\min$ and $n$. I am almost tempted to use eqnarray 🙂

Best Answer

A bit late but it might help other people looking for the same answer. The package optidef was intended as the easy way to define optimization problems.

\usepackage{optidef}
\begin{mini}|l|
  {w,u}{f(w)+ R(w+6x)}{}{}
  \addConstraint{g(w_k)+h(w_k)}{=0,}{k=0,\ldots,N-1}
  \addConstraint{l(w_k)}{=5u,\quad}{k=0,\ldots,N-1}
 \end{mini}

The package has several more options. Below some examples are provided. To have a completely overview of the features and options check the documentation.


Using a shorter description of minimize/subject to.

\usepackage[short]{optidef}
\begin{mini}
  {w,u}{f(w)+ R(w+6x)}{}{}
  \addConstraint{g(w_k)+h(w_k)}{=0,}{k=0,\ldots,N-1}
  \addConstraint{l(w_k)}{=5u,\quad}{k=0,\ldots,N-1}
\end{mini}


Breaking the objective accross several lines.

\usepackage[long]{optidef}
\begin{mini}
  {w,u}{f(w)+ R(w+6x)+ H(100w-x*w/500)}{}{}
  \breakObjective{-g(w^3-x^2*200+10000*w^5)}
  \addConstraint{g(w_k)+h(w_k)}{=0,}{k=0,\ldots,N-1}
  \addConstraint{l(w_k)}{=5u,\quad}{k=0,\ldots,N-1}
\end{mini}


Multilabeling/no labeling:

\begin{mini*}
    {w}{f(w)+ R(w+6x)}
    {}{}
    \addConstraint{g(w)}{=0}
\end{mini*}

\begin{mini!}
    {w}{f(w)+ R(w+6x)}
    {}{}
    \addConstraint{g(w)}{=0}
\end{mini!}


Alignment position of constraints with respect to the objective:

Alternative 1

\begin{mini}[2]
  {w}{f(w)+ R(w+6x)}
  {\label{eq:Ex1}}{}
  \addConstraint{g(w)+h(w)}{=0}
  \addConstraint{t(w)}{=0.}
\end{mini}

Alternative 2

\begin{mini}[3]
    {w}{f(w)+ R(w+6x)}
    {\label{eq:Ex1}}{}
    \addConstraint{g(w)+h(w)}{=0}
    \addConstraint{t(w)}{=0.}
\end{mini}

Alternative 3

\begin{mini}[4]
    {w}{f(w)+ R(w+6x)}
    {\label{eq:Ex1}}{}
    \addConstraint{g(w)+h(w)}{=0}
    \addConstraint{t(w)}{=0.}
\end{mini}


Other optimization environments

argmini

\begin{argmini}
    {w}{f(w)+ R(w+6x)}
    {}{}
    \addConstraint{g(w)}{=0}
\end{argmini}

maxi

\begin{maxi}
    {w}{f(w)+ R(w+6x)}
    {}{}
    \addConstraint{g(w)}{=0}
\end{maxi}

argmaxi

\begin{argmaxi}
    {w}{f(w)+ R(w+6x)}
    {}{}
    \addConstraint{g(w)}{=0}
\end{argmaxi}


Full details on the different implementations above (and more details) can be found in the documentation: http://ctan.cs.uu.nl/macros/latex/contrib/optidef/optidef.pdf.

Feature requests and discussion of issues can be done through the github page: https://github.com/jeslago/optidef