summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/optidef/optidef.tex
blob: 746870c3cdbc492448333988eb0fd891b21616e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
\documentclass[]{report}
\usepackage{remreset}
\usepackage{optidef}

% Title Page
\title{\textit{\textbf{Optidef}} \\ A Latex library for optimization problems\\ \textnormal{Version - 1.0}}

\author{Jesus Lago Garcia}

\makeatletter
\renewcommand \thesection {\@arabic\c@section}
\@removefromreset{section}{chapter}
\makeatother


\begin{document}
\maketitle

\section{Introduction and features}

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 the most convenient way allowing even two different output formats:
		\begin{enumerate}
			\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}

\item It provides an easy interface to define optimization problem for three different reference situations:
\begin{enumerate}
	\item Where no equation is referenced/numbered.
	\item Where the problem is referenced with a single number.
	\item Where each equation has an individual reference.
\end{enumerate} 

\item It also allows a definition of any optimization problem without a limitless number of constraints.

\end{enumerate}

\section{Environment types}
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}
			{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*}
				{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!}
				{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#}[Format]
   {Optimization variable}
   {Objective function \label{Objective function referece}}
   {\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 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 6:

\begin{enumerate}
	\item \verb|Optimization variable|, e.g. $w \in \Re^N$.
	\item \verb|Objective function|, e.g. $\|w\|_2$.
	\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 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:
\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.

\subsubsection{Example 1 - mini environment}
The code:

\begin{verbatim}
\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}
   \addConstraint{h(x)}{=0.}
\end{mini}
\end{verbatim}

\noindent outputs:

\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}
	\addConstraint{h(x)}{=0.}
\end{mini}

\subsubsection{Example 2 - mini* environment}
On the other hand:

\begin{verbatim}
\begin{mini*}
   {w}{f(w)+ R(w+6x)}
   {}{}

   \addConstraint{g(w)}{=0}   
   \addConstraint{n(w)}{= 6,}
   \addConstraint{L(w)+r(x)}{=Kw+p}
   \addConstraint{h(x)}{=0.}  
\end{mini*}
\end{verbatim}

\noindent it is almost the same but removing the reference:

\begin{mini*}
	{w}{f(w)+ R(w+6x)}
	{}{}
	\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}

\noindent Finally, the multireferencing environment outputs:

\begin{verbatim}
\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}}
   \addConstraint{h(x)}{=0. \label{eq:C4Example1}}
\end{mini!}
\end{verbatim}

\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}}
	\addConstraint{h(x)}{=0. \label{eq:C4Example3}}
\end{mini!}

\subsubsection{Example 4 - mini + problem result}

\noindent Adding the problem result:

\begin{verbatim}
\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}
\addConstraint{h(x)}{=0.}
\end{mini}
\end{verbatim}

\noindent outputs:

\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}
	\addConstraint{h(x)}{=0.}
\end{mini}

\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}[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)}}
\addConstraint{h(x)}{=0.\quad && \text{(Path constraint)}}  
\end{mini*}
\end{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)}}
	\addConstraint{h(x)}{=0. \quad && \text{(Path constraint).}}
\end{mini*}


\subsubsection{Example 7 - mini environment on the unconstrained case}

\begin{verbatim}

\begin{mini}
   {w}{f(w)+ R(w+6x)}  
   {\label{eq:Ex4}}
   {}   
\end{mini}
\end{verbatim}

\noindent outputs:

\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}
   {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}
   \addConstraint{h(x)}{=0.}
\end{argmini}
\end{verbatim}

\noindent outputs:

\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}
	\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}
   {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}
   \addConstraint{h(x)}{=0.}
\end{maxi}
\end{verbatim}

\noindent outputs:

\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}
	\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!}
	{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}}
	{\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}
	\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!}
	{\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}}
	{\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}
	\addConstraint{r(x_0,x_N)}{= 0.  \label{dOCP:boundary}}
\end{mini!}

\noindent If you want to increase the size of the optimization variables:
\noindent A possible way to avoid this is to stack them with the command: \begin{verbatim}
\substack{\displaystyle x_0,u_0,x_1,\hdots,\\ \displaystyle u_{N-1},x_N}
\end{verbatim}

\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}}
	{\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}
	\addConstraint{r(x_0,x_N)}{= 0.  \label{dOCP:boundary}}
\end{mini!}

\section{Code definition}
\begin{verbatim}
% optidef - Version 08/06/2016
%
%Copyright 2016 J. Lago Garcia
%
%This work may be distributed and/or modified under the conditions of the LaTeX Project Public License, either version 1.3 of this license or (at your option) any later version.
%The latest version of this license is in http://www.latex-project.org/lppl.txt and version 1.3 or later is part of all distributions of LaTeX version 2005/12/01 or later.
%
%This work has the LPPL maintenance status 'maintained'. The Current Maintainer of this work is J. Lago Garcia, under the supervision of Prof. Dr. Moritz Diehl and Prof. Dr. Sebastien Gross.
%
%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{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 &#1 & #2}

\newcommand{\bodyconstRight}[2]
{\\ &\text{subject to} \quad &#1 & #2}

\newcommand{\bodyconstBelow}[2]
{\\ &\text{subject to} \span\span \\
&\quad&#1 & #2}

\newcommand{\bodyconstBelowMult}[2]
{\\ &\text{subject to} \span\span\span\span \nonumber \\
&\quad&#1 & #2}

\newcommand{\addConstraint}[2]{
\iftoggle{bodyCon}{
\bodyconst{#1}{#2}
\togglefalse{bodyCon}
}{
,\\&\quad &#1 & #2
\togglefalse{bodyCon}
}
}

\newcommand{\breakObjectiveOneConstraint}[1]{&&&#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}