diff options
Diffstat (limited to 'Master/texmf-dist/doc/latex/optidef/optidef.tex')
-rw-r--r-- | Master/texmf-dist/doc/latex/optidef/optidef.tex | 869 |
1 files changed, 373 insertions, 496 deletions
diff --git a/Master/texmf-dist/doc/latex/optidef/optidef.tex b/Master/texmf-dist/doc/latex/optidef/optidef.tex index a5147d46c1a..746870c3cdb 100644 --- a/Master/texmf-dist/doc/latex/optidef/optidef.tex +++ b/Master/texmf-dist/doc/latex/optidef/optidef.tex @@ -3,7 +3,7 @@ \usepackage{optidef} % Title Page -\title{\textit{\textbf{Optidef}} \\ A Latex library for minimization/maximization problems definition} +\title{\textit{\textbf{Optidef}} \\ A Latex library for optimization problems\\ \textnormal{Version - 1.0}} \author{Jesus Lago Garcia} @@ -20,11 +20,11 @@ This small library provides a standard set of environments for writing minimization problems. The most important features are: \begin{enumerate} - \item It automatically aligns the problems in three points with an optional fourth: + \item It automatically aligns the problems in the most convenient way allowing even two different output formats: \begin{enumerate} - \item Beginning of the words "minimize/argmin" and "subject to" - \item The objective function and the longest left hand side of the constraints - \item The $= | > | <$ signs of the constraints. + \item Alignment at the beginning of the words \textit{minimize/argmin} and \textit{subject to}. + \item Double format for the location of the constraints: either to the right of \textit{subject to} aligned with the objective function or below \textit{subject to}. + \item Alignment at the $=,~>,~<$ signs of the constraints. \item Optionally, the user can add manually a double align character \&\& to align some common constraints feature. A clear example could be the constraints names, e.g. (boundary constraint) alignment with (dynamic constraint), or the index of the constraints, e.g. in the case of having something like $h(x_k,u_k)\leq 0,\quad k=0,\ldots,N$, align the indexes $k=0,\ldots,N$ across constraint lines. \end{enumerate} @@ -43,70 +43,89 @@ This small library provides a standard set of environments for writing minimizat There are three basic environments depending on the type of referencing that should be used. \begin{enumerate} \item The \textbf{mini} environment for defining problems with a single reference label: - \begin{mini}{1} - {w}{f(w)+ R(w+6x) + \nabla_w R} - {g(w)}{=0} + \begin{mini} + {w}{f(w)+ R(w+6x)} {\label{eq:Ex1}}{} + \addConstraint{g(w)}{=0} \end{mini} \item The \textbf{mini*} environment if the problem does not have to be referenced: - \begin{mini*}{1} - {w}{f(w)+ R(w+6x) + \nabla_w R} - {g(w)}{=0} + \begin{mini*} + {w}{f(w)+ R(w+6x)} {}{} + \addConstraint{g(w)}{=0} \end{mini*} \item The \textbf{mini!} environment if each equation should be referenced: - \begin{mini!}{1} - {w}{f(w)+ R(w+6x) + \nabla_w R \label{eq:Ex2}} - {g(w)}{=0} + \begin{mini!} + {w}{f(w)+ R(w+6x)\label{eq:Ex2}} {\label{eq:Ex1}}{} + \addConstraint{g(w)}{=0} \end{mini!} \end{enumerate} +\section{Environment types} +There are two basic output formats. By default the constraints are aligned with the objective function and to the right of \textit{subject to}. However the user can choose to locate them below \textit{subject to}. +\begin{enumerate} + \item Standard format: + \begin{mini} + {w}{f(w)+ R(w+6x)} + {\label{eq:Ex1}}{} + \addConstraint{g(w)}{=0} + \end{mini} + \item Alternative format: + \begin{mini}[1] + {w}{f(w)+ R(w+6x)} + {\label{eq:Ex1}}{} + \addConstraint{g(w)}{=0} + \end{mini} +\end{enumerate} + \section{Environment Syntaxes} The three environments use the same syntax with the same number of parameters. In particular, considering that LHS stands for Left-hand-side and RHS for Right-hand-side, the basic structure to define a general optimization problem is: \begin{verbatim} -\begin{mini#}{Number of constraints} +\begin{mini#}[Format] {Optimization variable} {Objective function \label{Objective function referece}} - {LHS Constraint 1}{RHS Constraint 1 \label{Reference Constraint 1}} {\label{Global referece of Optimization Problem}} {Result of the optimization problem or any expression on the left of the minimize word} + \addConstraint{LHS Constraint 1}{RHS Constraint 1 \label{Reference Constraint 1}} \addConstraint{LHS Constraint 2}{RHS Constraint 2 \label{Reference Constraint 2}} - \addConstraint{LHS Constraint 3}{RHS Constraint 3 \label{Reference Constraint 3}} . . - \finalConstraint{LHS N} {RHSConstraint N \label{Reference Constraint N}} + \addConstraint{LHS N}{RHSConstraint N \label{Reference Constraint N}} \end{mini#} \end{verbatim} \noindent where \# $\in \{*, !, ~ \}$. \subsection{Parameters definition} -The number of parameters that the environment uses is 7: +The number of parameters that the environment uses is 6: \begin{enumerate} - \item \verb|Number of constraints|, e.g. 0,1,2,3,4... \item \verb|Optimization variable|, e.g. $w \in \Re^N$. \item \verb|Objective function|, e.g. $\|w\|_2$. - \item \verb|LHS Constraint 1| (optional): the left-hand side of the first constraint, e.g. $3w^\top w$. For unconstrained problems leave it blank, i.e. \{\} - \item \verb|RHS Constraint 1| (optional): the right-hand side of the first constraints including the equal, less and greater signs, e.g. $\leq \|w\|_\infty$. For unconstrained problems leave it blank, i.e. \{\} \item \verb|\label{Global referece of Optimization Problem}|: it defines the main and general reference for the optimization problem. It is used for the \verb|mini| and \verb|mini!| enviroments. In the \verb|mini*| environment leave it blank, i.e. \{\}. \item \verb|Result of the optimization problem|: optionally a term expressing the result of the optimization problem, e.g. $J(w^*)~=$. + \item \verb|Format|: optional parameter if the user want to start the constraints right below \textit{subject to}, instead to the default location on the right of \textit{subject to}. \end{enumerate} -\noindent Notice that only the first three will be really necessary in every definition, nevertheless and for the sake of having homogeneous definitions, we opted for requiring the 7 parameters in every definition and expecting empty parameters definitions, i.e. \{\}, when they are not needed. +\noindent Notice that only the first two mandatory parameters (variable and objective) will be really necessary in every definition, nevertheless and for the sake of having homogeneous definitions, we opted for requiring the 4 parameters in every definition and expecting empty parameters definitions, i.e. \{\}, when they are not needed. + After the definition of this parameters, the environment accepts the definition of an infinite number of constraints. For this definitions the command: +~\\ \verb|\addConstraint{LHS Constraint k}| \verb|{RHS Constraint k \label{Reference Constraint k}}| +~\\ -\noindent has to be used, where the left hand side and right hand side syntax is the same as used for the mandatory third and fourth environment parameters. - -Notice that the last constraint has to be defined using the \verb|\finalConstraint| command, instead of the \verb|\addConstraint|. +\noindent has to be used, where: +\begin{enumerate} + \item \verb|LHS Constraint|: the left-hand side of the any constraint, e.g. $3w^\top w$. + \item \verb|RHS Constraint|: the right-hand side of the first constraints including the equal, less and greater signs, e.g. $\leq \|w\|_\infty$, as well as the constraint label. +\end{enumerate} \subsubsection{Constraints referencing} Notice that the label for the constraints is always included in the right hand side expression and it only makes sense for the case of using the \verb|mini!| enviroment. The label of the objective function can also be included in a similar way. @@ -115,56 +134,52 @@ Notice that the label for the constraints is always included in the right hand s The code: \begin{verbatim} -\begin{mini}{4} - {w}{f(w)+ R(w+6x) + \nabla_w R} - {g(w)}{=0} - - {\label{eq:Example1}} - {} +\begin{mini} + {w}{f(w)+ R(w+6x)} + {\label{eq:Example1}}{} + \addConstraint{g(w)}{=0} \addConstraint{n(w)}{= 6} \addConstraint{L(w)+r(x)}{=Kw+p} - \finalConstraint{h(x)}{=0.} + \addConstraint{h(x)}{=0.} \end{mini} \end{verbatim} \noindent outputs: -\begin{mini}{4} - {w}{f(w)+ R(w+6x) + \nabla_w R} - {g(w)}{=0} - {\label{eq:Ex1}}{} +\begin{mini} + {w}{f(w)+ R(w+6x)} + {\label{eq:Ex11}}{} + \addConstraint{g(w)}{=0} \addConstraint{n(w)}{= 6} \addConstraint{L(w)+r(x)}{=Kw+p} - \finalConstraint{h(x)}{=0.} + \addConstraint{h(x)}{=0.} \end{mini} \subsubsection{Example 2 - mini* environment} - On the other hand: \begin{verbatim} -\begin{mini*}{4} - {w}{f(w)+ R(w+6x) + \nabla_w R} - {g(w)}{=0,} - +\begin{mini*} + {w}{f(w)+ R(w+6x)} {}{} - + + \addConstraint{g(w)}{=0} \addConstraint{n(w)}{= 6,} \addConstraint{L(w)+r(x)}{=Kw+p} - \finalConstraint{h(x)}{=0.} + \addConstraint{h(x)}{=0.} \end{mini*} \end{verbatim} \noindent it is almost the same but removing the reference: -\begin{mini*}{3} - {w}{f(w)+ R(w+6x) + \nabla_w R} - {g(w)}{=0,} +\begin{mini*} + {w}{f(w)+ R(w+6x)} {}{} - \addConstraint{n(w)}{= 6, } - \addConstraint{L(w)+r(x)}{=Kw+p, } - \finalConstraint{h(x)}{=0.} + \addConstraint{g(w)}{=0} + \addConstraint{n(w)}{= 6} + \addConstraint{L(w)+r(x)}{=Kw+p} + \addConstraint{h(x)}{=0.} \end{mini*} \subsubsection{Example 3 - mini! environment} @@ -172,27 +187,25 @@ On the other hand: \noindent Finally, the multireferencing environment outputs: \begin{verbatim} -\begin{mini!}{4} - {w}{f(w)+ R(w+6x) + \nabla_w R \label{eq:ObjectiveExample1}} - {g(w)}{=0 \label{eq:C1Example1}} - - {\label{eq:Example1}} - {} +\begin{mini!} + {w}{f(w)+ R(w+6x) \label{eq:ObjectiveExample1}} + {\label{eq:Example1}}{} + \addConstraint{g(w)}{=0 \label{eq:C1Example3}} \addConstraint{n(w)}{= 6 \label{eq:C2Example1}} \addConstraint{L(w)+r(x)}{=Kw+p \label{eq:C3Example1}} - \finalConstraint{h(x)}{=0. \label{eq:C4Example1}} + \addConstraint{h(x)}{=0. \label{eq:C4Example1}} \end{mini!} \end{verbatim} -\begin{mini!}{4} - {w}{f(w)+ R(w+6x) + \nabla_w R\label{eq:ObjectiveExample3}} - {g(w)}{=0 \label{eq:C1Example3}} +\begin{mini!} + {w}{f(w)+ R(w+6x)\label{eq:ObjectiveExample3}} {\label{eq:Example3}} {} + \addConstraint{g(w)}{=0 \label{eq:C1Example3}} \addConstraint{n(w)}{= 6 \label{eq:C2Example3}} \addConstraint{L(w)+r(x)}{=Kw+p \label{eq:C3Example3}} - \finalConstraint{h(x)}{=0. \label{eq:C4Example3}} + \addConstraint{h(x)}{=0. \label{eq:C4Example3}} \end{mini!} \subsubsection{Example 4 - mini + problem result} @@ -200,65 +213,90 @@ On the other hand: \noindent Adding the problem result: \begin{verbatim} -\begin{mini}{4} -{w}{f(w)+ R(w+6x) + \nabla_w R} -{g(w)}{=0} - +\begin{mini} +{w}{f(w)+ R(w+6x)} {\label{eq:Example1}} {J(w^*)=} +\addConstraint{g(w)}{=0} \addConstraint{n(w)}{= 6} \addConstraint{L(w)+r(x)}{=Kw+p} -\finalConstraint{h(x)}{=0.} +\addConstraint{h(x)}{=0.} \end{mini} \end{verbatim} \noindent outputs: -\begin{mini}{4} - {w}{f(w)+ R(w+6x) + \nabla_w R} - {g(w)}{=0} +\begin{mini} + {w}{f(w)+ R(w+6x)} {\label{eq:Ex1}}{J(w^*)~=~} + \addConstraint{g(w)}{=0} \addConstraint{n(w)}{= 6} \addConstraint{L(w)+r(x)}{=Kw+p} - \finalConstraint{h(x)}{=0.} + \addConstraint{h(x)}{=0.} \end{mini} -\subsubsection{Example 5 - mini* + extra constraint alignment} -Adding the fourth optional alignment to add constraint names: +\subsubsection{Example 5 - second format} + +\noindent If including a 1 as optional parameter, the first constraint will appear aligned to the left right below \textit{subject to}. \begin{verbatim} -\begin{mini*}{4} -{w}{f(w)+ R(w+6x) + \nabla_w R} -{g(w)}{=0, \quad && \text{(Dynamic constraint)}} +\begin{mini}[1] +{w}{f(w)+ R(w+6x)} +{\label{eq:Example1}} +{} +\addConstraint{g(w)}{=0} +\addConstraint{n(w)}{= 6} +\addConstraint{L(w)+r(x)}{=Kw+p} +\addConstraint{h(x)}{=0.} +\end{mini} +\end{verbatim} + +\noindent outputs: + +\begin{mini}[1] + {w}{f(w)+ R(w+6x)} + {\label{eq:Ex1}}{} + \addConstraint{g(w)}{=0} + \addConstraint{n(w)}{= 6} + \addConstraint{L(w)+r(x)}{=Kw+p} + \addConstraint{h(x)}{=0.} +\end{mini} + + +\subsubsection{Example 6 - mini* + extra constraint alignment} +Adding the fourth optional alignment to add constraint names: + +\begin{verbatim} +\begin{mini*} +{w}{f(w)+ R(w+6x)} {}{} +\addConstraint{g(w)}{=0, \quad && \text{(Dynamic constraint)}} \addConstraint{n(w)}{= 6, \quad && \text{(Boundary constraint)}} \addConstraint{L(w)+r(x)}{=Kw+p, \quad && \text{(Random constraint)}} -\finalConstraint{h(x)}{=0.\quad && \text{(Path constraint)}} +\addConstraint{h(x)}{=0.\quad && \text{(Path constraint)}} \end{mini*} \end{verbatim} -\begin{mini*}{3} - {w}{f(w)+ R(w+6x) + \nabla_w R} - {g(w)}{=0, \quad && \text{(Dynamic constraint)}} +\begin{mini*} + {w}{f(w)+ R(w+6x)} {}{} + \addConstraint{g(w)}{=0, \quad && \text{(Dynamic constraint)}} \addConstraint{n(w)}{= 6, \quad && \text{(Boundary constraint)}} \addConstraint{L(w)+r(x)}{=Kw+p, \quad && \text{(Random constraint)}} - \finalConstraint{h(x)}{=0. \quad && \text{(Path constraint).}} + \addConstraint{h(x)}{=0. \quad && \text{(Path constraint).}} \end{mini*} -\subsubsection{Example 6 - mini environment on the unconstrained case} +\subsubsection{Example 7 - mini environment on the unconstrained case} \begin{verbatim} -\begin{mini}{0} - {w}{f(w)+ R(w+6x) + \nabla_w R} - {}{} - {}{} +\begin{mini} + {w}{f(w)+ R(w+6x)} {\label{eq:Ex4}} {} \end{mini} @@ -266,90 +304,91 @@ Adding the fourth optional alignment to add constraint names: \noindent outputs: -\begin{mini}{0} - {w}{f(w)+ R(w+6x) + \nabla_w R} - {}{} +\begin{mini} + {w}{f(w)+ R(w+6x)} {\label{eq:Ex4}}{} \end{mini} + \section{The \textit{argmini} environment} Similar to the \verb|mini|, \verb|mini*| and \verb|mini!| environments, the environments \verb|argmini|, \verb|argmini*| and \verb|argmini!| are very similar environments that use the same syntax but the output is slightly different. The following code serves for illustration: \begin{verbatim} -\begin{argmini}{4} - {w}{f(w)+ R(w+6x) + \nabla_w R} - {g(w)}{=0} +\begin{argmini} + {w}{f(w)+ R(w+6x)} {\label{eq:Example1}}{w^*=} + \addConstraint{g(w)}{=0} \addConstraint{n(w)}{= 6} \addConstraint{L(w)+r(x)}{=Kw+p} - \finalConstraint{h(x)}{=0.} + \addConstraint{h(x)}{=0.} \end{argmini} \end{verbatim} \noindent outputs: -\begin{argmini}{3} - {w}{f(w)+ R(w+6x) + \nabla_w R} - {g(w)}{=0} +\begin{argmini} + {w}{f(w)+ R(w+6x)} {\label{eq:Ex1}}{w^*~=~} + \addConstraint{g(w)}{=0} \addConstraint{n(w)}{= 6} \addConstraint{L(w)+r(x)}{=Kw+p} - \finalConstraint{h(x)}{=0.} + \addConstraint{h(x)}{=0.} \end{argmini} \section{The \textit{maxi} and \textit{argmaxi} environments} Exactly the same syntax and definition as the previous environments, but now for defining maximization environments. The following code serves for illustration: \begin{verbatim} -\begin{maxi}{4} - {w}{f(w)+ R(w+6x) + \nabla_w R} +\begin{maxi} + {w}{f(w)+ R(w+6x)} {g(w)}{=0} {\label{eq:Example1}}{} + \addConstraint{g(w)}{=0} \addConstraint{n(w)}{= 6} \addConstraint{L(w)+r(x)}{=Kw+p} - \finalConstraint{h(x)}{=0.} + \addConstraint{h(x)}{=0.} \end{maxi} \end{verbatim} \noindent outputs: -\begin{maxi}{4} - {w}{f(w)+ R(w+6x) + \nabla_w R} - {g(w)}{=0} +\begin{maxi} + {w}{f(w)+ R(w+6x)} {\label{eq:Example1}}{} + \addConstraint{g(w)}{=0} \addConstraint{n(w)}{= 6} \addConstraint{L(w)+r(x)}{=Kw+p} - \finalConstraint{h(x)}{=0.} + \addConstraint{h(x)}{=0.} \end{maxi} \section{Problems and limitations} One current limitation is that the size of the optimization variables must be smaller than the word minimize, otherwise, the output is not properly aligned. Example: -\begin{mini!}{3} +\begin{mini!} {x_0,u_0,x_1,\hdots,u_{N-1},x_N} {\sum_{k=0}^{N-1} L(x_k,u_k)\!\!+\!\!E(x_N)\label{OCPobj}} - {x_{k+1}-f(x_k,u_k)}{= 0, \label{dOCP:modelc}\quad k=0,\dots,N-1} {\label{eq:OCP}}{} + \addConstraint{x_{k+1}-f(x_k,u_k)}{= 0, \label{dOCP:modelc}\quad k=0,\dots,N-1} \addConstraint{h(x_k,u_k)}{\leq 0, \quad k=0,\dots,N-1} - \finalConstraint{r(x_0,x_N)}{= 0. \label{dOCP:boundary}} + \addConstraint{r(x_0,x_N)}{= 0. \label{dOCP:boundary}} \end{mini!} \noindent A possible way to avoid this is to stack them with the command: \begin{verbatim} \substack{x_0,u_0,x_1,\hdots,\\u_{N-1},x_N} \end{verbatim} -\begin{mini!}{3} +\begin{mini!} {\substack{x_0,u_0,x_1,\hdots,\\ u_{N-1},x_N}} {\sum_{k=0}^{N-1} L(x_k,u_k)\!\!+\!\!E(x_N)\label{OCPobj}} - {x_{k+1}-f(x_k,u_k)}{= 0, \label{dOCP:modelc}\quad k=0,\dots,N-1} {\label{eq:OCP}}{} + \addConstraint{x_{k+1}-f(x_k,u_k)}{= 0, \label{dOCP:modelc}\quad k=0,\dots,N-1} \addConstraint{h(x_k,u_k)}{\leq 0, \quad k=0,\dots,N-1} - \finalConstraint{r(x_0,x_N)}{= 0. \label{dOCP:boundary}} + \addConstraint{r(x_0,x_N)}{= 0. \label{dOCP:boundary}} \end{mini!} \noindent If you want to increase the size of the optimization variables: @@ -357,26 +396,15 @@ One current limitation is that the size of the optimization variables must be sm \substack{\displaystyle x_0,u_0,x_1,\hdots,\\ \displaystyle u_{N-1},x_N} \end{verbatim} -\begin{mini!}{3} +\begin{mini!} {\substack{\displaystyle x_0,u_0,x_1,\hdots,\\ \displaystyle u_{N-1},x_N}} {\sum_{k=0}^{N-1} L(x_k,u_k)\!\!+\!\!E(x_N)\label{OCPobj}} - {x_{k+1}-f(x_k,u_k)}{= 0, \label{dOCP:modelc}\quad k=0,\dots,N-1} {\label{eq:OCP}}{} + \addConstraint{x_{k+1}-f(x_k,u_k)}{= 0, \label{dOCP:modelc}\quad k=0,\dots,N-1} \addConstraint{h(x_k,u_k)}{\leq 0, \quad k=0,\dots,N-1} - \finalConstraint{r(x_0,x_N)}{= 0. \label{dOCP:boundary}} + \addConstraint{r(x_0,x_N)}{= 0. \label{dOCP:boundary}} \end{mini!} -The other option is to define the set of variables before the problem definition as a single variable, i.e. $w = [x_0,u_0,x_1,\hdots,u_{N-1},x_N]$ and: - -%\begin{mini3!} -% {w} -% {\sum_{k=0}^{N-1} L(x_k,u_k)\!\!+\!\!E(x_N)}{\label{OCPobj}} -% {x_{k+1}-f(x_k,u_k)}{= 0, \label{dOCP:modelc}\quad k=0,\dots,N-1} -% {h(x_k,u_k)} {\leq 0, \quad k=0,\dots,N-1} -% {r(x_0,x_N)}{= 0. \label{dOCP:boundary}} -% \label{eq:OCP} -%\end{mini3!} - \section{Code definition} \begin{verbatim} % optidef - Version 08/06/2016 @@ -391,378 +419,227 @@ The other option is to define the set of variables before the problem definition %E-mail: jesus.lago.garcia@venus.uni-freiburg.de % %This work consists of the file optidef.sty. - - \NeedsTeXFormat{LaTeX2e} - \ProvidesPackage{optidef}[2016/06/06 Package for defining optimization problems] - - \RequirePackage{environ} - \RequirePackage{ifthen} - \RequirePackage{mathtools} - \RequirePackage{xifthen} - - % Input minimization evironments - - % Macros for objective definition, constraint definition and extra constraint definition - \newcommand{\bodyobj}[4] - { - \ifthenelse{\isempty{#4}} - { - &\underset{\displaystyle #1}{\mbox{#3}} \quad #2\span\span\span\span - } - { - #4 ~~ &\underset{\displaystyle #1}{\mbox{#3}} \quad #2\span\span\span\span - } - } - - - \newcommand{\bodyconst}[2] - {&\mbox{subject to} \quad  & #2\span\span} - - \newcommand{\addConstraint}[2]{&\quad  & #2, \\} - \newcommand{\finalConstraint}[2]{&\quad  & #2} - - - %\newcommand(\breakObjectiveUnconstraint)[1]{\\% - %\bodyobjUn{}{#1}{\phantom{minimize}}{}} - \newcommand{\breakObjectiveOneConstraint}[1]{&&\\} - %\newcommand(\breakObjective)[1]{\bodyobj{}{#4}{\phantom{minimize}}{}\nonumber\\} } - - \newcommand{\bodyconstOne}[2] - {&\text{subject to} \quad & #2} - - % This body of the objective is only valid for - % one constraint problem since there is no need to - % use mathllap to achieve second alignment level - \newcommand{\bodyobjOne}[4] - { - \ifthenelse{\isempty{#4}} - { - &\underset{\displaystyle #1}{\text{#3}} \quad & - } - { - #4 ~~ &\underset{\displaystyle #1}{\text{#3}} \quad &} - } - - - % This body of the objective is only valid for - % no constraint problem since there is no need to - % align - \newcommand{\bodyobjUn}[4] - { - \ifthenelse{\isempty{#4}} - { - } - { - #4~ - } - \underset{\displaystyle #1}{\text{#3}} \quad #2 - } - - %MINIMIZATION ENVIRONMENTS - - \NewEnviron{mini}[7]{% - \ifthenelse{\equal{#1}{0}}{% - \begin{equation} - #6 - \bodyobjUn{#2}{#3}{minimize}{#7} - \end{equation} - }% - {% - \ifthenelse{\equal{#1}{1}}{% - \begin{equation} - #6 - \begin{alignedat}{3} - \bodyobjOne{#2}{#3}{minimize}{#7}\\ - \bodyconstOne{#4}{#5} - \end{alignedat} - \end{equation} - }% - {% - \begin{equation} - #6 - \begin{alignedat}{4} - \bodyobj{#2}{#3}{minimize}{#7}\\ - \bodyconst{#4}{#5,} \\ - \BODY - \end{alignedat} - \end{equation} - }% - }% - } - - \NewEnviron{argmini}[7]{% - \ifthenelse{\equal{#1}{0}}{% - \begin{equation} - #6 - \bodyobjUn{#2}{#3}{arg min}{#7} - \end{equation} - }% - {% - \ifthenelse{\equal{#1}{1}}{% - \begin{equation} - #6 - \begin{alignedat}{3} - \bodyobjOne{#2}{#3}{arg min}{#7}\\ - \bodyconstOne{#4}{#5} - \end{alignedat} - \end{equation} - }% - {% - \begin{equation} - #6 - \begin{alignedat}{4} - \bodyobj{#2}{#3}{arg min}{#7}\\ - \bodyconst{#4}{#5,} \\ - \BODY - \end{alignedat} - \end{equation} - }% - }% - } - - \NewEnviron{mini*}[7]{% - \ifthenelse{\equal{#1}{0}}{% - \begin{equation*} - \bodyobjUn{#2}{#3}{minimize}{#7} - \end{equation*} - }% - {% - \ifthenelse{\equal{#1}{1}}{% - \begin{alignat*}{3} - \bodyobjOne{#2}{#3}{minimize}{#7}\\ - \bodyconstOne{#4}{#5} - \end{alignat*} - }% - {% - \begin{alignat*}{5} - \bodyobj{#2}{#3}{minimize}{#7}\\ - \bodyconst{#4}{#5,} \\ - \BODY - \end{alignat*} - }% - }% - } - - \NewEnviron{argmini*}[7]{% - \ifthenelse{\equal{#1}{0}}{% - \begin{equation*} - \bodyobjUn{#2}{#3}{arg min}{#7} - \end{equation*} - }% - {% - \ifthenelse{\equal{#1}{1}}{% - \begin{alignat*}{3} - \bodyobjOne{#2}{#3}{arg min}{#7}\\ - \bodyconstOne{#4}{#5} - \end{alignat*} - }% - {% - \begin{alignat*}{4} - \bodyobj{#2}{#3}{arg min}{#7}\\ - \bodyconst{#4}{#5,} \\ - \BODY - \end{alignat*} - }% - }% - } - - - \NewEnviron{mini!}[7]{% - \ifthenelse{\equal{#1}{1}}{% - \begin{subequations} - #6 - \begin{alignat}{3} - \bodyobjOne{#2}{#3}{minimize}{#7}\\ - \bodyconstOne{#4}{#5} - \end{alignat} - \end{subequations} - }% - {% - \begin{subequations} - #6 - \begin{alignat}{4} - \bodyobj{#2}{#3}{minimize}{#7}\\ - \bodyconst{#4}{#5,} \\ - \BODY - \end{alignat} - \end{subequations} - }% - } - - \NewEnviron{argmini!}[7]{% - \ifthenelse{\equal{#1}{1}}{% - \begin{subequations} - #6 - \begin{alignat}{3} - \bodyobjOne{#2}{#3}{arg min}{#7}\\ - \bodyconstOne{#4}{#5} - \end{alignat} - \end{subequations} - }% - {% - \begin{subequations} - #6 - \begin{alignat}{4} - \bodyobj{#2}{#3}{arg min}{#7}\\ - \bodyconst{#4}{#5,} \\ - \BODY - \end{alignat} - \end{subequations} - }% - } - - %MAXIMIZATION ENVIRONMENTS - - \NewEnviron{maxi}[7]{% - \ifthenelse{\equal{#1}{0}}{% - \begin{equation} - #6 - \bodyobjUn{#2}{#3}{maximize}{#7} - \end{equation} - }% - {% - \ifthenelse{\equal{#1}{1}}{% - \begin{equation} - #6 - \begin{alignedat}{3} - \bodyobjOne{#2}{#3}{maximize}{#7}\\ - \bodyconstOne{#4}{#5} - \end{alignedat} - \end{equation} - }% - {% - \begin{equation} - #6 - \begin{alignedat}{4} - \bodyobj{#2}{#3}{maximize}{#7}\\ - \bodyconst{#4}{#5,} \\ - \BODY - \end{alignedat} - \end{equation} - }% - }% - } - - \NewEnviron{argmaxi}[7]{% - \ifthenelse{\equal{#1}{0}}{% - \begin{equation} - #6 - \bodyobjUn{#2}{#3}{arg max}{#7} - \end{equation} - }% - {% - \ifthenelse{\equal{#1}{1}}{% - \begin{equation} - #6 - \begin{alignedat}{3} - \bodyobjOne{#2}{#3}{arg max}{#7}\\ - \bodyconstOne{#4}{#5} - \end{alignedat} - \end{equation} - }% - {% - \begin{equation} - #6 - \begin{alignedat}{4} - \bodyobj{#2}{#3}{arg max}{#7}\\ - \bodyconst{#4}{#5,} \\ - \BODY - \end{alignedat} - \end{equation} - }% - }% - } - - \NewEnviron{maxi*}[7]{% - \ifthenelse{\equal{#1}{0}}{% - \begin{equation*} - \bodyobjUn{#2}{#3}{maximize}{#7} - \end{equation*} - }% - {% - \ifthenelse{\equal{#1}{1}}{% - \begin{alignat*}{3} - \bodyobjOne{#2}{#3}{maximize}{#7}\\ - \bodyconstOne{#4}{#5} - \end{alignat*} - }% - {% - \begin{alignat*}{5} - \bodyobj{#2}{#3}{maximize}{#7}\\ - \bodyconst{#4}{#5,} \\ - \BODY - \end{alignat*} - }% - }% - } - - \NewEnviron{argmaxi*}[7]{% - \ifthenelse{\equal{#1}{0}}{% - \begin{equation*} - \bodyobjUn{#2}{#3}{arg max}{#7} - \end{equation*} - }% - {% - \ifthenelse{\equal{#1}{1}}{% - \begin{alignat*}{3} - \bodyobjOne{#2}{#3}{arg max}{#7}\\ - \bodyconstOne{#4}{#5} - \end{alignat*} - }% - {% - \begin{alignat*}{4} - \bodyobj{#2}{#3}{arg max}{#7}\\ - \bodyconst{#4}{#5,} \\ - \BODY - \end{alignat*} - }% - }% - } - - - \NewEnviron{maxi!}[7]{% - \ifthenelse{\equal{#1}{1}}{% - \begin{subequations} - #6 - \begin{alignat}{3} - \bodyobjOne{#2}{#3}{maximize}{#7}\\ - \bodyconstOne{#4}{#5} - \end{alignat} - \end{subequations} - }% - {% - \begin{subequations} - #6 - \begin{alignat}{4} - \bodyobj{#2}{#3}{maximize}{#7}\\ - \bodyconst{#4}{#5,} \\ - \BODY - \end{alignat} - \end{subequations} - }% - } - - \NewEnviron{argmaxi!}[7]{% - \ifthenelse{\equal{#1}{1}}{% - \begin{subequations} - #6 - \begin{alignat}{3} - \bodyobjOne{#2}{#3}{arg max}{#7}\\ - \bodyconstOne{#4}{#5} - \end{alignat} - \end{subequations} - }% - {% - \begin{subequations} - #6 - \begin{alignat}{4} - \bodyobj{#2}{#3}{arg max}{#7}\\ - \bodyconst{#4}{#5,} \\ - \BODY - \end{alignat} - \end{subequations} - }% - } + +\NeedsTeXFormat{LaTeX2e} +\ProvidesPackage{optidef}[2016/06/06 Package for defining optimization problems] + +\RequirePackage{environ} +\RequirePackage{mathtools} +\RequirePackage{xifthen} +\RequirePackage{etoolbox} +\newtoggle{bodyCon} +\toggletrue{bodyCon} + +% Input minimization evironments + +% Macros for objective definition, constraint definition and extra constraint definition +\newcommand{\bodyobj}[4] +{ +\ifthenelse{\isempty{#4}} +{ +&\underset{\displaystyle #1}{\mbox{#3}} \quad #2\span\span\span\span +} +{ +#4 ~~ &\underset{\displaystyle #1}{\mbox{#3}} \quad #2\span\span\span\span +} +} + + +\newcommand{\bodyconst}[2] +{\\ &\text{subject to} \quad  & #2} + +\newcommand{\bodyconstRight}[2] +{\\ &\text{subject to} \quad  & #2} + +\newcommand{\bodyconstBelow}[2] +{\\ &\text{subject to} \span\span \\ +&\quad & #2} + +\newcommand{\bodyconstBelowMult}[2] +{\\ &\text{subject to} \span\span\span\span \nonumber \\ +&\quad & #2} + +\newcommand{\addConstraint}[2]{ +\iftoggle{bodyCon}{ +\bodyconst{#1}{#2} +\togglefalse{bodyCon} +}{ +,\\&\quad  & #2 +\togglefalse{bodyCon} +} +} + +\newcommand{\breakObjectiveOneConstraint}[1]{&&\\} + + + +%MINIMIZATION ENVIRONMENTS + +\NewEnviron{mini}[5][]{% +\ifthenelse{\equal{#1}{1}}{ +\let\bodyconst\bodyconstBelow +}{} +\begin{equation} +#4 +\begin{alignedat}{4} +\bodyobj{#2}{#3}{minimize}{#5} +\BODY +\end{alignedat} +\end{equation} +\toggletrue{bodyCon} +\let\bodyconst\bodyconstRight +} + +\NewEnviron{argmini}[5][]{% +\ifthenelse{\equal{#1}{1}}{ +\let\bodyconst\bodyconstBelow +}{} +\begin{equation} +#4 +\begin{alignedat}{4} +\bodyobj{#2}{#3}{arg min}{#5} +\BODY +\end{alignedat} +\end{equation} +} + +\NewEnviron{mini*}[5][]{% +\ifthenelse{\equal{#1}{1}}{ +\let\bodyconst\bodyconstBelow +}{} +\begin{equation*} +#4 +\begin{alignedat}{4} +\bodyobj{#2}{#3}{minimize}{#5} +\BODY +\end{alignedat} +\end{equation*} +\toggletrue{bodyCon} +\let\bodyconst\bodyconstRight +} + +\NewEnviron{argmini*}[5][]{% +\ifthenelse{\equal{#1}{1}}{ +\let\bodyconst\bodyconstBelow +}{} +\begin{equation*} +#4 +\begin{alignedat}{4} +\bodyobj{#2}{#3}{arg min}{#5} +\BODY +\end{alignedat} +\end{equation*} +} + + +\NewEnviron{mini!}[5][]{% +\ifthenelse{\equal{#1}{1}}{ +\let\bodyconst\bodyconstBelowMult +}{} +\begin{subequations} +#4 +\begin{alignat}{4} +\bodyobj{#2}{#3}{minimize}{#5} +\BODY +\end{alignat} +\end{subequations} +\toggletrue{bodyCon} +\let\bodyconst\bodyconstRight +} + +\NewEnviron{argmini!}[5][]{% +\ifthenelse{\equal{#1}{1}}{ +\let\bodyconst\bodyconstBelowMult +}{} +\begin{subequations} +#4 +\begin{alignat}{4} +\bodyobj{#2}{#3}{arg min}{#5} +\BODY +\end{alignat} +\end{subequations} +} + +%MAXIMIZATION ENVIRONMENTS + +\NewEnviron{maxi}[5][]{% +\ifthenelse{\equal{#1}{1}}{ +\let\bodyconst\bodyconstBelow +}{} +\begin{equation} +#4 +\begin{alignedat}{4} +\bodyobj{#2}{#3}{maximize}{#5} +\BODY +\end{alignedat} +\end{equation} +} + +\NewEnviron{argmaxi}[5][]{% +\ifthenelse{\equal{#1}{1}}{ +\let\bodyconst\bodyconstBelow +}{} +\begin{equation} +#4 +\begin{alignedat}{4} +\bodyobj{#2}{#3}{arg maxi}{#5} +\BODY +\end{alignedat} +\end{equation} +} + +\NewEnviron{maxi*}[5][]{% +\ifthenelse{\equal{#1}{1}}{ +\let\bodyconst\bodyconstBelow +}{} +\begin{equation*} +#4 +\begin{alignedat}{4} +\bodyobj{#2}{#3}{maximize}{#5} +\BODY +\end{alignedat} +\end{equation*} +} + +\NewEnviron{argmaxi*}[5][]{% +\ifthenelse{\equal{#1}{1}}{ +\let\bodyconst\bodyconstBelow +}{} +\begin{equation*} +#4 +\begin{alignedat}{4} +\bodyobj{#2}{#3}{arg maxi}{#5} +\BODY +\end{alignedat} +\end{equation*} +} + + +\NewEnviron{maxi!}[5][]{% +\ifthenelse{\equal{#1}{1}}{ +\let\bodyconst\bodyconstBelowMult +}{} +\begin{subequations} +#4 +\begin{alignat}{4} +\bodyobj{#2}{#3}{maximize}{#5} +\BODY +\end{alignat} +\end{subequations} +} + +\NewEnviron{argmaxi!}[5][]{% +\ifthenelse{\equal{#1}{1}}{ +\let\bodyconst\bodyconstBelowMult +}{} +\begin{subequations} +#4 +\begin{alignat}{4} +\bodyobj{#2}{#3}{arg maxi}{#5} +\BODY +\end{alignat} +\end{subequations} +} \end{verbatim} \end{document} |