alpar@1: %* gmpl.tex *% alpar@1: alpar@1: %*********************************************************************** alpar@1: % This code is part of GLPK (GNU Linear Programming Kit). alpar@1: % alpar@1: % Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, alpar@1: % 2009, 2010 Andrew Makhorin, Department for Applied Informatics, alpar@1: % Moscow Aviation Institute, Moscow, Russia. All rights reserved. alpar@1: % E-mail: . alpar@1: % alpar@1: % GLPK is free software: you can redistribute it and/or modify it alpar@1: % under the terms of the GNU General Public License as published by alpar@1: % the Free Software Foundation, either version 3 of the License, or alpar@1: % (at your option) any later version. alpar@1: % alpar@1: % GLPK is distributed in the hope that it will be useful, but WITHOUT alpar@1: % ANY WARRANTY; without even the implied warranty of MERCHANTABILITY alpar@1: % or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public alpar@1: % License for more details. alpar@1: % alpar@1: % You should have received a copy of the GNU General Public License alpar@1: % along with GLPK. If not, see . alpar@1: %*********************************************************************** alpar@1: alpar@1: \documentclass[10pt]{article} alpar@1: \usepackage[dvipdfm,linktocpage,colorlinks,linkcolor=blue]{hyperref} alpar@1: alpar@1: \begin{document} alpar@1: alpar@1: \thispagestyle{empty} alpar@1: alpar@1: \begin{center} alpar@1: alpar@1: \vspace*{1in} alpar@1: alpar@1: \begin{huge} alpar@1: \sf\bfseries Modeling Language GNU MathProg alpar@1: \end{huge} alpar@1: alpar@1: \vspace{0.5in} alpar@1: alpar@1: \begin{LARGE} alpar@1: \sf Language Reference alpar@1: \end{LARGE} alpar@1: alpar@1: \vspace{0.5in} alpar@1: alpar@1: \begin{LARGE} alpar@1: \sf for GLPK Version 4.45 alpar@1: \end{LARGE} alpar@1: alpar@1: \vspace{0.5in} alpar@1: \begin{Large} alpar@1: \sf (DRAFT, December 2010) alpar@1: \end{Large} alpar@1: alpar@1: \end{center} alpar@1: alpar@1: \newpage alpar@1: alpar@1: \vspace*{1in} alpar@1: alpar@1: \vfill alpar@1: alpar@1: \noindent alpar@1: The GLPK package is part of the GNU Project released under the aegis of alpar@1: GNU. alpar@1: alpar@1: \medskip\noindent alpar@1: Copyright \copyright{} 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, alpar@1: 2008, 2009, 2010 Andrew Makhorin, Department for Applied Informatics, alpar@1: Moscow Aviation Institute, Moscow, Russia. All rights reserved. alpar@1: alpar@1: \medskip\noindent alpar@1: Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, alpar@1: MA 02110-1301, USA. alpar@1: alpar@1: \medskip\noindent alpar@1: Permission is granted to make and distribute verbatim copies of this alpar@1: manual provided the copyright notice and this permission notice are alpar@1: preserved on all copies. alpar@1: alpar@1: \medskip\noindent alpar@1: Permission is granted to copy and distribute modified versions of this alpar@1: manual under the conditions for verbatim copying, provided also that alpar@1: the entire resulting derived work is distributed under the terms of alpar@1: a permission notice identical to this one. alpar@1: alpar@1: \medskip\noindent alpar@1: Permission is granted to copy and distribute translations of this alpar@1: manual into another language, under the above conditions for modified alpar@1: versions. alpar@1: alpar@1: \newpage alpar@1: alpar@1: \tableofcontents alpar@1: alpar@1: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% alpar@1: alpar@1: \newpage alpar@1: alpar@1: \section{Introduction} alpar@1: alpar@1: {\it GNU MathProg} is a modeling language intended for describing alpar@1: linear mathematical programming models.\footnote{The GNU MathProg alpar@1: language is a subset of the AMPL language. Its GLPK implementation is alpar@1: mainly based on the paper: {\it Robert Fourer}, {\it David M. Gay}, and alpar@1: {\it Brian W. Kernighan}, ``A Modeling Language for Mathematical alpar@1: Programming.'' {\it Management Science} 36 (1990)\linebreak pp. 519-54.} alpar@1: alpar@1: Model descriptions written in the GNU MathProg language consist of alpar@1: a set of statements and data blocks constructed by the user from the alpar@1: language elements described in this document. alpar@1: alpar@1: In a process called {\it translation}, a program called the {\it model alpar@1: translator} analyzes the model description and translates it into alpar@1: internal data structures, which may be then used either for generating alpar@1: mathematical programming problem instance or directly by a program alpar@1: called the {\it solver} to obtain numeric solution of the problem. alpar@1: alpar@1: \subsection{Linear programming problem} alpar@1: \label{problem} alpar@1: alpar@1: In MathProg the linear programming (LP) problem is stated as follows: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\hspace{.7in}minimize (or maximize) alpar@1: $$z=c_1x_1+c_2x_2+\dots+c_nx_n+c_0\eqno(1.1)$$ alpar@1: \noindent\hspace{.7in}subject to linear constraints alpar@1: $$ alpar@1: \begin{array}{l@{\ }c@{\ }r@{\ }c@{\ }r@{\ }c@{\ }r@{\ }c@{\ }l} alpar@1: L_1&\leq&a_{11}x_1&+&a_{12}x_2&+\dots+&a_{1n}x_n&\leq&U_1\\ alpar@1: L_2&\leq&a_{21}x_1&+&a_{22}x_2&+\dots+&a_{2n}x_n&\leq&U_2\\ alpar@1: \multicolumn{9}{c}{.\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .}\\ alpar@1: L_m&\leq&a_{m1}x_1&+&a_{m2}x_2&+\dots+&a_{mn}x_n&\leq&U_m\\ alpar@1: \end{array}\eqno(1.2) alpar@1: $$ alpar@1: \noindent\hspace{.7in}and bounds of variables alpar@1: $$ alpar@1: \begin{array}{l@{\ }c@{\ }c@{\ }c@{\ }l} alpar@1: l_1&\leq&x_1&\leq&u_1\\ alpar@1: l_2&\leq&x_2&\leq&u_2\\ alpar@1: \multicolumn{5}{c}{.\ \ .\ \ .\ \ .\ \ .}\\ alpar@1: l_n&\leq&x_n&\leq&u_n\\ alpar@1: \end{array}\eqno(1.3) alpar@1: $$ alpar@1: where $x_1$, $x_2$, \dots, $x_n$ are variables; $z$ is the objective alpar@1: function; $c_1$, $c_2$, \dots, $c_n$ are objective coefficients; $c_0$ alpar@1: is the constant term (``shift'') of the objective function; $a_{11}$, alpar@1: $a_{12}$, \dots, $a_{mn}$ are constraint coefficients; $L_1$, $L_2$, alpar@1: \dots, $L_m$ are lower constraint bounds; $U_1$, $U_2$, \dots, $U_m$ alpar@1: are upper constraint bounds; $l_1$, $l_2$, \dots, $l_n$ are lower alpar@1: bounds of variables; $u_1$, $u_2$, \dots, $u_n$ are upper bounds of alpar@1: variables. alpar@1: alpar@1: Bounds of variables and constraint bounds can be finite as well as alpar@1: infinite. Besides, lower bounds can be equal to corresponding upper alpar@1: bounds. Thus, the following types of variables and constraints are alpar@1: allowed: alpar@1: alpar@1: \newpage alpar@1: alpar@1: \begin{tabular}{@{}r@{\ }c@{\ }c@{\ }c@{\ }l@{\hspace*{38pt}}l} alpar@1: $-\infty$&$<$&$x$&$<$&$+\infty$&Free (unbounded) variable\\ alpar@1: $l$&$\leq$&$x$&$<$&$+\infty$&Variable with lower bound\\ alpar@1: $-\infty$&$<$&$x$&$\leq$&$u$&Variable with upper bound\\ alpar@1: $l$&$\leq$&$x$&$\leq$&$u$&Double-bounded variable\\ alpar@1: $l$&$=$&$x$&=&$u$&Fixed variable\\ alpar@1: \end{tabular} alpar@1: alpar@1: \bigskip alpar@1: alpar@1: \begin{tabular}{@{}r@{\ }c@{\ }c@{\ }c@{\ }ll} alpar@1: $-\infty$&$<$&$\sum a_jx_j$&$<$&$+\infty$&Free (unbounded) linear alpar@1: form\\ alpar@1: $L$&$\leq$&$\sum a_jx_j$&$<$&$+\infty$&Inequality constraint ``greater alpar@1: than or equal to''\\ alpar@1: $-\infty$&$<$&$\sum a_jx_j$&$\leq$&$U$&Inequality constraint ``less alpar@1: than or equal to''\\ alpar@1: $L$&$\leq$&$\sum a_jx_j$&$\leq$&$U$&Double-bounded inequality alpar@1: constraint\\ alpar@1: $L$&$=$&$\sum a_jx_j$&=&$U$&Equality constraint\\ alpar@1: \end{tabular} alpar@1: alpar@1: \bigskip alpar@1: alpar@1: In addition to pure LP problems MathProg also allows mixed integer alpar@1: linear programming (MIP) problems, where some or all variables are alpar@1: restricted to be integer or binary. alpar@1: alpar@1: \subsection{Model objects} alpar@1: alpar@1: In MathProg the model is described in terms of sets, parameters, alpar@1: variables, constraints, and objectives, which are called {\it model alpar@1: objects}. alpar@1: alpar@1: The user introduces particular model objects using the language alpar@1: statements. Each model object is provided with a symbolic name that alpar@1: uniquely identifies the object and is intended for referencing purposes. alpar@1: alpar@1: Model objects, including sets, can be multidimensional arrays built alpar@1: over indexing sets. Formally, $n$-dimensional array $A$ is the mapping: alpar@1: $$A:\Delta\rightarrow\Xi,\eqno(1.4)$$ alpar@1: where $\Delta\subseteq S_1\times\dots\times S_n$ is a subset of the alpar@1: Cartesian product of indexing sets,\linebreak $\Xi$ is a set of array members. alpar@1: In MathProg the set $\Delta$ is called the {\it subscript domain}. Its alpar@1: members are $n$-tuples $(i_1,\dots,i_n)$, where $i_1\in S_1$, \dots, alpar@1: $i_n\in S_n$. alpar@1: alpar@1: If $n=0$, the Cartesian product above has exactly one member (namely, alpar@1: \linebreak 0-tuple), so it is convenient to think scalar objects as alpar@1: 0-dimensional arrays having one member. alpar@1: alpar@1: The type of array members is determined by the type of corresponding alpar@1: model object as follows: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\hfil alpar@1: \begin{tabular}{@{}ll@{}} alpar@1: Model object&Array member\\ alpar@1: \hline alpar@1: Set&Elemental plain set\\ alpar@1: Parameter&Number or symbol\\ alpar@1: Variable&Elemental variable\\ alpar@1: Constraint&Elemental constraint\\ alpar@1: Objective&Elemental objective\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: In order to refer to a particular object member the object should be alpar@1: provided with {\it subscripts}. For example, if $a$ is a 2-dimensional alpar@1: parameter defined over $I\times J$, a reference to its particular alpar@1: member can be written as $a[i,j]$, where $i\in I$ and $j\in J$. It is alpar@1: understood that scalar objects being 0-dimensional need no subscripts. alpar@1: alpar@1: \subsection{Structure of model description} alpar@1: alpar@1: It is sometimes desirable to write a model which, at various points, alpar@1: may require different data for each problem instance to be solved using alpar@1: that model. For this reason in MathProg the model description consists alpar@1: of two parts: the {\it model section} and the {\it data section}. alpar@1: alpar@1: The model section is a main part of the model description that contains alpar@1: declarations of model objects and is common for all problems based on alpar@1: the corresponding model. alpar@1: alpar@1: The data section is an optional part of the model description that alpar@1: contains data specific for a particular problem instance. alpar@1: alpar@1: Depending on what is more convenient the model and data sections can be alpar@1: placed either in one file or in two separate files. The latter feature alpar@1: allows having arbitrary number of different data sections to be used alpar@1: with the same model section. alpar@1: alpar@1: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% alpar@1: alpar@1: \newpage alpar@1: alpar@1: \section{Coding model description} alpar@1: \label{coding} alpar@1: alpar@1: The model description is coded in plain text format using ASCII alpar@1: character set. Characters valid in the model description are the alpar@1: following: alpar@1: alpar@1: \begin{itemize} alpar@1: \item alphabetic characters:\\ alpar@1: \verb|A B C D E F G H I J K L M N O P Q R S T U V W X Y Z|\\ alpar@1: \verb|a b c d e f g h i j k l m n o p q r s t u v w x y z _| alpar@1: \item numeric characters:\\ alpar@1: \verb|0 1 2 3 4 5 6 7 8 9| alpar@1: \item special characters:\\ alpar@1: \verb?! " # & ' ( ) * + , - . / : ; < = > [ ] ^ { | }? alpar@1: \item white-space characters:\\ alpar@1: \verb|SP HT CR NL VT FF| alpar@1: \end{itemize} alpar@1: alpar@1: Within string literals and comments any ASCII characters (except alpar@1: control characters) are valid. alpar@1: alpar@1: White-space characters are non-significant. They can be used freely alpar@1: between lexical units to improve readability of the model description. alpar@1: They are also used to separate lexical units from each other if there alpar@1: is no other way to do that. alpar@1: alpar@1: Syntactically model description is a sequence of lexical units in the alpar@1: following categories: alpar@1: alpar@1: \begin{itemize} alpar@1: \item symbolic names; alpar@1: \item numeric literals; alpar@1: \item string literals; alpar@1: \item keywords; alpar@1: \item delimiters; alpar@1: \item comments. alpar@1: \end{itemize} alpar@1: alpar@1: The lexical units of the language are discussed below. alpar@1: alpar@1: \subsection{Symbolic names} alpar@1: alpar@1: A {\it symbolic name} consists of alphabetic and numeric characters, alpar@1: the first of which must be alphabetic. All symbolic names are distinct alpar@1: (case sensitive). alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent{\bf Examples} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\verb|alpha123| alpar@1: alpar@1: \noindent\verb|This_is_a_name| alpar@1: alpar@1: \noindent\verb|_P123_abc_321| alpar@1: alpar@1: \newpage alpar@1: alpar@1: Symbolic names are used to identify model objects (sets, parameters, alpar@1: variables, constraints, objectives) and dummy indices. alpar@1: alpar@1: All symbolic names (except names of dummy indices) must be unique, i.e. alpar@1: the model description must have no objects with identical names. alpar@1: Symbolic names of dummy indices must be unique within the scope, where alpar@1: they are valid. alpar@1: alpar@1: \subsection{Numeric literals} alpar@1: alpar@1: A {\it numeric literal} has the form {\it xx}{\tt E}{\it syy}, where alpar@1: {\it xx} is a number with optional decimal point, {\it s} is the sign alpar@1: {\tt+} or {\tt-}, {\it yy} is a decimal exponent. The letter {\tt E} is alpar@1: case insensitive and can be coded as {\tt e}. alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent{\bf Examples} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\verb|123| alpar@1: alpar@1: \noindent\verb|3.14159| alpar@1: alpar@1: \noindent\verb|56.E+5| alpar@1: alpar@1: \noindent\verb|.78| alpar@1: alpar@1: \noindent\verb|123.456e-7| alpar@1: alpar@1: \medskip alpar@1: alpar@1: Numeric literals are used to represent numeric quantities. They have alpar@1: obvious fixed meaning. alpar@1: alpar@1: \subsection{String literals} alpar@1: alpar@1: A {\it string literal} is a sequence of arbitrary characters enclosed alpar@1: either in single quotes or in double quotes. Both these forms are alpar@1: equivalent. alpar@1: alpar@1: If the single quote is part of a string literal enclosed in single alpar@1: quotes, it must be coded twice. Analogously, if the double quote is alpar@1: part of a string literal enclosed in double quotes, it must be coded alpar@1: twice. alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent{\bf Examples} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\verb|'This is a string'| alpar@1: alpar@1: \noindent\verb|"This is another string"| alpar@1: alpar@1: \noindent\verb|'1 + 2 = 3'| alpar@1: alpar@1: \noindent\verb|'That''s all'| alpar@1: alpar@1: \noindent\verb|"She said: ""No"""| alpar@1: alpar@1: \medskip alpar@1: alpar@1: String literals are used to represent symbolic quantities. alpar@1: alpar@1: \subsection{Keywords} alpar@1: alpar@1: A {\it keyword} is a sequence of alphabetic characters and possibly alpar@1: some special characters. alpar@1: alpar@1: All keywords fall into two categories: {\it reserved keywords}, which alpar@1: cannot be used as symbolic names, and {\it non-reserved keywords}, alpar@1: which being recognized by context can be used as symbolic names. alpar@1: alpar@1: \newpage alpar@1: alpar@1: The reserved keywords are the following: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\hfil alpar@1: \begin{tabular}{@{}p{.7in}p{.7in}p{.7in}p{.7in}@{}} alpar@1: {\tt and}&{\tt else}&{\tt mod}&{\tt union}\\ alpar@1: {\tt by}&{\tt if}&{\tt not}&{\tt within}\\ alpar@1: {\tt cross}&{\tt in}&{\tt or}\\ alpar@1: {\tt diff}&{\tt inter}&{\tt symdiff}\\ alpar@1: {\tt div}&{\tt less}&{\tt then}\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: Non-reserved keywords are described in following sections. alpar@1: alpar@1: All the keywords have fixed meaning, which will be explained on alpar@1: discussion of corresponding syntactic constructions, where the keywords alpar@1: are used. alpar@1: alpar@1: \subsection{Delimiters} alpar@1: alpar@1: A {\it delimiter} is either a single special character or a sequence of alpar@1: two special characters as follows: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\hfil alpar@1: \begin{tabular}{@{}p{.3in}p{.3in}p{.3in}p{.3in}p{.3in}p{.3in}@{}} alpar@1: {\tt+}&{\tt\textasciicircum}&{\tt==}&{\tt!}&{\tt:}&{\tt)}\\ alpar@1: {\tt-}&{\tt\&}&{\tt>=}&{\tt\&\&}&{\tt;}&{\tt[}\\ alpar@1: {\tt*}&{\tt<}&{\tt>}&{\tt||}&{\tt:=}&{\tt|}\\ alpar@1: {\tt/}&{\tt<=}&{\tt<>}&{\tt.}&{\tt..}&{\tt\{}\\ alpar@1: {\tt**}&{\tt=}&{\tt!=}&{\tt,}&{\tt(}&{\tt\}}\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: If the delimiter consists of two characters, there must be no spaces alpar@1: between the characters. alpar@1: alpar@1: All the delimiters have fixed meaning, which will be explained on alpar@1: discussion corresponding syntactic constructions, where the delimiters alpar@1: are used. alpar@1: alpar@1: \subsection{Comments} alpar@1: alpar@1: For documenting purposes the model description can be provided with alpar@1: {\it comments}, which may have two different forms. The first form is alpar@1: a {\it single-line comment}, which begins with the character {\tt\#} alpar@1: and extends until end of line. The second form is a {\it comment alpar@1: sequence}, which is a sequence of any characters enclosed within alpar@1: {\tt/*} and {\tt*/}. alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent{\bf Examples} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\verb|param n := 10; # This is a comment| alpar@1: alpar@1: \noindent\verb|/* This is another comment */| alpar@1: alpar@1: \medskip alpar@1: alpar@1: Comments are ignored by the model translator and can appear anywhere in alpar@1: the model description, where white-space characters are allowed. alpar@1: alpar@1: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% alpar@1: alpar@1: \newpage alpar@1: alpar@1: \section{Expressions} alpar@1: alpar@1: An {\it expression} is a rule for computing a value. In model alpar@1: description expressions are used as constituents of certain statements. alpar@1: alpar@1: In general case expressions consist of operands and operators. alpar@1: alpar@1: Depending on the type of the resultant value all expressions fall into alpar@1: the following categories: alpar@1: alpar@1: \begin{itemize} alpar@1: \item numeric expressions; alpar@1: \item symbolic expressions; alpar@1: \item indexing expressions; alpar@1: \item set expressions; alpar@1: \item logical expressions; alpar@1: \item linear expressions. alpar@1: \end{itemize} alpar@1: alpar@1: \subsection{Numeric expressions} alpar@1: alpar@1: A {\it numeric expression} is a rule for computing a single numeric alpar@1: value represented as a floating-point number. alpar@1: alpar@1: The primary numeric expression may be a numeric literal, dummy index, alpar@1: unsubscripted parameter, subscripted parameter, built-in function alpar@1: reference, iterated numeric expression, conditional numeric expression, alpar@1: or another numeric expression enclosed in parentheses. alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent{\bf Examples} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent alpar@1: \begin{tabular}{@{}ll@{}} alpar@1: \verb|1.23|&(numeric literal)\\ alpar@1: \verb|j|&(dummy index)\\ alpar@1: \verb|time|&(unsubscripted parameter)\\ alpar@1: \verb|a['May 2003',j+1]|&(subscripted parameter)\\ alpar@1: \verb|abs(b[i,j])|&(function reference)\\ alpar@1: \verb|sum{i in S diff T} alpha[i] * b[i,j]|&(iterated expression)\\ alpar@1: \verb|if i in I then 2 * p else q[i+1]|&(conditional expression)\\ alpar@1: \verb|(b[i,j] + .5 * c)|&(parenthesized expression)\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: More general numeric expressions containing two or more primary numeric alpar@1: expressions may be constructed by using certain arithmetic operators. alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent{\bf Examples} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\verb|j+1| alpar@1: alpar@1: \noindent\verb|2 * a[i-1,j+1] - b[i,j]| alpar@1: alpar@1: \noindent\verb|sum{j in J} a[i,j] * x[j] + sum{k in K} b[i,k] * x[k]| alpar@1: alpar@1: \noindent\verb|(if i in I then 2 * p else q[i+1]) / (a[i,j] + 1.5)| alpar@1: alpar@1: \subsubsection{Numeric literals} alpar@1: alpar@1: If the primary numeric expression is a numeric literal, the resultant alpar@1: value is obvious. alpar@1: alpar@1: \subsubsection{Dummy indices} alpar@1: alpar@1: If the primary numeric expression is a dummy index, the resultant value alpar@1: is current value assigned to that dummy index. alpar@1: alpar@1: \subsubsection{Unsubscripted parameters} alpar@1: alpar@1: If the primary numeric expression is an unsubscripted parameter (which alpar@1: must be 0-dimensional), the resultant value is the value of that alpar@1: parameter. alpar@1: alpar@1: \subsubsection{Subscripted parameters} alpar@1: alpar@1: The primary numeric expression, which refers to a subscripted parameter, alpar@1: has the following syntactic form: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\hfil alpar@1: {\it name}{\tt[}$i_1${\tt,} $i_2${\tt,} \dots{\tt,} $i_n${\tt]} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent where {\it name} is the symbolic name of the parameter, alpar@1: $i_1$, $i_2$, \dots, $i_n$ are subscripts. alpar@1: alpar@1: Each subscript must be a numeric or symbolic expression. The number of alpar@1: subscripts in the subscript list must be the same as the dimension of alpar@1: the parameter with which the subscript list is associated. alpar@1: alpar@1: Actual values of subscript expressions are used to identify alpar@1: a particular member of the parameter that determines the resultant alpar@1: value of the primary expression. alpar@1: alpar@1: \subsubsection{Function references} alpar@1: alpar@1: In MathProg there exist the following built-in functions which may be alpar@1: used in numeric expressions: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{96pt}p{222pt}@{}} alpar@1: {\tt abs(}$x${\tt)}&$|x|$, absolute value of $x$\\ alpar@1: {\tt atan(}$x${\tt)}&$\arctan x$, principal value of the arc tangent of alpar@1: $x$ (in radians)\\ alpar@1: {\tt atan(}$y${\tt,} $x${\tt)}&$\arctan y/x$, principal value of the alpar@1: arc tangent of $y/x$ (in radians). In this case the signs of both alpar@1: arguments $y$ and $x$ are used to determine the quadrant of the alpar@1: resultant value\\ alpar@1: {\tt card(}$X${\tt)}&$|X|$, cardinality (the number of elements) of alpar@1: set $X$\\ alpar@1: {\tt ceil(}$x${\tt)}&$\lceil x\rceil$, smallest integer not less than alpar@1: $x$ (``ceiling of $x$'')\\ alpar@1: {\tt cos(}$x${\tt)}&$\cos x$, cosine of $x$ (in radians)\\ alpar@1: {\tt exp(}$x${\tt)}&$e^x$, base-$e$ exponential of $x$\\ alpar@1: {\tt floor(}$x${\tt)}&$\lfloor x\rfloor$, largest integer not greater alpar@1: than $x$ (``floor of $x$'')\\ alpar@1: \end{tabular} alpar@1: alpar@1: \begin{tabular}{@{}p{96pt}p{222pt}@{}} alpar@1: {\tt gmtime()}&the number of seconds elapsed since 00:00:00~Jan~1, 1970, alpar@1: Coordinated Universal Time (for details see Subsection \ref{gmtime}, alpar@1: page \pageref{gmtime})\\ alpar@1: {\tt length(}$s${\tt)}&$|s|$, length of character string $s$\\ alpar@1: {\tt log(}$x${\tt)}&$\log x$, natural logarithm of $x$\\ alpar@1: {\tt log10(}$x${\tt)}&$\log_{10}x$, common (decimal) logarithm of $x$\\ alpar@1: {\tt max(}$x_1${\tt,} $x_2${\tt,} \dots{\tt,} $x_n${\tt)}&the largest alpar@1: of values $x_1$, $x_2$, \dots, $x_n$\\ alpar@1: {\tt min(}$x_1${\tt,} $x_2${\tt,} \dots{\tt,} $x_n${\tt)}&the smallest alpar@1: of values $x_1$, $x_2$, \dots, $x_n$\\ alpar@1: {\tt round(}$x${\tt)}&rounding $x$ to nearest integer\\ alpar@1: {\tt round(}$x${\tt,} $n${\tt)}&rounding $x$ to $n$ fractional decimal alpar@1: digits\\ alpar@1: {\tt sin(}$x${\tt)}&$\sin x$, sine of $x$ (in radians)\\ alpar@1: {\tt sqrt(}$x${\tt)}&$\sqrt{x}$, non-negative square root of $x$\\ alpar@1: {\tt str2time(}$s${\tt,} $f${\tt)}&converting character string $s$ to alpar@1: calendar time (for details see Subsection \ref{str2time}, page alpar@1: \pageref{str2time})\\ alpar@1: {\tt trunc(}$x${\tt)}&truncating $x$ to nearest integer\\ alpar@1: {\tt trunc(}$x${\tt,} $n${\tt)}&truncating $x$ to $n$ fractional alpar@1: decimal digits\\ alpar@1: {\tt Irand224()}&generating pseudo-random integer uniformly distributed alpar@1: in $[0,2^{24})$\\ alpar@1: {\tt Uniform01()}&generating pseudo-random number uniformly distributed alpar@1: in $[0,1)$\\ alpar@1: {\tt Uniform(}$a${\tt,} $b${\tt)}&generating pseudo-random number alpar@1: uniformly distributed in $[a,b)$\\ alpar@1: {\tt Normal01()}&generating Gaussian pseudo-random variate with alpar@1: $\mu=0$ and $\sigma=1$\\ alpar@1: {\tt Normal(}$\mu${\tt,} $\sigma${\tt)}&generating Gaussian alpar@1: pseudo-random variate with given $\mu$ and $\sigma$\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: Arguments of all built-in functions, except {\tt card}, {\tt length}, alpar@1: and {\tt str2time}, must be numeric expressions. The argument of alpar@1: {\tt card} must be a set expression. The argument of {\tt length} and alpar@1: both arguments of {\tt str2time} must be symbolic expressions. alpar@1: alpar@1: The resultant value of the numeric expression, which is a function alpar@1: reference, is the result of applying the function to its argument(s). alpar@1: alpar@1: Note that each pseudo-random generator function has a latent argument alpar@1: (i.e. some internal state), which is changed whenever the function has alpar@1: been applied. Thus, if the function is applied repeatedly even to alpar@1: identical arguments, due to the side effect different resultant values alpar@1: are always produced. alpar@1: alpar@1: \subsubsection{Iterated expressions} alpar@1: \label{itexpr} alpar@1: alpar@1: An {\it iterated numeric expression} is a primary numeric expression, alpar@1: which has the following syntactic form: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\hfil alpar@1: {\it iterated-operator indexing-expression integrand} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent where {\it iterated-operator} is the symbolic name of the alpar@1: iterated operator to be performed (see below), {\it indexing-expression} alpar@1: is an indexing expression which introduces dummy indices and controls alpar@1: iterating, {\it integrand} is a numeric expression that participates in alpar@1: the operation. alpar@1: alpar@1: In MathProg there exist four iterated operators, which may be used in alpar@1: numeric expressions: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\hfil alpar@1: \begin{tabular}{@{}lll@{}} alpar@1: {\tt sum}&summation&$\displaystyle\sum_{(i_1,\dots,i_n)\in\Delta} alpar@1: f(i_1,\dots,i_n)$\\ alpar@1: {\tt prod}&production&$\displaystyle\prod_{(i_1,\dots,i_n)\in\Delta} alpar@1: f(i_1,\dots,i_n)$\\ alpar@1: {\tt min}&minimum&$\displaystyle\min_{(i_1,\dots,i_n)\in\Delta} alpar@1: f(i_1,\dots,i_n)$\\ alpar@1: {\tt max}&maximum&$\displaystyle\max_{(i_1,\dots,i_n)\in\Delta} alpar@1: f(i_1,\dots,i_n)$\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent where $i_1$, \dots, $i_n$ are dummy indices introduced in alpar@1: the indexing expression, $\Delta$ is the domain, a set of $n$-tuples alpar@1: specified by the indexing expression which defines particular values alpar@1: assigned to the dummy indices on performing the iterated operation, alpar@1: $f(i_1,\dots,i_n)$ is the integrand, a numeric expression whose alpar@1: resultant value depends on the dummy indices. alpar@1: alpar@1: The resultant value of an iterated numeric expression is the result of alpar@1: applying of the iterated operator to its integrand over all $n$-tuples alpar@1: contained in the domain. alpar@1: alpar@1: \subsubsection{Conditional expressions} alpar@1: \label{ifthen} alpar@1: alpar@1: A {\it conditional numeric expression} is a primary numeric expression, alpar@1: which has one of the following two syntactic forms: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\hfil alpar@1: {\tt if} $b$ {\tt then} $x$ {\tt else} $y$ alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\hspace{126.5pt} alpar@1: {\tt if} $b$ {\tt then} $x$ alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent where $b$ is an logical expression, $x$ and $y$ are numeric alpar@1: expressions. alpar@1: alpar@1: The resultant value of the conditional expression depends on the value alpar@1: of the logical expression that follows the keyword {\tt if}. If it alpar@1: takes on the value {\it true}, the value of the conditional expression alpar@1: is the value of the expression that follows the keyword {\tt then}. alpar@1: Otherwise, if the logical expression takes on the value {\it false}, alpar@1: the value of the conditional expression is the value of the expression alpar@1: that follows the keyword {\it else}. If the second, reduced form of the alpar@1: conditional expression is used and the logical expression takes on the alpar@1: value {\it false}, the resultant value of the conditional expression is alpar@1: zero. alpar@1: alpar@1: \subsubsection{Parenthesized expressions} alpar@1: alpar@1: Any numeric expression may be enclosed in parentheses that alpar@1: syntactically makes it a primary numeric expression. alpar@1: alpar@1: Parentheses may be used in numeric expressions, as in algebra, to alpar@1: specify the desired order in which operations are to be performed. alpar@1: Where parentheses are used, the expression within the parentheses is alpar@1: evaluated before the resultant value is used. alpar@1: alpar@1: The resultant value of the parenthesized expression is the same as the alpar@1: value of the expression enclosed within parentheses. alpar@1: alpar@1: \subsubsection{Arithmetic operators} alpar@1: alpar@1: In MathProg there exist the following arithmetic operators, which may alpar@1: be used in numeric expressions: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{96pt}p{222pt}@{}} alpar@1: {\tt +} $x$&unary plus\\ alpar@1: {\tt -} $x$&unary minus\\ alpar@1: $x$ {\tt +} $y$&addition\\ alpar@1: $x$ {\tt -} $y$&subtraction\\ alpar@1: $x$ {\tt less} $y$&positive difference (if $x1$, the second form must be used. alpar@1: alpar@1: If the first form of the indexing entry is used, the index $i$ can be alpar@1: a dummy index only (see below). If the second form is used, the indices alpar@1: $i_1$, $i_2$, \dots, $i_n$ can be either dummy indices or some numeric alpar@1: or symbolic expressions, where at least one index must be a dummy index. alpar@1: The third, reduced form of the indexing entry has the same effect as if alpar@1: there were $i$ (if $S$ is 1-dimensional) or $i_1$, $i_2$, \dots, $i_n$ alpar@1: (if $S$ is $n$-dimensional) all specified as dummy indices. alpar@1: alpar@1: A {\it dummy index} is an auxiliary model object, which acts like an alpar@1: individual variable. Values assigned to dummy indices are components of alpar@1: $n$-tuples from basic sets, i.e. some numeric and symbolic quantities. alpar@1: alpar@1: For referencing purposes dummy indices can be provided with symbolic alpar@1: names. However, unlike other model objects (sets, parameters, etc.) alpar@1: dummy indices need not be explicitly declared. Each {\it undeclared} alpar@1: symbolic name being used in the indexing position of an indexing entry alpar@1: is recognized as the symbolic name of corresponding dummy index. alpar@1: alpar@1: Symbolic names of dummy indices are valid only within the scope of the alpar@1: indexing expression, where the dummy indices were introduced. Beyond alpar@1: the scope the dummy indices are completely inaccessible, so the same alpar@1: symbolic names may be used for other purposes, in particular, to alpar@1: represent dummy indices in other indexing expressions. alpar@1: alpar@1: The scope of indexing expression, where implicit declarations of dummy alpar@1: indices are valid, depends on the context, in which the indexing alpar@1: expression is used: alpar@1: alpar@1: \begin{enumerate} alpar@1: \item If the indexing expression is used in iterated operator, its alpar@1: scope extends until the end of the integrand. alpar@1: \item If the indexing expression is used as a primary set expression, alpar@1: its scope extends until the end of that indexing expression. alpar@1: \item If the indexing expression is used to define the subscript domain alpar@1: in declarations of some model objects, its scope extends until the end alpar@1: of the corresponding statement. alpar@1: \end{enumerate} alpar@1: alpar@1: The indexing mechanism implemented by means of indexing expressions is alpar@1: best explained by some examples discussed below. alpar@1: alpar@1: Let there be given three sets: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\hspace{33.5pt} alpar@1: $A=\{4,7,9\}$, alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\hfil alpar@1: $B=\{(1,Jan),(1,Feb),(2,Mar),(2,Apr),(3,May),(3,Jun)\}$, alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\hspace{33.5pt} alpar@1: $C=\{a,b,c\}$, alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent where $A$ and $C$ consist of 1-tuples (singlets), $B$ alpar@1: consists of 2-tuples (doublets). Consider the following indexing alpar@1: expression: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\hfil alpar@1: {\tt\{i in A, (j,k) in B, l in C\}} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent where {\tt i}, {\tt j}, {\tt k}, and {\tt l} are dummy alpar@1: indices. alpar@1: alpar@1: Although MathProg is not a procedural language, for any indexing alpar@1: expression an equivalent algorithmic description can be given. In alpar@1: particular, the algorithmic description of the indexing expression alpar@1: above could look like follows: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\hfil alpar@1: \begin{tabular}{@{}l@{}} alpar@1: {\bf for all} $i\in A$ {\bf do}\\ alpar@1: \hspace{12pt}{\bf for all} $(j,k)\in B$ {\bf do}\\ alpar@1: \hspace{24pt}{\bf for all} $l\in C$ {\bf do}\\ alpar@1: \hspace{36pt}{\it action};\\ alpar@1: \end{tabular} alpar@1: alpar@1: \newpage alpar@1: alpar@1: \noindent where the dummy indices $i$, $j$, $k$, $l$ are consecutively alpar@1: assigned corresponding components of $n$-tuples from the basic sets $A$, alpar@1: $B$, $C$, and {\it action} is some action that depends on the context, alpar@1: where the indexing expression is used. For example, if the action were alpar@1: printing current values of dummy indices, the printout would look like alpar@1: follows: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\hfil alpar@1: \begin{tabular}{@{}llll@{}} alpar@1: $i=4$&$j=1$&$k=Jan$&$l=a$\\ alpar@1: $i=4$&$j=1$&$k=Jan$&$l=b$\\ alpar@1: $i=4$&$j=1$&$k=Jan$&$l=c$\\ alpar@1: $i=4$&$j=1$&$k=Feb$&$l=a$\\ alpar@1: $i=4$&$j=1$&$k=Feb$&$l=b$\\ alpar@1: \multicolumn{4}{c}{.\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .}\\ alpar@1: $i=9$&$j=3$&$k=Jun$&$l=b$\\ alpar@1: $i=9$&$j=3$&$k=Jun$&$l=c$\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: Let the example indexing expression be used in the following iterated alpar@1: operation: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\hfil alpar@1: {\tt sum\{i in A, (j,k) in B, l in C\} p[i,j,k,l]} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent where {\tt p} is a 4-dimensional numeric parameter or some alpar@1: numeric expression whose resultant value depends on {\tt i}, {\tt j}, alpar@1: {\tt k}, and {\tt l}. In this case the action is summation, so the alpar@1: resultant value of the primary numeric expression is: alpar@1: $$\sum_{i\in A,(j,k)\in B,l\in C}(p_{ijkl}).$$ alpar@1: alpar@1: Now let the example indexing expression be used as a primary set alpar@1: expression. In this case the action is gathering all 4-tuples alpar@1: (quadruplets) of the form $(i,j,k,l)$ in one set, so the resultant alpar@1: value of such operation is simply the Cartesian product of the basic alpar@1: sets: alpar@1: $$A\times B\times C=\{(i,j,k,l):i\in A,(j,k)\in B,l\in C\}.$$ alpar@1: Note that in this case the same indexing expression might be written in alpar@1: the reduced form: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\hfil alpar@1: {\tt\{A, B, C\}} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent because the dummy indices $i$, $j$, $k$, and $l$ are not alpar@1: referenced and therefore their symbolic names need not be specified. alpar@1: alpar@1: Finally, let the example indexing expression be used as the subscript alpar@1: domain in the declaration of a 4-dimensional model object, say, alpar@1: a numeric parameter: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\hfil alpar@1: {\tt param p\{i in A, (j,k) in B, l in C\}} \dots {\tt;} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent In this case the action is generating the parameter members, alpar@1: where each member has the form $p[i,j,k,l]$. alpar@1: alpar@1: As was said above, some indices in the second form of indexing entries alpar@1: may be numeric or symbolic expressions, not only dummy indices. In this alpar@1: case resultant values of such expressions play role of some logical alpar@1: conditions to select only that $n$-tuples from the Cartesian product of alpar@1: basic sets that satisfy these conditions. alpar@1: alpar@1: Consider, for example, the following indexing expression: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\hfil alpar@1: {\tt\{i in A, (i-1,k) in B, l in C\}} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent where {\tt i}, {\tt k}, {\tt l} are dummy indices, and alpar@1: {\tt i-1} is a numeric expression. The algorithmic decsription of this alpar@1: indexing expression is the following: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\hfil alpar@1: \begin{tabular}{@{}l@{}} alpar@1: {\bf for all} $i\in A$ {\bf do}\\ alpar@1: \hspace{12pt}{\bf for all} $(j,k)\in B$ {\bf and} $j=i-1$ {\bf do}\\ alpar@1: \hspace{24pt}{\bf for all} $l\in C$ {\bf do}\\ alpar@1: \hspace{36pt}{\it action};\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent Thus, if this indexing expression were used as a primary set alpar@1: expression, the resultant set would be the following: alpar@1: $$\{(4,May,a),(4,May,b),(4,May,c),(4,Jun,a),(4,Jun,b),(4,Jun,c)\}.$$ alpar@1: Should note that in this case the resultant set consists of 3-tuples, alpar@1: not of 4-tuples, because in the indexing expression there is no dummy alpar@1: index that corresponds to the first component of 2-tuples from the set alpar@1: $B$. alpar@1: alpar@1: The general rule is: the number of components of $n$-tuples defined by alpar@1: an indexing expression is the same as the number of dummy indices in alpar@1: that expression, where the correspondence between dummy indices and alpar@1: components on $n$-tuples in the resultant set is positional, i.e. the alpar@1: first dummy index corresponds to the first component, the second dummy alpar@1: index corresponds to the second component, etc. alpar@1: alpar@1: In some cases it is needed to select a subset from the Cartesian alpar@1: product of some sets. This may be attained by using an optional logical alpar@1: predicate, which is specified in the indexing expression. alpar@1: alpar@1: Consider, for example, the following indexing expression: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\hfil alpar@1: {\tt\{i in A, (j,k) in B, l in C: i <= 5 and k <> 'Mar'\}} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent where the logical expression following the colon is a alpar@1: predicate. The algorithmic description of this indexing expression is alpar@1: the following: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\hfil alpar@1: \begin{tabular}{@{}l@{}} alpar@1: {\bf for all} $i\in A$ {\bf do}\\ alpar@1: \hspace{12pt}{\bf for all} $(j,k)\in B$ {\bf do}\\ alpar@1: \hspace{24pt}{\bf for all} $l\in C$ {\bf do}\\ alpar@1: \hspace{36pt}{\bf if} $i\leq 5$ {\bf and} $l\neq`Mar'$ {\bf then}\\ alpar@1: \hspace{48pt}{\it action};\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent Thus, if this indexing expression were used as a primary set alpar@1: expression, the resultant set would be the following: alpar@1: $$\{(4,1,Jan,a),(4,1,Feb,a),(4,2,Apr,a),\dots,(4,3,Jun,c)\}.$$ alpar@1: alpar@1: If no predicate is specified in the indexing expression, one, which alpar@1: takes on the value {\it true}, is assumed. alpar@1: alpar@1: \subsection{Set expressions} alpar@1: alpar@1: A {\it set expression} is a rule for computing an elemental set, i.e. alpar@1: a collection of $n$-tuples, where components of $n$-tuples are numeric alpar@1: and symbolic quantities. alpar@1: alpar@1: The primary set expression may be a literal set, unsubscripted set, alpar@1: subscripted set, ``arithmetic'' set, indexing expression, iterated set alpar@1: expression, conditional set expression, or another set expression alpar@1: enclosed in parentheses. alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent{\bf Examples} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent alpar@1: \begin{tabular}{@{}ll@{}} alpar@1: \verb|{(123,'aa'), (i,'bb'), (j-1,'cc')}|&(literal set)\\ alpar@1: \verb|I|&(unsubscripted set)\\ alpar@1: \verb|S[i-1,j+1]|&(subscripted set)\\ alpar@1: \verb|1..t-1 by 2|&(``arithmetic'' set)\\ alpar@1: \verb|{t in 1..T, (t+1,j) in S: (t,j) in F}|&(indexing expression)\\ alpar@1: \verb|setof{i in I, j in J}(i+1,j-1)|&(iterated expression)\\ alpar@1: \verb|if i < j then S[i] else F diff S[j]|&(conditional expression)\\ alpar@1: \verb|(1..10 union 21..30)|&(parenthesized expression)\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: More general set expressions containing two or more primary set alpar@1: expressions may be constructed by using certain set operators. alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent{\bf Examples} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\verb|(A union B) inter (I cross J)| alpar@1: alpar@1: \noindent alpar@1: \verb|1..10 cross (if i < j then {'a', 'b', 'c'} else {'d', 'e', 'f'})| alpar@1: alpar@1: \subsubsection{Literal sets} alpar@1: alpar@1: A {\it literal set} is a primary set expression, which has the alpar@1: following two syntactic forms: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\hspace{39pt} alpar@1: {\tt\{}$e_1${\tt,} $e_2${\tt,} \dots{\tt,} $e_m${\tt\}} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\hfil alpar@1: {\tt\{(}$e_{11}${\tt,} \dots{\tt,} $e_{1n}${\tt),} alpar@1: {\tt(}$e_{21}${\tt,} \dots{\tt,} $e_{2n}${\tt),} \dots{\tt,} alpar@1: {\tt(}$e_{m1}${\tt,} \dots{\tt,} $e_{mn}${\tt)\}} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent where $e_1$, \dots, $e_m$, $e_{11}$, \dots, $e_{mn}$ are alpar@1: numeric or symbolic expressions. alpar@1: alpar@1: If the first form is used, the resultant set consists of 1-tuples alpar@1: (singlets) enumerated within the curly braces. It is allowed to specify alpar@1: an empty set as {\tt\{\ \}}, which has no 1-tuples. If the second form alpar@1: is used, the resultant set consists of $n$-tuples enumerated within the alpar@1: curly braces, where a particular $n$-tuple consists of corresponding alpar@1: components enumerated within the parentheses. All $n$-tuples must have alpar@1: the same number of components. alpar@1: alpar@1: \subsubsection{Unsubscripted sets} alpar@1: alpar@1: If the primary set expression is an unsubscripted set (which must be alpar@1: 0-dimen\-sional), the resultant set is an elemental set associated with alpar@1: the corresponding set object. alpar@1: alpar@1: \newpage alpar@1: alpar@1: \subsubsection{Subscripted sets} alpar@1: alpar@1: The primary set expression, which refers to a subscripted set, has the alpar@1: following syntactic form: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\hfil alpar@1: {\it name}{\tt[}$i_1${\tt,} $i_2${\tt,} \dots{\tt,} $i_n${\tt]} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent where {\it name} is the symbolic name of the set object, alpar@1: $i_1$, $i_2$, \dots, $i_n$ are subscripts. alpar@1: alpar@1: Each subscript must be a numeric or symbolic expression. The number of alpar@1: subscripts in the subscript list must be the same as the dimension of alpar@1: the set object with which the subscript list is associated. alpar@1: alpar@1: Actual values of subscript expressions are used to identify a alpar@1: particular member of the set object that determines the resultant set. alpar@1: alpar@1: \subsubsection{``Arithmetic'' sets} alpar@1: alpar@1: The primary set expression, which is an ``arithmetic'' set, has the alpar@1: following two syntactic forms: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\hfil alpar@1: $t_0$ {\tt..} $t_1$ {\tt by} $\delta t$ alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\hspace{138.5pt} alpar@1: $t_0$ {\tt..} $t_1$ alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent where $t_0$, $t_1$, and $\delta t$ are numeric expressions alpar@1: (the value of $\delta t$ must not be zero). The second form is alpar@1: equivalent to the first form, where $\delta t=1$. alpar@1: alpar@1: If $\delta t>0$, the resultant set is determined as follows: alpar@1: $$\{t:\exists k\in{\cal Z}(t=t_0+k\delta t,\ t_0\leq t\leq t_1)\}.$$ alpar@1: Otherwise, if $\delta t<0$, the resultant set is determined as follows: alpar@1: $$\{t:\exists k\in{\cal Z}(t=t_0+k\delta t,\ t_1\leq t\leq t_0)\}.$$ alpar@1: alpar@1: \subsubsection{Indexing expressions} alpar@1: alpar@1: If the primary set expression is an indexing expression, the resultant alpar@1: set is determined as described above in Subsection \ref{indexing}, page alpar@1: \pageref{indexing}. alpar@1: alpar@1: \subsubsection{Iterated expressions} alpar@1: alpar@1: An {\it iterated set expression} is a primary set expression, which has alpar@1: the following syntactic form: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\hfil alpar@1: {\tt setof} {\it indexing-expression} {\it integrand} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent where {\it indexing-expression} is an indexing expression, alpar@1: which introduces dummy indices and controls iterating, {\it integrand} alpar@1: is either a single numeric or symbolic expression or a list of numeric alpar@1: and symbolic expressions separated by commae and enclosed in alpar@1: parentheses. alpar@1: alpar@1: If the integrand is a single numeric or symbolic expression, the alpar@1: resultant set consists of 1-tuples and is determined as follows: alpar@1: $$\{x:(i_1,\dots,i_n)\in\Delta\},$$ alpar@1: \noindent where $x$ is a value of the integrand, $i_1$, \dots, $i_n$ alpar@1: are dummy indices introduced in the indexing expression, $\Delta$ is alpar@1: the domain, a set of $n$-tuples specified by the indexing expression, alpar@1: which defines particular values assigned to the dummy indices on alpar@1: performing the iterated operation. alpar@1: alpar@1: If the integrand is a list containing $m$ numeric and symbolic alpar@1: expressions, the resultant set consists of $m$-tuples and is determined alpar@1: as follows: alpar@1: $$\{(x_1,\dots,x_m):(i_1,\dots,i_n)\in\Delta\},$$ alpar@1: where $x_1$, \dots, $x_m$ are values of the expressions in the alpar@1: integrand list, $i_1$, \dots, $i_n$ and $\Delta$ have the same meaning alpar@1: as above. alpar@1: alpar@1: \subsubsection{Conditional expressions} alpar@1: alpar@1: A {\it conditional set expression} is a primary set expression that has alpar@1: the following syntactic form: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\hfil alpar@1: {\tt if} $b$ {\tt then} $X$ {\tt else} $Y$ alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent where $b$ is an logical expression, $X$ and $Y$ are set alpar@1: expressions, which must define sets of the same dimension. alpar@1: alpar@1: The resultant value of the conditional expression depends on the value alpar@1: of the logical expression that follows the keyword {\tt if}. If it alpar@1: takes on the value {\it true}, the resultant set is the value of the alpar@1: expression that follows the keyword {\tt then}. Otherwise, if the alpar@1: logical expression takes on the value {\it false}, the resultant set is alpar@1: the value of the expression that follows the keyword {\tt else}. alpar@1: alpar@1: \subsubsection{Parenthesized expressions} alpar@1: alpar@1: Any set expression may be enclosed in parentheses that syntactically alpar@1: makes it a primary set expression. alpar@1: alpar@1: Parentheses may be used in set expressions, as in algebra, to specify alpar@1: the desired order in which operations are to be performed. Where alpar@1: parentheses are used, the expression within the parentheses is alpar@1: evaluated before the resultant value is used. alpar@1: alpar@1: The resultant value of the parenthesized expression is the same as the alpar@1: value of the expression enclosed within parentheses. alpar@1: alpar@1: \subsubsection{Set operators} alpar@1: alpar@1: In MathProg there exist the following set operators, which may be used alpar@1: in set expressions: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{96pt}p{222pt}@{}} alpar@1: $X$ {\tt union} $Y$&union $X\cup Y$\\ alpar@1: $X$ {\tt diff} $Y$&difference $X\backslash Y$\\ alpar@1: $X$ {\tt symdiff} $Y$&symmetric difference $X\oplus Y$\\ alpar@1: $X$ {\tt inter} $Y$&intersection $X\cap Y$\\ alpar@1: $X$ {\tt cross} $Y$&cross (Cartesian) product $X\times Y$\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent where $X$ and Y are set expressions, which must define sets alpar@1: of the identical dimension (except the Cartesian product). alpar@1: alpar@1: If the expression includes more than one set operator, all operators alpar@1: are performed from left to right according to the hierarchy of alpar@1: operations (see below). alpar@1: alpar@1: The resultant value of the expression, which contains set operators, is alpar@1: the result of applying the operators to their operands. alpar@1: alpar@1: The dimension of the resultant set, i.e. the dimension of $n$-tuples, alpar@1: of which the resultant set consists of, is the same as the dimension of alpar@1: the operands, except the Cartesian product, where the dimension of the alpar@1: resultant set is the sum of the dimensions of its operands. alpar@1: alpar@1: \subsubsection{Hierarchy of operations} alpar@1: alpar@1: The following list shows the hierarchy of operations in set alpar@1: expressions: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\hfil alpar@1: \begin{tabular}{@{}ll@{}} alpar@1: Operation&Hierarchy\\ alpar@1: \hline alpar@1: Evaluation of numeric operations&1st-7th\\ alpar@1: Evaluation of symbolic operations&8th-9th\\ alpar@1: Evaluation of iterated or ``arithmetic'' set ({\tt setof}, {\tt..})& alpar@1: 10th\\ alpar@1: Cartesian product ({\tt cross})&11th\\ alpar@1: Intersection ({\tt inter})&12th\\ alpar@1: Union and difference ({\tt union}, {\tt diff}, {\tt symdiff})&13th\\ alpar@1: Conditional evaluation ({\tt if} \dots {\tt then} \dots {\tt else})& alpar@1: 14th\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: This hierarchy has the same meaning as was explained above for numeric alpar@1: expressions (see Subsection \ref{hierarchy}, page \pageref{hierarchy}). alpar@1: alpar@1: \subsection{Logical expressions} alpar@1: alpar@1: A {\it logical expression} is a rule for computing a single logical alpar@1: value, which can be either {\it true} or {\it false}. alpar@1: alpar@1: The primary logical expression may be a numeric expression, relational alpar@1: expression, iterated logical expression, or another logical expression alpar@1: enclosed in parentheses. alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent{\bf Examples} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent alpar@1: \begin{tabular}{@{}ll@{}} alpar@1: \verb|i+1|&(numeric expression)\\ alpar@1: \verb|a[i,j] < 1.5|&(relational expression)\\ alpar@1: \verb|s[i+1,j-1] <> 'Mar'|&(relational expression)\\ alpar@1: \verb|(i+1,'Jan') not in I cross J|&(relational expression)\\ alpar@1: \verb|S union T within A[i] inter B[j]|&(relational expression)\\ alpar@1: \verb|forall{i in I, j in J} a[i,j] < .5 * b|&(iterated expression)\\ alpar@1: \verb|(a[i,j] < 1.5 or b[i] >= a[i,j])|&(parenthesized expression)\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: More general logical expressions containing two or more primary logical alpar@1: expressions may be constructed by using certain logical operators. alpar@1: alpar@1: \newpage alpar@1: alpar@1: \noindent{\bf Examples} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\verb|not (a[i,j] < 1.5 or b[i] >= a[i,j]) and (i,j) in S| alpar@1: alpar@1: \noindent\verb|(i,j) in S or (i,j) not in T diff U| alpar@1: alpar@1: \subsubsection{Numeric expressions} alpar@1: alpar@1: The resultant value of the primary logical expression, which is a alpar@1: numeric expression, is {\it true}, if the resultant value of the alpar@1: numeric expression is non-zero. Otherwise the resultant value of the alpar@1: logical expression is {\it false}. alpar@1: alpar@1: \subsubsection{Relational operators} alpar@1: alpar@1: In MathProg there exist the following relational operators, which may alpar@1: be used in logical expressions: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}ll@{}} alpar@1: $x$ {\tt<} $y$&test on $x=} $y$&test on $x\geq y$\\ alpar@1: $x$ {\tt>} $y$&test on $x>y$\\ alpar@1: $x$ {\tt<>} $y$, $x$ {\tt!=} $y$&test on $x\neq y$\\ alpar@1: $x$ {\tt in} $Y$&test on $x\in Y$\\ alpar@1: {\tt(}$x_1${\tt,}\dots{\tt,}$x_n${\tt)} {\tt in} $Y$&test on alpar@1: $(x_1,\dots,x_n)\in Y$\\ alpar@1: $x$ {\tt not} {\tt in} $Y$, $x$ {\tt!in} $Y$&test on $x\not\in Y$\\ alpar@1: {\tt(}$x_1${\tt,}\dots{\tt,}$x_n${\tt)} {\tt not} {\tt in} $Y$, alpar@1: {\tt(}$x_1${\tt,}\dots{\tt,}$x_n${\tt)} {\tt !in} $Y$&test on alpar@1: $(x_1,\dots,x_n)\not\in Y$\\ alpar@1: $X$ {\tt within} $Y$&test on $X\subseteq Y$\\ alpar@1: $X$ {\tt not} {\tt within} $Y$, $X$ {\tt !within} $Y$&test on alpar@1: $X\not\subseteq Y$\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent where $x$, $x_1$, \dots, $x_n$, $y$ are numeric or symbolic alpar@1: expressions, $X$ and $Y$ are set expression. alpar@1: alpar@1: {\it Notes:} alpar@1: alpar@1: 1. In the operations {\tt in}, {\tt not in}, and {\tt !in} the alpar@1: number of components in the first operands must be the same as the alpar@1: dimension of the second operand. alpar@1: alpar@1: 2. In the operations {\tt within}, {\tt not within}, and {\tt !within} alpar@1: both operands must have identical dimension. alpar@1: alpar@1: All the relational operators listed above have their conventional alpar@1: mathematical meaning. The resultant value is {\it true}, if alpar@1: corresponding relation is satisfied for its operands, otherwise alpar@1: {\it false}. (Note that symbolic values are ordered lexicographically, alpar@1: and any numeric value precedes any symbolic value.) alpar@1: alpar@1: \subsubsection{Iterated expressions} alpar@1: alpar@1: An {\it iterated logical expression} is a primary logical expression, alpar@1: which has the following syntactic form: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\hfil alpar@1: {\it iterated-operator} {\it indexing-expression} {\it integrand} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent where {\it iterated-operator} is the symbolic name of the alpar@1: iterated operator to be performed (see below), {\it indexing-expression} alpar@1: is an indexing expression which introduces dummy indices and controls alpar@1: iterating, {\it integrand} is a numeric expression that participates in alpar@1: the operation. alpar@1: alpar@1: In MathProg there exist two iterated operators, which may be used in alpar@1: logical expressions: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\hfil alpar@1: \begin{tabular}{@{}lll@{}} alpar@1: {\tt forall}&$\forall$-quantification&$\displaystyle alpar@1: \forall(i_1,\dots,i_n)\in\Delta[f(i_1,\dots,i_n)],$\\ alpar@1: {\tt exists}&$\exists$-quantification&$\displaystyle alpar@1: \exists(i_1,\dots,i_n)\in\Delta[f(i_1,\dots,i_n)],$\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent where $i_1$, \dots, $i_n$ are dummy indices introduced in alpar@1: the indexing expression, $\Delta$ is the domain, a set of $n$-tuples alpar@1: specified by the indexing expression which defines particular values alpar@1: assigned to the dummy indices on performing the iterated operation, alpar@1: $f(i_1,\dots,i_n)$ is the integrand, a logical expression whose alpar@1: resultant value depends on the dummy indices. alpar@1: alpar@1: For $\forall$-quantification the resultant value of the iterated alpar@1: logical expression is {\it true}, if the value of the integrand is alpar@1: {\it true} for all $n$-tuples contained in the domain, otherwise alpar@1: {\it false}. alpar@1: alpar@1: For $\exists$-quantification the resultant value of the iterated alpar@1: logical expression is {\it false}, if the value of the integrand is alpar@1: {\it false} for all $n$-tuples contained in the domain, otherwise alpar@1: {\it true}. alpar@1: alpar@1: \subsubsection{Parenthesized expressions} alpar@1: alpar@1: Any logical expression may be enclosed in parentheses that alpar@1: syntactically makes it a primary logical expression. alpar@1: alpar@1: Parentheses may be used in logical expressions, as in algebra, to alpar@1: specify the desired order in which operations are to be performed. alpar@1: Where parentheses are used, the expression within the parentheses is alpar@1: evaluated before the resultant value is used. alpar@1: alpar@1: The resultant value of the parenthesized expression is the same as the alpar@1: value of the expression enclosed within parentheses. alpar@1: alpar@1: \subsubsection{Logical operators} alpar@1: alpar@1: In MathProg there exist the following logical operators, which may be alpar@1: used in logical expressions: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{96pt}p{222pt}@{}} alpar@1: {\tt not} $x$, {\tt!}$x$&negation $\neg\ x$\\ alpar@1: $x$ {\tt and} $y$, $x$ {\tt\&\&} $y$&conjunction (logical ``and'') alpar@1: $x\;\&\;y$\\ alpar@1: $x$ {\tt or} $y$, $x$ {\tt||} $y$&disjunction (logical ``or'') alpar@1: $x\vee y$\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent where $x$ and $y$ are logical expressions. alpar@1: alpar@1: If the expression includes more than one logical operator, all alpar@1: operators are performed from left to right according to the hierarchy alpar@1: of the operations (see below). The resultant value of the expression, alpar@1: which contains logical operators, is the result of applying the alpar@1: operators to their operands. alpar@1: alpar@1: \subsubsection{Hierarchy of operations} alpar@1: alpar@1: The following list shows the hierarchy of operations in logical alpar@1: expressions: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\hfil alpar@1: \begin{tabular}{@{}ll@{}} alpar@1: Operation&Hierarchy\\ alpar@1: \hline alpar@1: Evaluation of numeric operations&1st-7th\\ alpar@1: Evaluation of symbolic operations&8th-9th\\ alpar@1: Evaluation of set operations&10th-14th\\ alpar@1: Relational operations ({\tt<}, {\tt<=}, etc.)&15th\\ alpar@1: Negation ({\tt not}, {\tt!})&16th\\ alpar@1: Conjunction ({\tt and}, {\tt\&\&})&17th\\ alpar@1: $\forall$- and $\exists$-quantification ({\tt forall}, {\tt exists})& alpar@1: 18th\\ alpar@1: Disjunction ({\tt or}, {\tt||})&19th\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: This hierarchy has the same meaning as was explained above for numeric alpar@1: expressions (see Subsection \ref{hierarchy}, page \pageref{hierarchy}). alpar@1: alpar@1: \subsection{Linear expressions} alpar@1: alpar@1: An {\it linear expression} is a rule for computing so called alpar@1: a {\it linear form} or simply a {\it formula}, which is a linear (or alpar@1: affine) function of elemental variables. alpar@1: alpar@1: The primary linear expression may be an unsubscripted variable, alpar@1: subscripted variable, iterated linear expression, conditional linear alpar@1: expression, or another linear expression enclosed in parentheses. alpar@1: alpar@1: It is also allowed to use a numeric expression as the primary linear alpar@1: expression, in which case the resultant value of the numeric expression alpar@1: is automatically converted to a formula that includes the constant term alpar@1: only. alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent{\bf Examples} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent alpar@1: \begin{tabular}{@{}ll@{}} alpar@1: \verb|z|&(unsubscripted variable)\\ alpar@1: \verb|x[i,j]|&(subscripted variable)\\ alpar@1: \verb|sum{j in J} (a[i] * x[i,j] + 3 * y)|&(iterated expression)\\ alpar@1: \verb|if i in I then x[i,j] else 1.5 * z + 3|&(conditional expression)\\ alpar@1: \verb|(a[i,j] * x[i,j] + y[i-1] + .1)|&(parenthesized expression)\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: More general linear expressions containing two or more primary linear alpar@1: expressions may be constructed by using certain arithmetic operators. alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent{\bf Examples} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\verb|2 * x[i-1,j+1] + 3.5 * y[k] + .5 * z| alpar@1: alpar@1: \noindent\verb|(- x[i,j] + 3.5 * y[k]) / sum{t in T} abs(d[i,j,t])| alpar@1: alpar@1: \subsubsection{Unsubscripted variables} alpar@1: alpar@1: If the primary linear expression is an unsubscripted variable (which alpar@1: must be 0-dimensional), the resultant formula is that unsubscripted alpar@1: variable. alpar@1: alpar@1: \subsubsection{Subscripted variables} alpar@1: alpar@1: The primary linear expression, which refers to a subscripted variable, alpar@1: has the following syntactic form: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\hfil alpar@1: {\it name}{\tt[}$i_1${\tt,} $i_2${\tt,} \dots{\tt,} $i_n${\tt]} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent where {\it name} is the symbolic name of the model variable, alpar@1: $i_1$, $i_2$, \dots, $i_n$ are subscripts. alpar@1: alpar@1: Each subscript must be a numeric or symbolic expression. The number of alpar@1: subscripts in the subscript list must be the same as the dimension of alpar@1: the model variable with which the subscript list is associated. alpar@1: alpar@1: Actual values of the subscript expressions are used to identify a alpar@1: particular member of the model variable that determines the resultant alpar@1: formula, which is an elemental variable associated with corresponding alpar@1: member. alpar@1: alpar@1: \subsubsection{Iterated expressions} alpar@1: alpar@1: An {\it iterated linear expression} is a primary linear expression, alpar@1: which has the following syntactic form: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\hfil alpar@1: {\tt sum} {\it indexing-expression} {\it integrand} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent where {\it indexing-expression} is an indexing expression, alpar@1: which introduces dummy indices and controls iterating, {\it integrand} alpar@1: is a linear expression that participates in the operation. alpar@1: alpar@1: The iterated linear expression is evaluated exactly in the same way as alpar@1: the iterated numeric expression (see Subection \ref{itexpr}, page alpar@1: \pageref{itexpr}) with exception that the integrand participated in the alpar@1: summation is a formula, not a numeric value. alpar@1: alpar@1: \subsubsection{Conditional expressions} alpar@1: alpar@1: A {\it conditional linear expression} is a primary linear expression, alpar@1: which has one of the following two syntactic forms: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\hfil alpar@1: {\tt if} $b$ {\tt then} $f$ {\tt else} $g$ alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\hspace{127pt} alpar@1: {\tt if} $b$ {\tt then} $f$ alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent where $b$ is an logical expression, $f$ and $g$ are linear alpar@1: expressions. alpar@1: alpar@1: The conditional linear expression is evaluated exactly in the same way alpar@1: as the conditional numeric expression (see Subsection \ref{ifthen}, alpar@1: page \pageref{ifthen}) with exception that operands participated in the alpar@1: operation are formulae, not numeric values. alpar@1: alpar@1: \subsubsection{Parenthesized expressions} alpar@1: alpar@1: Any linear expression may be enclosed in parentheses that syntactically alpar@1: makes it a primary linear expression. alpar@1: alpar@1: Parentheses may be used in linear expressions, as in algebra, to alpar@1: specify the desired order in which operations are to be performed. alpar@1: Where parentheses are used, the expression within the parentheses is alpar@1: evaluated before the resultant formula is used. alpar@1: alpar@1: The resultant value of the parenthesized expression is the same as the alpar@1: value of the expression enclosed within parentheses. alpar@1: alpar@1: \subsubsection{Arithmetic operators} alpar@1: alpar@1: In MathProg there exists the following arithmetic operators, which may alpar@1: be used in linear expressions: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{96pt}p{222pt}@{}} alpar@1: {\tt+} $f$&unary plus\\ alpar@1: {\tt-} $f$&unary minus\\ alpar@1: $f$ {\tt+} $g$&addition\\ alpar@1: $f$ {\tt-} $g$&subtraction\\ alpar@1: $x$ {\tt*} $f$, $f$ {\tt*} $x$&multiplication\\ alpar@1: $f$ {\tt/} $x$&division alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent where $f$ and $g$ are linear expressions, $x$ is a numeric alpar@1: expression (more precisely, a linear expression containing only the alpar@1: constant term). alpar@1: alpar@1: If the expression includes more than one arithmetic operator, all alpar@1: operators are performed from left to right according to the hierarchy alpar@1: of operations (see below). The resultant value of the expression, which alpar@1: contains arithmetic operators, is the result of applying the operators alpar@1: to their operands. alpar@1: alpar@1: \subsubsection{Hierarchy of operations} alpar@1: alpar@1: The hierarchy of arithmetic operations used in linear expressions is alpar@1: the same as for numeric expressions (see Subsection \ref{hierarchy}, alpar@1: page \pageref{hierarchy}). alpar@1: alpar@1: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% alpar@1: alpar@1: \newpage alpar@1: alpar@1: \section{Statements} alpar@1: alpar@1: {\it Statements} are basic units of the model description. In MathProg alpar@1: all statements are divided into two categories: declaration statements alpar@1: and functional statements. alpar@1: alpar@1: {\it Declaration statements} (set statement, parameter statement, alpar@1: variable statement, constraint statement, and objective statement) are alpar@1: used to declare model objects of certain kinds and define certain alpar@1: properties of such objects. alpar@1: alpar@1: {\it Functional statements} (solve statement, check statement, display alpar@1: statement, printf statement, loop statement) are intended for alpar@1: performing some specific actions. alpar@1: alpar@1: Note that declaration statements may follow in arbitrary order, which alpar@1: does not affect the result of translation. However, any model object alpar@1: must be declared before it is referenced in other statements. alpar@1: alpar@1: \subsection{Set statement} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \framebox[345pt][l]{ alpar@1: \parbox[c][24pt]{345pt}{ alpar@1: \hspace{6pt} {\tt set} {\it name} {\it alias} {\it domain} {\tt,} alpar@1: {\it attrib} {\tt,} \dots {\tt,} {\it attrib} {\tt;} alpar@1: }} alpar@1: alpar@1: \setlength{\leftmargini}{60pt} alpar@1: alpar@1: \begin{description} alpar@1: \item[{\rm Where:}\hspace*{23pt}] {\it name} is a symbolic name of the alpar@1: set; alpar@1: \item[\hspace*{54pt}] {\it alias} is an optional string literal, which alpar@1: specifies an alias of the set; alpar@1: \item[\hspace*{54pt}] {\it domain} is an optional indexing expression, alpar@1: which specifies a subscript domain of the set; alpar@1: \item[\hspace*{54pt}] {\it attrib}, \dots, {\it attrib} are optional alpar@1: attributes of the set. (Commae preceding attributes may be omitted.) alpar@1: \end{description} alpar@1: alpar@1: \noindent Optional attributes: alpar@1: alpar@1: \begin{description} alpar@1: \item[{\tt dimen} $n$\hspace*{19pt}] specifies the dimension of alpar@1: $n$-tuples, which the set consists of; alpar@1: \item[{\tt within} {\it expression}]\hspace*{0pt}\\ alpar@1: specifies a superset which restricts the set or all its members alpar@1: (elemental sets) to be within that superset; alpar@1: \item[{\tt:=} {\it expression}]\hspace*{0pt}\\ alpar@1: specifies an elemental set assigned to the set or its members; alpar@1: \item[{\tt default} {\it expression}]\hspace*{0pt}\\ alpar@1: specifies an elemental set assigned to the set or its members whenever alpar@1: no appropriate data are available in the data section. alpar@1: \end{description} alpar@1: alpar@1: \newpage alpar@1: alpar@1: \noindent{\bf Examples} alpar@1: alpar@1: \begin{verbatim} alpar@1: set V; alpar@1: set E within V cross V; alpar@1: set step{s in 1..maxiter} dimen 2 := if s = 1 then E else alpar@1: step[s-1] union setof{k in V, (i,k) in step[s-1], (k,j) alpar@1: in step[s-1]}(i,j); alpar@1: set A{i in I, j in J}, within B[i+1] cross C[j-1], within alpar@1: D diff E, default {('abc',123), (321,'cba')}; alpar@1: \end{verbatim} alpar@1: alpar@1: The set statement declares a set. If the subscript domain is not alpar@1: specified, the set is a simple set, otherwise it is an array of alpar@1: elemental sets. alpar@1: alpar@1: The {\tt dimen} attribute specifies the dimension of $n$-tuples, which alpar@1: the set (if it is a simple set) or its members (if the set is an array alpar@1: of elemental sets) consist of, where $n$ must be unsigned integer from alpar@1: 1 to 20. At most one {\tt dimen} attribute can be specified. If the alpar@1: {\tt dimen} attribute is not specified, the dimension of\linebreak alpar@1: $n$-tuples is implicitly determined by other attributes (for example, alpar@1: if there is a set expression that follows {\tt:=} or the keyword alpar@1: {\tt default}, the dimension of $n$-tuples of corresponding elemental alpar@1: set is used). If no dimension information is available, {\tt dimen 1} alpar@1: is assumed. alpar@1: alpar@1: The {\tt within} attribute specifies a set expression whose resultant alpar@1: value is a superset used to restrict the set (if it is a simple set) or alpar@1: its members (if the set is an array of elemental sets) to be within alpar@1: that superset. Arbitrary number of {\tt within} attributes may be alpar@1: specified in the same set statement. alpar@1: alpar@1: The assign ({\tt:=}) attribute specifies a set expression used to alpar@1: evaluate elemental set(s) assigned to the set (if it is a simple set) alpar@1: or its members (if the set is an array of elemental sets). If the alpar@1: assign attribute is specified, the set is {\it computable} and alpar@1: therefore needs no data to be provided in the data section. If the alpar@1: assign attribute is not specified, the set must be provided with data alpar@1: in the data section. At most one assign or default attribute can be alpar@1: specified for the same set. alpar@1: alpar@1: The {\tt default} attribute specifies a set expression used to evaluate alpar@1: elemental set(s) assigned to the set (if it is a simple set) or its alpar@1: members (if the set is an array of elemental sets) whenever alpar@1: no appropriate data are available in the data section. If neither alpar@1: assign nor default attribute is specified, missing data will cause an alpar@1: error. alpar@1: alpar@1: \subsection{Parameter statement} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \framebox[345pt][l]{ alpar@1: \parbox[c][24pt]{345pt}{ alpar@1: \hspace{6pt} {\tt param} {\it name} {\it alias} {\it domain} {\tt,} alpar@1: {\it attrib} {\tt,} \dots {\tt,} {\it attrib} {\tt;} alpar@1: }} alpar@1: alpar@1: \setlength{\leftmargini}{60pt} alpar@1: alpar@1: \begin{description} alpar@1: \item[{\rm Where:}\hspace*{23pt}] {\it name} is a symbolic name of the alpar@1: parameter; alpar@1: \item[\hspace*{54pt}] {\it alias} is an optional string literal, which alpar@1: specifies an alias of the parameter; alpar@1: \item[\hspace*{54pt}] {\it domain} is an optional indexing expression, alpar@1: which specifies a subscript domain of the parameter; alpar@1: \item[\hspace*{54pt}] {\it attrib}, \dots, {\it attrib} are optional alpar@1: attributes of the parameter. (Commae preceding attributes may be alpar@1: omitted.) alpar@1: \end{description} alpar@1: alpar@1: \noindent Optional attributes: alpar@1: alpar@1: \begin{description} alpar@1: \item[{\tt integer}\hspace*{18.5pt}] specifies that the parameter is alpar@1: integer; alpar@1: \item[{\tt binary}\hspace*{24pt}] specifies that the parameter is alpar@1: binary; alpar@1: \item[{\tt symbolic}\hspace*{13.5pt}] specifies that the parameter is alpar@1: symbolic; alpar@1: \item[{\it relation expression}]\hspace*{0pt}\\ alpar@1: (where {\it relation} is one of: {\tt<}, {\tt<=}, {\tt=}, {\tt==}, alpar@1: {\tt>=}, {\tt>}, {\tt<>}, {\tt!=})\\ alpar@1: specifies a condition that restricts the parameter or its members to alpar@1: satisfy that condition; alpar@1: \item[{\tt in} {\it expression}]\hspace*{0pt}\\ alpar@1: specifies a superset that restricts the parameter or its members to be alpar@1: in that superset; alpar@1: \item[{\tt:=} {\it expression}]\hspace*{0pt}\\ alpar@1: specifies a value assigned to the parameter or its members; alpar@1: \item[{\tt default} {\it expression}]\hspace*{0pt}\\ alpar@1: specifies a value assigned to the parameter or its members whenever alpar@1: no appropriate data are available in the data section. alpar@1: \end{description} alpar@1: alpar@1: \noindent{\bf Examples} alpar@1: alpar@1: \begin{verbatim} alpar@1: param units{raw, prd} >= 0; alpar@1: param profit{prd, 1..T+1}; alpar@1: param N := 20, integer, >= 0, <= 100; alpar@1: param comb 'n choose k' {n in 0..N, k in 0..n} := alpar@1: if k = 0 or k = n then 1 else comb[n-1,k-1] + comb[n-1,k]; alpar@1: param p{i in I, j in J}, integer, >= 0, <= i+j, alpar@1: in A[i] symdiff B[j], in C[i,j], default 0.5 * (i + j); alpar@1: param month symbolic default 'May' in {'Mar', 'Apr', 'May'}; alpar@1: \end{verbatim} alpar@1: alpar@1: The parameter statement declares a parameter. If a subscript domain is alpar@1: not specified, the parameter is a simple (scalar) parameter, otherwise alpar@1: it is a $n$-dimensional array. alpar@1: alpar@1: The type attributes {\tt integer}, {\tt binary}, and {\tt symbolic} alpar@1: qualify the type of values that can be assigned to the parameter as alpar@1: shown below: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\hfil alpar@1: \begin{tabular}{@{}ll@{}} alpar@1: Type attribute&Assigned values\\ alpar@1: \hline alpar@1: (not specified)&Any numeric values\\ alpar@1: {\tt integer}&Only integer numeric values\\ alpar@1: {\tt binary}&Either 0 or 1\\ alpar@1: {\tt symbolic}&Any numeric and symbolic values\\ alpar@1: \end{tabular} alpar@1: alpar@1: \newpage alpar@1: alpar@1: The {\tt symbolic} attribute cannot be specified along with other type alpar@1: attributes. Being specified it must precede all other attributes. alpar@1: alpar@1: The condition attribute specifies an optional condition that restricts alpar@1: values assigned to the parameter to satisfy that condition. This alpar@1: attribute has the following syntactic forms: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}ll@{}} alpar@1: {\tt<} $v$&check for $x=} $v$&check for $x\geq v$\\ alpar@1: {\tt>} $v$&check for $x\geq v$\\ alpar@1: {\tt<>} $v$, {\tt!=} $v$&check for $x\neq v$\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent where $x$ is a value assigned to the parameter, $v$ is the alpar@1: resultant value of a numeric or symbolic expression specified in the alpar@1: condition attribute. Arbitrary number of condition attributes can be alpar@1: specified for the same parameter. If a value being assigned to the alpar@1: parameter during model evaluation violates at least one of specified alpar@1: conditions, an error is raised. (Note that symbolic values are ordered alpar@1: lexicographically, and any numeric value precedes any symbolic value.) alpar@1: alpar@1: The {\tt in} attribute is similar to the condition attribute and alpar@1: specifies a set expression whose resultant value is a superset used to alpar@1: restrict numeric or symbolic values assigned to the parameter to be in alpar@1: that superset. Arbitrary number of the {\tt in} attributes can be alpar@1: specified for the same parameter. If a value being assigned to the alpar@1: parameter during model evaluation is not in at least one of specified alpar@1: supersets, an error is raised. alpar@1: alpar@1: The assign ({\tt:=}) attribute specifies a numeric or symbolic alpar@1: expression used to compute a value assigned to the parameter (if it is alpar@1: a simple parameter) or its member (if the parameter is an array). If alpar@1: the assign attribute is specified, the parameter is {\it computable} alpar@1: and therefore needs no data to be provided in the data section. If the alpar@1: assign attribute is not specified, the parameter must be provided with alpar@1: data in the data section. At most one assign or {\tt default} attribute alpar@1: can be specified for the same parameter. alpar@1: alpar@1: The {\tt default} attribute specifies a numeric or symbolic expression alpar@1: used to compute a value assigned to the parameter or its member alpar@1: whenever no appropriate data are available in the data section. If alpar@1: neither assign nor {\tt default} attribute is specified, missing data alpar@1: will cause an error. alpar@1: alpar@1: \subsection{Variable statement} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \framebox[345pt][l]{ alpar@1: \parbox[c][24pt]{345pt}{ alpar@1: \hspace{6pt} {\tt var} {\it name} {\it alias} {\it domain} {\tt,} alpar@1: {\it attrib} {\tt,} \dots {\tt,} {\it attrib} {\tt;} alpar@1: }} alpar@1: alpar@1: \setlength{\leftmargini}{60pt} alpar@1: alpar@1: \begin{description} alpar@1: \item[{\rm Where:}\hspace*{23pt}] {\it name} is a symbolic name of the alpar@1: variable; alpar@1: \item[\hspace*{54pt}] {\it alias} is an optional string literal, which alpar@1: specifies an alias of the variable; alpar@1: \item[\hspace*{54pt}] {\it domain} is an optional indexing expression, alpar@1: which specifies a subscript domain of the variable; alpar@1: \item[\hspace*{54pt}] {\it attrib}, \dots, {\it attrib} are optional alpar@1: attributes of the variable. (Commae preceding attributes may be alpar@1: omitted.) alpar@1: \end{description} alpar@1: alpar@1: \noindent Optional attributes: alpar@1: alpar@1: \begin{description} alpar@1: \item[{\tt integer}\hspace*{18.5pt}] restricts the variable to be alpar@1: integer; alpar@1: \item[{\tt binary}\hspace*{24pt}] restricts the variable to be binary; alpar@1: \item[{\tt>=} {\it expression}]\hspace*{0pt}\\ alpar@1: specifies an lower bound of the variable; alpar@1: \item[{\tt<=} {\it expression}]\hspace*{0pt}\\ alpar@1: specifies an upper bound of the variable; alpar@1: \item[{\tt=} {\it expression}]\hspace*{0pt}\\ alpar@1: specifies a fixed value of the variable; alpar@1: \end{description} alpar@1: alpar@1: \noindent{\bf Examples} alpar@1: alpar@1: \begin{verbatim} alpar@1: var x >= 0; alpar@1: var y{I,J}; alpar@1: var make{p in prd}, integer, >= commit[p], <= market[p]; alpar@1: var store{raw, 1..T+1} >= 0; alpar@1: var z{i in I, j in J} >= i+j; alpar@1: \end{verbatim} alpar@1: alpar@1: The variable statement declares a variable. If a subscript domain is alpar@1: not specified, the variable is a simple (scalar) variable, otherwise it alpar@1: is a $n$-dimensional array of elemental variables. alpar@1: alpar@1: Elemental variable(s) associated with the model variable (if it is a alpar@1: simple variable) or its members (if it is an array) correspond to the alpar@1: variables in the LP/MIP problem formulation (see Subsection alpar@1: \ref{problem}, page \pageref{problem}). Note that only elemental alpar@1: variables actually referenced in some constraints and/or objectives are alpar@1: included in the LP/MIP problem instance to be generated. alpar@1: alpar@1: The type attributes {\tt integer} and {\tt binary} restrict the alpar@1: variable to be integer or binary, respectively. If no type attribute is alpar@1: specified, the variable is continuous. If all variables in the model alpar@1: are continuous, the corresponding problem is of LP class. If there is alpar@1: at least one integer or binary variable, the problem is of MIP class. alpar@1: alpar@1: The lower bound ({\tt>=}) attribute specifies a numeric expression for alpar@1: computing an lower bound of the variable. At most one lower bound can alpar@1: be specified. By default all variables (except binary ones) have no alpar@1: lower bound, so if a variable is required to be non-negative, its zero alpar@1: lower bound should be explicitly specified. alpar@1: alpar@1: The upper bound ({\tt<=}) attribute specifies a numeric expression for alpar@1: computing an upper bound of the variable. At most one upper bound alpar@1: attribute can be specified. alpar@1: alpar@1: The fixed value ({\tt=}) attribute specifies a numeric expression for alpar@1: computing a value, at which the variable is fixed. This attribute alpar@1: cannot be specified along with the bound attributes. alpar@1: alpar@1: \subsection{Constraint statement} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \framebox[345pt][l]{ alpar@1: \parbox[c][96pt]{345pt}{ alpar@1: \hspace{6pt} {\tt s.t.} {\it name} {\it alias} {\it domain} {\tt:} alpar@1: {\it expression} {\tt,} {\tt=} {\it expression} {\tt;} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \hspace{6pt} {\tt s.t.} {\it name} {\it alias} {\it domain} {\tt:} alpar@1: {\it expression} {\tt,} {\tt<=} {\it expression} {\tt;} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \hspace{6pt} {\tt s.t.} {\it name} {\it alias} {\it domain} {\tt:} alpar@1: {\it expression} {\tt,} {\tt>=} {\it expression} {\tt;} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \hspace{6pt} {\tt s.t.} {\it name} {\it alias} {\it domain} {\tt:} alpar@1: {\it expression} {\tt,} {\tt<=} {\it expression} {\tt,} {\tt<=} alpar@1: {\it expression} {\tt;} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \hspace{6pt} {\tt s.t.} {\it name} {\it alias} {\it domain} {\tt:} alpar@1: {\it expression} {\tt,} {\tt>=} {\it expression} {\tt,} {\tt>=} alpar@1: {\it expression} {\tt;} alpar@1: }} alpar@1: alpar@1: \setlength{\leftmargini}{60pt} alpar@1: alpar@1: \begin{description} alpar@1: \item[{\rm Where:}\hspace*{23pt}] {\it name} is a symbolic name of the alpar@1: constraint; alpar@1: \item[\hspace*{54pt}] {\it alias} is an optional string literal, which alpar@1: specifies an alias of the constraint; alpar@1: \item[\hspace*{54pt}] {\it domain} is an optional indexing expression, alpar@1: which specifies a subscript domain of the constraint; alpar@1: \item[\hspace*{54pt}] {\it expression} is a linear expression used to alpar@1: compute a component of the constraint. (Commae following expressions alpar@1: may be omitted.) alpar@1: \end{description} alpar@1: alpar@1: \begin{description} alpar@1: \item[{\rm Note:}\hspace*{31pt}] The keyword {\tt s.t.} may be written alpar@1: as {\tt subject to} or as {\tt subj to}, or may be omitted at all. alpar@1: \end{description} alpar@1: alpar@1: \noindent{\bf Examples} alpar@1: alpar@1: \begin{verbatim} alpar@1: s.t. r: x + y + z, >= 0, <= 1; alpar@1: limit{t in 1..T}: sum{j in prd} make[j,t] <= max_prd; alpar@1: subject to balance{i in raw, t in 1..T}: store[i,t+1] - alpar@1: store[i,t] - sum{j in prd} units[i,j] * make[j,t]; alpar@1: subject to rlim 'regular-time limit' {t in time}: alpar@1: sum{p in prd} pt[p] * rprd[p,t] <= 1.3 * dpp[t] * crews[t]; alpar@1: \end{verbatim} alpar@1: alpar@1: The constraint statement declares a constraint. If a subscript domain alpar@1: is not specified, the constraint is a simple (scalar) constraint, alpar@1: otherwise it is a $n$-dimensional array of elemental constraints. alpar@1: alpar@1: Elemental constraint(s) associated with the model constraint (if it is alpar@1: a simple constraint) or its members (if it is an array) correspond to alpar@1: the linear constraints in the LP/MIP problem formulation (see alpar@1: Subsection \ref{problem}, page \pageref{problem}). alpar@1: alpar@1: If the constraint has the form of equality or single inequality, i.e. alpar@1: includes two expressions, one of which follows the colon and other alpar@1: follows the relation sign {\tt=}, {\tt<=}, or {\tt>=}, both expressions alpar@1: in the statement can be linear expressions. If the constraint has the alpar@1: form of double inequality, i.e. includes three expressions, the middle alpar@1: expression can be a linear expression while the leftmost and rightmost alpar@1: ones can be only numeric expressions. alpar@1: alpar@1: Generating the model is, roughly speaking, generating its constraints, alpar@1: which are always evaluated for the entire subscript domain. Evaluation alpar@1: of the constraints leads, in turn, to evaluation of other model objects alpar@1: such as sets, parameters, and variables. alpar@1: alpar@1: Constructing an actual linear constraint included in the problem alpar@1: instance, which (constraint) corresponds to a particular elemental alpar@1: constraint, is performed as follows. alpar@1: alpar@1: If the constraint has the form of equality or single inequality, alpar@1: evaluation of both linear expressions gives two resultant linear forms: alpar@1: $$\begin{array}{r@{\ }c@{\ }r@{\ }c@{\ }r@{\ }c@{\ }r@{\ }c@{\ }r} alpar@1: f&=&a_1x_1&+&a_2x_2&+\dots+&a_nx_n&+&a_0,\\ alpar@1: g&=&b_1x_1&+&a_2x_2&+\dots+&a_nx_n&+&b_0,\\ alpar@1: \end{array}$$ alpar@1: where $x_1$, $x_2$, \dots, $x_n$ are elemental variables; $a_1$, $a_2$, alpar@1: \dots, $a_n$, $b_1$, $b_2$, \dots, $b_n$ are numeric coefficients; alpar@1: $a_0$ and $b_0$ are constant terms. Then all linear terms of $f$ and alpar@1: $g$ are carried to the left-hand side, and the constant terms are alpar@1: carried to the right-hand side, that gives the final elemental alpar@1: constraint in the standard form: alpar@1: $$(a_1-b_1)x_1+(a_2-b_2)x_2+\dots+(a_n-b_n)x_n\left\{ alpar@1: \begin{array}{@{}c@{}}=\\\leq\\\geq\\\end{array}\right\}b_0-a_0.$$ alpar@1: alpar@1: If the constraint has the form of double inequality, evaluation of the alpar@1: middle linear expression gives the resultant linear form: alpar@1: $$f=a_1x_1+a_2x_2+\dots+a_nx_n+a_0,$$ alpar@1: and evaluation of the leftmost and rightmost numeric expressions gives alpar@1: two numeric values $l$ and $u$, respectively. Then the constant term of alpar@1: the linear form is carried to both left-hand and right-handsides that alpar@1: gives the final elemental constraint in the standard form: alpar@1: $$l-a_0\leq a_1x_1+a_2x_2+\dots+a_nx_n\leq u-a_0.$$ alpar@1: alpar@1: \subsection{Objective statement} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \framebox[345pt][l]{ alpar@1: \parbox[c][44pt]{345pt}{ alpar@1: \hspace{6pt} {\tt minimize} {\it name} {\it alias} {\it domain} {\tt:} alpar@1: {\it expression} {\tt;} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \hspace{6pt} {\tt maximize} {\it name} {\it alias} {\it domain} {\tt:} alpar@1: {\it expression} {\tt;} alpar@1: }} alpar@1: alpar@1: \setlength{\leftmargini}{60pt} alpar@1: alpar@1: \begin{description} alpar@1: \item[{\rm Where:}\hspace*{23pt}] {\it name} is a symbolic name of the alpar@1: objective; alpar@1: \item[\hspace*{54pt}] {\it alias} is an optional string literal, which alpar@1: specifies an alias of the objective; alpar@1: \item[\hspace*{54pt}] {\it domain} is an optional indexing expression, alpar@1: which specifies a subscript domain of the objective; alpar@1: \item[\hspace*{54pt}] {\it expression} is a linear expression used to alpar@1: compute the linear form of the objective. alpar@1: \end{description} alpar@1: alpar@1: \noindent{\bf Examples} alpar@1: alpar@1: \begin{verbatim} alpar@1: minimize obj: x + 1.5 * (y + z); alpar@1: maximize total_profit: sum{p in prd} profit[p] * make[p]; alpar@1: \end{verbatim} alpar@1: alpar@1: The objective statement declares an objective. If a subscript domain is alpar@1: not specified, the objective is a simple (scalar) objective. Otherwise alpar@1: it is a $n$-dimensional array of elemental objectives. alpar@1: alpar@1: Elemental objective(s) associated with the model objective (if it is a alpar@1: simple objective) or its members (if it is an array) correspond to alpar@1: general linear constraints in the LP/MIP problem formulation (see alpar@1: Subsection \ref{problem}, page \pageref{problem}). However, unlike alpar@1: constraints the corresponding linear forms are free (unbounded). alpar@1: alpar@1: Constructing an actual linear constraint included in the problem alpar@1: instance, which (constraint) corresponds to a particular elemental alpar@1: constraint, is performed as follows. The linear expression specified in alpar@1: the objective statement is evaluated that, gives the resultant linear alpar@1: form: alpar@1: $$f=a_1x_1+a_2x_2+\dots+a_nx_n+a_0,$$ alpar@1: where $x_1$, $x_2$, \dots, $x_n$ are elemental variables; $a_1$, $a_2$, alpar@1: \dots, $a_n$ are numeric coefficients; $a_0$ is the constant term. Then alpar@1: the linear form is used to construct the final elemental constraint in alpar@1: the standard form: alpar@1: $$-\infty= 0 and y >= 0; alpar@1: check sum{i in ORIG} supply[i] = sum{j in DEST} demand[j]; alpar@1: check{i in I, j in 1..10}: S[i,j] in U[i] union V[j]; alpar@1: \end{verbatim} alpar@1: alpar@1: The check statement allows checking the resultant value of an logical alpar@1: expression specified in the statement. If the value is {\it false}, an alpar@1: error is reported. alpar@1: alpar@1: If the subscript domain is not specified, the check is performed only alpar@1: once. Specifying the subscript domain allows performing multiple checks alpar@1: for every\linebreak $n$-tuple in the domain set. In the latter case the alpar@1: logical expression may include dummy indices introduced in alpar@1: corresponding indexing expression. alpar@1: alpar@1: \subsection{Display statement} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \framebox[345pt][l]{ alpar@1: \parbox[c][24pt]{345pt}{ alpar@1: \hspace{6pt} {\tt display} {\it domain} {\tt:} {\it item} {\tt,} alpar@1: \dots {\tt,} {\it item} {\tt;} alpar@1: }} alpar@1: alpar@1: \setlength{\leftmargini}{60pt} alpar@1: alpar@1: \begin{description} alpar@1: \item[{\rm Where:}\hspace*{23pt}] {\it domain} is an optional indexing alpar@1: expression, which specifies a subscript domain of the check statement; alpar@1: \item[\hspace*{54pt}] {\it item}, \dots, {\it item} are items to be alpar@1: displayed. (The colon preceding the first item may be omitted.) alpar@1: \end{description} alpar@1: alpar@1: \noindent{\bf Examples} alpar@1: alpar@1: \begin{verbatim} alpar@1: display: 'x =', x, 'y =', y, 'z =', z; alpar@1: display sqrt(x ** 2 + y ** 2 + z ** 2); alpar@1: display{i in I, j in J}: i, j, a[i,j], b[i,j]; alpar@1: \end{verbatim} alpar@1: alpar@1: \newpage alpar@1: alpar@1: The display statement evaluates all items specified in the statement alpar@1: and writes their values to the terminal in plain text format. alpar@1: alpar@1: If a subscript domain is not specified, items are evaluated and then alpar@1: displayed only once. Specifying the subscript domain causes items to be alpar@1: evaluated and displayed for every $n$-tuple in the domain set. In the alpar@1: latter case items may include dummy indices introduced in corresponding alpar@1: indexing expression. alpar@1: alpar@1: An item to be displayed can be a model object (set, parameter, variable, alpar@1: constraint, objective) or an expression. alpar@1: alpar@1: If the item is a computable object (i.e. a set or parameter provided alpar@1: with the assign attribute), the object is evaluated over the entire alpar@1: domain and then its content (i.e. the content of the object array) is alpar@1: displayed. Otherwise, if the item is not a computable object, only its alpar@1: current content (i.e. members actually generated during the model alpar@1: evaluation) is displayed. alpar@1: alpar@1: If the item is an expression, the expression is evaluated and its alpar@1: resultant value is displayed. alpar@1: alpar@1: \subsection{Printf statement} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \framebox[345pt][l]{ alpar@1: \parbox[c][60pt]{345pt}{ alpar@1: \hspace{6pt} {\tt printf} {\it domain} {\tt:} {\it format} {\tt,} alpar@1: {\it expression} {\tt,} \dots {\tt,} {\it expression} {\tt;} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \hspace{6pt} {\tt printf} {\it domain} {\tt:} {\it format} {\tt,} alpar@1: {\it expression} {\tt,} \dots {\tt,} {\it expression} {\tt>} alpar@1: {\it filename} {\tt;} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \hspace{6pt} {\tt printf} {\it domain} {\tt:} {\it format} {\tt,} alpar@1: {\it expression} {\tt,} \dots {\tt,} {\it expression} {\tt>>} alpar@1: {\it filename} {\tt;} alpar@1: }} alpar@1: alpar@1: \setlength{\leftmargini}{60pt} alpar@1: alpar@1: \begin{description} alpar@1: \item[{\rm Where:}\hspace*{23pt}] {\it domain} is an optional indexing alpar@1: expression, which specifies a subscript domain of the printf statement; alpar@1: \item[\hspace*{54pt}] {\it format} is a symbolic expression whose value alpar@1: specifies a format control string. (The colon preceding the format alpar@1: expression may be omitted.) alpar@1: \item[\hspace*{54pt}] {\it expression}, \dots, {\it expression} are alpar@1: zero or more expressions whose values have to be formatted and printed. alpar@1: Each expression must be of numeric, symbolic, or logical type. alpar@1: \item[\hspace*{54pt}] {\it filename} is a symbolic expression whose alpar@1: value specifies a name of a text file, to which the output is alpar@1: redirected. The flag {\tt>} means creating a new empty file while the alpar@1: flag {\tt>>} means appending the output to an existing file. If no file alpar@1: name is specified, the output is written to the terminal. alpar@1: \end{description} alpar@1: alpar@1: \noindent{\bf Examples} alpar@1: alpar@1: \begin{verbatim} alpar@1: printf 'Hello, world!\n'; alpar@1: printf: "x = %.3f; y = %.3f; z = %.3f\n", alpar@1: x, y, z > "result.txt"; alpar@1: printf{i in I, j in J}: "flow from %s to %s is %d\n", alpar@1: i, j, x[i,j] >> result_file & ".txt"; alpar@1: \end{verbatim} alpar@1: alpar@1: \newpage alpar@1: alpar@1: \begin{verbatim} alpar@1: printf{i in I} 'total flow from %s is %g\n', alpar@1: i, sum{j in J} x[i,j]; alpar@1: printf{k in K} "x[%s] = " & (if x[k] < 0 then "?" else "%g"), alpar@1: k, x[k]; alpar@1: \end{verbatim} alpar@1: alpar@1: The printf statement is similar to the display statement, however, it alpar@1: allows formatting data to be written. alpar@1: alpar@1: If a subscript domain is not specified, the printf statement is alpar@1: executed only once. Specifying a subscript domain causes executing the alpar@1: printf statement for every $n$-tuple in the domain set. In the latter alpar@1: case the format and expression may include dummy indices introduced in alpar@1: corresponding indexing expression. alpar@1: alpar@1: The format control string is a value of the symbolic expression alpar@1: {\it format} specified in the printf statement. It is composed of zero alpar@1: or more directives as follows: ordinary characters (not {\tt\%}), which alpar@1: are copied unchanged to the output stream, and conversion alpar@1: specifications, each of which causes evaluating corresponding alpar@1: expression specified in the printf statement, formatting it, and alpar@1: writing its resultant value to the output stream. alpar@1: alpar@1: Conversion specifications that may be used in the format control string alpar@1: are the following: {\tt d}, {\tt i}, {\tt f}, {\tt F}, {\tt e}, {\tt E}, alpar@1: {\tt g}, {\tt G}, and {\tt s}. These specifications have the same alpar@1: syntax and semantics as in the C programming language. alpar@1: alpar@1: \subsection{For statement} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \framebox[345pt][l]{ alpar@1: \parbox[c][44pt]{345pt}{ alpar@1: \hspace{6pt} {\tt for} {\it domain} {\tt:} {\it statement} {\tt;} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \hspace{6pt} {\tt for} {\it domain} {\tt:} {\tt\{} {\it statement} alpar@1: \dots {\it statement} {\tt\}} {\tt;} alpar@1: }} alpar@1: alpar@1: \setlength{\leftmargini}{60pt} alpar@1: alpar@1: \begin{description} alpar@1: \item[{\rm Where:}\hspace*{23pt}] {\it domain} is an indexing alpar@1: expression which specifies a subscript domain of the for statement. alpar@1: (The colon following the indexing expression may be omitted.) alpar@1: \item[\hspace*{54pt}] {\it statement} is a statement, which should be alpar@1: executed under control of the for statement; alpar@1: \item[\hspace*{54pt}] {\it statement}, \dots, {\it statement} is a alpar@1: sequence of statements (enclosed in curly braces), which should be alpar@1: executed under control of the for statement. alpar@1: \end{description} alpar@1: alpar@1: \begin{description} alpar@1: \item[{\rm Note:}\hspace*{31pt}] Only the following statements can be alpar@1: used within the for statement: check, display, printf, and another for. alpar@1: \end{description} alpar@1: alpar@1: \noindent{\bf Examples} alpar@1: alpar@1: \begin{verbatim} alpar@1: for {(i,j) in E: i != j} alpar@1: { printf "flow from %s to %s is %g\n", i, j, x[i,j]; alpar@1: check x[i,j] >= 0; alpar@1: } alpar@1: \end{verbatim} alpar@1: alpar@1: \newpage alpar@1: alpar@1: \begin{verbatim} alpar@1: for {i in 1..n} alpar@1: { for {j in 1..n} printf " %s", if x[i,j] then "Q" else "."; alpar@1: printf("\n"); alpar@1: } alpar@1: for {1..72} printf("*"); alpar@1: \end{verbatim} alpar@1: alpar@1: The for statement causes a statement or a sequence of statements alpar@1: specified as part of the for statement to be executed for every alpar@1: $n$-tuple in the domain set. Thus, statements within the for statement alpar@1: may include dummy indices introduced in corresponding indexing alpar@1: expression. alpar@1: alpar@1: \subsection{Table statement} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \framebox[345pt][l]{ alpar@1: \parbox[c][68pt]{345pt}{ alpar@1: \hspace{6pt} {\tt table} {\it name} {\it alias} {\tt IN} {\it driver} alpar@1: {\it arg} \dots {\it arg} {\tt:} alpar@1: alpar@1: \hspace{6pt} {\tt\ \ \ \ \ } {\it set} {\tt<-} {\tt[} {\it fld} {\tt,} alpar@1: \dots {\tt,} {\it fld} {\tt]} {\tt,} {\it par} {\tt\textasciitilde} alpar@1: {\it fld} {\tt,} \dots {\tt,} {\it par} {\tt\textasciitilde} {\it fld} alpar@1: {\tt;} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \hspace{6pt} {\tt table} {\it name} {\it alias} {\it domain} {\tt OUT} alpar@1: {\it driver} {\it arg} \dots {\it arg} {\tt:} alpar@1: alpar@1: \hspace{6pt} {\tt\ \ \ \ \ } {\it expr} {\tt\textasciitilde} {\it fld} alpar@1: {\tt,} \dots {\tt,} {\it expr} {\tt\textasciitilde} {\it fld} {\tt;} alpar@1: }} alpar@1: alpar@1: \setlength{\leftmargini}{60pt} alpar@1: alpar@1: \begin{description} alpar@1: \item[{\rm Where:}\hspace*{23pt}] {\it name} is a symbolic name of the alpar@1: table; alpar@1: \item[\hspace*{54pt}] {\it alias} is an optional string literal, which alpar@1: specifies an alias of the table; alpar@1: \item[\hspace*{54pt}] {\it domain} is an indexing expression, which alpar@1: specifies a subscript domain of the (output) table; alpar@1: \item[\hspace*{54pt}] {\tt IN} means reading data from the input table; alpar@1: \item[\hspace*{54pt}] {\tt OUT} means writing data to the output table; alpar@1: \item[\hspace*{54pt}] {\it driver} is a symbolic expression, which alpar@1: specifies the driver used to access the table (for details see Section alpar@1: \ref{drivers}, page \pageref{drivers}); alpar@1: \item[\hspace*{54pt}] {\it arg} is an optional symbolic expression, alpar@1: which is an argument pass\-ed to the table driver. This symbolic alpar@1: expression must not include dummy indices specified in the domain; alpar@1: \item[\hspace*{54pt}] {\it set} is the name of an optional simple set alpar@1: called {\it control set}. It can be omitted along with the delimiter alpar@1: {\tt<-}; alpar@1: \item[\hspace*{54pt}] {\it fld} is a field name. Within square brackets alpar@1: at least one field should be specified. The field name following alpar@1: a parameter name or expression is optional and can be omitted along alpar@1: with the delimiter {\tt\textasciitilde}, in which case the name of alpar@1: corresponding model object is used as the field name; alpar@1: \item[\hspace*{54pt}] {\it par} is a symbolic name of a model parameter; alpar@1: \item[\hspace*{54pt}] {\it expr} is a numeric or symbolic expression. alpar@1: \end{description} alpar@1: alpar@1: \newpage alpar@1: alpar@1: \noindent{\bf Examples} alpar@1: alpar@1: \begin{verbatim} alpar@1: table data IN "CSV" "data.csv": alpar@1: S <- [FROM,TO], d~DISTANCE, c~COST; alpar@1: table result{(f,t) in S} OUT "CSV" "result.csv": alpar@1: f~FROM, t~TO, x[f,t]~FLOW; alpar@1: \end{verbatim} alpar@1: alpar@1: The table statement allows reading data from a table into model alpar@1: objects such as sets and (non-scalar) parameters as well as writing alpar@1: data from the model to a table. alpar@1: alpar@1: \subsubsection{Table structure} alpar@1: alpar@1: A {\it data table} is an (unordered) set of {\it records}, where each alpar@1: record consists of the same number of {\it fields}, and each field is alpar@1: provided with a unique symbolic name called the {\it field name}. For alpar@1: example: alpar@1: alpar@1: \bigskip alpar@1: alpar@1: \begin{tabular}{@{\hspace*{38mm}}c@{\hspace*{11mm}}c@{\hspace*{10mm}}c alpar@1: @{\hspace*{9mm}}c} alpar@1: First&Second&&Last\\ alpar@1: field&field&.\ \ .\ \ .&field\\ alpar@1: $\downarrow$&$\downarrow$&&$\downarrow$\\ alpar@1: \end{tabular} alpar@1: alpar@1: \begin{tabular}{ll@{}} alpar@1: Table header&$\rightarrow$\\ alpar@1: First record&$\rightarrow$\\ alpar@1: Second record&$\rightarrow$\\ alpar@1: \\ alpar@1: \hfil .\ \ .\ \ .\\ alpar@1: \\ alpar@1: Last record&$\rightarrow$\\ alpar@1: \end{tabular} alpar@1: \begin{tabular}{|l|l|c|c|} alpar@1: \hline alpar@1: {\tt FROM}&{\tt TO}&{\tt DISTANCE}&{\tt COST}\\ alpar@1: \hline alpar@1: {\tt Seattle} &{\tt New-York}&{\tt 2.5}&{\tt 0.12}\\ alpar@1: {\tt Seattle} &{\tt Chicago} &{\tt 1.7}&{\tt 0.08}\\ alpar@1: {\tt Seattle} &{\tt Topeka} &{\tt 1.8}&{\tt 0.09}\\ alpar@1: {\tt San-Diego}&{\tt New-York}&{\tt 2.5}&{\tt 0.15}\\ alpar@1: {\tt San-Diego}&{\tt Chicago} &{\tt 1.8}&{\tt 0.10}\\ alpar@1: {\tt San-Diego}&{\tt Topeka} &{\tt 1.4}&{\tt 0.07}\\ alpar@1: \hline alpar@1: \end{tabular} alpar@1: alpar@1: \subsubsection{Reading data from input table} alpar@1: alpar@1: The input table statement causes reading data from the specified table alpar@1: record by record. alpar@1: alpar@1: Once a next record has been read, numeric or symbolic values of fields, alpar@1: whose names are enclosed in square brackets in the table statement, are alpar@1: gathered into $n$-tuple, and if the control set is specified in the alpar@1: table statement, this $n$-tuple is added to it. Besides, a numeric or alpar@1: symbolic value of each field associated with a model parameter is alpar@1: assigned to the parameter member identified by subscripts, which are alpar@1: components of the $n$-tuple just read. alpar@1: alpar@1: For example, the following input table statement: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\hfil alpar@1: \verb|table data IN "...": S <- [FROM,TO], d~DISTANCE, c~COST;| alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent alpar@1: causes reading values of four fields named {\tt FROM}, {\tt TO}, alpar@1: {\tt DISTANCE}, and {\tt COST} from each record of the specified table. alpar@1: Values of fields {\tt FROM} and {\tt TO} give a pair $(f,t)$, which is alpar@1: added to the control set {\tt S}. The value of field {\tt DISTANCE} is alpar@1: assigned to parameter member ${\tt d}[f,t]$, and the value of field alpar@1: {\tt COST} is assigned to parameter member ${\tt c}[f,t]$. alpar@1: alpar@1: Note that the input table may contain extra fields whose names are not alpar@1: specified in the table statement, in which case values of these fields alpar@1: on reading the table are ignored. alpar@1: alpar@1: \subsubsection{Writing data to output table} alpar@1: alpar@1: The output table statement causes writing data to the specified table. alpar@1: Note that some drivers (namely, CSV and xBASE) destroy the output table alpar@1: before writing data, i.e. delete all its existing records. alpar@1: alpar@1: Each $n$-tuple in the specified domain set generates one record written alpar@1: to the output table. Values of fields are numeric or symbolic values of alpar@1: corresponding expressions specified in the table statement. These alpar@1: expressions are evaluated for each $n$-tuple in the domain set and, alpar@1: thus, may include dummy indices introduced in the corresponding indexing alpar@1: expression. alpar@1: alpar@1: For example, the following output table statement: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent alpar@1: \verb| table result{(f,t) in S} OUT "...": f~FROM, t~TO, x[f,t]~FLOW;| alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent alpar@1: causes writing records, by one record for each pair $(f,t)$ in set alpar@1: {\tt S}, to the output table, where each record consists of three alpar@1: fields named {\tt FROM}, {\tt TO}, and {\tt FLOW}. The values written alpar@1: to fields {\tt FROM} and {\tt TO} are current values of dummy indices alpar@1: {\tt f} and {\tt t}, and the value written to field {\tt FLOW} is alpar@1: a value of member ${\tt x}[f,t]$ of corresponding subscripted parameter alpar@1: or variable. alpar@1: alpar@1: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% alpar@1: alpar@1: \newpage alpar@1: alpar@1: \section{Model data} alpar@1: alpar@1: {\it Model data} include elemental sets, which are ``values'' of model alpar@1: sets, and numeric and symbolic values of model parameters. alpar@1: alpar@1: In MathProg there are two different ways to saturate model sets and alpar@1: parameters with data. One way is simply providing necessary data using alpar@1: the assign attribute. However, in many cases it is more practical to alpar@1: separate the model itself and particular data needed for the model. For alpar@1: the latter reason in MathProg there is another way, when the model alpar@1: description is divided into two parts: model section and data section. alpar@1: alpar@1: A {\it model section} is a main part of the model description that alpar@1: contains declarations of all model objects and is common for all alpar@1: problems based on that model. alpar@1: alpar@1: A {\it data section} is an optional part of the model description that alpar@1: contains model data specific for a particular problem. alpar@1: alpar@1: In MathProg model and data sections can be placed either in one text alpar@1: file or in two separate text files. alpar@1: alpar@1: 1. If both model and data sections are placed in one file, the file is alpar@1: composed as follows: alpar@1: alpar@1: \bigskip alpar@1: alpar@1: \noindent\hfil alpar@1: \framebox{\begin{tabular}{l} alpar@1: {\it statement}{\tt;}\\ alpar@1: {\it statement}{\tt;}\\ alpar@1: \hfil.\ \ .\ \ .\\ alpar@1: {\it statement}{\tt;}\\ alpar@1: {\tt data;}\\ alpar@1: {\it data block}{\tt;}\\ alpar@1: {\it data block}{\tt;}\\ alpar@1: \hfil.\ \ .\ \ .\\ alpar@1: {\it data block}{\tt;}\\ alpar@1: {\tt end;} alpar@1: \end{tabular}} alpar@1: alpar@1: \bigskip alpar@1: alpar@1: 2. If the model and data sections are placed in two separate files, the alpar@1: files are composed as follows: alpar@1: alpar@1: \bigskip alpar@1: alpar@1: \noindent\hfil alpar@1: \begin{tabular}{@{}c@{}} alpar@1: \framebox{\begin{tabular}{l} alpar@1: {\it statement}{\tt;}\\ alpar@1: {\it statement}{\tt;}\\ alpar@1: \hfil.\ \ .\ \ .\\ alpar@1: {\it statement}{\tt;}\\ alpar@1: {\tt end;}\\ alpar@1: \end{tabular}}\\ alpar@1: \\\\Model file\\ alpar@1: \end{tabular} alpar@1: \hspace{32pt} alpar@1: \begin{tabular}{@{}c@{}} alpar@1: \framebox{\begin{tabular}{l} alpar@1: {\tt data;}\\ alpar@1: {\it data block}{\tt;}\\ alpar@1: {\it data block}{\tt;}\\ alpar@1: \hfil.\ \ .\ \ .\\ alpar@1: {\it data block}{\tt;}\\ alpar@1: {\tt end;}\\ alpar@1: \end{tabular}}\\ alpar@1: \\Data file\\ alpar@1: \end{tabular} alpar@1: alpar@1: \bigskip alpar@1: alpar@1: \begin{description} alpar@1: \item[{\rm Note:}\hspace*{31pt}] If the data section is placed in a alpar@1: separate file, the keyword {\tt data} is optional and may be omitted alpar@1: along with the semicolon that follows it. alpar@1: \end{description} alpar@1: alpar@1: \subsection{Coding data section} alpar@1: alpar@1: The {\it data section} is a sequence of data blocks in various formats, alpar@1: which are discussed in following subsections. The order, in which data alpar@1: blocks follow in the data section, may be arbitrary, not necessarily alpar@1: the same, in which corresponding model objects follow in the model alpar@1: section. alpar@1: alpar@1: The rules of coding the data section are commonly the same as the rules alpar@1: of coding the model description (see Subsection \ref{coding}, page alpar@1: \pageref{coding}), i.e. data blocks are composed from basic lexical alpar@1: units such as symbolic names, numeric and string literals, keywords, alpar@1: delimiters, and comments. However, for the sake of convenience and alpar@1: improving readability there is one deviation from the common rule: if alpar@1: a string literal consists of only alphanumeric characters (including alpar@1: the underscore character), the signs {\tt+} and {\tt-}, and/or the alpar@1: decimal point, it may be coded without bordering by (single or double) alpar@1: quotes. alpar@1: alpar@1: All numeric and symbolic material provided in the data section is coded alpar@1: in the form of numbers and symbols, i.e. unlike the model section alpar@1: no expressions are allowed in the data section. Nevertheless, the signs alpar@1: {\tt+} and {\tt-} can precede numeric literals to allow coding signed alpar@1: numeric quantities, in which case there must be no white-space alpar@1: characters between the sign and following numeric literal (if there is alpar@1: at least one white-space, the sign and following numeric literal are alpar@1: recognized as two different lexical units). alpar@1: alpar@1: \subsection{Set data block} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \framebox[345pt][l]{ alpar@1: \parbox[c][44pt]{345pt}{ alpar@1: \hspace{6pt} {\tt set} {\it name} {\tt,} {\it record} {\tt,} \dots alpar@1: {\tt,} {\it record} {\tt;} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \hspace{6pt} {\tt set} {\it name} {\tt[} {\it symbol} {\tt,} \dots alpar@1: {\tt,} {\it symbol} {\tt]} {\tt,} {\it record} {\tt,} \dots {\tt,} alpar@1: {\it record} {\tt;} alpar@1: }} alpar@1: alpar@1: \setlength{\leftmargini}{60pt} alpar@1: alpar@1: \begin{description} alpar@1: \item[{\rm Where:}\hspace*{23pt}] {\it name} is a symbolic name of the alpar@1: set; alpar@1: \item[\hspace*{54pt}] {\it symbol}, \dots, {\it symbol} are subscripts, alpar@1: which specify a particular member of the set (if the set is an array, alpar@1: i.e. a set of sets); alpar@1: \item[\hspace*{54pt}] {\it record}, \dots, {\it record} are data alpar@1: records. alpar@1: \end{description} alpar@1: alpar@1: \begin{description} alpar@1: \item[{\rm Note:}\hspace*{31pt}] Commae preceding data records may be alpar@1: omitted. alpar@1: \end{description} alpar@1: alpar@1: \noindent Data records: alpar@1: alpar@1: \begin{description} alpar@1: \item[{\tt :=}\hspace*{45pt}] is a non-significant data record, which alpar@1: may be used freely to improve readability; alpar@1: \item[{\tt(} {\it slice} {\tt)}\hspace*{18.5pt}] specifies a slice; alpar@1: \item[{\it simple-data}\hspace*{5.5pt}] specifies set data in the alpar@1: simple format; alpar@1: \item[{\tt:} {\it matrix-data}]\hspace*{0pt}\\ alpar@1: specifies set data in the matrix format; alpar@1: \item[{\tt(tr)} {\tt:} {\it matrix-data}]\hspace*{0pt}\\ alpar@1: specifies set data in the transposed matrix format. (In this case the alpar@1: colon following the keyword {\tt(tr)} may be omitted.) alpar@1: \end{description} alpar@1: alpar@1: \noindent{\bf Examples} alpar@1: alpar@1: \begin{verbatim} alpar@1: set month := Jan Feb Mar Apr May Jun; alpar@1: set month "Jan", "Feb", "Mar", "Apr", "May", "Jun"; alpar@1: set A[3,Mar] := (1,2) (2,3) (4,2) (3,1) (2,2) (4,4) (3,4); alpar@1: set A[3,'Mar'] := 1 2 2 3 4 2 3 1 2 2 4 4 2 4; alpar@1: set A[3,'Mar'] : 1 2 3 4 := alpar@1: 1 - + - - alpar@1: 2 - + + - alpar@1: 3 + - - + alpar@1: 4 - + - + ; alpar@1: set B := (1,2,3) (1,3,2) (2,3,1) (2,1,3) (1,2,2) (1,1,1) (2,1,1); alpar@1: set B := (*,*,*) 1 2 3, 1 3 2, 2 3 1, 2 1 3, 1 2 2, 1 1 1, 2 1 1; alpar@1: set B := (1,*,2) 3 2 (2,*,1) 3 1 (1,2,3) (2,1,3) (1,1,1); alpar@1: set B := (1,*,*) : 1 2 3 := alpar@1: 1 + - - alpar@1: 2 - + + alpar@1: 3 - + - alpar@1: (2,*,*) : 1 2 3 := alpar@1: 1 + - + alpar@1: 2 - - - alpar@1: 3 + - - ; alpar@1: \end{verbatim} alpar@1: alpar@1: \noindent(In these examples {\tt month} is a simple set of singlets, alpar@1: {\tt A} is a 2-dimensional array of doublets, and {\tt B} is a simple alpar@1: set of triplets. Data blocks for the same set are equivalent in the alpar@1: sense that they specify the same data in different formats.) alpar@1: alpar@1: \medskip alpar@1: alpar@1: The {\it set data block} is used to specify a complete elemental set, alpar@1: which is assigned to a set (if it is a simple set) or one of its alpar@1: members (if the set is an array of sets).\footnote{There is another way alpar@1: to specify data for a simple set along with data for parameters. This alpar@1: feature is discussed in the next subsection.} alpar@1: alpar@1: Data blocks can be specified only for non-computable sets, i.e. for alpar@1: sets, which have no assign ({\tt:=}) attribute in the corresponding set alpar@1: statements. alpar@1: alpar@1: If the set is a simple set, only its symbolic name should be specified alpar@1: in the header of the data block. Otherwise, if the set is a alpar@1: $n$-dimensional array, its symbolic name should be provided with a alpar@1: complete list of subscripts separated by commae and enclosed in square alpar@1: brackets to specify a particular member of the set array. The number of alpar@1: subscripts must be the same as the dimension of the set array, where alpar@1: each subscript must be a number or symbol. alpar@1: alpar@1: An elemental set defined in the set data block is coded as a sequence alpar@1: of data records described below.\footnote{{\it Data record} is simply a alpar@1: technical term. It does not mean that data records have any special alpar@1: formatting.} alpar@1: alpar@1: \newpage alpar@1: alpar@1: \subsubsection{Assign data record} alpar@1: alpar@1: The {\it assign} ({\tt:=}) {\it data record} is a non-signficant alpar@1: element. It may be used for improving readability of data blocks. alpar@1: alpar@1: \subsubsection{Slice data record} alpar@1: alpar@1: The {\it slice data record} is a control record, which specifies a alpar@1: {\it slice} of the elemental set defined in the data block. It has the alpar@1: following syntactic form: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\hfil alpar@1: {\tt(} $s_1$ {\tt,} $s_2$ {\tt,} \dots {\tt,} $s_n$ {\tt)} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent where $s_1$, $s_2$, \dots, $s_n$ are components of the slice. alpar@1: alpar@1: Each component of the slice can be a number or symbol or the asterisk alpar@1: ({\tt*}). The number of components in the slice must be the same as the alpar@1: dimension of $n$-tuples in the elemental set to be defined. For alpar@1: instance, if the elemental set contains 4-tuples (quadruplets), the alpar@1: slice must have four components. The number of asterisks in the slice alpar@1: is called the {\it slice dimension}. alpar@1: alpar@1: The effect of using slices is the following. If a $m$-dimensional slice alpar@1: (i.e. a slice having $m$ asterisks) is specified in the data block, all alpar@1: subsequent data records must specify tuples of the dimension $m$. alpar@1: Whenever a $m$-tuple is encountered, each asterisk in the slice is alpar@1: replaced by corresponding components of the $m$-tuple that gives the alpar@1: resultant $n$-tuple, which is included in the elemental set to be alpar@1: defined. For example, if the slice $(a,*,1,2,*)$ is in effect, and alpar@1: 2-tuple $(3,b)$ is encountered in a subsequent data record, the alpar@1: resultant 5-tuple included in the elemental set is $(a,3,1,2,b)$. alpar@1: alpar@1: The slice having no asterisks itself defines a complete $n$-tuple, alpar@1: which is included in the elemental set. alpar@1: alpar@1: Being once specified the slice effects until either a new slice or the alpar@1: end of data block is encountered. Note that if no slice is specified in alpar@1: the data block, one, components of which are all asterisks, is assumed. alpar@1: alpar@1: \subsubsection{Simple data record} alpar@1: alpar@1: The {\it simple data record} defines one $n$-tuple in a simple format alpar@1: and has the following syntactic form: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\hfil alpar@1: $t_1$ {\tt,} $t_2$ {\tt,} \dots {\tt,} $t_n$ alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent where $t_1$, $t_2$, \dots, $t_n$ are components of the alpar@1: $n$-tuple. Each component can be a number or symbol. Commae between alpar@1: components are optional and may be omitted. alpar@1: alpar@1: \subsubsection{Matrix data record} alpar@1: alpar@1: The {\it matrix data record} defines several 2-tuples (doublets) in alpar@1: a matrix format and has the following syntactic form: alpar@1: alpar@1: \newpage alpar@1: alpar@1: $$\begin{array}{cccccc} alpar@1: \mbox{{\tt:}}&c_1&c_2&\dots&c_n&\mbox{{\tt:=}}\\ alpar@1: r_1&a_{11}&a_{12}&\dots&a_{1n}&\\ alpar@1: r_2&a_{21}&a_{22}&\dots&a_{2n}&\\ alpar@1: \multicolumn{5}{c}{.\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .}&\\ alpar@1: r_m&a_{m1}&a_{m2}&\dots&a_{mn}&\\ alpar@1: \end{array}$$ alpar@1: where $r_1$, $r_2$, \dots, $r_m$ are numbers and/or symbols alpar@1: corresponding to rows of the matrix; $c_1$, $c_2$, \dots, $c_n$ are alpar@1: numbers and/or symbols corresponding to columns of the matrix, $a_{11}$, alpar@1: $a_{12}$, \dots, $a_{mn}$ are matrix elements, which can be either alpar@1: {\tt+} or {\tt-}. (In this data record the delimiter {\tt:} preceding alpar@1: the column list and the delimiter {\tt:=} following the column list alpar@1: cannot be omitted.) alpar@1: alpar@1: Each element $a_{ij}$ of the matrix data block (where $1\leq i\leq m$, alpar@1: $1\leq j\leq n$) corresponds to 2-tuple $(r_i,c_j)$. If $a_{ij}$ is the alpar@1: plus sign ({\tt+}), that 2-tuple (or a longer $n$-tuple, if a slice is alpar@1: used) is included in the elemental set. Otherwise, if $a_{ij}$ is the alpar@1: minus sign ({\tt-}), that 2-tuple is not included in the elemental set. alpar@1: alpar@1: Since the matrix data record defines 2-tuples, either the elemental set alpar@1: must consist of 2-tuples or the slice currently used must be alpar@1: 2-dimensional. alpar@1: alpar@1: \subsubsection{Transposed matrix data record} alpar@1: alpar@1: The {\it transposed matrix data record} has the following syntactic alpar@1: form: alpar@1: $$\begin{array}{cccccc} alpar@1: \mbox{{\tt(tr) :}}&c_1&c_2&\dots&c_n&\mbox{{\tt:=}}\\ alpar@1: r_1&a_{11}&a_{12}&\dots&a_{1n}&\\ alpar@1: r_2&a_{21}&a_{22}&\dots&a_{2n}&\\ alpar@1: \multicolumn{5}{c}{.\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .}&\\ alpar@1: r_m&a_{m1}&a_{m2}&\dots&a_{mn}&\\ alpar@1: \end{array}$$ alpar@1: (In this case the delimiter {\tt:} following the keyword {\tt(tr)} is alpar@1: optional and may be omitted.) alpar@1: alpar@1: This data record is completely analogous to the matrix data record (see alpar@1: above) with only exception that in this case each element $a_{ij}$ of alpar@1: the matrix corresponds to 2-tuple $(c_j,r_i)$ rather than $(r_i,c_j)$. alpar@1: alpar@1: Being once specified the {\tt(tr)} indicator affects all subsequent alpar@1: data records until either a slice or the end of data block is alpar@1: encountered. alpar@1: alpar@1: \subsection{Parameter data block} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \framebox[345pt][l]{ alpar@1: \parbox[c][80pt]{345pt}{ alpar@1: \hspace{6pt} {\tt param} {\it name} {\tt,} {\it record} {\tt,} \dots alpar@1: {\tt,} {\it record} {\tt;} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \hspace{6pt} {\tt param} {\it name} {\tt default} {\it value} {\tt,} alpar@1: {\it record} {\tt,} \dots {\tt,} {\it record} {\tt;} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \hspace{6pt} {\tt param} {\tt:} {\it tabbing-data} {\tt;} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \hspace{6pt} {\tt param} {\tt default} {\it value} {\tt:} alpar@1: {\it tabbing-data} {\tt;} alpar@1: }} alpar@1: alpar@1: \newpage alpar@1: alpar@1: \setlength{\leftmargini}{60pt} alpar@1: alpar@1: \begin{description} alpar@1: \item[{\rm Where:}\hspace*{23pt}] {\it name} is a symbolic name of the alpar@1: parameter; alpar@1: \item[\hspace*{54pt}] {\it value} is an optional default value of the alpar@1: parameter; alpar@1: \item[\hspace*{54pt}] {\it record}, \dots, {\it record} are data alpar@1: records; alpar@1: \item[\hspace*{54pt}] {\it tabbing-data} specifies parameter data in alpar@1: the tabbing format. alpar@1: \end{description} alpar@1: alpar@1: \begin{description} alpar@1: \item[{\rm Note:}\hspace*{31pt}] Commae preceding data records may be alpar@1: omitted. alpar@1: \end{description} alpar@1: alpar@1: \noindent Data records: alpar@1: alpar@1: \begin{description} alpar@1: \item[{\tt :=}\hspace*{45pt}] is a non-significant data record, which alpar@1: may be used freely to improve readability; alpar@1: \item[{\tt[} {\it slice} {\tt]}\hspace*{18.5pt}] specifies a slice; alpar@1: \item[{\it plain-data}\hspace*{11pt}] specifies parameter data in the alpar@1: plain format; alpar@1: \item[{\tt:} {\it tabular-data}]\hspace*{0pt}\\ alpar@1: specifies parameter data in the tabular format; alpar@1: \item[{\tt(tr)} {\tt:} {\it tabular-data}]\hspace*{0pt}\\ alpar@1: specifies set data in the transposed tabular format. (In this case the alpar@1: colon following the keyword {\tt(tr)} may be omitted.) alpar@1: \end{description} alpar@1: alpar@1: \noindent{\bf Examples} alpar@1: alpar@1: \begin{verbatim} alpar@1: param T := 4; alpar@1: param month := 1 'Jan' 2 'Feb' 3 'Mar' 4 'Apr' 5 'May'; alpar@1: param month := [1] Jan, [2] Feb, [3] Mar, [4] Apr, [5] May; alpar@1: param day := [Sun] 0, [Mon] 1, [Tue] 2, [Wed] 3, [Thu] 4, alpar@1: [Fri] 5, [Sat] 6; alpar@1: param init_stock := iron 7.32 nickel 35.8; alpar@1: param init_stock [*] iron 7.32, nickel 35.8; alpar@1: param cost [iron] .025 [nickel] .03; alpar@1: param value := iron -.1, nickel .02; alpar@1: param : init_stock cost value := alpar@1: iron 7.32 .025 -.1 alpar@1: nickel 35.8 .03 .02 ; alpar@1: param : raw : init_stock cost value := alpar@1: iron 7.32 .025 -.1 alpar@1: nickel 35.8 .03 .02 ; alpar@1: param demand default 0 (tr) alpar@1: : FRA DET LAN WIN STL FRE LAF := alpar@1: bands 300 . 100 75 . 225 250 alpar@1: coils 500 750 400 250 . 850 500 alpar@1: plate 100 . . 50 200 . 250 ; alpar@1: \end{verbatim} alpar@1: alpar@1: \newpage alpar@1: alpar@1: \begin{verbatim} alpar@1: param trans_cost := alpar@1: [*,*,bands]: FRA DET LAN WIN STL FRE LAF := alpar@1: GARY 30 10 8 10 11 71 6 alpar@1: CLEV 22 7 10 7 21 82 13 alpar@1: PITT 19 11 12 10 25 83 15 alpar@1: [*,*,coils]: FRA DET LAN WIN STL FRE LAF := alpar@1: GARY 39 14 11 14 16 82 8 alpar@1: CLEV 27 9 12 9 26 95 17 alpar@1: PITT 24 14 17 13 28 99 20 alpar@1: [*,*,plate]: FRA DET LAN WIN STL FRE LAF := alpar@1: GARY 41 15 12 16 17 86 8 alpar@1: CLEV 29 9 13 9 28 99 18 alpar@1: PITT 26 14 17 13 31 104 20 ; alpar@1: \end{verbatim} alpar@1: alpar@1: The {\it parameter data block} is used to specify complete data for a alpar@1: parameter (or parameters, if data are specified in the tabbing format). alpar@1: alpar@1: Data blocks can be specified only for non-computable parameters, i.e. alpar@1: for parameters, which have no assign ({\tt:=}) attribute in the alpar@1: corresponding parameter statements. alpar@1: alpar@1: Data defined in the parameter data block are coded as a sequence of alpar@1: data records described below. Additionally the data block can be alpar@1: provided with the optional {\tt default} attribute, which specifies a alpar@1: default numeric or symbolic value of the parameter (parameters). This alpar@1: default value is assigned to the parameter or its members, if alpar@1: no appropriate value is defined in the parameter data block. The alpar@1: {\tt default} attribute cannot be used, if it is already specified in alpar@1: the corresponding parameter statement. alpar@1: alpar@1: \subsubsection{Assign data record} alpar@1: alpar@1: The {\it assign} ({\tt:=}) {\it data record} is a non-signficant alpar@1: element. It may be used for improving readability of data blocks. alpar@1: alpar@1: \subsubsection{Slice data record} alpar@1: alpar@1: The {\it slice data record} is a control record, which specifies a alpar@1: {\it slice} of the parameter array. It has the following syntactic form: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\hfil alpar@1: {\tt[} $s_1$ {\tt,} $s_2$ {\tt,} \dots {\tt,} $s_n$ {\tt]} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent where $s_1$, $s_2$, \dots, $s_n$ are components of the slice. alpar@1: alpar@1: Each component of the slice can be a number or symbol or the asterisk alpar@1: ({\tt*}). The number of components in the slice must be the same as the alpar@1: dimension of the parameter. For instance, if the parameter is a alpar@1: 4-dimensional array, the slice must have four components. The number of alpar@1: asterisks in the slice is called the {\it slice dimension}. alpar@1: alpar@1: The effect of using slices is the following. If a $m$-dimensional slice alpar@1: (i.e. a slice having $m$ asterisks) is specified in the data block, all alpar@1: subsequent data records must specify subscripts of the parameter alpar@1: members as if the parameter were $m$-dimensional, not $n$-dimensional. alpar@1: alpar@1: Whenever $m$ subscripts are encountered, each asterisk in the slice is alpar@1: replaced by corresponding subscript that gives $n$ subscripts, which alpar@1: define the actual parameter member. For example, if the slice alpar@1: $[a,*,1,2,*]$ is in effect, and subscripts 3 and $b$ are encountered in alpar@1: a subsequent data record, the complete subscript list used to choose a alpar@1: parameter member is $[a,3,1,2,b]$. alpar@1: alpar@1: It is allowed to specify a slice having no asterisks. Such slice itself alpar@1: defines a complete subscript list, in which case the next data record alpar@1: should define only a single value of corresponding parameter member. alpar@1: alpar@1: Being once specified the slice effects until either a new slice or the alpar@1: end of data block is encountered. Note that if no slice is specified in alpar@1: the data block, one, components of which are all asterisks, is assumed. alpar@1: alpar@1: \subsubsection{Plain data record} alpar@1: alpar@1: The {\it plain data record} defines a subscript list and a single value alpar@1: in the plain format. This record has the following syntactic form: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent\hfil alpar@1: $t_1$ {\tt,} $t_2$ {\tt,} \dots {\tt,} $t_n$ {\tt,} $v$ alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent where $t_1$, $t_2$, \dots, $t_n$ are subscripts, and $v$ is a alpar@1: value. Each subscript as well as the value can be a number or symbol. alpar@1: Commae following subscripts are optional and may be omitted. alpar@1: alpar@1: In case of 0-dimensional parameter or slice the plain data record has alpar@1: no subscripts and consists of a single value only. alpar@1: alpar@1: \subsubsection{Tabular data record} alpar@1: alpar@1: The {\it tabular data record} defines several values, where each value alpar@1: is provided with two subscripts. This record has the following alpar@1: syntactic form: alpar@1: $$\begin{array}{cccccc} alpar@1: \mbox{{\tt:}}&c_1&c_2&\dots&c_n&\mbox{{\tt:=}}\\ alpar@1: r_1&a_{11}&a_{12}&\dots&a_{1n}&\\ alpar@1: r_2&a_{21}&a_{22}&\dots&a_{2n}&\\ alpar@1: \multicolumn{5}{c}{.\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .}&\\ alpar@1: r_m&a_{m1}&a_{m2}&\dots&a_{mn}&\\ alpar@1: \end{array}$$ alpar@1: where $r_1$, $r_2$, \dots, $r_m$ are numbers and/or symbols alpar@1: corresponding to rows of the table; $c_1$, $c_2$, \dots, $c_n$ are alpar@1: numbers and/or symbols corresponding to columns of the table, $a_{11}$, alpar@1: $a_{12}$, \dots, $a_{mn}$ are table elements. Each element can be a alpar@1: number or symbol or the single decimal point ({\tt.}). (In this data alpar@1: record the delimiter {\tt:} preceding the column list and the delimiter alpar@1: {\tt:=} following the column list cannot be omitted.) alpar@1: alpar@1: Each element $a_{ij}$ of the tabular data block ($1\leq i\leq m$, alpar@1: $1\leq j\leq n$) defines two subscripts, where the first subscript is alpar@1: $r_i$, and the second one is $c_j$. These subscripts are used in alpar@1: conjunction with the current slice to form the complete subscript list alpar@1: that identifies a particular member of the parameter array. If $a_{ij}$ alpar@1: is a number or symbol, this value is assigned to the parameter member. alpar@1: However, if $a_{ij}$ is the single decimal point, the member is alpar@1: assigned a default value specified either in the parameter data block alpar@1: or in the parameter statement, or, if no default value is specified, alpar@1: the member remains undefined. alpar@1: alpar@1: Since the tabular data record provides two subscripts for each value, alpar@1: either the parameter or the slice currently used must be 2-dimensional. alpar@1: alpar@1: \subsubsection{Transposed tabular data record} alpar@1: alpar@1: The {\it transposed tabular data record} has the following syntactic alpar@1: form: alpar@1: $$\begin{array}{cccccc} alpar@1: \mbox{{\tt(tr) :}}&c_1&c_2&\dots&c_n&\mbox{{\tt:=}}\\ alpar@1: r_1&a_{11}&a_{12}&\dots&a_{1n}&\\ alpar@1: r_2&a_{21}&a_{22}&\dots&a_{2n}&\\ alpar@1: \multicolumn{5}{c}{.\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .}&\\ alpar@1: r_m&a_{m1}&a_{m2}&\dots&a_{mn}&\\ alpar@1: \end{array}$$ alpar@1: (In this case the delimiter {\tt:} following the keyword {\tt(tr)} is alpar@1: optional and may be omitted.) alpar@1: alpar@1: This data record is completely analogous to the tabular data record alpar@1: (see above) with only exception that the first subscript defined by alpar@1: element $a_{ij}$ is $c_j$ while the second one is $r_i$. alpar@1: alpar@1: Being once specified the {\tt(tr)} indicator affects all subsequent alpar@1: data records until either a slice or the end of data block is alpar@1: encountered. alpar@1: alpar@1: \subsubsection{Tabbing data format} alpar@1: alpar@1: The parameter data block in the {\it tabbing format} has the following alpar@1: syntactic form: alpar@1: $$\begin{array}{p{12pt}@{\ }l@{\ }c@{\ }l@{\ }c@{\ }l@{\ }r@{\ }l@{\ }c alpar@1: @{\ }l@{\ }c@{\ }l@{\ }l} alpar@1: \multicolumn{7}{@{}c@{}}{\mbox{\tt param}\ \mbox{\tt default}\ \mbox alpar@1: {\it value}\ \mbox{\tt:}\ \mbox{\it s}\ \mbox{\tt:}}& alpar@1: p_1&\mbox{\tt,}&p_2&\mbox{\tt,} \dots \mbox{\tt,}&p_k&\mbox{\tt:=}\\ alpar@1: &t_{11}&\mbox{\tt,}&t_{12}&\mbox{\tt,} \dots \mbox{\tt,}&t_{1n}& alpar@1: \mbox{\tt,}&a_{11}&\mbox{\tt,}&a_{12}&\mbox{\tt,} \dots \mbox{\tt,}& alpar@1: a_{1k}\\ alpar@1: &t_{21}&\mbox{\tt,}&t_{22}&\mbox{\tt,} \dots \mbox{\tt,}&t_{2n}& alpar@1: \mbox{\tt,}&a_{21}&\mbox{\tt,}&a_{22}&\mbox{\tt,} \dots \mbox{\tt,}& alpar@1: a_{2k}\\ alpar@1: \multicolumn{13}{c} alpar@1: {.\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .}\\ alpar@1: &t_{m1}&\mbox{\tt,}&t_{m2}&\mbox{\tt,} \dots \mbox{\tt,}&t_{mn}& alpar@1: \mbox{\tt,}&a_{m1}&\mbox{\tt,}&a_{m2}&\mbox{\tt,} \dots \mbox{\tt,}& alpar@1: a_{mk}&\mbox{\tt;}\\ alpar@1: \end{array}$$ alpar@1: alpar@1: {\it Notes:} alpar@1: alpar@1: 1. The keyword {\tt default} may be omitted along with a value alpar@1: following it. alpar@1: alpar@1: 2. Symbolic name {\tt s} may be omitted along with the colon following alpar@1: it. alpar@1: alpar@1: 3. All comae are optional and may be omitted. alpar@1: alpar@1: \medskip alpar@1: alpar@1: The data block in the tabbing format shown above is exactly equivalent alpar@1: to the following data blocks for $j=1,2,\dots,k$: alpar@1: alpar@1: \medskip alpar@1: alpar@1: {\tt set} {\it s} {\tt:=} alpar@1: {\tt(}$t_{11}${\tt,}$t_{12}${\tt,}\dots{\tt,}$t_{1n}${\tt)} alpar@1: {\tt(}$t_{21}${\tt,}$t_{22}${\tt,}\dots{\tt,}$t_{2n}${\tt)} \dots alpar@1: {\tt(}$t_{m1}${\tt,}$t_{m2}${\tt,}\dots{\tt,}$t_{mn}${\tt)} {\tt;} alpar@1: alpar@1: {\tt param} $p_j$ {\tt default} {\it value} {\tt:=} alpar@1: alpar@1: $\!${\tt[}$t_{11}${\tt,}$t_{12}${\tt,}\dots{\tt,}$t_{1n}${\tt]} alpar@1: $a_{1j}$ alpar@1: {\tt[}$t_{21}${\tt,}$t_{22}${\tt,}\dots{\tt,}$t_{2n}${\tt]} $a_{2j}$ alpar@1: \dots alpar@1: {\tt[}$t_{m1}${\tt,}$t_{m2}${\tt,}\dots{\tt,}$t_{mn}${\tt]} $a_{mj}$ alpar@1: {\tt;} alpar@1: alpar@1: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% alpar@1: alpar@1: \appendix alpar@1: alpar@1: \newpage alpar@1: alpar@1: \section{Using suffixes} alpar@1: alpar@1: Suffixes can be used to retrieve additional values associated with alpar@1: model variables, constraints, and objectives. alpar@1: alpar@1: A {\it suffix} consists of a period ({\tt.}) followed by a non-reserved alpar@1: keyword. For example, if {\tt x} is a two-dimensional variable, alpar@1: {\tt x[i,j].lb} is a numeric value equal to the lower bound of alpar@1: elemental variable {\tt x[i,j]}, which (value) can be used everywhere alpar@1: in expressions like a numeric parameter. alpar@1: alpar@1: For model variables suffixes have the following meaning: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{96pt}p{222pt}@{}} alpar@1: {\tt.lb}&lower bound\\ alpar@1: {\tt.ub}&upper bound\\ alpar@1: {\tt.status}&status in the solution:\\ alpar@1: &0 --- undefined\\ alpar@1: &1 --- basic\\ alpar@1: &2 --- non-basic on lower bound\\ alpar@1: &3 --- non-basic on upper bound\\ alpar@1: &4 --- non-basic free (unbounded) variable\\ alpar@1: &5 --- non-basic fixed variable\\ alpar@1: {\tt.val}&primal value in the solution\\ alpar@1: {\tt.dual}&dual value (reduced cost) in the solution\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: For model constraints and objectives suffixes have the following alpar@1: meaning: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{96pt}p{222pt}@{}} alpar@1: {\tt.lb}&lower bound of the linear form\\ alpar@1: {\tt.ub}&upper bound of the linear form\\ alpar@1: {\tt.status}&status in the solution:\\ alpar@1: &0 --- undefined\\ alpar@1: &1 --- non-active\\ alpar@1: &2 --- active on lower bound\\ alpar@1: &3 --- active on upper bound\\ alpar@1: &4 --- active free (unbounded) row\\ alpar@1: &5 --- active equality constraint\\ alpar@1: {\tt.val}&primal value of the linear form in the solution\\ alpar@1: {\tt.dual}&dual value (reduced cost) of the linear form in the alpar@1: solution\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: Note that suffixes {\tt.status}, {\tt.val}, and {\tt.dual} can be used alpar@1: only below the solve statement. alpar@1: alpar@1: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% alpar@1: alpar@1: \newpage alpar@1: alpar@1: \section{Date and time functions} alpar@1: alpar@1: \noindent\hfil alpar@1: by Andrew Makhorin \verb|| alpar@1: alpar@1: \noindent\hfil alpar@1: and Heinrich Schuchardt \verb|| alpar@1: alpar@1: \subsection{Obtaining current calendar time} alpar@1: \label{gmtime} alpar@1: alpar@1: To obtain the current calendar time in MathProg there exists the alpar@1: function {\tt gmtime}. It has no arguments and returns the number of alpar@1: seconds elapsed since 00:00:00 on January 1, 1970, Coordinated alpar@1: Universal Time (UTC). For example: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \verb| param utc := gmtime();| alpar@1: alpar@1: \medskip alpar@1: alpar@1: MathProg has no function to convert UTC time returned by the function alpar@1: {\tt gmtime} to {\it local} calendar times. Thus, if you need to alpar@1: determine the current local calendar time, you have to add to the UTC alpar@1: time returned the time offset from UTC expressed in seconds. For alpar@1: example, the time in Berlin during the winter is one hour ahead of UTC alpar@1: that corresponds to the time offset +1 hour = +3600 secs, so the alpar@1: current winter calendar time in Berlin may be determined as follows: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \verb| param now := gmtime() + 3600;| alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent Similarly, the summer time in Chicago (Central Daylight Time) alpar@1: is five hours behind UTC, so the corresponding current local calendar alpar@1: time may be determined as follows: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \verb| param now := gmtime() - 5 * 3600;| alpar@1: alpar@1: \medskip alpar@1: alpar@1: Note that the value returned by {\tt gmtime} is volatile, i.e. being alpar@1: called several times this function may return different values. alpar@1: alpar@1: \subsection{Converting character string to calendar time} alpar@1: \label{str2time} alpar@1: alpar@1: The function {\tt str2time(}{\it s}{\tt,} {\it f}{\tt)} converts a alpar@1: character string (timestamp) specified by its first argument {\it s}, alpar@1: which must be a symbolic expression, to the calendar time suitable for alpar@1: arithmetic calculations. The conversion is controlled by the specified alpar@1: format string {\it f} (the second argument), which also must be a alpar@1: symbolic expression. alpar@1: alpar@1: The result of conversion returned by {\tt str2time} has the same alpar@1: meaning as values returned by the function {\tt gmtime} (see Subsection alpar@1: \ref{gmtime}, page \pageref{gmtime}). Note that {\tt str2time} does alpar@1: {\tt not} correct the calendar time returned for the local timezone, alpar@1: i.e. being applied to 00:00:00 on January 1, 1970 it always returns 0. alpar@1: alpar@1: For example, the model statements: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \verb| param s, symbolic, := "07/14/98 13:47";| alpar@1: alpar@1: \verb| param t := str2time(s, "%m/%d/%y %H:%M");| alpar@1: alpar@1: \verb| display t;| alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent produce the following printout: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \verb| t = 900424020| alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent where the calendar time printed corresponds to 13:47:00 on alpar@1: July 14, 1998. alpar@1: alpar@1: \newpage alpar@1: alpar@1: The format string passed to the function {\tt str2time} consists of alpar@1: conversion specifiers and ordinary characters. Each conversion alpar@1: specifier begins with a percent ({\tt\%}) character followed by a alpar@1: letter. alpar@1: alpar@1: The following conversion specifiers may be used in the format string: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{20pt}p{298pt}@{}} alpar@1: {\tt\%b}&The abbreviated month name (case insensitive). At least three alpar@1: first letters of the month name must appear in the input string.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{20pt}p{298pt}@{}} alpar@1: {\tt\%d}&The day of the month as a decimal number (range 1 to 31). alpar@1: Leading zero is permitted, but not required.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{20pt}p{298pt}@{}} alpar@1: {\tt\%h}&The same as {\tt\%b}.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{20pt}p{298pt}@{}} alpar@1: {\tt\%H}&The hour as a decimal number, using a 24-hour clock (range 0 alpar@1: to 23). Leading zero is permitted, but not required.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{20pt}p{298pt}@{}} alpar@1: {\tt\%m}&The month as a decimal number (range 1 to 12). Leading zero is alpar@1: permitted, but not required.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{20pt}p{298pt}@{}} alpar@1: {\tt\%M}&The minute as a decimal number (range 0 to 59). Leading zero alpar@1: is permitted, but not required.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{20pt}p{298pt}@{}} alpar@1: {\tt\%S}&The second as a decimal number (range 0 to 60). Leading zero alpar@1: is permitted, but not required.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{20pt}p{298pt}@{}} alpar@1: {\tt\%y}&The year without a century as a decimal number (range 0 to 99). alpar@1: Leading zero is permitted, but not required. Input values in the range alpar@1: 0 to 68 are considered as the years 2000 to 2068 while the values 69 to alpar@1: 99 as the years 1969 to 1999.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{20pt}p{298pt}@{}} alpar@1: {\tt\%z}&The offset from GMT in ISO 8601 format.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{20pt}p{298pt}@{}} alpar@1: {\tt\%\%}&A literal {\tt\%} character.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: All other (ordinary) characters in the format string must have a alpar@1: matching character in the input string to be converted. Exceptions are alpar@1: spaces in the input string which can match zero or more space alpar@1: characters in the format string. alpar@1: alpar@1: If some date and/or time component(s) are missing in the format and, alpar@1: therefore, in the input string, the function {\tt str2time} uses their alpar@1: default values corresponding to 00:00:00 on January 1, 1970, that is, alpar@1: the default value of the year is 1970, the default value of the month alpar@1: is January, etc. alpar@1: alpar@1: The function {\tt str2time} is applicable to all calendar times in the alpar@1: range 00:00:00 on January 1, 0001 to 23:59:59 on December 31, 4000 of alpar@1: the Gregorian calendar. alpar@1: alpar@1: \subsection{Converting calendar time to character string} alpar@1: \label{time2str} alpar@1: alpar@1: The function {\tt time2str(}{\it t}{\tt,} {\it f}{\tt)} converts the alpar@1: calendar time specified by its first argument {\it t}, which must be a alpar@1: numeric expression, to a character string (symbolic value). The alpar@1: conversion is controlled by the specified format string {\it f} (the alpar@1: second argument), which must be a symbolic expression. alpar@1: alpar@1: The calendar time passed to {\tt time2str} has the same meaning as alpar@1: values returned by the function {\tt gmtime} (see Subsection alpar@1: \ref{gmtime}, page \pageref{gmtime}). Note that {\tt time2str} does alpar@1: {\it not} correct the specified calendar time for the local timezone, alpar@1: i.e. the calendar time 0 always corresponds to 00:00:00 on January 1, alpar@1: 1970. alpar@1: alpar@1: For example, the model statements: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \verb| param s, symbolic, := time2str(gmtime(), "%FT%TZ");| alpar@1: alpar@1: \verb| display s;| alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent may produce the following printout: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \verb| s = '2008-12-04T00:23:45Z'| alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent which is a timestamp in the ISO format. alpar@1: alpar@1: The format string passed to the function {\tt time2str} consists of alpar@1: conversion specifiers and ordinary characters. Each conversion alpar@1: specifier begins with a percent ({\tt\%}) character followed by a alpar@1: letter. alpar@1: alpar@1: The following conversion specifiers may be used in the format string: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{20pt}p{298pt}@{}} alpar@1: {\tt\%a}&The abbreviated (2-character) weekday name.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{20pt}p{298pt}@{}} alpar@1: {\tt\%A}&The full weekday name.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{20pt}p{298pt}@{}} alpar@1: {\tt\%b}&The abbreviated (3-character) month name.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{20pt}p{298pt}@{}} alpar@1: {\tt\%B}&The full month name.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{20pt}p{298pt}@{}} alpar@1: {\tt\%C}&The century of the year, that is the greatest integer not alpar@1: greater than the year divided by 100.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{20pt}p{298pt}@{}} alpar@1: {\tt\%d}&The day of the month as a decimal number (range 01 to 31).\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{20pt}p{298pt}@{}} alpar@1: {\tt\%D}&The date using the format \verb|%m/%d/%y|.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{20pt}p{298pt}@{}} alpar@1: {\tt\%e}&The day of the month like with \verb|%d|, but padded with alpar@1: blank rather than zero.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{20pt}p{298pt}@{}} alpar@1: {\tt\%F}&The date using the format \verb|%Y-%m-%d|.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{20pt}p{298pt}@{}} alpar@1: {\tt\%g}&The year corresponding to the ISO week number, but without the alpar@1: century (range 00 to 99). This has the same format and value as alpar@1: \verb|%y|, except that if the ISO week number (see \verb|%V|) belongs alpar@1: to the previous or next year, that year is used instead.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{20pt}p{298pt}@{}} alpar@1: {\tt\%G}&The year corresponding to the ISO week number. This has the alpar@1: same format and value as \verb|%Y|, except that if the ISO week number alpar@1: (see \verb|%V|) belongs to the previous or next year, that year is used alpar@1: instead. alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{20pt}p{298pt}@{}} alpar@1: {\tt\%h}&The same as \verb|%b|.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{20pt}p{298pt}@{}} alpar@1: {\tt\%H}&The hour as a decimal number, using a 24-hour clock (range 00 alpar@1: to 23).\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{20pt}p{298pt}@{}} alpar@1: {\tt\%I}&The hour as a decimal number, using a 12-hour clock (range 01 alpar@1: to 12).\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{20pt}p{298pt}@{}} alpar@1: {\tt\%j}&The day of the year as a decimal number (range 001 to 366).\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{20pt}p{298pt}@{}} alpar@1: {\tt\%k}&The hour as a decimal number, using a 24-hour clock like alpar@1: \verb|%H|, but padded with blank rather than zero.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{20pt}p{298pt}@{}} alpar@1: {\tt\%l}&The hour as a decimal number, using a 12-hour clock like alpar@1: \verb|%I|, but padded with blank rather than zero. alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{20pt}p{298pt}@{}} alpar@1: {\tt\%m}&The month as a decimal number (range 01 to 12).\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{20pt}p{298pt}@{}} alpar@1: {\tt\%M}&The minute as a decimal number (range 00 to 59).\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{20pt}p{298pt}@{}} alpar@1: {\tt\%p}&Either {\tt AM} or {\tt PM}, according to the given time value. alpar@1: Midnight is treated as {\tt AM} and noon as {\tt PM}.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{20pt}p{298pt}@{}} alpar@1: {\tt\%P}&Either {\tt am} or {\tt pm}, according to the given time value. alpar@1: Midnight is treated as {\tt am} and noon as {\tt pm}.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{20pt}p{298pt}@{}} alpar@1: {\tt\%R}&The hour and minute in decimal numbers using the format alpar@1: \verb|%H:%M|.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{20pt}p{298pt}@{}} alpar@1: {\tt\%S}&The second as a decimal number (range 00 to 59).\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{20pt}p{298pt}@{}} alpar@1: {\tt\%T}&The time of day in decimal numbers using the format alpar@1: \verb|%H:%M:%S|.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{20pt}p{298pt}@{}} alpar@1: {\tt\%u}&The day of the week as a decimal number (range 1 to 7), Monday alpar@1: being 1.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{20pt}p{298pt}@{}} alpar@1: {\tt\%U}&The week number of the current year as a decimal number (range alpar@1: 00 to 53), starting with the first Sunday as the first day of the first alpar@1: week. Days preceding the first Sunday in the year are considered to be alpar@1: in week 00. alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{20pt}p{298pt}@{}} alpar@1: {\tt\%V}&The ISO week number as a decimal number (range 01 to 53). ISO alpar@1: weeks start with Monday and end with Sunday. Week 01 of a year is the alpar@1: first week which has the majority of its days in that year; this is alpar@1: equivalent to the week containing January 4. Week 01 of a year can alpar@1: contain days from the previous year. The week before week 01 of a year alpar@1: is the last week (52 or 53) of the previous year even if it contains alpar@1: days from the new year. In other word, if 1 January is Monday, Tuesday, alpar@1: Wednesday or Thursday, it is in week 01; if 1 January is Friday, alpar@1: Saturday or Sunday, it is in week 52 or 53 of the previous year.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{20pt}p{298pt}@{}} alpar@1: {\tt\%w}&The day of the week as a decimal number (range 0 to 6), Sunday alpar@1: being 0.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{20pt}p{298pt}@{}} alpar@1: {\tt\%W}&The week number of the current year as a decimal number (range alpar@1: 00 to 53), starting with the first Monday as the first day of the first alpar@1: week. Days preceding the first Monday in the year are considered to be alpar@1: in week 00.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{20pt}p{298pt}@{}} alpar@1: {\tt\%y}&The year without a century as a decimal number (range 00 to alpar@1: 99), that is the year modulo 100.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{20pt}p{298pt}@{}} alpar@1: {\tt\%Y}&The year as a decimal number, using the Gregorian calendar.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: \begin{tabular}{@{}p{20pt}p{298pt}@{}} alpar@1: {\tt\%\%}&A literal \verb|%| character.\\ alpar@1: \end{tabular} alpar@1: alpar@1: \medskip alpar@1: alpar@1: All other (ordinary) characters in the format string are simply copied alpar@1: to the resultant string. alpar@1: alpar@1: The first argument (calendar time) passed to the function {\tt time2str} alpar@1: must be in the range from $-62135596800$ to $+64092211199$ that alpar@1: corresponds to the period from 00:00:00 on January 1, 0001 to 23:59:59 alpar@1: on December 31, 4000 of the Gregorian calendar. alpar@1: alpar@1: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% alpar@1: alpar@1: \newpage alpar@1: alpar@1: \section{Table drivers} alpar@1: \label{drivers} alpar@1: alpar@1: \noindent\hfil alpar@1: by Andrew Makhorin \verb|| alpar@1: alpar@1: \noindent\hfil alpar@1: and Heinrich Schuchardt \verb|| alpar@1: alpar@1: \bigskip\bigskip alpar@1: alpar@1: The {\it table driver} is a program module which provides transmitting alpar@1: data between MathProg model objects and data tables. alpar@1: alpar@1: Currently the GLPK package has four table drivers: alpar@1: alpar@1: \setlength{\leftmargini}{2.5em} alpar@1: alpar@1: \begin{itemize} alpar@1: \item built-in CSV table driver; alpar@1: \item built-in xBASE table driver; alpar@1: \item ODBC table driver; alpar@1: \item MySQL table driver. alpar@1: \end{itemize} alpar@1: alpar@1: \subsection{CSV table driver} alpar@1: alpar@1: The CSV table driver assumes that the data table is represented in the alpar@1: form of a plain text file in the CSV (comma-separated values) file alpar@1: format as described below. alpar@1: alpar@1: To choose the CSV table driver its name in the table statement should alpar@1: be specified as \verb|"CSV"|, and the only argument should specify the alpar@1: name of a plain text file containing the table. For example: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \verb| table data IN "CSV" "data.csv": ... ;| alpar@1: alpar@1: \medskip alpar@1: alpar@1: The filename suffix may be arbitrary, however, it is recommended to use alpar@1: the suffix `\verb|.csv|'. alpar@1: alpar@1: On reading input tables the CSV table driver provides an implicit field alpar@1: named \verb|RECNO|, which contains the current record number. This alpar@1: field can be specified in the input table statement as if there were alpar@1: the actual field having the name \verb|RECNO| in the CSV file. For alpar@1: example: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \verb| table list IN "CSV" "list.csv": num <- [RECNO], ... ;| alpar@1: alpar@1: \subsubsection*{CSV format\footnote{This material is based on the RFC alpar@1: document 4180.}} alpar@1: alpar@1: The CSV (comma-separated values) format is a plain text file format alpar@1: defined as follows. alpar@1: alpar@1: 1. Each record is located on a separate line, delimited by a line alpar@1: break. For example: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \verb| aaa,bbb,ccc\n| alpar@1: alpar@1: \verb| xxx,yyy,zzz\n| alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent alpar@1: where \verb|\n| means the control character \verb|LF| ({\tt 0x0A}). alpar@1: alpar@1: \newpage alpar@1: alpar@1: 2. The last record in the file may or may not have an ending line alpar@1: break. For example: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \verb| aaa,bbb,ccc\n| alpar@1: alpar@1: \verb| xxx,yyy,zzz| alpar@1: alpar@1: \medskip alpar@1: alpar@1: 3. There should be a header line appearing as the first line of the alpar@1: file in the same format as normal record lines. This header should alpar@1: contain names corresponding to the fields in the file. The number of alpar@1: field names in the header line should be the same as the number of alpar@1: fields in the records of the file. For example: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \verb| name1,name2,name3\n| alpar@1: alpar@1: \verb| aaa,bbb,ccc\n| alpar@1: alpar@1: \verb| xxx,yyy,zzz\n| alpar@1: alpar@1: \medskip alpar@1: alpar@1: 4. Within the header and each record there may be one or more fields alpar@1: separated by commas. Each line should contain the same number of fields alpar@1: throughout the file. Spaces are considered as part of a field and alpar@1: therefore not ignored. The last field in the record should not be alpar@1: followed by a comma. For example: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \verb| aaa,bbb,ccc\n| alpar@1: alpar@1: \medskip alpar@1: alpar@1: 5. Fields may or may not be enclosed in double quotes. For example: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \verb| "aaa","bbb","ccc"\n| alpar@1: alpar@1: \verb| zzz,yyy,xxx\n| alpar@1: alpar@1: \medskip alpar@1: alpar@1: 6. If a field is enclosed in double quotes, each double quote which is alpar@1: part of the field should be coded twice. For example: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \verb| "aaa","b""bb","ccc"\n| alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent{\bf Example} alpar@1: alpar@1: \begin{verbatim} alpar@1: FROM,TO,DISTANCE,COST alpar@1: Seattle,New-York,2.5,0.12 alpar@1: Seattle,Chicago,1.7,0.08 alpar@1: Seattle,Topeka,1.8,0.09 alpar@1: San-Diego,New-York,2.5,0.15 alpar@1: San-Diego,Chicago,1.8,0.10 alpar@1: San-Diego,Topeka,1.4,0.07 alpar@1: \end{verbatim} alpar@1: alpar@1: \subsection{xBASE table driver} alpar@1: alpar@1: The xBASE table driver assumes that the data table is stored in the alpar@1: .dbf file format. alpar@1: alpar@1: To choose the xBASE table driver its name in the table statement should alpar@1: be specified as \verb|"xBASE"|, and the first argument should specify alpar@1: the name of a .dbf file containing the table. For the output table there alpar@1: should be the second argument defining the table format in the form alpar@1: \verb|"FF...F"|, where \verb|F| is either {\tt C({\it n})}, alpar@1: which specifies a character field of length $n$, or alpar@1: {\tt N({\it n}{\rm [},{\it p}{\rm ]})}, which specifies a numeric field alpar@1: of length $n$ and precision $p$ (by default $p$ is 0). alpar@1: alpar@1: The following is a simple example which illustrates creating and alpar@1: reading a .dbf file: alpar@1: alpar@1: \begin{verbatim} alpar@1: table tab1{i in 1..10} OUT "xBASE" "foo.dbf" alpar@1: "N(5)N(10,4)C(1)C(10)": 2*i+1 ~ B, Uniform(-20,+20) ~ A, alpar@1: "?" ~ FOO, "[" & i & "]" ~ C; alpar@1: set S, dimen 4; alpar@1: table tab2 IN "xBASE" "foo.dbf": S <- [B, C, RECNO, A]; alpar@1: display S; alpar@1: end; alpar@1: \end{verbatim} alpar@1: alpar@1: \subsection{ODBC table driver} alpar@1: alpar@1: The ODBC table driver allows connecting to SQL databases using an alpar@1: implementation of the ODBC interface based on the Call Level Interface alpar@1: (CLI).\footnote{The corresponding software standard is defined in alpar@1: ISO/IEC 9075-3:2003.} alpar@1: alpar@1: \paragraph{Debian GNU/Linux.} alpar@1: Under Debian GNU/Linux the ODBC table driver uses the iODBC alpar@1: package,\footnote{See {\tt}.} which should be alpar@1: installed before building the GLPK package. The installation can be alpar@1: effected with the following command: alpar@1: alpar@1: \begin{verbatim} alpar@1: sudo apt-get install libiodbc2-dev alpar@1: \end{verbatim} alpar@1: alpar@1: Note that on configuring the GLPK package to enable using the iODBC alpar@1: library the option `\verb|--enable-odbc|' should be passed to the alpar@1: configure script. alpar@1: alpar@1: The individual databases must be entered for systemwide usage in alpar@1: \linebreak \verb|/etc/odbc.ini| and \verb|/etc/odbcinst.ini|. Database alpar@1: connections to be used by a single user are specified by files in the alpar@1: home directory (\verb|.odbc.ini| and \verb|.odbcinst.ini|). alpar@1: alpar@1: \paragraph{Microsoft Windows.} alpar@1: Under Microsoft Windows the ODBC table driver uses the Microsoft ODBC alpar@1: library. To enable this feature the symbol: alpar@1: alpar@1: \begin{verbatim} alpar@1: #define ODBC_DLNAME "odbc32.dll" alpar@1: \end{verbatim} alpar@1: alpar@1: \noindent alpar@1: should be defined in the GLPK configuration file `\verb|config.h|'. alpar@1: alpar@1: Data sources can be created via the Administrative Tools from the alpar@1: Control Panel. alpar@1: alpar@1: \bigskip alpar@1: alpar@1: To choose the ODBC table driver its name in the table statement should alpar@1: be specified as \verb|'ODBC'| or \verb|'iODBC'|. alpar@1: alpar@1: The argument list is specified as follows. alpar@1: alpar@1: The first argument is the connection string passed to the ODBC library, alpar@1: for example: alpar@1: alpar@1: \verb|'DSN=glpk;UID=user;PWD=password'|, or alpar@1: alpar@1: \verb|'DRIVER=MySQL;DATABASE=glpkdb;UID=user;PWD=password'|. alpar@1: alpar@1: Different parts of the string are separated by semicolons. Each part alpar@1: consists of a pair {\it fieldname} and {\it value} separated by the alpar@1: equal sign. Allowable fieldnames depend on the ODBC library. Typically alpar@1: the following fieldnames are allowed: alpar@1: alpar@1: \verb|DATABASE | database; alpar@1: alpar@1: \verb|DRIVER | ODBC driver; alpar@1: alpar@1: \verb|DSN | name of a data source; alpar@1: alpar@1: \verb|FILEDSN | name of a file data source; alpar@1: alpar@1: \verb|PWD | user password; alpar@1: alpar@1: \verb|SERVER | database; alpar@1: alpar@1: \verb|UID | user name. alpar@1: alpar@1: The second argument and all following are considered to be SQL alpar@1: statements alpar@1: alpar@1: SQL statements may be spread over multiple arguments. If the last alpar@1: character of an argument is a semicolon this indicates the end of alpar@1: a SQL statement. alpar@1: alpar@1: The arguments of a SQL statement are concatenated separated by space. alpar@1: The eventual trailing semicolon will be removed. alpar@1: alpar@1: All but the last SQL statement will be executed directly. alpar@1: alpar@1: For IN-table the last SQL statement can be a SELECT command starting alpar@1: with the capitalized letters \verb|'SELECT '|. If the string does not alpar@1: start with \verb|'SELECT '| it is considered to be a table name and a alpar@1: SELECT statement is automatically generated. alpar@1: alpar@1: For OUT-table the last SQL statement can contain one or multiple alpar@1: question marks. If it contains a question mark it is considered a alpar@1: template for the write routine. Otherwise the string is considered a alpar@1: table name and an INSERT template is automatically generated. alpar@1: alpar@1: The writing routine uses the template with the question marks and alpar@1: replaces the first question mark by the first output parameter, the alpar@1: second question mark by the second output parameter and so forth. Then alpar@1: the SQL command is issued. alpar@1: alpar@1: The following is an example of the output table statement: alpar@1: alpar@1: \begin{small} alpar@1: \begin{verbatim} alpar@1: table ta { l in LOCATIONS } OUT alpar@1: 'ODBC' alpar@1: 'DSN=glpkdb;UID=glpkuser;PWD=glpkpassword' alpar@1: 'DROP TABLE IF EXISTS result;' alpar@1: 'CREATE TABLE result ( ID INT, LOC VARCHAR(255), QUAN DOUBLE );' alpar@1: 'INSERT INTO result 'VALUES ( 4, ?, ? )' : alpar@1: l ~ LOC, quantity[l] ~ QUAN; alpar@1: \end{verbatim} alpar@1: \end{small} alpar@1: alpar@1: \noindent alpar@1: Alternatively it could be written as follows: alpar@1: alpar@1: \begin{small} alpar@1: \begin{verbatim} alpar@1: table ta { l in LOCATIONS } OUT alpar@1: 'ODBC' alpar@1: 'DSN=glpkdb;UID=glpkuser;PWD=glpkpassword' alpar@1: 'DROP TABLE IF EXISTS result;' alpar@1: 'CREATE TABLE result ( ID INT, LOC VARCHAR(255), QUAN DOUBLE );' alpar@1: 'result' : alpar@1: l ~ LOC, quantity[l] ~ QUAN, 4 ~ ID; alpar@1: \end{verbatim} alpar@1: \end{small} alpar@1: alpar@1: Using templates with `\verb|?|' supports not only INSERT, but also alpar@1: UPDATE, DELETE, etc. For example: alpar@1: alpar@1: \begin{small} alpar@1: \begin{verbatim} alpar@1: table ta { l in LOCATIONS } OUT alpar@1: 'ODBC' alpar@1: 'DSN=glpkdb;UID=glpkuser;PWD=glpkpassword' alpar@1: 'UPDATE result SET DATE = ' & date & ' WHERE ID = 4;' alpar@1: 'UPDATE result SET QUAN = ? WHERE LOC = ? AND ID = 4' : alpar@1: quantity[l], l; alpar@1: \end{verbatim} alpar@1: \end{small} alpar@1: alpar@1: \subsection{MySQL table driver} alpar@1: alpar@1: The MySQL table driver allows connecting to MySQL databases. alpar@1: alpar@1: \paragraph{Debian GNU/Linux.} alpar@1: Under Debian GNU/Linux the MySQL table\linebreak driver uses the MySQL alpar@1: package,\footnote{For download development files see alpar@1: {\tt}.} which should be installed alpar@1: before building the GLPK package. The installation can be effected with alpar@1: the following command: alpar@1: alpar@1: \begin{verbatim} alpar@1: sudo apt-get install libmysqlclient15-dev alpar@1: \end{verbatim} alpar@1: alpar@1: Note that on configuring the GLPK package to enable using the MySQL alpar@1: library the option `\verb|--enable-mysql|' should be passed to the alpar@1: configure script. alpar@1: alpar@1: \paragraph{Microsoft Windows.} alpar@1: Under Microsoft Windows the MySQL table driver also uses the MySQL alpar@1: library. To enable this feature the symbol: alpar@1: alpar@1: \begin{verbatim} alpar@1: #define MYSQL_DLNAME "libmysql.dll" alpar@1: \end{verbatim} alpar@1: alpar@1: \noindent alpar@1: should be defined in the GLPK configuration file `\verb|config.h|'. alpar@1: alpar@1: \bigskip alpar@1: alpar@1: To choose the MySQL table driver its name in the table statement should alpar@1: be specified as \verb|'MySQL'|. alpar@1: alpar@1: The argument list is specified as follows. alpar@1: alpar@1: The first argument specifies how to connect the data base in the DSN alpar@1: style, for example: alpar@1: alpar@1: \verb|'Database=glpk;UID=glpk;PWD=gnu'|. alpar@1: alpar@1: Different parts of the string are separated by semicolons. Each part alpar@1: consists of a pair {\it fieldname} and {\it value} separated by the alpar@1: equal sign. The following fieldnames are allowed: alpar@1: alpar@1: \verb|Server | server running the database (defaulting to localhost); alpar@1: alpar@1: \verb|Database | name of the database; alpar@1: alpar@1: \verb|UID | user name; alpar@1: alpar@1: \verb|PWD | user password; alpar@1: alpar@1: \verb|Port | port used by the server (defaulting to 3306). alpar@1: alpar@1: The second argument and all following are considered to be SQL alpar@1: statements alpar@1: alpar@1: SQL statements may be spread over multiple arguments. If the last alpar@1: character of an argument is a semicolon this indicates the end of alpar@1: a SQL statement. alpar@1: alpar@1: The arguments of a SQL statement are concatenated separated by space. alpar@1: The eventual trailing semicolon will be removed. alpar@1: alpar@1: All but the last SQL statement will be executed directly. alpar@1: alpar@1: For IN-table the last SQL statement can be a SELECT command starting alpar@1: with the capitalized letters \verb|'SELECT '|. If the string does not alpar@1: start with \verb|'SELECT '| it is considered to be a table name and a alpar@1: SELECT statement is automatically generated. alpar@1: alpar@1: For OUT-table the last SQL statement can contain one or multiple alpar@1: question marks. If it contains a question mark it is considered a alpar@1: template for the write routine. Otherwise the string is considered a alpar@1: table name and an INSERT template is automatically generated. alpar@1: alpar@1: The writing routine uses the template with the question marks and alpar@1: replaces the first question mark by the first output parameter, the alpar@1: second question mark by the second output parameter and so forth. Then alpar@1: the SQL command is issued. alpar@1: alpar@1: The following is an example of the output table statement: alpar@1: alpar@1: \begin{small} alpar@1: \begin{verbatim} alpar@1: table ta { l in LOCATIONS } OUT alpar@1: 'MySQL' alpar@1: 'Database=glpkdb;UID=glpkuser;PWD=glpkpassword' alpar@1: 'DROP TABLE IF EXISTS result;' alpar@1: 'CREATE TABLE result ( ID INT, LOC VARCHAR(255), QUAN DOUBLE );' alpar@1: 'INSERT INTO result VALUES ( 4, ?, ? )' : alpar@1: l ~ LOC, quantity[l] ~ QUAN; alpar@1: \end{verbatim} alpar@1: \end{small} alpar@1: alpar@1: \noindent alpar@1: Alternatively it could be written as follows: alpar@1: alpar@1: \begin{small} alpar@1: \begin{verbatim} alpar@1: table ta { l in LOCATIONS } OUT alpar@1: 'MySQL' alpar@1: 'Database=glpkdb;UID=glpkuser;PWD=glpkpassword' alpar@1: 'DROP TABLE IF EXISTS result;' alpar@1: 'CREATE TABLE result ( ID INT, LOC VARCHAR(255), QUAN DOUBLE );' alpar@1: 'result' : alpar@1: l ~ LOC, quantity[l] ~ QUAN, 4 ~ ID; alpar@1: \end{verbatim} alpar@1: \end{small} alpar@1: alpar@1: Using templates with `\verb|?|' supports not only INSERT, but also alpar@1: UPDATE, DELETE, etc. For example: alpar@1: alpar@1: \begin{small} alpar@1: \begin{verbatim} alpar@1: table ta { l in LOCATIONS } OUT alpar@1: 'MySQL' alpar@1: 'Database=glpkdb;UID=glpkuser;PWD=glpkpassword' alpar@1: 'UPDATE result SET DATE = ' & date & ' WHERE ID = 4;' alpar@1: 'UPDATE result SET QUAN = ? WHERE LOC = ? AND ID = 4' : alpar@1: quantity[l], l; alpar@1: \end{verbatim} alpar@1: \end{small} alpar@1: alpar@1: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% alpar@1: alpar@1: \newpage alpar@1: alpar@1: \section{Solving models with glpsol} alpar@1: alpar@1: The GLPK package\footnote{{\tt http://www.gnu.org/software/glpk/}} alpar@1: includes the program {\tt glpsol}, which is a stand-alone LP/MIP solver. alpar@1: This program can be launched from the command line or from the shell to alpar@1: solve models written in the GNU MathProg modeling language. alpar@1: alpar@1: In order to tell the solver that the input file contains a model alpar@1: description, you need to specify the option \verb|--model| in the alpar@1: command line. For example: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \verb| glpsol --model foo.mod| alpar@1: alpar@1: \medskip alpar@1: alpar@1: Sometimes it is necessary to use the data section placed in a separate alpar@1: file, in which case you may use the following command: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \verb| glpsol --model foo.mod --data foo.dat| alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent Note that if the model file also contains the data section, alpar@1: that section is ignored. alpar@1: alpar@1: If the model description contains some display and/or printf statements, alpar@1: by default the output is sent to the terminal. In order to redirect the alpar@1: output to a file you may use the following command: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \verb| glpsol --model foo.mod --display foo.out| alpar@1: alpar@1: \medskip alpar@1: alpar@1: If you need to look at the problem, which has been generated by the alpar@1: model translator, you may use the option \verb|--wlp| as follows: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \verb| glpsol --model foo.mod --wlp foo.lp| alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent in which case the problem data is written to file alpar@1: \verb|foo.lp| in CPLEX LP format suitable for visual analysis. alpar@1: alpar@1: Sometimes it is needed merely to check the model description not alpar@1: solving the generated problem instance. In this case you may specify alpar@1: the option \verb|--check|, for example: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \verb| glpsol --check --model foo.mod --wlp foo.lp| alpar@1: alpar@1: \medskip alpar@1: alpar@1: In order to write a numeric solution obtained by the solver you may use alpar@1: the following command: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \verb| glpsol --model foo.mod --output foo.sol| alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent in which case the solution is written to file \verb|foo.sol| alpar@1: in a plain text format. alpar@1: alpar@1: The complete list of the \verb|glpsol| options can be found in the alpar@1: reference manual included in the GLPK distribution. alpar@1: alpar@1: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% alpar@1: alpar@1: \newpage alpar@1: alpar@1: \section{Example model description} alpar@1: alpar@1: \subsection{Model description written in MathProg} alpar@1: alpar@1: Below here is a complete example of the model description written in alpar@1: the GNU MathProg modeling language. alpar@1: alpar@1: \begin{small} alpar@1: \begin{verbatim} alpar@1: # A TRANSPORTATION PROBLEM alpar@1: # alpar@1: # This problem finds a least cost shipping schedule that meets alpar@1: # requirements at markets and supplies at factories. alpar@1: # alpar@1: # References: alpar@1: # Dantzig G B, "Linear Programming and Extensions." alpar@1: # Princeton University Press, Princeton, New Jersey, 1963, alpar@1: # Chapter 3-3. alpar@1: alpar@1: set I; alpar@1: /* canning plants */ alpar@1: alpar@1: set J; alpar@1: /* markets */ alpar@1: alpar@1: param a{i in I}; alpar@1: /* capacity of plant i in cases */ alpar@1: alpar@1: param b{j in J}; alpar@1: /* demand at market j in cases */ alpar@1: alpar@1: param d{i in I, j in J}; alpar@1: /* distance in thousands of miles */ alpar@1: alpar@1: param f; alpar@1: /* freight in dollars per case per thousand miles */ alpar@1: alpar@1: param c{i in I, j in J} := f * d[i,j] / 1000; alpar@1: /* transport cost in thousands of dollars per case */ alpar@1: alpar@1: var x{i in I, j in J} >= 0; alpar@1: /* shipment quantities in cases */ alpar@1: alpar@1: minimize cost: sum{i in I, j in J} c[i,j] * x[i,j]; alpar@1: /* total transportation costs in thousands of dollars */ alpar@1: alpar@1: s.t. supply{i in I}: sum{j in J} x[i,j] <= a[i]; alpar@1: /* observe supply limit at plant i */ alpar@1: alpar@1: s.t. demand{j in J}: sum{i in I} x[i,j] >= b[j]; alpar@1: /* satisfy demand at market j */ alpar@1: alpar@1: data; alpar@1: alpar@1: set I := Seattle San-Diego; alpar@1: alpar@1: set J := New-York Chicago Topeka; alpar@1: alpar@1: param a := Seattle 350 alpar@1: San-Diego 600; alpar@1: alpar@1: param b := New-York 325 alpar@1: Chicago 300 alpar@1: Topeka 275; alpar@1: alpar@1: param d : New-York Chicago Topeka := alpar@1: Seattle 2.5 1.7 1.8 alpar@1: San-Diego 2.5 1.8 1.4 ; alpar@1: alpar@1: param f := 90; alpar@1: alpar@1: end; alpar@1: \end{verbatim} alpar@1: \end{small} alpar@1: alpar@1: \subsection{Generated LP problem instance} alpar@1: alpar@1: Below here is the result of the translation of the example model alpar@1: produced by the solver \verb|glpsol| and written in CPLEX LP format alpar@1: with the option \verb|--wlp|. alpar@1: alpar@1: \begin{small} alpar@1: \begin{verbatim} alpar@1: \* Problem: transp *\ alpar@1: alpar@1: Minimize alpar@1: cost: + 0.225 x(Seattle,New~York) + 0.153 x(Seattle,Chicago) alpar@1: + 0.162 x(Seattle,Topeka) + 0.225 x(San~Diego,New~York) alpar@1: + 0.162 x(San~Diego,Chicago) + 0.126 x(San~Diego,Topeka) alpar@1: alpar@1: Subject To alpar@1: supply(Seattle): + x(Seattle,New~York) + x(Seattle,Chicago) alpar@1: + x(Seattle,Topeka) <= 350 alpar@1: supply(San~Diego): + x(San~Diego,New~York) + x(San~Diego,Chicago) alpar@1: + x(San~Diego,Topeka) <= 600 alpar@1: demand(New~York): + x(Seattle,New~York) + x(San~Diego,New~York) >= 325 alpar@1: demand(Chicago): + x(Seattle,Chicago) + x(San~Diego,Chicago) >= 300 alpar@1: demand(Topeka): + x(Seattle,Topeka) + x(San~Diego,Topeka) >= 275 alpar@1: alpar@1: End alpar@1: \end{verbatim} alpar@1: \end{small} alpar@1: alpar@1: \subsection{Optimal LP solution} alpar@1: alpar@1: Below here is the optimal solution of the generated LP problem instance alpar@1: found by the solver \verb|glpsol| and written in plain text format alpar@1: with the option \verb|--output|. alpar@1: alpar@1: \newpage alpar@1: alpar@1: \begin{small} alpar@1: \begin{verbatim} alpar@1: Problem: transp alpar@1: Rows: 6 alpar@1: Columns: 6 alpar@1: Non-zeros: 18 alpar@1: Status: OPTIMAL alpar@1: Objective: cost = 153.675 (MINimum) alpar@1: alpar@1: No. Row name St Activity Lower bound Upper bound Marginal alpar@1: --- ------------ -- ------------ ------------ ------------ ------------ alpar@1: 1 cost B 153.675 alpar@1: 2 supply[Seattle] alpar@1: B 300 350 alpar@1: 3 supply[San-Diego] alpar@1: NU 600 600 < eps alpar@1: 4 demand[New-York] alpar@1: NL 325 325 0.225 alpar@1: 5 demand[Chicago] alpar@1: NL 300 300 0.153 alpar@1: 6 demand[Topeka] alpar@1: NL 275 275 0.126 alpar@1: alpar@1: No. Column name St Activity Lower bound Upper bound Marginal alpar@1: --- ------------ -- ------------ ------------ ------------ ------------ alpar@1: 1 x[Seattle,New-York] alpar@1: B 0 0 alpar@1: 2 x[Seattle,Chicago] alpar@1: B 300 0 alpar@1: 3 x[Seattle,Topeka] alpar@1: NL 0 0 0.036 alpar@1: 4 x[San-Diego,New-York] alpar@1: B 325 0 alpar@1: 5 x[San-Diego,Chicago] alpar@1: NL 0 0 0.009 alpar@1: 6 x[San-Diego,Topeka] alpar@1: B 275 0 alpar@1: alpar@1: End of output alpar@1: \end{verbatim} alpar@1: \end{small} alpar@1: alpar@1: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% alpar@1: alpar@1: \newpage alpar@1: alpar@1: \setcounter{secnumdepth}{-1} alpar@1: alpar@1: \section{Acknowledgment} alpar@1: alpar@1: The authors would like to thank the following people, who kindly read, alpar@1: commented, and corrected the draft of this document: alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent Juan Carlos Borras \verb|| alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent Harley Mackenzie \verb|| alpar@1: alpar@1: \medskip alpar@1: alpar@1: \noindent Robbie Morrison \verb|| alpar@1: alpar@1: \end{document}