[Tex/LaTex] Auto numbering constraints in optimization problems

equationsnumbering

The following code

\documentclass{report}
\begin{document}

\begin{equation}
\setlength\arraycolsep{1.5pt}
\begin{array}{l@{\qquad} r c r c r}
(P)     & z(P) = \min   &  cx \\
        & \mathrm{s.t.} &  Ax & = & b \\
        &               &   x & \in &  X \\
\end{array}
\end{equation}

\end{document}

produces a single equation number associated with the whole model as can be seen from the picture below.

enter image description here

How can I define a number for each constraint (without writing it myself)?
See example below.

enter image description here

Best Answer

This answer uses the optidef package. I appears to require writing the objective function differently to what was posted as an example. Otherwise, the function and the constraints are individually numbered.

The following examples illustrate four different usages, providing different alignments, and a long and short style of notation.

This is the result:

enter image description here

This is the code:

\documentclass[a4paper,12pt]{report}

\usepackage[nocomma]{optidef}

\begin{document}

Short notation, alternative 1 layout for constraints
\begin{mini!}|s|[1]                   % mini! = minimize 
    {x}                               % optimization variable
    {z(P) = \min cx \label{eq:eq1}}   % objective function and label
    {\label{eq:Example1}}             % label for optimizatio problem
    {}                                % optimization result
    \addConstraint{Ax}{=b \label{eq:con1}}    % constraint 1
    \addConstraint{x}{\in X \label{eq:con2}}  % constraint 2
\end{mini!}

Short notation, alternative 2 layout for constraints
\begin{mini!}|s|[2]                   % mini! = minimize 
    {x}                               % optimization variable
    {z(P) = \min cx \label{eq:eq1}}   % objective function and label
    {\label{eq:Example1}}             % label for optimizatio problem
    {}                                % optimization result
    \addConstraint{Ax}{=b \label{eq:con1}}    % constraint 1
    \addConstraint{x}{\in X \label{eq:con2}}  % constraint 2
\end{mini!}

Short notation, alternative 3 layout for constraints
\begin{mini!}|s|[3]                   % mini! = minimize
    {x}                               % optimization variable
    {z(P) = \min cx \label{eq:eq1}}   % objective function and label
    {\label{eq:Example1}}             % label for optimizatio problem
    {}                                % optimization result
    \addConstraint{Ax}{=b \label{eq:con1}}    % constraint 1
    \addConstraint{x}{\in X \label{eq:con2}}  % constraint 2
\end{mini!}

Long notation, alternative 2 layout for constraints
\begin{mini!}|l|[2]                   % mini! = minimize 
    {x}                               % optimization variable
    {z(P) = \min cx \label{eq:eq1}}   % objective function and label
    {\label{eq:Example1}}             % label for optimizatio problem
    {}                                % optimization result
    \addConstraint{Ax}{=b \label{eq:con1}}    % constraint 1
    \addConstraint{x}{\in X \label{eq:con2}}  % constraint 2
\end{mini!}

\end{document}