You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

4301 lines
145 KiB

2 months ago
  1. %* gmpl.tex *%
  2. %***********************************************************************
  3. % This code is part of GLPK (GNU Linear Programming Kit).
  4. %
  5. % Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
  6. % 2009, 2010, 2011, 2013, 2014, 2015, 2016 Andrew Makhorin, Department
  7. % for Applied Informatics, Moscow Aviation Institute, Moscow, Russia.
  8. % All rights reserved. E-mail: <mao@gnu.org>.
  9. %
  10. % GLPK is free software: you can redistribute it and/or modify it
  11. % under the terms of the GNU General Public License as published by
  12. % the Free Software Foundation, either version 3 of the License, or
  13. % (at your option) any later version.
  14. %
  15. % GLPK is distributed in the hope that it will be useful, but WITHOUT
  16. % ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  17. % or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
  18. % License for more details.
  19. %
  20. % You should have received a copy of the GNU General Public License
  21. % along with GLPK. If not, see <http://www.gnu.org/licenses/>.
  22. %***********************************************************************
  23. % To produce gmpl.pdf from gmpl.tex run the following two commands:
  24. % latex gmpl.tex
  25. % dvipdfm -p letter gmpl.dvi
  26. % Note: You need TeX Live 2010 or later version.
  27. \documentclass[11pt]{report}
  28. \usepackage{amssymb}
  29. \usepackage[dvipdfm,linktocpage,colorlinks,linkcolor=blue,
  30. urlcolor=blue]{hyperref}
  31. \usepackage{indentfirst}
  32. \setlength{\textwidth}{6.5in}
  33. \setlength{\textheight}{8.5in}
  34. \setlength{\oddsidemargin}{0in}
  35. \setlength{\topmargin}{0in}
  36. \setlength{\headheight}{0in}
  37. \setlength{\headsep}{0in}
  38. \setlength{\footskip}{0.5in}
  39. \setlength{\parindent}{16pt}
  40. \setlength{\parskip}{5pt}
  41. \setlength{\topsep}{0pt}
  42. \setlength{\partopsep}{0pt}
  43. \setlength{\itemsep}{\parskip}
  44. \setlength{\parsep}{0pt}
  45. \setlength{\leftmargini}{\parindent}
  46. \renewcommand{\labelitemi}{---}
  47. \def\para#1{\noindent{\bf#1}}
  48. \renewcommand\contentsname{\sf\bfseries Contents}
  49. \renewcommand\chaptername{\sf\bfseries Chapter}
  50. \renewcommand\appendixname{\sf\bfseries Appendix}
  51. \begin{document}
  52. \thispagestyle{empty}
  53. \begin{center}
  54. \vspace*{1.5in}
  55. \begin{huge}
  56. \sf\bfseries Modeling Language GNU MathProg
  57. \end{huge}
  58. \vspace{0.5in}
  59. \begin{LARGE}
  60. \sf Language Reference
  61. \end{LARGE}
  62. \vspace{0.5in}
  63. \begin{LARGE}
  64. \sf for GLPK Version 4.58
  65. \end{LARGE}
  66. \vspace{0.5in}
  67. \begin{Large}
  68. \sf (DRAFT, February 2016)
  69. \end{Large}
  70. \end{center}
  71. \newpage
  72. \vspace*{1in}
  73. \vfill
  74. \noindent
  75. The GLPK package is part of the GNU Project released under the aegis of
  76. GNU.
  77. \noindent
  78. Copyright \copyright{} 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
  79. 2008, 2009, 2010, 2011, 2013, 2014, 2015, 2016 Andrew Makhorin,
  80. Department for Applied Informatics, Moscow Aviation Institute, Moscow,
  81. Russia. All rights reserved.
  82. \noindent
  83. Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
  84. MA 02110-1301, USA.
  85. \noindent
  86. Permission is granted to make and distribute verbatim copies of this
  87. manual provided the copyright notice and this permission notice are
  88. preserved on all copies.
  89. \noindent
  90. Permission is granted to copy and distribute modified versions of this
  91. manual under the conditions for verbatim copying, provided also that
  92. the entire resulting derived work is distributed under the terms of
  93. a permission notice identical to this one.
  94. \noindent
  95. Permission is granted to copy and distribute translations of this
  96. manual into another language, under the above conditions for modified
  97. versions.
  98. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  99. \newpage
  100. {\setlength{\parskip}{0pt}
  101. \tableofcontents
  102. }
  103. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  104. \chapter{Introduction}
  105. {\it GNU MathProg} is a modeling language intended for describing
  106. linear mathematical programming models.\footnote{The GNU MathProg
  107. language is a subset of the AMPL language. Its GLPK implementation is
  108. mainly based on the paper: {\it Robert Fourer}, {\it David M. Gay}, and
  109. {\it Brian W. Kernighan}, ``A Modeling Language for Mathematical
  110. Programming.'' {\it Management Science} 36 (1990), pp.~519-54.}
  111. Model descriptions written in the GNU MathProg language consist of
  112. a set of statements and data blocks constructed by the user from the
  113. language elements described in this document.
  114. In a process called {\it translation}, a program called the {\it model
  115. translator} analyzes the model description and translates it into
  116. internal data structures, which may be then used either for generating
  117. mathematical programming problem instance or directly by a program
  118. called the {\it solver} to obtain numeric solution of the problem.
  119. \section{Linear programming problem}
  120. \label{problem}
  121. In MathProg the linear programming (LP) problem is stated as follows:
  122. \medskip
  123. \noindent\hspace{1in}minimize (or maximize)
  124. $$z=c_1x_1+c_2x_2+\dots+c_nx_n+c_0\eqno(1.1)$$
  125. \noindent\hspace{1in}subject to linear constraints
  126. $$
  127. \begin{array}{l@{\ }c@{\ }r@{\ }c@{\ }r@{\ }c@{\ }r@{\ }c@{\ }l}
  128. L_1&\leq&a_{11}x_1&+&a_{12}x_2&+\dots+&a_{1n}x_n&\leq&U_1\\
  129. L_2&\leq&a_{21}x_1&+&a_{22}x_2&+\dots+&a_{2n}x_n&\leq&U_2\\
  130. \multicolumn{9}{c}{.\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .}\\
  131. L_m&\leq&a_{m1}x_1&+&a_{m2}x_2&+\dots+&a_{mn}x_n&\leq&U_m\\
  132. \end{array}\eqno(1.2)
  133. $$
  134. \noindent\hspace{1in}and bounds of variables
  135. $$
  136. \begin{array}{l@{\ }c@{\ }c@{\ }c@{\ }l}
  137. l_1&\leq&x_1&\leq&u_1\\
  138. l_2&\leq&x_2&\leq&u_2\\
  139. \multicolumn{5}{c}{.\ \ .\ \ .\ \ .\ \ .}\\
  140. l_n&\leq&x_n&\leq&u_n\\
  141. \end{array}\eqno(1.3)
  142. $$
  143. \newpage
  144. \noindent
  145. where $x_1$, $x_2$, \dots, $x_n$ are variables; $z$ is the objective
  146. function; $c_1$, $c_2$, \dots, $c_n$ are objective coefficients; $c_0$
  147. is the constant term (``shift'') of the objective function; $a_{11}$,
  148. $a_{12}$, \dots, $a_{mn}$ are constraint coefficients; $L_1$, $L_2$,
  149. \dots, $L_m$ are lower constraint bounds; $U_1$, $U_2$, \dots, $U_m$
  150. are upper constraint bounds; $l_1$, $l_2$, \dots, $l_n$ are lower
  151. bounds of variables; $u_1$, $u_2$, \dots, $u_n$ are upper bounds of
  152. variables.
  153. Bounds of variables and constraint bounds can be finite as well as
  154. infinite. Besides, lower bounds can be equal to corresponding upper
  155. bounds. Thus, the following types of variables and constraints are
  156. allowed:
  157. \medskip
  158. {\def\arraystretch{1.4}
  159. \noindent\hspace{54pt}
  160. \begin{tabular}{@{}r@{\ }c@{\ }c@{\ }c@{\ }l@{\hspace*{39.5pt}}l}
  161. $-\infty$&$<$&$x$&$<$&$+\infty$&Free (unbounded) variable\\
  162. $l$&$\leq$&$x$&$<$&$+\infty$&Variable with lower bound\\
  163. $-\infty$&$<$&$x$&$\leq$&$u$&Variable with upper bound\\
  164. $l$&$\leq$&$x$&$\leq$&$u$&Double-bounded variable\\
  165. $l$&$=$&$x$&=&$u$&Fixed variable\\
  166. \end{tabular}
  167. \noindent\hfil
  168. \begin{tabular}{@{}r@{\ }c@{\ }c@{\ }c@{\ }ll}
  169. $-\infty$&$<$&$\sum a_jx_j$&$<$&$+\infty$&Free (unbounded) linear
  170. form\\
  171. $L$&$\leq$&$\sum a_jx_j$&$<$&$+\infty$&Inequality constraint ``greater
  172. than or equal to''\\
  173. $-\infty$&$<$&$\sum a_jx_j$&$\leq$&$U$&Inequality constraint ``less
  174. than or equal to''\\
  175. $L$&$\leq$&$\sum a_jx_j$&$\leq$&$U$&Double-bounded inequality
  176. constraint\\
  177. $L$&$=$&$\sum a_jx_j$&=&$U$&Equality constraint\\
  178. \end{tabular}
  179. }
  180. \medskip
  181. In addition to pure LP problems MathProg also allows mixed integer
  182. linear programming (MIP) problems, where some or all variables are
  183. restricted to be integer or binary.
  184. \section{Model objects}
  185. In MathProg the model is described in terms of sets, parameters,
  186. variables, constraints, and objectives, which are called {\it model
  187. objects}.
  188. The user introduces particular model objects using the language
  189. statements. Each model object is provided with a symbolic name which
  190. uniquely identifies the object and is intended for referencing
  191. purposes.
  192. Model objects, including sets, can be multidimensional arrays built
  193. over indexing sets. Formally, $n$-dimensional array $A$ is the mapping:
  194. $$A:\Delta\rightarrow\Xi,\eqno(1.4)$$
  195. where $\Delta\subseteq S_1\times\dots\times S_n$ is a subset of the
  196. Cartesian product of indexing sets, $\Xi$ is a set of array members.
  197. In MathProg the set $\Delta$ is called the {\it subscript domain}. Its
  198. members are $n$-tuples $(i_1,\dots,i_n)$, where $i_1\in S_1$, \dots,
  199. $i_n\in S_n$.
  200. If $n=0$, the Cartesian product above has exactly one member (namely,
  201. 0-tuple), so it is convenient to think scalar objects as 0-dimensional
  202. arrays having one member.
  203. \newpage
  204. The type of array members is determined by the type of corresponding
  205. model object as follows:
  206. \medskip
  207. \noindent\hfil
  208. \begin{tabular}{@{}ll@{}}
  209. Model object&Array member\\
  210. \hline
  211. Set&Elemental plain set\\
  212. Parameter&Number or symbol\\
  213. Variable&Elemental variable\\
  214. Constraint&Elemental constraint\\
  215. Objective&Elemental objective\\
  216. \end{tabular}
  217. \medskip
  218. In order to refer to a particular object member the object should be
  219. provided with {\it subscripts}. For example, if $a$ is a 2-dimensional
  220. parameter defined over $I\times J$, a reference to its particular
  221. member can be written as $a[i,j]$, where $i\in I$ and $j\in J$. It is
  222. understood that scalar objects being 0-dimensional need no subscripts.
  223. \section{Structure of model description}
  224. It is sometimes desirable to write a model which, at various points,
  225. may require different data for each problem instance to be solved using
  226. that model. For this reason in MathProg the model description consists
  227. of two parts: the {\it model section} and the {\it data section}.
  228. The model section is a main part of the model description that contains
  229. declarations of model objects and is common for all problems based on
  230. the corresponding model.
  231. The data section is an optional part of the model description that
  232. contains data specific for a particular problem instance.
  233. Depending on what is more convenient the model and data sections can be
  234. placed either in one file or in two separate files. The latter feature
  235. allows having arbitrary number of different data sections to be used
  236. with the same model section.
  237. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  238. \chapter{Coding model description}
  239. \label{coding}
  240. The model description is coded in a plain text format using ASCII
  241. character set. Characters valid in the model description are the
  242. following:
  243. \begin{itemize}
  244. \item alphabetic characters:\\
  245. \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|\\
  246. \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 _|
  247. \item numeric characters:\\
  248. \verb|0 1 2 3 4 5 6 7 8 9|
  249. \item special characters:\\
  250. \verb?! " # & ' ( ) * + , - . / : ; < = > [ ] ^ { | } ~?
  251. \item white-space characters:\\
  252. \verb|SP HT CR NL VT FF|
  253. \end{itemize}
  254. Within string literals and comments any ASCII characters (except
  255. control characters) are valid.
  256. White-space characters are non-significant. They can be used freely
  257. between lexical units to improve readability of the model description.
  258. They are also used to separate lexical units from each other if there
  259. is no other way to do that.
  260. Syntactically model description is a sequence of lexical units in the
  261. following categories:
  262. \begin{itemize}
  263. \item symbolic names;
  264. \item numeric literals;
  265. \item string literals;
  266. \item keywords;
  267. \item delimiters;
  268. \item comments.
  269. \end{itemize}
  270. The lexical units of the language are discussed below.
  271. \newpage
  272. \section{Symbolic names}
  273. A {\it symbolic name} consists of alphabetic and numeric characters,
  274. the first of which should be alphabetic. All symbolic names are
  275. distinct (case sensitive).
  276. \para{Examples}
  277. \begin{verbatim}
  278. alpha123
  279. This_is_a_name
  280. _P123_abc_321
  281. \end{verbatim}
  282. Symbolic names are used to identify model objects (sets, parameters,
  283. variables, constraints, objectives) and dummy indices.
  284. All symbolic names (except names of dummy indices) should be unique,
  285. i.e. the model description should have no objects with identical names.
  286. Symbolic names of dummy indices should be unique within the scope,
  287. where they are valid.
  288. \section{Numeric literals}
  289. A {\it numeric literal} has the form {\it xx}{\tt E}{\it syy}, where
  290. {\it xx} is a number with optional decimal point, {\it s} is the sign
  291. {\tt+} or {\tt-}, {\it yy} is a decimal exponent. The letter {\tt E} is
  292. case insensitive and can be coded as {\tt e}.
  293. \para{Examples}
  294. \begin{verbatim}
  295. 123
  296. 3.14159
  297. 56.E+5
  298. .78
  299. 123.456e-7
  300. \end{verbatim}
  301. Numeric literals are used to represent numeric quantities. They have
  302. obvious fixed meaning.
  303. \section{String literals}
  304. A {\it string literal} is a sequence of arbitrary characters enclosed
  305. either in single quotes or in double quotes. Both these forms are
  306. equivalent.
  307. If a single quote is part of a string literal enclosed in single
  308. quotes, it should be coded twice. Analogously, if a double quote is
  309. part of a string literal enclosed in double quotes, it should be coded
  310. twice.
  311. \para{Examples}
  312. \begin{verbatim}
  313. 'This is a string'
  314. "This is another string"
  315. 'That''s all'
  316. """Hello there,"" said the captain."
  317. \end{verbatim}
  318. String literals are used to represent symbolic quantities.
  319. \section{Keywords}
  320. A {\it keyword} is a sequence of alphabetic characters and possibly
  321. some special characters.
  322. All keywords fall into two categories: {\it reserved keywords}, which
  323. cannot be used as symbolic names, and {\it non-reserved keywords},
  324. which are recognized by context and therefore can be used as symbolic
  325. names.
  326. The reserved keywords are the following:
  327. \noindent\hfil
  328. \begin{tabular}{@{}p{.7in}p{.7in}p{.7in}p{.7in}@{}}
  329. {\tt and}&{\tt else}&{\tt mod}&{\tt union}\\
  330. {\tt by}&{\tt if}&{\tt not}&{\tt within}\\
  331. {\tt cross}&{\tt in}&{\tt or}\\
  332. {\tt diff}&{\tt inter}&{\tt symdiff}\\
  333. {\tt div}&{\tt less}&{\tt then}\\
  334. \end{tabular}
  335. Non-reserved keywords are described in following sections.
  336. All the keywords have fixed meaning, which will be explained on
  337. discussion of corresponding syntactic constructions, where the keywords
  338. are used.
  339. \section{Delimiters}
  340. A {\it delimiter} is either a single special character or a sequence of
  341. two special characters as follows:
  342. \noindent\hfil
  343. \begin{tabular}{@{}p{.3in}p{.3in}p{.3in}p{.3in}p{.3in}p{.3in}p{.3in}
  344. p{.3in}p{.3in}@{}}
  345. {\tt+}&{\tt**}&{\tt<=}&{\tt>}&{\tt\&\&}&{\tt:}&{\tt|}&{\tt[}&
  346. {\tt>>}\\
  347. {\tt-}&{\tt\textasciicircum}&{\tt=}&{\tt<>}&{\tt||}&{\tt;}&
  348. {\tt\char126}&{\tt]}&{\tt<-}\\
  349. {\tt*}&{\tt\&}&{\tt==}&{\tt!=}&{\tt.}&{\tt:=}&{\tt(}&{\tt\{}\\
  350. {\tt/}&{\tt<}&{\tt>=}&{\tt!}&{\tt,}&{\tt..}&{\tt)}&{\tt\}}\\
  351. \end{tabular}
  352. If the delimiter consists of two characters, there should be no spaces
  353. between the characters.
  354. All the delimiters have fixed meaning, which will be explained on
  355. discussion corresponding syntactic constructions, where the delimiters
  356. are used.
  357. \section{Comments}
  358. For documenting purposes the model description can be provided with
  359. {\it comments}, which may have two different forms. The first form is
  360. a {\it single-line comment}, which begins with the character {\tt\#}
  361. and extends until end of line. The second form is a {\it comment
  362. sequence}, which is a sequence of any characters enclosed within
  363. {\tt/*} and {\tt*/}.
  364. \para{Examples}
  365. \begin{verbatim}
  366. param n := 10; # This is a comment
  367. /* This is another comment */
  368. \end{verbatim}
  369. Comments are ignored by the model translator and can appear anywhere in
  370. the model description, where white-space characters are allowed.
  371. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  372. \newpage
  373. \chapter{Expressions}
  374. An {\it expression} is a rule for computing a value. In model
  375. description expressions are used as constituents of certain statements.
  376. In general case expressions consist of operands and operators.
  377. Depending on the type of the resultant value all expressions fall into
  378. the following categories:
  379. \vspace*{-8pt}
  380. \begin{itemize}
  381. \item numeric expressions;
  382. \item symbolic expressions;
  383. \item indexing expressions;
  384. \item set expressions;
  385. \item logical expressions;
  386. \item linear expressions.
  387. \end{itemize}
  388. \vspace*{-8pt}
  389. \section{Numeric expressions}
  390. A {\it numeric expression} is a rule for computing a single numeric
  391. value represented as a floating-point number.
  392. The primary numeric expression may be a numeric literal, dummy index,
  393. unsubscripted parameter, subscripted parameter, built-in function
  394. reference, iterated numeric expression, conditional numeric expression,
  395. or another numeric expression enclosed in parentheses.
  396. \para{Examples}
  397. \noindent
  398. \begin{tabular}{@{}ll@{}}
  399. \verb|1.23 |&(numeric literal)\\
  400. \verb|j|&(dummy index)\\
  401. \verb|time|&(unsubscripted parameter)\\
  402. \verb|a['May 2003',j+1]|&(subscripted parameter)\\
  403. \verb|abs(b[i,j])|&(function reference)\\
  404. \end{tabular}
  405. \newpage
  406. \noindent
  407. \begin{tabular}{@{}ll@{}}
  408. \verb|sum{i in S diff T} alpha[i] * b[i,j]|&(iterated expression)\\
  409. \verb|if i in I then 2 * p else q[i+1]|&(conditional expression)\\
  410. \verb|(b[i,j] + .5 * c)|&(parenthesized expression)\\
  411. \end{tabular}
  412. More general numeric expressions containing two or more primary numeric
  413. expressions may be constructed by using certain arithmetic operators.
  414. \para{Examples}
  415. \begin{verbatim}
  416. j+1
  417. 2 * a[i-1,j+1] - b[i,j]
  418. sum{j in J} a[i,j] * x[j] + sum{k in K} b[i,k] * x[k]
  419. (if i in I and p >= 1 then 2 * p else q[i+1]) / (a[i,j] + 1.5)
  420. \end{verbatim}
  421. \subsection{Numeric literals}
  422. If the primary numeric expression is a numeric literal, the resultant
  423. value is obvious.
  424. \subsection{Dummy indices}
  425. If the primary numeric expression is a dummy index, the resultant value
  426. is current value assigned to that dummy index.
  427. \subsection{Unsubscripted parameters}
  428. If the primary numeric expression is an unsubscripted parameter (which
  429. should be 0-dimen\-sional), the resultant value is the value of that
  430. parameter.
  431. \subsection{Subscripted parameters}
  432. The primary numeric expression, which refers to a subscripted
  433. parameter, has the following syntactic form:
  434. $$
  435. \mbox{{\it name}{\tt[}$i_1${\tt,} $i_2${\tt,} \dots{\tt,} $i_n${\tt]}}
  436. $$
  437. where {\it name} is the symbolic name of the parameter, $i_1$, $i_2$,
  438. \dots, $i_n$ are subscripts.
  439. Each subscript should be a numeric or symbolic expression. The number
  440. of subscripts in the subscript list should be the same as the dimension
  441. of the parameter with which the subscript list is associated.
  442. Actual values of subscript expressions are used to identify
  443. a particular member of the parameter that determines the resultant
  444. value of the primary expression.
  445. \newpage
  446. \subsection{Function references}
  447. In MathProg there exist the following built-in functions which may be
  448. used in numeric expressions:
  449. \begin{tabular}{@{}p{112pt}p{328pt}@{}}
  450. {\tt abs(}$x${\tt)}&$|x|$, absolute value of $x$\\
  451. {\tt atan(}$x${\tt)}&$\arctan x$, principal value of the arc tangent of
  452. $x$ (in radians)\\
  453. {\tt atan(}$y${\tt,} $x${\tt)}&$\arctan y/x$, principal value of the
  454. arc tangent of $y/x$ (in radians). In this case the signs of both
  455. arguments $y$ and $x$ are used to determine the quadrant of the
  456. resultant value\\
  457. {\tt card(}$X${\tt)}&$|X|$, cardinality (the number of elements) of
  458. set $X$\\
  459. {\tt ceil(}$x${\tt)}&$\lceil x\rceil$, smallest integer not less than
  460. $x$ (``ceiling of $x$'')\\
  461. {\tt cos(}$x${\tt)}&$\cos x$, cosine of $x$ (in radians)\\
  462. {\tt exp(}$x${\tt)}&$e^x$, base-$e$ exponential of $x$\\
  463. {\tt floor(}$x${\tt)}&$\lfloor x\rfloor$, largest integer not greater
  464. than $x$ (``floor of $x$'')\\
  465. {\tt gmtime()}&the number of seconds elapsed since 00:00:00~Jan~1, 1970,
  466. Coordinated Universal Time (for details see Section \ref{gmtime},
  467. page \pageref{gmtime})\\
  468. {\tt length(}$s${\tt)}&$|s|$, length of character string $s$\\
  469. {\tt log(}$x${\tt)}&$\log x$, natural logarithm of $x$\\
  470. {\tt log10(}$x${\tt)}&$\log_{10}x$, common (decimal) logarithm of $x$\\
  471. {\tt max(}$x_1${\tt,} $x_2${\tt,} \dots{\tt,} $x_n${\tt)}&the largest
  472. of values $x_1$, $x_2$, \dots, $x_n$\\
  473. {\tt min(}$x_1${\tt,} $x_2${\tt,} \dots{\tt,} $x_n${\tt)}&the smallest
  474. of values $x_1$, $x_2$, \dots, $x_n$\\
  475. {\tt round(}$x${\tt)}&rounding $x$ to nearest integer\\
  476. {\tt round(}$x${\tt,} $n${\tt)}&rounding $x$ to $n$ fractional decimal
  477. digits\\
  478. {\tt sin(}$x${\tt)}&$\sin x$, sine of $x$ (in radians)\\
  479. {\tt sqrt(}$x${\tt)}&$\sqrt{x}$, non-negative square root of $x$\\
  480. {\tt str2time(}$s${\tt,} $f${\tt)}&converting character string $s$ to
  481. calendar time (for details see Section \ref{str2time}, page
  482. \pageref{str2time})\\
  483. {\tt tan(}$x${\tt)}&$\tan x$, tangent of $x$ (in radians)\\
  484. {\tt trunc(}$x${\tt)}&truncating $x$ to nearest integer\\
  485. {\tt trunc(}$x${\tt,} $n${\tt)}&truncating $x$ to $n$ fractional
  486. decimal digits\\
  487. {\tt Irand224()}&generating pseudo-random integer uniformly distributed
  488. in $[0,2^{24})$\\
  489. {\tt Uniform01()}&generating pseudo-random number uniformly distributed
  490. in $[0,1)$\\
  491. {\tt Uniform(}$a${\tt,} $b${\tt)}&generating pseudo-random number
  492. uniformly distributed in $[a,b)$\\
  493. {\tt Normal01()}&generating Gaussian pseudo-random variate with
  494. $\mu=0$ and $\sigma=1$\\
  495. {\tt Normal(}$\mu${\tt,} $\sigma${\tt)}&generating Gaussian
  496. pseudo-random variate with given $\mu$ and $\sigma$\\
  497. \end{tabular}
  498. Arguments of all built-in functions, except {\tt card}, {\tt length},
  499. and {\tt str2time}, should be numeric expressions. The argument of
  500. {\tt card} should be a set expression. The argument of {\tt length} and
  501. both arguments of {\tt str2time} should be symbolic expressions.
  502. The resultant value of the numeric expression, which is a function
  503. reference, is the result of applying the function to its argument(s).
  504. Note that each pseudo-random generator function has a latent argument
  505. (i.e. some internal state), which is changed whenever the function has
  506. been applied. Thus, if the function is applied repeatedly even to
  507. identical arguments, due to the side effect different resultant values
  508. are always produced.
  509. \newpage
  510. \subsection{Iterated expressions}
  511. \label{itexpr}
  512. An {\it iterated numeric expression} is a primary numeric expression,
  513. which has the following syntactic form:
  514. $$\mbox{\it iterated-operator indexing-expression integrand}$$
  515. where {\it iterated-operator} is the symbolic name of the iterated
  516. operator to be performed (see below), {\it indexing-expression} is an
  517. indexing expression which introduces dummy indices and controls
  518. iterating, {\it integrand} is a numeric expression that participates in
  519. the operation.
  520. In MathProg there exist four iterated operators, which may be used in
  521. numeric expressions:
  522. {\def\arraystretch{2}
  523. \noindent\hfil
  524. \begin{tabular}{@{}lll@{}}
  525. {\tt sum}&summation&$\displaystyle\sum_{(i_1,\dots,i_n)\in\Delta}
  526. f(i_1,\dots,i_n)$\\
  527. {\tt prod}&production&$\displaystyle\prod_{(i_1,\dots,i_n)\in\Delta}
  528. f(i_1,\dots,i_n)$\\
  529. {\tt min}&minimum&$\displaystyle\min_{(i_1,\dots,i_n)\in\Delta}
  530. f(i_1,\dots,i_n)$\\
  531. {\tt max}&maximum&$\displaystyle\max_{(i_1,\dots,i_n)\in\Delta}
  532. f(i_1,\dots,i_n)$\\
  533. \end{tabular}
  534. }
  535. \noindent where $i_1$, \dots, $i_n$ are dummy indices introduced in
  536. the indexing expression, $\Delta$ is the domain, a set of $n$-tuples
  537. specified by the indexing expression which defines particular values
  538. assigned to the dummy indices on performing the iterated operation,
  539. $f(i_1,\dots,i_n)$ is the integrand, a numeric expression whose
  540. resultant value depends on the dummy indices.
  541. The resultant value of an iterated numeric expression is the result of
  542. applying of the iterated operator to its integrand over all $n$-tuples
  543. contained in the domain.
  544. \subsection{Conditional expressions}
  545. \label{ifthen}
  546. A {\it conditional numeric expression} is a primary numeric expression,
  547. which has one of the following two syntactic forms:
  548. $$
  549. {\def\arraystretch{1.4}
  550. \begin{array}{l}
  551. \mbox{{\tt if} $b$ {\tt then} $x$ {\tt else} $y$}\\
  552. \mbox{{\tt if} $b$ {\tt then} $x$}\\
  553. \end{array}
  554. }
  555. $$
  556. where $b$ is an logical expression, $x$ and $y$ are numeric
  557. expressions.
  558. The resultant value of the conditional expression depends on the value
  559. of the logical expression that follows the keyword {\tt if}. If it
  560. takes on the value {\it true}, the value of the conditional expression
  561. is the value of the expression that follows the keyword {\tt then}.
  562. Otherwise, if the logical expression takes on the value {\it false},
  563. the value of the conditional expression is the value of the expression
  564. that follows the keyword {\it else}. If the second, reduced form of the
  565. conditional expression is used and the logical expression takes on the
  566. value {\it false}, the resultant value of the conditional expression is
  567. zero.
  568. \newpage
  569. \subsection{Parenthesized expressions}
  570. Any numeric expression may be enclosed in parentheses that
  571. syntactically makes it a primary numeric expression.
  572. Parentheses may be used in numeric expressions, as in algebra, to
  573. specify the desired order in which operations are to be performed.
  574. Where parentheses are used, the expression within the parentheses is
  575. evaluated before the resultant value is used.
  576. The resultant value of the parenthesized expression is the same as the
  577. value of the expression enclosed within parentheses.
  578. \subsection{Arithmetic operators}
  579. In MathProg there exist the following arithmetic operators, which may
  580. be used in numeric expressions:
  581. \begin{tabular}{@{}ll@{}}
  582. {\tt +} $x$&unary plus\\
  583. {\tt -} $x$&unary minus\\
  584. $x$ {\tt +} $y$&addition\\
  585. $x$ {\tt -} $y$&subtraction\\
  586. $x$ {\tt less} $y$&positive difference (if $x<y$ then 0 else $x-y$)\\
  587. $x$ {\tt *} $y$&multiplication\\
  588. $x$ {\tt /} $y$&division\\
  589. $x$ {\tt div} $y$&quotient of exact division\\
  590. $x$ {\tt mod} $y$&remainder of exact division\\
  591. $x$ {\tt **} $y$, $x$ {\tt\textasciicircum} $y$&exponentiation (raising
  592. to power)\\
  593. \end{tabular}
  594. \noindent where $x$ and $y$ are numeric expressions.
  595. If the expression includes more than one arithmetic operator, all
  596. operators are performed from left to right according to the hierarchy
  597. of operations (see below) with the only exception that the
  598. exponentiaion operators are performed from right to left.
  599. The resultant value of the expression, which contains arithmetic
  600. operators, is the result of applying the operators to their operands.
  601. \subsection{Hierarchy of operations}
  602. \label{hierarchy}
  603. The following list shows the hierarchy of operations in numeric
  604. expressions:
  605. \noindent\hfil
  606. \begin{tabular}{@{}ll@{}}
  607. Operation&Hierarchy\\
  608. \hline
  609. Evaluation of functions ({\tt abs}, {\tt ceil}, etc.)&1st\\
  610. Exponentiation ({\tt**}, {\tt\textasciicircum})&2nd\\
  611. Unary plus and minus ({\tt+}, {\tt-})&3rd\\
  612. Multiplication and division ({\tt*}, {\tt/}, {\tt div}, {\tt mod})&4th\\
  613. Iterated operations ({\tt sum}, {\tt prod}, {\tt min}, {\tt max})&5th\\
  614. Addition and subtraction ({\tt+}, {\tt-}, {\tt less})&6th\\
  615. Conditional evaluation ({\tt if} \dots {\tt then} \dots {\tt else})&
  616. 7th\\
  617. \end{tabular}
  618. \newpage
  619. This hierarchy is used to determine which of two consecutive operations
  620. is performed first. If the first operator is higher than or equal to
  621. the second, the first operation is performed. If it is not, the second
  622. operator is compared to the third, etc. When the end of the expression
  623. is reached, all of the remaining operations are performed in the
  624. reverse order.
  625. \section{Symbolic expressions}
  626. A {\it symbolic expression} is a rule for computing a single symbolic
  627. value represented as a character string.
  628. The primary symbolic expression may be a string literal, dummy index,
  629. unsubscripted parameter, subscripted parameter, built-in function
  630. reference, conditional symbolic expression, or another symbolic
  631. expression enclosed in parentheses.
  632. It is also allowed to use a numeric expression as the primary symbolic
  633. expression, in which case the resultant value of the numeric expression
  634. is automatically converted to the symbolic type.
  635. \para{Examples}
  636. \noindent
  637. \begin{tabular}{@{}ll@{}}
  638. \verb|'May 2003'|&(string literal)\\
  639. \verb|j|&(dummy index)\\
  640. \verb|p|&(unsubscripted parameter)\\
  641. \verb|s['abc',j+1]|&(subscripted parameter)\\
  642. \verb|substr(name[i],k+1,3)|&(function reference)\\
  643. \verb|if i in I then s[i,j] & "..." else t[i+1]|
  644. & (conditional expression) \\
  645. \verb|((10 * b[i,j]) & '.bis')|&(parenthesized expression)\\
  646. \end{tabular}
  647. More general symbolic expressions containing two or more primary
  648. symbolic expressions may be constructed by using the concatenation
  649. operator.
  650. \para{Examples}
  651. \begin{verbatim}
  652. 'abc[' & i & ',' & j & ']'
  653. "from " & city[i] " to " & city[j]
  654. \end{verbatim}
  655. The principles of evaluation of symbolic expressions are completely
  656. analogous to the ones given for numeric expressions (see above).
  657. \subsection{Function references}
  658. In MathProg there exist the following built-in functions which may be
  659. used in symbolic expressions:
  660. \begin{tabular}{@{}p{112pt}p{328pt}@{}}
  661. {\tt substr(}$s${\tt,} $x${\tt)}&substring of $s$ starting from
  662. position $x$\\
  663. {\tt substr(}$s${\tt,} $x${\tt,} $y${\tt)}&substring of $s$ starting
  664. from position $x$ and having length $y$\\
  665. {\tt time2str(}$t${\tt,} $f${\tt)}&converting calendar time to
  666. character string (for details see Section \ref{time2str}, page
  667. \pageref{time2str})\\
  668. \end{tabular}
  669. The first argument of {\tt substr} should be a symbolic expression
  670. while its second and optional third arguments should be numeric
  671. expressions.
  672. The first argument of {\tt time2str} should be a numeric expression,
  673. and its second argument should be a symbolic expression.
  674. The resultant value of the symbolic expression, which is a function
  675. reference, is the result of applying the function to its arguments.
  676. \subsection{Symbolic operators}
  677. Currently in MathProg there exists the only symbolic operator:
  678. $$\mbox{\tt s \& t}$$
  679. where $s$ and $t$ are symbolic expressions. This operator means
  680. concatenation of its two symbolic operands, which are character
  681. strings.
  682. \subsection{Hierarchy of operations}
  683. The following list shows the hierarchy of operations in symbolic
  684. expressions:
  685. \noindent\hfil
  686. \begin{tabular}{@{}ll@{}}
  687. Operation&Hierarchy\\
  688. \hline
  689. Evaluation of numeric operations&1st-7th\\
  690. Concatenation ({\tt\&})&8th\\
  691. Conditional evaluation ({\tt if} \dots {\tt then} \dots {\tt else})&
  692. 9th\\
  693. \end{tabular}
  694. This hierarchy has the same meaning as was explained above for numeric
  695. expressions (see Subsection \ref{hierarchy}, page \pageref{hierarchy}).
  696. \section{Indexing expressions and dummy indices}
  697. \label{indexing}
  698. An {\it indexing expression} is an auxiliary construction, which
  699. specifies a plain set of $n$-tuples and introduces dummy indices. It
  700. has two syntactic forms:
  701. $$
  702. {\def\arraystretch{1.4}
  703. \begin{array}{l}
  704. \mbox{{\tt\{} {\it entry}$_1${\tt,} {\it entry}$_2${\tt,} \dots{\tt,}
  705. {\it entry}$_m$ {\tt\}}}\\
  706. \mbox{{\tt\{} {\it entry}$_1${\tt,} {\it entry}$_2${\tt,} \dots{\tt,}
  707. {\it entry}$_m$ {\tt:} {\it predicate} {\tt\}}}\\
  708. \end{array}
  709. }
  710. $$
  711. where {\it entry}{$_1$}, {\it entry}{$_2$}, \dots, {\it entry}{$_m$}
  712. are indexing entries, {\it predicate} is a logical expression that
  713. specifies an optional predicate (logical condition).
  714. Each {\it indexing entry} in the indexing expression has one of the
  715. following three forms:
  716. $$
  717. {\def\arraystretch{1.4}
  718. \begin{array}{l}
  719. \mbox{$i$ {\tt in} $S$}\\
  720. \mbox{{\tt(}$i_1${\tt,} $i_2${\tt,} \dots{\tt,}$i_n${\tt)} {\tt in}
  721. $S$}\\
  722. \mbox{$S$}\\
  723. \end{array}
  724. }
  725. $$
  726. where $i_1$, $i_2$, \dots, $i_n$ are indices, $S$ is a set expression
  727. (discussed in the next section) that specifies the basic set.
  728. \newpage
  729. The number of indices in the indexing entry should be the same as the
  730. dimension of the basic set $S$, i.e. if $S$ consists of 1-tuples, the
  731. first form should be used, and if $S$ consists of $n$-tuples, where
  732. $n>1$, the second form should be used.
  733. If the first form of the indexing entry is used, the index $i$ can be
  734. a dummy index only (see below). If the second form is used, the indices
  735. $i_1$, $i_2$, \dots, $i_n$ can be either dummy indices or some numeric
  736. or symbolic expressions, where at least one index should be a dummy
  737. index. The third, reduced form of the indexing entry has the same
  738. effect as if there were $i$ (if $S$ is 1-dimensional) or
  739. $i_1$, $i_2$, \dots, $i_n$ (if $S$ is $n$-dimensional) all specified as
  740. dummy indices.
  741. A {\it dummy index} is an auxiliary model object, which acts like an
  742. individual variable. Values assigned to dummy indices are components of
  743. $n$-tuples from basic sets, i.e. some numeric and symbolic quantities.
  744. For referencing purposes dummy indices can be provided with symbolic
  745. names. However, unlike other model objects (sets, parameters, etc.)
  746. dummy indices need not be explicitly declared. Each {\it undeclared}
  747. symbolic name being used in the indexing position of an indexing entry
  748. is recognized as the symbolic name of corresponding dummy index.
  749. Symbolic names of dummy indices are valid only within the scope of the
  750. indexing expression, where the dummy indices were introduced. Beyond
  751. the scope the dummy indices are completely inaccessible, so the same
  752. symbolic names may be used for other purposes, in particular, to
  753. represent dummy indices in other indexing expressions.
  754. The scope of indexing expression, where implicit declarations of dummy
  755. indices are valid, depends on the context, in which the indexing
  756. expression is used:
  757. \vspace*{-8pt}
  758. \begin{itemize}
  759. \item If the indexing expression is used in iterated operator, its
  760. scope extends until the end of the integrand.
  761. \item If the indexing expression is used as a primary set expression,
  762. its scope extends until the end of that indexing expression.
  763. \item If the indexing expression is used to define the subscript domain
  764. in declarations of some model objects, its scope extends until the end
  765. of the corresponding statement.
  766. \end{itemize}
  767. \vspace*{-8pt}
  768. The indexing mechanism implemented by means of indexing expressions is
  769. best explained by some examples discussed below.
  770. Let there be given three sets:
  771. $$
  772. {\def\arraystretch{1.4}
  773. \begin{array}{l}
  774. A=\{4,7,9\},\\
  775. B=\{(1,Jan),(1,Feb),(2,Mar),(2,Apr),(3,May),(3,Jun)\},\\
  776. C=\{a,b,c\},\\
  777. \end{array}
  778. }
  779. $$
  780. where $A$ and $C$ consist of 1-tuples (singlets), $B$ consists of
  781. 2-tuples (doublets). Consider the following indexing expression:
  782. $$\mbox{{\tt\{i in A, (j,k) in B, l in C\}}}$$
  783. where {\tt i}, {\tt j}, {\tt k}, and {\tt l} are dummy indices.
  784. \newpage
  785. Although MathProg is not a procedural language, for any indexing
  786. expression an equivalent algorithmic description can be given. In
  787. particular, the algorithmic description of the indexing expression
  788. above could look like follows:
  789. \noindent\hfil
  790. \begin{tabular}{@{}l@{}}
  791. {\bf for all} $i\in A$ {\bf do}\\
  792. \hspace{16pt}{\bf for all} $(j,k)\in B$ {\bf do}\\
  793. \hspace{32pt}{\bf for all} $l\in C$ {\bf do}\\
  794. \hspace{48pt}{\it action};\\
  795. \end{tabular}
  796. \noindent where the dummy indices $i$, $j$, $k$, $l$ are consecutively
  797. assigned corresponding components of $n$-tuples from the basic sets $A$,
  798. $B$, $C$, and {\it action} is some action that depends on the context,
  799. where the indexing expression is used. For example, if the action were
  800. printing current values of dummy indices, the printout would look like
  801. follows:
  802. \noindent\hfil
  803. \begin{tabular}{@{}llll@{}}
  804. $i=4$&$j=1$&$k=Jan$&$l=a$\\
  805. $i=4$&$j=1$&$k=Jan$&$l=b$\\
  806. $i=4$&$j=1$&$k=Jan$&$l=c$\\
  807. $i=4$&$j=1$&$k=Feb$&$l=a$\\
  808. $i=4$&$j=1$&$k=Feb$&$l=b$\\
  809. \multicolumn{4}{c}{.\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .}\\
  810. $i=9$&$j=3$&$k=Jun$&$l=b$\\
  811. $i=9$&$j=3$&$k=Jun$&$l=c$\\
  812. \end{tabular}
  813. Let the example indexing expression be used in the following iterated
  814. operation:
  815. $$\mbox{{\tt sum\{i in A, (j,k) in B, l in C\} p[i,j,k,l]}}$$
  816. where {\tt p} is a 4-dimensional numeric parameter or some numeric
  817. expression whose resultant value depends on {\tt i}, {\tt j}, {\tt k},
  818. and {\tt l}. In this case the action is summation, so the resultant
  819. value of the primary numeric expression is:
  820. $$\sum_{i\in A,(j,k)\in B,l\in C}(p_{ijkl}).$$
  821. Now let the example indexing expression be used as a primary set
  822. expression. In this case the action is gathering all 4-tuples
  823. (quadruplets) of the form $(i,j,k,l)$ in one set, so the resultant
  824. value of such operation is simply the Cartesian product of the basic
  825. sets:
  826. $$A\times B\times C=\{(i,j,k,l):i\in A,(j,k)\in B,l\in C\}.$$
  827. Note that in this case the same indexing expression might be written in
  828. the reduced form:
  829. $$\mbox{{\tt\{A, B, C\}}}$$
  830. because the dummy indices $i$, $j$, $k$, and $l$ are not referenced and
  831. therefore their symbolic names need not be specified.
  832. \newpage
  833. Finally, let the example indexing expression be used as the subscript
  834. domain in the declaration of a 4-dimensional model object, say,
  835. a numeric parameter:
  836. $$\mbox{{\tt param p\{i in A, (j,k) in B, l in C\}} \dots {\tt;}}$$
  837. \noindent In this case the action is generating the parameter members,
  838. where each member has the form $p[i,j,k,l]$.
  839. As was said above, some indices in the second form of indexing entries
  840. may be numeric or symbolic expressions, not only dummy indices. In this
  841. case resultant values of such expressions play role of some logical
  842. conditions to select only that $n$-tuples from the Cartesian product of
  843. basic sets that satisfy these conditions.
  844. Consider, for example, the following indexing expression:
  845. $$\mbox{{\tt\{i in A, (i-1,k) in B, l in C\}}}$$
  846. where {\tt i}, {\tt k}, {\tt l} are dummy indices, and {\tt i-1} is
  847. a numeric expression. The algorithmic decsription of this indexing
  848. expression is the following:
  849. \noindent\hfil
  850. \begin{tabular}{@{}l@{}}
  851. {\bf for all} $i\in A$ {\bf do}\\
  852. \hspace{16pt}{\bf for all} $(j,k)\in B$ {\bf and} $j=i-1$ {\bf do}\\
  853. \hspace{32pt}{\bf for all} $l\in C$ {\bf do}\\
  854. \hspace{48pt}{\it action};\\
  855. \end{tabular}
  856. \noindent Thus, if this indexing expression were used as a primary set
  857. expression, the resultant set would be the following:
  858. $$\{(4,May,a),(4,May,b),(4,May,c),(4,Jun,a),(4,Jun,b),(4,Jun,c)\}.$$
  859. Should note that in this case the resultant set consists of 3-tuples,
  860. not of 4-tuples, because in the indexing expression there is no dummy
  861. index that corresponds to the first component of 2-tuples from the set
  862. $B$.
  863. The general rule is: the number of components of $n$-tuples defined by
  864. an indexing expression is the same as the number of dummy indices in
  865. that expression, where the correspondence between dummy indices and
  866. components on $n$-tuples in the resultant set is positional, i.e. the
  867. first dummy index corresponds to the first component, the second dummy
  868. index corresponds to the second component, etc.
  869. In some cases it is needed to select a subset from the Cartesian
  870. product of some sets. This may be attained by using an optional logical
  871. predicate, which is specified in the indexing expression.
  872. Consider, for example, the following indexing expression:
  873. $$\mbox{{\tt\{i in A, (j,k) in B, l in C: i <= 5 and k <> 'Mar'\}}}$$
  874. where the logical expression following the colon is a predicate. The
  875. algorithmic description of this indexing expression is the following:
  876. \noindent\hfil
  877. \begin{tabular}{@{}l@{}}
  878. {\bf for all} $i\in A$ {\bf do}\\
  879. \hspace{16pt}{\bf for all} $(j,k)\in B$ {\bf do}\\
  880. \hspace{32pt}{\bf for all} $l\in C$ {\bf do}\\
  881. \hspace{48pt}{\bf if} $i\leq 5$ {\bf and} $k\neq`Mar'$ {\bf then}\\
  882. \hspace{64pt}{\it action};\\
  883. \end{tabular}
  884. \noindent Thus, if this indexing expression were used as a primary set
  885. expression, the resultant set would be the following:
  886. $$\{(4,1,Jan,a),(4,1,Feb,a),(4,2,Apr,a),\dots,(4,3,Jun,c)\}.$$
  887. If no predicate is specified in the indexing expression, one, which
  888. takes on the value {\it true}, is assumed.
  889. \section{Set expressions}
  890. A {\it set expression} is a rule for computing an elemental set, i.e.
  891. a collection of $n$-tuples, where components of $n$-tuples are numeric
  892. and symbolic quantities.
  893. The primary set expression may be a literal set, unsubscripted set,
  894. subscripted set, ``arithmetic'' set, indexing expression, iterated set
  895. expression, conditional set expression, or another set expression
  896. enclosed in parentheses.
  897. \para{Examples}
  898. \noindent
  899. \begin{tabular}{@{}ll@{}}
  900. \verb|{(123,'aaa'), (i+1,'bbb'), (j-1,'ccc')}| &(literal set)\\
  901. \verb|I| &(unsubscripted set)\\
  902. \verb|S[i-1,j+1]| &(subscripted set)\\
  903. \verb|1..t-1 by 2| &(``arithmetic'' set)\\
  904. \verb|{t in 1..T, (t+1,j) in S: (t,j) in F}| &(indexing expression)\\
  905. \verb|setof{i in I, j in J}(i+1,j-1)| &(iterated set expression)\\
  906. \verb|if i < j then S[i,j] else F diff S[i,j]| &(conditional set
  907. expression)\\
  908. \verb|(1..10 union 21..30)| &(parenthesized set expression)\\
  909. \end{tabular}
  910. More general set expressions containing two or more primary set
  911. expressions may be constructed by using certain set operators.
  912. \para{Examples}
  913. \begin{verbatim}
  914. (A union B) inter (I cross J)
  915. 1..10 cross (if i < j then {'a', 'b', 'c'} else {'d', 'e', 'f'})
  916. \end{verbatim}
  917. \subsection{Literal sets}
  918. A {\it literal set} is a primary set expression, which has the
  919. following two syntactic forms:
  920. $$
  921. {\def\arraystretch{1.4}
  922. \begin{array}{l}
  923. \mbox{{\tt\{}$e_1${\tt,} $e_2${\tt,} \dots{\tt,} $e_m${\tt\}}}\\
  924. \mbox{{\tt\{(}$e_{11}${\tt,} \dots{\tt,} $e_{1n}${\tt),}
  925. {\tt(}$e_{21}${\tt,} \dots{\tt,} $e_{2n}${\tt),} \dots{\tt,}
  926. {\tt(}$e_{m1}${\tt,} \dots{\tt,} $e_{mn}${\tt)\}}}\\
  927. \end{array}
  928. }
  929. $$
  930. where $e_1$, \dots, $e_m$, $e_{11}$, \dots, $e_{mn}$ are numeric or
  931. symbolic expressions.
  932. If the first form is used, the resultant set consists of 1-tuples
  933. (singlets) enumerated within the curly braces. It is allowed to specify
  934. an empty set as {\tt\{\ \}}, which has no 1-tuples. If the second form
  935. is used, the resultant set consists of $n$-tuples enumerated within the
  936. curly braces, where a particular $n$-tuple consists of corresponding
  937. components enumerated within the parentheses. All $n$-tuples should
  938. have the same number of components.
  939. \subsection{Unsubscripted sets}
  940. If the primary set expression is an unsubscripted set (which should be
  941. 0-dimen\-sional), the resultant set is an elemental set associated with
  942. the corresponding set object.
  943. \subsection{Subscripted sets}
  944. The primary set expression, which refers to a subscripted set, has the
  945. following syntactic form:
  946. $$\mbox{{\it name}{\tt[}$i_1${\tt,} $i_2${\tt,} \dots{\tt,}
  947. $i_n${\tt]}}$$
  948. where {\it name} is the symbolic name of the set object, $i_1$, $i_2$,
  949. \dots, $i_n$ are subscripts.
  950. Each subscript should be a numeric or symbolic expression. The number
  951. of subscripts in the subscript list should be the same as the dimension
  952. of the set object with which the subscript list is associated.
  953. Actual values of subscript expressions are used to identify a
  954. particular member of the set object that determines the resultant set.
  955. \subsection{``Arithmetic'' sets}
  956. The primary set expression, which is an ``arithmetic'' set, has the
  957. following two syntactic forms:
  958. $$
  959. {\def\arraystretch{1.4}
  960. \begin{array}{l}
  961. \mbox{$t_0$ {\tt..} $t_1$ {\tt by} $\delta t$}\\
  962. \mbox{$t_0$ {\tt..} $t_1$}\\
  963. \end{array}
  964. }
  965. $$
  966. where $t_0$, $t_1$, and $\delta t$ are numeric expressions (the value
  967. of $\delta t$ should not be zero). The second form is equivalent to the
  968. first form, where $\delta t=1$.
  969. If $\delta t>0$, the resultant set is determined as follows:
  970. $$\{t:\exists k\in{\cal Z}(t=t_0+k\delta t,\ t_0\leq t\leq t_1)\}.$$
  971. Otherwise, if $\delta t<0$, the resultant set is determined as follows:
  972. $$\{t:\exists k\in{\cal Z}(t=t_0+k\delta t,\ t_1\leq t\leq t_0)\}.$$
  973. \subsection{Indexing expressions}
  974. If the primary set expression is an indexing expression, the resultant
  975. set is determined as described above in Section \ref{indexing}, page
  976. \pageref{indexing}.
  977. \newpage
  978. \subsection{Iterated expressions}
  979. An {\it iterated set expression} is a primary set expression, which has
  980. the following syntactic form:
  981. $$\mbox{{\tt setof} {\it indexing-expression} {\it integrand}}$$
  982. where {\it indexing-expression} is an indexing expression, which
  983. introduces dummy indices and controls iterating, {\it integrand} is
  984. either a single numeric or symbolic expression or a list of numeric and
  985. symbolic expressions separated by commae and enclosed in parentheses.
  986. If the integrand is a single numeric or symbolic expression, the
  987. resultant set consists of 1-tuples and is determined as follows:
  988. $$\{x:(i_1,\dots,i_n)\in\Delta\},$$
  989. \noindent where $x$ is a value of the integrand, $i_1$, \dots, $i_n$
  990. are dummy indices introduced in the indexing expression, $\Delta$ is
  991. the domain, a set of $n$-tuples specified by the indexing expression,
  992. which defines particular values assigned to the dummy indices on
  993. performing the iterated operation.
  994. If the integrand is a list containing $m$ numeric and symbolic
  995. expressions, the resultant set consists of $m$-tuples and is determined
  996. as follows:
  997. $$\{(x_1,\dots,x_m):(i_1,\dots,i_n)\in\Delta\},$$
  998. where $x_1$, \dots, $x_m$ are values of the expressions in the
  999. integrand list, $i_1$, \dots, $i_n$ and $\Delta$ have the same meaning
  1000. as above.
  1001. \subsection{Conditional expressions}
  1002. A {\it conditional set expression} is a primary set expression that has
  1003. the following syntactic form:
  1004. $$\mbox{{\tt if} $b$ {\tt then} $X$ {\tt else} $Y$}$$
  1005. where $b$ is an logical expression, $X$ and $Y$ are set expressions,
  1006. which should define sets of the same dimension.
  1007. The resultant value of the conditional expression depends on the value
  1008. of the logical expression that follows the keyword {\tt if}. If it
  1009. takes on the value {\it true}, the resultant set is the value of the
  1010. expression that follows the keyword {\tt then}. Otherwise, if the
  1011. logical expression takes on the value {\it false}, the resultant set is
  1012. the value of the expression that follows the keyword {\tt else}.
  1013. \subsection{Parenthesized expressions}
  1014. Any set expression may be enclosed in parentheses that syntactically
  1015. makes it a primary set expression.
  1016. Parentheses may be used in set expressions, as in algebra, to specify
  1017. the desired order in which operations are to be performed. Where
  1018. parentheses are used, the expression within the parentheses is
  1019. evaluated before the resultant value is used.
  1020. The resultant value of the parenthesized expression is the same as the
  1021. value of the expression enclosed within parentheses.
  1022. \newpage
  1023. \subsection{Set operators}
  1024. In MathProg there exist the following set operators, which may be used
  1025. in set expressions:
  1026. \begin{tabular}{@{}ll@{}}
  1027. $X$ {\tt union} $Y$&union $X\cup Y$\\
  1028. $X$ {\tt diff} $Y$&difference $X\backslash Y$\\
  1029. $X$ {\tt symdiff} $Y$&symmetric difference
  1030. $X\oplus Y=(X\backslash Y)\cup(Y\backslash X)$\\
  1031. $X$ {\tt inter} $Y$&intersection $X\cap Y$\\
  1032. $X$ {\tt cross} $Y$&cross (Cartesian) product $X\times Y$\\
  1033. \end{tabular}
  1034. \noindent where $X$ and Y are set expressions, which should define sets
  1035. of identical dimension (except the Cartesian product).
  1036. If the expression includes more than one set operator, all operators
  1037. are performed from left to right according to the hierarchy of
  1038. operations (see below).
  1039. The resultant value of the expression, which contains set operators, is
  1040. the result of applying the operators to their operands.
  1041. The dimension of the resultant set, i.e. the dimension of $n$-tuples,
  1042. of which the resultant set consists of, is the same as the dimension of
  1043. the operands, except the Cartesian product, where the dimension of the
  1044. resultant set is the sum of the dimensions of its operands.
  1045. \subsection{Hierarchy of operations}
  1046. The following list shows the hierarchy of operations in set
  1047. expressions:
  1048. \noindent\hfil
  1049. \begin{tabular}{@{}ll@{}}
  1050. Operation&Hierarchy\\
  1051. \hline
  1052. Evaluation of numeric operations&1st-7th\\
  1053. Evaluation of symbolic operations&8th-9th\\
  1054. Evaluation of iterated or ``arithmetic'' set ({\tt setof}, {\tt..})&
  1055. 10th\\
  1056. Cartesian product ({\tt cross})&11th\\
  1057. Intersection ({\tt inter})&12th\\
  1058. Union and difference ({\tt union}, {\tt diff}, {\tt symdiff})&13th\\
  1059. Conditional evaluation ({\tt if} \dots {\tt then} \dots {\tt else})&
  1060. 14th\\
  1061. \end{tabular}
  1062. This hierarchy has the same meaning as was explained above for numeric
  1063. expressions (see Subsection \ref{hierarchy}, page \pageref{hierarchy}).
  1064. \newpage
  1065. \section{Logical expressions}
  1066. A {\it logical expression} is a rule for computing a single logical
  1067. value, which can be either {\it true} or {\it false}.
  1068. The primary logical expression may be a numeric expression, relational
  1069. expression, iterated logical expression, or another logical expression
  1070. enclosed in parentheses.
  1071. \para{Examples}
  1072. \noindent
  1073. \begin{tabular}{@{}ll@{}}
  1074. \verb|i+1| &(numeric expression)\\
  1075. \verb|a[i,j] < 1.5| &(relational expression)\\
  1076. \verb|s[i+1,j-1] <> 'Mar' & year | &(relational expression)\\
  1077. \verb|(i+1,'Jan') not in I cross J| &(relational expression)\\
  1078. \verb|S union T within A[i] inter B[j]| &(relational expression)\\
  1079. \verb|forall{i in I, j in J} a[i,j] < .5 * b[i]| &(iterated logical
  1080. expression)\\
  1081. \verb|(a[i,j] < 1.5 or b[i] >= a[i,j])| &(parenthesized logical
  1082. expression)\\
  1083. \end{tabular}
  1084. More general logical expressions containing two or more primary logical
  1085. expressions may be constructed by using certain logical operators.
  1086. \para{Examples}
  1087. \begin{verbatim}
  1088. not (a[i,j] < 1.5 or b[i] >= a[i,j]) and (i,j) in S
  1089. (i,j) in S or (i,j) not in T diff U
  1090. \end{verbatim}
  1091. \vspace*{-8pt}
  1092. \subsection{Numeric expressions}
  1093. The resultant value of the primary logical expression, which is a
  1094. numeric expression, is {\it true}, if the resultant value of the
  1095. numeric expression is non-zero. Otherwise the resultant value of the
  1096. logical expression is {\it false}.
  1097. \vspace*{-8pt}
  1098. \subsection{Relational operators}
  1099. In MathProg there exist the following relational operators, which may
  1100. be used in logical expressions:
  1101. \begin{tabular}{@{}ll@{}}
  1102. $x$ {\tt<} $y$&test on $x<y$\\
  1103. $x$ {\tt<=} $y$&test on $x\leq y$\\
  1104. $x$ {\tt=} $y$, $x$ {\tt==} $y$&test on $x=y$\\
  1105. $x$ {\tt>=} $y$&test on $x\geq y$\\
  1106. $x$ {\tt>} $y$&test on $x>y$\\
  1107. $x$ {\tt<>} $y$, $x$ {\tt!=} $y$&test on $x\neq y$\\
  1108. $x$ {\tt in} $Y$&test on $x\in Y$\\
  1109. {\tt(}$x_1${\tt,}\dots{\tt,}$x_n${\tt)} {\tt in} $Y$&test on
  1110. $(x_1,\dots,x_n)\in Y$\\
  1111. $x$ {\tt not} {\tt in} $Y$, $x$ {\tt!in} $Y$&test on $x\not\in Y$\\
  1112. {\tt(}$x_1${\tt,}\dots{\tt,}$x_n${\tt)} {\tt not} {\tt in} $Y$,
  1113. {\tt(}$x_1${\tt,}\dots{\tt,}$x_n${\tt)} {\tt !in} $Y$&test on
  1114. $(x_1,\dots,x_n)\not\in Y$\\
  1115. $X$ {\tt within} $Y$&test on $X\subseteq Y$\\
  1116. $X$ {\tt not} {\tt within} $Y$, $X$ {\tt !within} $Y$&test on
  1117. $X\not\subseteq Y$\\
  1118. \end{tabular}
  1119. \noindent where $x$, $x_1$, \dots, $x_n$, $y$ are numeric or symbolic
  1120. expressions, $X$ and $Y$ are set expression.
  1121. \newpage
  1122. 1. In the operations {\tt in}, {\tt not in}, and {\tt !in} the
  1123. number of components in the first operands should be the same as the
  1124. dimension of the second operand.
  1125. 2. In the operations {\tt within}, {\tt not within}, and {\tt !within}
  1126. both operands should have identical dimension.
  1127. All the relational operators listed above have their conventional
  1128. mathematical meaning. The resultant value is {\it true}, if
  1129. corresponding relation is satisfied for its operands, otherwise
  1130. {\it false}. (Note that symbolic values are ordered lexicographically,
  1131. and any numeric value precedes any symbolic value.)
  1132. \subsection{Iterated expressions}
  1133. An {\it iterated logical expression} is a primary logical expression,
  1134. which has the following syntactic form:
  1135. $$\mbox{{\it iterated-operator} {\it indexing-expression}
  1136. {\it integrand}}$$
  1137. where {\it iterated-operator} is the symbolic name of the iterated
  1138. operator to be performed (see below), {\it indexing-expression} is an
  1139. indexing expression which introduces dummy indices and controls
  1140. iterating, {\it integrand} is a numeric expression that participates in
  1141. the operation.
  1142. In MathProg there exist two iterated operators, which may be used in
  1143. logical expressions:
  1144. {\def\arraystretch{1.4}
  1145. \noindent\hfil
  1146. \begin{tabular}{@{}lll@{}}
  1147. {\tt forall}&$\forall$-quantification&$\displaystyle
  1148. \forall(i_1,\dots,i_n)\in\Delta[f(i_1,\dots,i_n)],$\\
  1149. {\tt exists}&$\exists$-quantification&$\displaystyle
  1150. \exists(i_1,\dots,i_n)\in\Delta[f(i_1,\dots,i_n)],$\\
  1151. \end{tabular}
  1152. }
  1153. \noindent where $i_1$, \dots, $i_n$ are dummy indices introduced in
  1154. the indexing expression, $\Delta$ is the domain, a set of $n$-tuples
  1155. specified by the indexing expression which defines particular values
  1156. assigned to the dummy indices on performing the iterated operation,
  1157. $f(i_1,\dots,i_n)$ is the integrand, a logical expression whose
  1158. resultant value depends on the dummy indices.
  1159. For $\forall$-quantification the resultant value of the iterated
  1160. logical expression is {\it true}, if the value of the integrand is
  1161. {\it true} for all $n$-tuples contained in the domain, otherwise
  1162. {\it false}.
  1163. For $\exists$-quantification the resultant value of the iterated
  1164. logical expression is {\it false}, if the value of the integrand is
  1165. {\it false} for all $n$-tuples contained in the domain, otherwise
  1166. {\it true}.
  1167. \subsection{Parenthesized expressions}
  1168. Any logical expression may be enclosed in parentheses that
  1169. syntactically makes it a primary logical expression.
  1170. Parentheses may be used in logical expressions, as in algebra, to
  1171. specify the desired order in which operations are to be performed.
  1172. Where parentheses are used, the expression within the parentheses is
  1173. evaluated before the resultant value is used.
  1174. The resultant value of the parenthesized expression is the same as the
  1175. value of the expression enclosed within parentheses.
  1176. \newpage
  1177. \subsection{Logical operators}
  1178. In MathProg there exist the following logical operators, which may be
  1179. used in logical expressions:
  1180. \begin{tabular}{@{}ll@{}}
  1181. {\tt not} $x$, {\tt!}$x$&negation $\neg\ x$\\
  1182. $x$ {\tt and} $y$, $x$ {\tt\&\&} $y$&conjunction (logical ``and'')
  1183. $x\;\&\;y$\\
  1184. $x$ {\tt or} $y$, $x$ {\tt||} $y$&disjunction (logical ``or'')
  1185. $x\vee y$\\
  1186. \end{tabular}
  1187. \noindent where $x$ and $y$ are logical expressions.
  1188. If the expression includes more than one logical operator, all
  1189. operators are performed from left to right according to the hierarchy
  1190. of the operations (see below). The resultant value of the expression,
  1191. which contains logical operators, is the result of applying the
  1192. operators to their operands.
  1193. \subsection{Hierarchy of operations}
  1194. The following list shows the hierarchy of operations in logical
  1195. expressions:
  1196. \noindent\hfil
  1197. \begin{tabular}{@{}ll@{}}
  1198. Operation&Hierarchy\\
  1199. \hline
  1200. Evaluation of numeric operations&1st-7th\\
  1201. Evaluation of symbolic operations&8th-9th\\
  1202. Evaluation of set operations&10th-14th\\
  1203. Relational operations ({\tt<}, {\tt<=}, etc.)&15th\\
  1204. Negation ({\tt not}, {\tt!})&16th\\
  1205. Conjunction ({\tt and}, {\tt\&\&})&17th\\
  1206. $\forall$- and $\exists$-quantification ({\tt forall}, {\tt exists})&
  1207. 18th\\
  1208. Disjunction ({\tt or}, {\tt||})&19th\\
  1209. \end{tabular}
  1210. This hierarchy has the same meaning as was explained above for numeric
  1211. expressions (see Subsection \ref{hierarchy}, page \pageref{hierarchy}).
  1212. \section{Linear expressions}
  1213. A {\it linear expression} is a rule for computing so called
  1214. a {\it linear form} or simply a {\it formula}, which is a linear (or
  1215. affine) function of elemental variables.
  1216. The primary linear expression may be an unsubscripted variable,
  1217. subscripted variable, iterated linear expression, conditional linear
  1218. expression, or another linear expression enclosed in parentheses.
  1219. It is also allowed to use a numeric expression as the primary linear
  1220. expression, in which case the resultant value of the numeric expression
  1221. is automatically converted to a formula that includes the constant term
  1222. only.
  1223. \para{Examples}
  1224. \noindent
  1225. \begin{tabular}{@{}ll@{}}
  1226. \verb|z| &(unsubscripted variable)\\
  1227. \verb|x[i,j]| &(subscripted variable)\\
  1228. \verb|sum{j in J} (a[i,j] * x[i,j] + 3 * y[i-1])| &
  1229. (iterated linear expression)\\
  1230. \verb|if i in I then x[i,j] else 1.5 * z + 3.25| &
  1231. (conditional linear expression)\\
  1232. \verb|(a[i,j] * x[i,j] + y[i-1] + .1)| &
  1233. (parenthesized linear expression)\\
  1234. \end{tabular}
  1235. More general linear expressions containing two or more primary linear
  1236. expressions may be constructed by using certain arithmetic operators.
  1237. \para{Examples}
  1238. \begin{verbatim}
  1239. 2 * x[i-1,j+1] + 3.5 * y[k] + .5 * z
  1240. (- x[i,j] + 3.5 * y[k]) / sum{t in T} abs(d[i,j,t])
  1241. \end{verbatim}
  1242. \vspace*{-5pt}
  1243. \subsection{Unsubscripted variables}
  1244. If the primary linear expression is an unsubscripted variable (which
  1245. should be 0-dimensional), the resultant formula is that unsubscripted
  1246. variable.
  1247. \vspace*{-5pt}
  1248. \subsection{Subscripted variables}
  1249. The primary linear expression, which refers to a subscripted variable,
  1250. has the following syntactic form:
  1251. $$\mbox{{\it name}{\tt[}$i_1${\tt,} $i_2${\tt,} \dots{\tt,}
  1252. $i_n${\tt]}}$$
  1253. where {\it name} is the symbolic name of the model variable, $i_1$,
  1254. $i_2$, \dots, $i_n$ are subscripts.
  1255. Each subscript should be a numeric or symbolic expression. The number
  1256. of subscripts in the subscript list should be the same as the dimension
  1257. of the model variable with which the subscript list is associated.
  1258. Actual values of the subscript expressions are used to identify a
  1259. particular member of the model variable that determines the resultant
  1260. formula, which is an elemental variable associated with corresponding
  1261. member.
  1262. \vspace*{-5pt}
  1263. \subsection{Iterated expressions}
  1264. An {\it iterated linear expression} is a primary linear expression,
  1265. which has the following syntactic form:
  1266. $$\mbox{{\tt sum} {\it indexing-expression} {\it integrand}}$$
  1267. where {\it indexing-expression} is an indexing expression, which
  1268. introduces dummy indices and controls iterating, {\it integrand} is
  1269. a linear expression that participates in the operation.
  1270. The iterated linear expression is evaluated exactly in the same way as
  1271. the iterated numeric expression (see Subection \ref{itexpr}, page
  1272. \pageref{itexpr}) with exception that the integrand participated in the
  1273. summation is a formula, not a numeric value.
  1274. \vspace*{-5pt}
  1275. \subsection{Conditional expressions}
  1276. A {\it conditional linear expression} is a primary linear expression,
  1277. which has one of the following two syntactic forms:
  1278. $$
  1279. {\def\arraystretch{1.4}
  1280. \begin{array}{l}
  1281. \mbox{{\tt if} $b$ {\tt then} $f$ {\tt else} $g$}\\
  1282. \mbox{{\tt if} $b$ {\tt then} $f$}\\
  1283. \end{array}
  1284. }
  1285. $$
  1286. where $b$ is an logical expression, $f$ and $g$ are linear expressions.
  1287. \newpage
  1288. The conditional linear expression is evaluated exactly in the same way
  1289. as the conditional numeric expression (see Subsection \ref{ifthen},
  1290. page \pageref{ifthen}) with exception that operands participated in the
  1291. operation are formulae, not numeric values.
  1292. \subsection{Parenthesized expressions}
  1293. Any linear expression may be enclosed in parentheses that syntactically
  1294. makes it a primary linear expression.
  1295. Parentheses may be used in linear expressions, as in algebra, to
  1296. specify the desired order in which operations are to be performed.
  1297. Where parentheses are used, the expression within the parentheses is
  1298. evaluated before the resultant formula is used.
  1299. The resultant value of the parenthesized expression is the same as the
  1300. value of the expression enclosed within parentheses.
  1301. \subsection{Arithmetic operators}
  1302. In MathProg there exists the following arithmetic operators, which may
  1303. be used in linear expressions:
  1304. \begin{tabular}{@{}ll@{}}
  1305. {\tt+} $f$&unary plus\\
  1306. {\tt-} $f$&unary minus\\
  1307. $f$ {\tt+} $g$&addition\\
  1308. $f$ {\tt-} $g$&subtraction\\
  1309. $x$ {\tt*} $f$, $f$ {\tt*} $x$&multiplication\\
  1310. $f$ {\tt/} $x$&division
  1311. \end{tabular}
  1312. \noindent where $f$ and $g$ are linear expressions, $x$ is a numeric
  1313. expression (more precisely, a linear expression containing only the
  1314. constant term).
  1315. If the expression includes more than one arithmetic operator, all
  1316. operators are performed from left to right according to the hierarchy
  1317. of operations (see below). The resultant value of the expression, which
  1318. contains arithmetic operators, is the result of applying the operators
  1319. to their operands.
  1320. \subsection{Hierarchy of operations}
  1321. The hierarchy of arithmetic operations used in linear expressions is
  1322. the same as for numeric expressions (see Subsection \ref{hierarchy},
  1323. page \pageref{hierarchy}).
  1324. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1325. \chapter{Statements}
  1326. {\it Statements} are basic units of the model description. In MathProg
  1327. all statements are divided into two categories: declaration statements
  1328. and functional statements.
  1329. {\it Declaration statements} (set statement, parameter statement,
  1330. variable statement, constraint statement, objective statement) are used
  1331. to declare model objects of certain kinds and define certain properties
  1332. of such objects.
  1333. {\it Functional statements} (solve statement, check statement, display
  1334. statement, printf statement, loop statement, table statement) are
  1335. intended for performing some specific actions.
  1336. Note that declaration statements may follow in arbitrary order, which
  1337. does not affect the result of translation. However, any model object
  1338. should be declared before it is referenced in other statements.
  1339. \section{Set statement}
  1340. \noindent
  1341. \framebox[468pt][l]{
  1342. \parbox[c][24pt]{468pt}{
  1343. \hspace{6pt} {\tt set} {\it name} {\it alias} {\it domain} {\tt,}
  1344. {\it attrib} {\tt,} \dots {\tt,} {\it attrib} {\tt;}
  1345. }}
  1346. \medskip
  1347. \noindent
  1348. {\it name} is a symbolic name of the set;
  1349. \noindent
  1350. {\it alias} is an optional string literal, which specifies an alias of
  1351. the set;
  1352. \noindent
  1353. {\it domain} is an optional indexing expression, which specifies
  1354. a subscript domain of the set;
  1355. \noindent
  1356. {\it attrib}, \dots, {\it attrib} are optional attributes of the set.
  1357. (Commae preceding attributes may be omitted.)
  1358. \para{Optional attributes}
  1359. \vspace*{-8pt}
  1360. \begin{description}
  1361. \item[{\tt dimen} $n$]\hspace*{0pt}\\
  1362. specifies the dimension of $n$-tuples which the set consists of;
  1363. \item[{\tt within} {\it expression}]\hspace*{0pt}\\
  1364. specifies a superset which restricts the set or all its members
  1365. (elemental sets) to be within that superset;
  1366. \item[{\tt:=} {\it expression}]\hspace*{0pt}\\
  1367. specifies an elemental set assigned to the set or its members;
  1368. \item[{\tt default} {\it expression}]\hspace*{0pt}\\
  1369. specifies an elemental set assigned to the set or its members whenever
  1370. no appropriate data are available in the data section.
  1371. \end{description}
  1372. \vspace*{-8pt}
  1373. \para{Examples}
  1374. \begin{verbatim}
  1375. set nodes;
  1376. set arcs within nodes cross nodes;
  1377. set step{s in 1..maxiter} dimen 2 := if s = 1 then arcs else step[s-1]
  1378. union setof{k in nodes, (i,k) in step[s-1], (k,j) in step[s-1]}(i,j);
  1379. set A{i in I, j in J}, within B[i+1] cross C[j-1], within D diff E,
  1380. default {('abc',123), (321,'cba')};
  1381. \end{verbatim}
  1382. The set statement declares a set. If the subscript domain is not
  1383. specified, the set is a simple set, otherwise it is an array of
  1384. elemental sets.
  1385. The {\tt dimen} attribute specifies the dimension of $n$-tuples, which
  1386. the set (if it is a simple set) or its members (if the set is an array
  1387. of elemental sets) consist of, where $n$ should be an unsigned integer
  1388. from 1 to 20. At most one {\tt dimen} attribute can be specified. If
  1389. the {\tt dimen} attribute is not specified, the dimension of $n$-tuples
  1390. is implicitly determined by other attributes (for example, if there is
  1391. a set expression that follows {\tt:=} or the keyword {\tt default}, the
  1392. dimension of $n$-tuples of corresponding elemental set is used).
  1393. If no dimension information is available, {\tt dimen 1} is assumed.
  1394. The {\tt within} attribute specifies a set expression whose resultant
  1395. value is a superset used to restrict the set (if it is a simple set) or
  1396. its members (if the set is an array of elemental sets) to be within
  1397. that superset. Arbitrary number of {\tt within} attributes may be
  1398. specified in the same set statement.
  1399. The assign ({\tt:=}) attribute specifies a set expression used to
  1400. evaluate elemental set(s) assigned to the set (if it is a simple set)
  1401. or its members (if the set is an array of elemental sets). If the
  1402. assign attribute is specified, the set is {\it computable} and
  1403. therefore needs no data to be provided in the data section. If the
  1404. assign attribute is not specified, the set should be provided with data
  1405. in the data section. At most one assign or default attribute can be
  1406. specified for the same set.
  1407. The {\tt default} attribute specifies a set expression used to evaluate
  1408. elemental set(s) assigned to the set (if it is a simple set) or its
  1409. members (if the set is an array of elemental sets) whenever
  1410. no appropriate data are available in the data section. If neither
  1411. assign nor default attribute is specified, missing data will cause an
  1412. error.
  1413. \newpage
  1414. \section{Parameter statement}
  1415. \noindent
  1416. \framebox[468pt][l]{
  1417. \parbox[c][24pt]{468pt}{
  1418. \hspace{6pt} {\tt param} {\it name} {\it alias} {\it domain} {\tt,}
  1419. {\it attrib} {\tt,} \dots {\tt,} {\it attrib} {\tt;}
  1420. }}
  1421. \medskip
  1422. \noindent
  1423. {\it name} is a symbolic name of the parameter;
  1424. \noindent
  1425. {\it alias} is an optional string literal, which specifies an alias of
  1426. the parameter;
  1427. \noindent
  1428. {\it domain} is an optional indexing expression, which specifies
  1429. a subscript domain of the parameter;
  1430. \noindent
  1431. {\it attrib}, \dots, {\it attrib} are optional attributes of the
  1432. parameter. (Commae preceding attributes may be omitted.)
  1433. \para{Optional attributes}
  1434. \vspace*{-8pt}
  1435. \begin{description}
  1436. \item[{\tt integer}]\hspace*{0pt}\\
  1437. specifies that the parameter is integer;
  1438. \item[{\tt binary}]\hspace*{0pt}\\
  1439. specifies that the parameter is binary;
  1440. \item[{\tt symbolic}]\hspace*{0pt}\\
  1441. specifies that the parameter is symbolic;
  1442. \item[{\it relation expression}]\hspace*{0pt}\\
  1443. (where {\it relation} is one of: {\tt<}, {\tt<=}, {\tt=}, {\tt==},
  1444. {\tt>=}, {\tt>}, {\tt<>}, {\tt!=})\\
  1445. specifies a condition that restricts the parameter or its members to
  1446. satisfy that condition;
  1447. \item[{\tt in} {\it expression}]\hspace*{0pt}\\
  1448. specifies a superset that restricts the parameter or its members to be
  1449. in that superset;
  1450. \item[{\tt:=} {\it expression}]\hspace*{0pt}\\
  1451. specifies a value assigned to the parameter or its members;
  1452. \item[{\tt default} {\it expression}]\hspace*{0pt}\\
  1453. specifies a value assigned to the parameter or its members whenever
  1454. no appropriate data are available in the data section.
  1455. \end{description}
  1456. \vspace*{-8pt}
  1457. \para{Examples}
  1458. \begin{verbatim}
  1459. param units{raw, prd} >= 0;
  1460. param profit{prd, 1..T+1};
  1461. param N := 20 integer >= 0 <= 100;
  1462. param comb 'n choose k' {n in 0..N, k in 0..n} :=
  1463. if k = 0 or k = n then 1 else comb[n-1,k-1] + comb[n-1,k];
  1464. param p{i in I, j in J}, integer, >= 0, <= i+j, in A[i] symdiff B[j],
  1465. in C[i,j], default 0.5 * (i + j);
  1466. param month symbolic default 'May' in {'Mar', 'Apr', 'May'};
  1467. \end{verbatim}
  1468. The parameter statement declares a parameter. If a subscript domain is
  1469. not specified, the parameter is a simple (scalar) parameter, otherwise
  1470. it is a $n$-dimensional array.
  1471. The type attributes {\tt integer}, {\tt binary}, and {\tt symbolic}
  1472. qualify the type of values that can be assigned to the parameter as
  1473. shown below:
  1474. \noindent\hfil
  1475. \begin{tabular}{@{}ll@{}}
  1476. Type attribute&Assigned values\\
  1477. \hline
  1478. (not specified)&Any numeric values\\
  1479. {\tt integer}&Only integer numeric values\\
  1480. {\tt binary}&Either 0 or 1\\
  1481. {\tt symbolic}&Any numeric and symbolic values\\
  1482. \end{tabular}
  1483. The {\tt symbolic} attribute cannot be specified along with other type
  1484. attributes. Being specified it should precede all other attributes.
  1485. The condition attribute specifies an optional condition that restricts
  1486. values assigned to the parameter to satisfy that condition. This
  1487. attribute has the following syntactic forms:
  1488. \begin{tabular}{@{}ll@{}}
  1489. {\tt<} $v$&check for $x<v$\\
  1490. {\tt<=} $v$&check for $x\leq v$\\
  1491. {\tt=} $v$, {\tt==} $v$&check for $x=v$\\
  1492. {\tt>=} $v$&check for $x\geq v$\\
  1493. {\tt>} $v$&check for $x\geq v$\\
  1494. {\tt<>} $v$, {\tt!=} $v$&check for $x\neq v$\\
  1495. \end{tabular}
  1496. \noindent where $x$ is a value assigned to the parameter, $v$ is the
  1497. resultant value of a numeric or symbolic expression specified in the
  1498. condition attribute. Arbitrary number of condition attributes can be
  1499. specified for the same parameter. If a value being assigned to the
  1500. parameter during model evaluation violates at least one of specified
  1501. conditions, an error is raised. (Note that symbolic values are ordered
  1502. lexicographically, and any numeric value precedes any symbolic value.)
  1503. The {\tt in} attribute is similar to the condition attribute and
  1504. specifies a set expression whose resultant value is a superset used to
  1505. restrict numeric or symbolic values assigned to the parameter to be in
  1506. that superset. Arbitrary number of the {\tt in} attributes can be
  1507. specified for the same parameter. If a value being assigned to the
  1508. parameter during model evaluation is not in at least one of specified
  1509. supersets, an error is raised.
  1510. The assign ({\tt:=}) attribute specifies a numeric or symbolic
  1511. expression used to compute a value assigned to the parameter (if it is
  1512. a simple parameter) or its member (if the parameter is an array). If
  1513. the assign attribute is specified, the parameter is {\it computable}
  1514. and therefore needs no data to be provided in the data section. If the
  1515. assign attribute is not specified, the parameter should be provided
  1516. with data in the data section. At most one assign or {\tt default}
  1517. attribute can be specified for the same parameter.
  1518. The {\tt default} attribute specifies a numeric or symbolic expression
  1519. used to compute a value assigned to the parameter or its member
  1520. whenever no appropriate data are available in the data section. If
  1521. neither assign nor {\tt default} attribute is specified, missing data
  1522. will cause an error.
  1523. \newpage
  1524. \section{Variable statement}
  1525. \noindent
  1526. \framebox[468pt][l]{
  1527. \parbox[c][24pt]{468pt}{
  1528. \hspace{6pt} {\tt var} {\it name} {\it alias} {\it domain} {\tt,}
  1529. {\it attrib} {\tt,} \dots {\tt,} {\it attrib} {\tt;}
  1530. }}
  1531. \medskip
  1532. \noindent
  1533. {\it name} is a symbolic name of the variable;
  1534. \noindent
  1535. {\it alias} is an optional string literal, which specifies an alias of
  1536. the variable;
  1537. \noindent
  1538. {\it domain} is an optional indexing expression, which specifies
  1539. a subscript domain of the variable;
  1540. \noindent
  1541. {\it attrib}, \dots, {\it attrib} are optional attributes of the
  1542. variable. (Commae preceding attributes may be omitted.)
  1543. \para{Optional attributes}
  1544. \vspace*{-8pt}
  1545. \begin{description}
  1546. \item[{\tt integer}]\hspace*{0pt}\\
  1547. restricts the variable to be integer;
  1548. \item[{\tt binary}]\hspace*{0pt}\\
  1549. restricts the variable to be binary;
  1550. \item[{\tt>=} {\it expression}]\hspace*{0pt}\\
  1551. specifies an lower bound of the variable;
  1552. \item[{\tt<=} {\it expression}]\hspace*{0pt}\\
  1553. specifies an upper bound of the variable;
  1554. \item[{\tt=} {\it expression}]\hspace*{0pt}\\
  1555. specifies a fixed value of the variable;
  1556. \end{description}
  1557. \vspace*{-8pt}
  1558. \para{Examples}
  1559. \begin{verbatim}
  1560. var x >= 0;
  1561. var y{I,J};
  1562. var make{p in prd}, integer, >= commit[p], <= market[p];
  1563. var store{raw, 1..T+1} >= 0;
  1564. var z{i in I, j in J} >= i+j;
  1565. \end{verbatim}
  1566. The variable statement declares a variable. If a subscript domain is
  1567. not specified, the variable is a simple (scalar) variable, otherwise it
  1568. is a $n$-dimensional array of elemental variables.
  1569. Elemental variable(s) associated with the model variable (if it is a
  1570. simple variable) or its members (if it is an array) correspond to the
  1571. variables in the LP/MIP problem formulation (see Section \ref{problem},
  1572. page \pageref{problem}). Note that only elemental variables actually
  1573. referenced in some constraints and/or objectives are included in the
  1574. LP/MIP problem instance to be generated.
  1575. The type attributes {\tt integer} and {\tt binary} restrict the
  1576. variable to be integer or binary, respectively. If no type attribute is
  1577. specified, the variable is continuous. If all variables in the model
  1578. are continuous, the corresponding problem is of LP class. If there is
  1579. at least one integer or binary variable, the problem is of MIP class.
  1580. The lower bound ({\tt>=}) attribute specifies a numeric expression for
  1581. computing an lower bound of the variable. At most one lower bound can
  1582. be specified. By default all variables (except binary ones) have no
  1583. lower bound, so if a variable is required to be non-negative, its zero
  1584. lower bound should be explicitly specified.
  1585. The upper bound ({\tt<=}) attribute specifies a numeric expression for
  1586. computing an upper bound of the variable. At most one upper bound
  1587. attribute can be specified.
  1588. The fixed value ({\tt=}) attribute specifies a numeric expression for
  1589. computing a value, at which the variable is fixed. This attribute
  1590. cannot be specified along with the bound attributes.
  1591. \section{Constraint statement}
  1592. \noindent
  1593. \framebox[468pt][l]{
  1594. \parbox[c][106pt]{468pt}{
  1595. \hspace{6pt} {\tt s.t.} {\it name} {\it alias} {\it domain} {\tt:}
  1596. {\it expression} {\tt,} {\tt=} {\it expression} {\tt;}
  1597. \medskip
  1598. \hspace{6pt} {\tt s.t.} {\it name} {\it alias} {\it domain} {\tt:}
  1599. {\it expression} {\tt,} {\tt<=} {\it expression} {\tt;}
  1600. \medskip
  1601. \hspace{6pt} {\tt s.t.} {\it name} {\it alias} {\it domain} {\tt:}
  1602. {\it expression} {\tt,} {\tt>=} {\it expression} {\tt;}
  1603. \medskip
  1604. \hspace{6pt} {\tt s.t.} {\it name} {\it alias} {\it domain} {\tt:}
  1605. {\it expression} {\tt,} {\tt<=} {\it expression} {\tt,} {\tt<=}
  1606. {\it expression} {\tt;}
  1607. \medskip
  1608. \hspace{6pt} {\tt s.t.} {\it name} {\it alias} {\it domain} {\tt:}
  1609. {\it expression} {\tt,} {\tt>=} {\it expression} {\tt,} {\tt>=}
  1610. {\it expression} {\tt;}
  1611. }}
  1612. \medskip
  1613. \noindent
  1614. {\it name} is a symbolic name of the constraint;
  1615. \noindent
  1616. {\it alias} is an optional string literal, which specifies an alias of
  1617. the constraint;
  1618. \noindent
  1619. {\it domain} is an optional indexing expression, which specifies
  1620. a subscript domain of the constraint;
  1621. \noindent
  1622. {\it expression} is a linear expression used to compute a component of
  1623. the constraint. (Commae following expressions may be omitted.)
  1624. \noindent
  1625. (The keyword {\tt s.t.} may be written as {\tt subject to} or as
  1626. {\tt subj to}, or may be omitted at all.)
  1627. \para{Examples}
  1628. \begin{verbatim}
  1629. s.t. r: x + y + z, >= 0, <= 1;
  1630. limit{t in 1..T}: sum{j in prd} make[j,t] <= max_prd;
  1631. subject to balance{i in raw, t in 1..T}:
  1632. store[i,t+1] = store[i,t] - sum{j in prd} units[i,j] * make[j,t];
  1633. subject to rlim 'regular-time limit' {t in time}:
  1634. sum{p in prd} pt[p] * rprd[p,t] <= 1.3 * dpp[t] * crews[t];
  1635. \end{verbatim}
  1636. The constraint statement declares a constraint. If a subscript domain
  1637. is not specified, the\linebreak constraint is a simple (scalar)
  1638. constraint, otherwise it is a $n$-dimensional array of elemental
  1639. constraints.
  1640. Elemental constraint(s) associated with the model constraint (if it is
  1641. a simple constraint) or its members (if it is an array) correspond to
  1642. the linear constraints in the LP/MIP problem formulation (see
  1643. Section \ref{problem}, page \pageref{problem}).
  1644. If the constraint has the form of equality or single inequality, i.e.
  1645. includes two expressions, one of which follows the colon and other
  1646. follows the relation sign {\tt=}, {\tt<=}, or {\tt>=}, both expressions
  1647. in the statement can be linear expressions. If the constraint has the
  1648. form of double inequality,\linebreak i.e. includes three expressions,
  1649. the middle expression can be a linear expression while the leftmost and
  1650. rightmost ones can be only numeric expressions.
  1651. Generating the model is, roughly speaking, generating its constraints,
  1652. which are always evaluated for the entire subscript domain. Evaluation
  1653. of the constraints leads, in turn, to evaluation of other model objects
  1654. such as sets, parameters, and variables.
  1655. Constructing an actual linear constraint included in the problem
  1656. instance, which (constraint) corresponds to a particular elemental
  1657. constraint, is performed as follows.
  1658. If the constraint has the form of equality or single inequality,
  1659. evaluation of both linear expressions gives two resultant linear forms:
  1660. $$\begin{array}{r@{\ }c@{\ }r@{\ }c@{\ }r@{\ }c@{\ }r@{\ }c@{\ }r}
  1661. f&=&a_1x_1&+&a_2x_2&+\dots+&a_nx_n&+&a_0,\\
  1662. g&=&b_1x_1&+&a_2x_2&+\dots+&a_nx_n&+&b_0,\\
  1663. \end{array}$$
  1664. where $x_1$, $x_2$, \dots, $x_n$ are elemental variables; $a_1$, $a_2$,
  1665. \dots, $a_n$, $b_1$, $b_2$, \dots, $b_n$ are numeric coefficients;
  1666. $a_0$ and $b_0$ are constant terms. Then all linear terms of $f$ and
  1667. $g$ are carried to the left-hand side, and the constant terms are
  1668. carried to the right-hand side, that gives the final elemental
  1669. constraint in the standard form:
  1670. $$(a_1-b_1)x_1+(a_2-b_2)x_2+\dots+(a_n-b_n)x_n\left\{
  1671. \begin{array}{@{}c@{}}=\\\leq\\\geq\\\end{array}\right\}b_0-a_0.$$
  1672. If the constraint has the form of double inequality, evaluation of the
  1673. middle linear expression gives the resultant linear form:
  1674. $$f=a_1x_1+a_2x_2+\dots+a_nx_n+a_0,$$
  1675. and evaluation of the leftmost and rightmost numeric expressions gives
  1676. two numeric values $l$ and $u$, respectively. Then the constant term of
  1677. the linear form is carried to both left-hand and right-handsides that
  1678. gives the final elemental constraint in the standard form:
  1679. $$l-a_0\leq a_1x_1+a_2x_2+\dots+a_nx_n\leq u-a_0.$$
  1680. \section{Objective statement}
  1681. \noindent
  1682. \framebox[468pt][l]{
  1683. \parbox[c][44pt]{468pt}{
  1684. \hspace{6pt} {\tt minimize} {\it name} {\it alias} {\it domain} {\tt:}
  1685. {\it expression} {\tt;}
  1686. \medskip
  1687. \hspace{6pt} {\tt maximize} {\it name} {\it alias} {\it domain} {\tt:}
  1688. {\it expression} {\tt;}
  1689. }}
  1690. \medskip
  1691. \noindent
  1692. {\it name} is a symbolic name of the objective;
  1693. \noindent
  1694. {\it alias} is an optional string literal, which specifies an alias of
  1695. the objective;
  1696. \noindent
  1697. {\it domain} is an optional indexing expression, which specifies
  1698. a subscript domain of the objective;
  1699. \noindent
  1700. {\it expression} is a linear expression used to compute the linear form
  1701. of the objective.
  1702. \newpage
  1703. \para{Examples}
  1704. \begin{verbatim}
  1705. minimize obj: x + 1.5 * (y + z);
  1706. maximize total_profit: sum{p in prd} profit[p] * make[p];
  1707. \end{verbatim}
  1708. The objective statement declares an objective. If a subscript domain is
  1709. not specified, the objective is a simple (scalar) objective. Otherwise
  1710. it is a $n$-dimensional array of elemental objectives.
  1711. Elemental objective(s) associated with the model objective (if it is a
  1712. simple objective) or its members (if it is an array) correspond to
  1713. general linear constraints in the LP/MIP problem formulation (see
  1714. Section \ref{problem}, page \pageref{problem}). However, unlike
  1715. constraints the corresponding linear forms are free (unbounded).
  1716. Constructing an actual linear constraint included in the problem
  1717. instance, which (constraint) corresponds to a particular elemental
  1718. constraint, is performed as follows. The linear expression specified in
  1719. the objective statement is evaluated that, gives the resultant linear
  1720. form:
  1721. $$f=a_1x_1+a_2x_2+\dots+a_nx_n+a_0,$$
  1722. where $x_1$, $x_2$, \dots, $x_n$ are elemental variables; $a_1$, $a_2$,
  1723. \dots, $a_n$ are numeric coefficients; $a_0$ is the constant term. Then
  1724. the linear form is used to construct the final elemental constraint in
  1725. the standard form:
  1726. $$-\infty<a_1x_1+a_2x_2+\dots+a_nx_n+a_0<+\infty.$$
  1727. As a rule the model description contains only one objective statement
  1728. that defines the objective function used in the problem instance.
  1729. However, it is allowed to declare arbitrary number of objectives, in
  1730. which case the actual objective function is the first objective
  1731. encountered in the model description. Other objectives are also
  1732. included in the problem instance, but they do not affect the objective
  1733. function.
  1734. \section{Solve statement}
  1735. \noindent
  1736. \framebox[468pt][l]{
  1737. \parbox[c][24pt]{468pt}{
  1738. \hspace{6pt} {\tt solve} {\tt;}
  1739. }}
  1740. \medskip
  1741. The solve statement is optional and can be used only once. If no solve
  1742. statement is used, one is assumed at the end of the model section.
  1743. The solve statement causes the model to be solved, that means computing
  1744. numeric values of all model variables. This allows using variables in
  1745. statements below the solve statement in the same way as if they were
  1746. numeric parameters.
  1747. Note that the variable, constraint, and objective statements cannot be
  1748. used below the solve statement, i.e. all principal components of the
  1749. model should be declared above the solve statement.
  1750. \newpage
  1751. \section{Check statement}
  1752. \noindent
  1753. \framebox[468pt][l]{
  1754. \parbox[c][24pt]{468pt}{
  1755. \hspace{6pt} {\tt check} {\it domain} {\tt:} {\it expression} {\tt;}
  1756. }}
  1757. \medskip
  1758. \noindent
  1759. {\it domain} is an optional indexing expression, which specifies
  1760. a subscript domain of the check statement;
  1761. \noindent
  1762. {\it expression} is an logical expression which specifies the logical
  1763. condition to be checked. (The colon preceding {\it expression} may be
  1764. omitted.)
  1765. \para{Examples}
  1766. \begin{verbatim}
  1767. check: x + y <= 1 and x >= 0 and y >= 0;
  1768. check sum{i in ORIG} supply[i] = sum{j in DEST} demand[j];
  1769. check{i in I, j in 1..10}: S[i,j] in U[i] union V[j];
  1770. \end{verbatim}
  1771. The check statement allows checking the resultant value of an logical
  1772. expression specified in the statement. If the value is {\it false}, an
  1773. error is reported.
  1774. If the subscript domain is not specified, the check is performed only
  1775. once. Specifying the subscript domain allows performing multiple check
  1776. for every $n$-tuple in the domain set. In the latter case the logical
  1777. expression may include dummy indices introduced in corresponding
  1778. indexing expression.
  1779. \section{Display statement}
  1780. \noindent
  1781. \framebox[468pt][l]{
  1782. \parbox[c][24pt]{468pt}{
  1783. \hspace{6pt} {\tt display} {\it domain} {\tt:} {\it item} {\tt,}
  1784. \dots {\tt,} {\it item} {\tt;}
  1785. }}
  1786. \medskip
  1787. \noindent
  1788. {\it domain} is an optional indexing expression, which specifies
  1789. a subscript domain of the display statement;
  1790. \noindent
  1791. {\it item}, \dots, {\it item} are items to be displayed. (The colon
  1792. preceding the first item may be omitted.)
  1793. \para{Examples}
  1794. \begin{verbatim}
  1795. display: 'x =', x, 'y =', y, 'z =', z;
  1796. display sqrt(x ** 2 + y ** 2 + z ** 2);
  1797. display{i in I, j in J}: i, j, a[i,j], b[i,j];
  1798. \end{verbatim}
  1799. The display statement evaluates all items specified in the statement
  1800. and writes their values on the standard output (terminal) in plain text
  1801. format.
  1802. If a subscript domain is not specified, items are evaluated and then
  1803. displayed only once. Specifying the subscript domain causes items to be
  1804. evaluated and displayed for every $n$-tuple in the domain set. In the
  1805. latter case items may include dummy indices introduced in corresponding
  1806. indexing expression.
  1807. An item to be displayed can be a model object (set, parameter,
  1808. variable, constraint, objective) or an expression.
  1809. If the item is a computable object (i.e. a set or parameter provided
  1810. with the assign attribute), the object is evaluated over the entire
  1811. domain and then its content (i.e. the content of the object array) is
  1812. displayed. Otherwise, if the item is not a computable object, only its
  1813. current content (i.e. members actually generated during the model
  1814. evaluation) is displayed.
  1815. If the item is an expression, the expression is evaluated and its
  1816. resultant value is displayed.
  1817. \section{Printf statement}
  1818. \noindent
  1819. \framebox[468pt][l]{
  1820. \parbox[c][64pt]{468pt}{
  1821. \hspace{6pt} {\tt printf} {\it domain} {\tt:} {\it format} {\tt,}
  1822. {\it expression} {\tt,} \dots {\tt,} {\it expression} {\tt;}
  1823. \medskip
  1824. \hspace{6pt} {\tt printf} {\it domain} {\tt:} {\it format} {\tt,}
  1825. {\it expression} {\tt,} \dots {\tt,} {\it expression} {\tt>}
  1826. {\it filename} {\tt;}
  1827. \medskip
  1828. \hspace{6pt} {\tt printf} {\it domain} {\tt:} {\it format} {\tt,}
  1829. {\it expression} {\tt,} \dots {\tt,} {\it expression} {\tt>>}
  1830. {\it filename} {\tt;}
  1831. }}
  1832. \medskip
  1833. \noindent
  1834. {\it domain} is an optional indexing expression, which specifies
  1835. a subscript domain of the printf statement;
  1836. \noindent
  1837. {\it format} is a symbolic expression whose value specifies a format
  1838. control string. (The colon preceding the format expression may be
  1839. omitted.)
  1840. \noindent
  1841. {\it expression}, \dots, {\it expression} are zero or more expressions
  1842. whose values have to be formatted and printed. Each expression should
  1843. be of numeric, symbolic, or logical type.
  1844. \noindent
  1845. {\it filename} is a symbolic expression whose value specifies a name
  1846. of a text file, to which the output is redirected. The flag {\tt>}
  1847. means creating a new empty file while the flag {\tt>>} means appending
  1848. the output to an existing file. If no file name is specified, the
  1849. output is written on the standard output (terminal).
  1850. \para{Examples}
  1851. \begin{verbatim}
  1852. printf 'Hello, world!\n';
  1853. printf: "x = %.3f; y = %.3f; z = %.3f\n", x, y, z > "result.txt";
  1854. printf{i in I, j in J}: "flow from %s to %s is %d\n", i, j, x[i,j]
  1855. >> result_file & ".txt";
  1856. printf{i in I} 'total flow from %s is %g\n', i, sum{j in J} x[i,j];
  1857. printf{k in K} "x[%s] = " & (if x[k] < 0 then "?" else "%g"),
  1858. k, x[k];
  1859. \end{verbatim}
  1860. The printf statement is similar to the display statement, however, it
  1861. allows formatting data to be written.
  1862. If a subscript domain is not specified, the printf statement is
  1863. executed only once. Specifying a subscript domain causes executing the
  1864. printf statement for every $n$-tuple in the domain set. In the latter
  1865. case the format and expression may include dummy indices introduced in
  1866. corresponding indexing expression.
  1867. The format control string is a value of the symbolic expression
  1868. {\it format} specified in the printf statement. It is composed of zero
  1869. or more directives as follows: ordinary characters (not {\tt\%}), which
  1870. are copied unchanged to the output stream, and conversion
  1871. specifications, each of which causes evaluating corresponding
  1872. expression specified in the printf statement, formatting it, and
  1873. writing its resultant value to the output stream.
  1874. Conversion specifications that may be used in the format control string
  1875. are the following:\linebreak {\tt d}, {\tt i}, {\tt f}, {\tt F},
  1876. {\tt e}, {\tt E}, {\tt g}, {\tt G}, and {\tt s}. These specifications
  1877. have the same syntax and semantics as in the C programming language.
  1878. \section{For statement}
  1879. \noindent
  1880. \framebox[468pt][l]{
  1881. \parbox[c][44pt]{468pt}{
  1882. \hspace{6pt} {\tt for} {\it domain} {\tt:} {\it statement} {\tt;}
  1883. \medskip
  1884. \hspace{6pt} {\tt for} {\it domain} {\tt:} {\tt\{} {\it statement}
  1885. \dots {\it statement} {\tt\}} {\tt;}
  1886. }}
  1887. \medskip
  1888. \noindent
  1889. {\it domain} is an indexing expression which specifies a subscript
  1890. domain of the for statement. (The colon following the indexing
  1891. expression may be omitted.)
  1892. \noindent
  1893. {\it statement} is a statement, which should be executed under control
  1894. of the for statement;
  1895. \noindent
  1896. {\it statement}, \dots, {\it statement} is a sequence of statements
  1897. (enclosed in curly braces), which should be executed under control of
  1898. the for statement.
  1899. Only the following statements can be used within the for statement:
  1900. check, display, printf, and another for.
  1901. \para{Examples}
  1902. \begin{verbatim}
  1903. for {(i,j) in E: i != j}
  1904. { printf "flow from %s to %s is %g\n", i, j, x[i,j];
  1905. check x[i,j] >= 0;
  1906. }
  1907. for {i in 1..n}
  1908. { for {j in 1..n} printf " %s", if x[i,j] then "Q" else ".";
  1909. printf("\n");
  1910. }
  1911. for {1..72} printf("*");
  1912. \end{verbatim}
  1913. The for statement causes a statement or a sequence of statements
  1914. specified as part of the for statement to be executed for every
  1915. $n$-tuple in the domain set. Thus, statements within the for statement
  1916. may include dummy indices introduced in corresponding indexing
  1917. expression.
  1918. \newpage
  1919. \section{Table statement}
  1920. \noindent
  1921. \framebox[468pt][l]{
  1922. \parbox[c][80pt]{468pt}{
  1923. \hspace{6pt} {\tt table} {\it name} {\it alias} {\tt IN} {\it driver}
  1924. {\it arg} \dots {\it arg} {\tt:}
  1925. \hspace{6pt} {\tt\ \ \ \ \ } {\it set} {\tt<-} {\tt[} {\it fld} {\tt,}
  1926. \dots {\tt,} {\it fld} {\tt]} {\tt,} {\it par} {\tt\textasciitilde}
  1927. {\it fld} {\tt,} \dots {\tt,} {\it par} {\tt\textasciitilde} {\it fld}
  1928. {\tt;}
  1929. \medskip
  1930. \hspace{6pt} {\tt table} {\it name} {\it alias} {\it domain} {\tt OUT}
  1931. {\it driver} {\it arg} \dots {\it arg} {\tt:}
  1932. \hspace{6pt} {\tt\ \ \ \ \ } {\it expr} {\tt\textasciitilde} {\it fld}
  1933. {\tt,} \dots {\tt,} {\it expr} {\tt\textasciitilde} {\it fld} {\tt;}
  1934. }}
  1935. \medskip
  1936. \noindent
  1937. {\it name} is a symbolic name of the table;
  1938. \noindent
  1939. {\it alias} is an optional string literal, which specifies an alias of
  1940. the table;
  1941. \noindent
  1942. {\it domain} is an indexing expression, which specifies a subscript
  1943. domain of the (output) table;
  1944. \noindent
  1945. {\tt IN} means reading data from the input table;
  1946. \noindent
  1947. {\tt OUT} means writing data to the output table;
  1948. \noindent
  1949. {\it driver} is a symbolic expression, which specifies the driver used
  1950. to access the table (for details see Appendix \ref{drivers}, page
  1951. \pageref{drivers});
  1952. \noindent
  1953. {\it arg} is an optional symbolic expression, which is an argument
  1954. pass\-ed to the table driver. This symbolic expression should not
  1955. include dummy indices specified in the domain;
  1956. \noindent
  1957. {\it set} is the name of an optional simple set called {\it control
  1958. set}. It can be omitted along with the delimiter {\tt<-};
  1959. \noindent
  1960. {\it fld} is a field name. Within square brackets at least one field
  1961. should be specified. The field name following a parameter name or
  1962. expression is optional and can be omitted along with the
  1963. delimiter~{\tt\textasciitilde}, in which case the name of corresponding
  1964. model object is used as the field name;
  1965. \noindent
  1966. {\it par} is a symbolic name of a model parameter;
  1967. \noindent
  1968. {\it expr} is a numeric or symbolic expression.
  1969. \para{Examples}
  1970. \begin{verbatim}
  1971. table data IN "CSV" "data.csv": S <- [FROM,TO], d~DISTANCE,
  1972. c~COST;
  1973. table result{(f,t) in S} OUT "CSV" "result.csv": f~FROM, t~TO,
  1974. x[f,t]~FLOW;
  1975. \end{verbatim}
  1976. The table statement allows reading data from a table into model
  1977. objects such as sets and (non-scalar) parameters as well as writing
  1978. data from the model to a table.
  1979. \newpage
  1980. \subsection{Table structure}
  1981. A {\it data table} is an (unordered) set of {\it records}, where each
  1982. record consists of the same number of {\it fields}, and each field is
  1983. provided with a unique symbolic name called the {\it field name}. For
  1984. example:
  1985. \bigskip
  1986. \begin{tabular}{@{\hspace*{42mm}}c@{\hspace*{11mm}}c@{\hspace*{10mm}}c
  1987. @{\hspace*{9mm}}c}
  1988. First&Second&&Last\\
  1989. field&field&.\ \ .\ \ .&field\\
  1990. $\downarrow$&$\downarrow$&&$\downarrow$\\
  1991. \end{tabular}
  1992. \begin{tabular}{ll@{}}
  1993. Table header&$\rightarrow$\\
  1994. First record&$\rightarrow$\\
  1995. Second record&$\rightarrow$\\
  1996. \\
  1997. \hfil .\ \ .\ \ .\\
  1998. \\
  1999. Last record&$\rightarrow$\\
  2000. \end{tabular}
  2001. \begin{tabular}{|l|l|c|c|}
  2002. \hline
  2003. {\tt FROM}&{\tt TO}&{\tt DISTANCE}&{\tt COST}\\
  2004. \hline
  2005. {\tt Seattle} &{\tt New-York}&{\tt 2.5}&{\tt 0.12}\\
  2006. {\tt Seattle} &{\tt Chicago} &{\tt 1.7}&{\tt 0.08}\\
  2007. {\tt Seattle} &{\tt Topeka} &{\tt 1.8}&{\tt 0.09}\\
  2008. {\tt San-Diego}&{\tt New-York}&{\tt 2.5}&{\tt 0.15}\\
  2009. {\tt San-Diego}&{\tt Chicago} &{\tt 1.8}&{\tt 0.10}\\
  2010. {\tt San-Diego}&{\tt Topeka} &{\tt 1.4}&{\tt 0.07}\\
  2011. \hline
  2012. \end{tabular}
  2013. \subsection{Reading data from input table}
  2014. The input table statement causes reading data from the specified table
  2015. record by record.
  2016. Once a next record has been read, numeric or symbolic values of fields,
  2017. whose names are enclosed in square brackets in the table statement, are
  2018. gathered into $n$-tuple, and if the control set is specified in the
  2019. table statement, this $n$-tuple is added to it. Besides, a numeric or
  2020. symbolic value of each field associated with a model parameter is
  2021. assigned to the parameter member identified by subscripts, which are
  2022. components of the $n$-tuple just read.
  2023. For example, the following input table statement:
  2024. \noindent\hfil
  2025. \verb|table data IN "...": S <- [FROM,TO], d~DISTANCE, c~COST;|
  2026. \noindent
  2027. causes reading values of four fields named {\tt FROM}, {\tt TO},
  2028. {\tt DISTANCE}, and {\tt COST} from each record of the specified table.
  2029. Values of fields {\tt FROM} and {\tt TO} give a pair $(f,t)$, which is
  2030. added to the control set {\tt S}. The value of field {\tt DISTANCE} is
  2031. assigned to parameter member ${\tt d}[f,t]$, and the value of field
  2032. {\tt COST} is assigned to parameter member ${\tt c}[f,t]$.
  2033. Note that the input table may contain extra fields whose names are not
  2034. specified in the table statement, in which case values of these fields
  2035. on reading the table are ignored.
  2036. \subsection{Writing data to output table}
  2037. The output table statement causes writing data to the specified table.
  2038. Note that some drivers (namely, CSV and xBASE) destroy the output table
  2039. before writing data, i.e. delete all its existing records.
  2040. Each $n$-tuple in the specified domain set generates one record written
  2041. to the output table. Values of fields are numeric or symbolic values of
  2042. corresponding expressions specified in the table statement. These
  2043. expressions are evaluated for each $n$-tuple in the domain set and,
  2044. thus, may include dummy indices introduced in the corresponding indexing
  2045. expression.
  2046. For example, the following output table statement:
  2047. \noindent\hfil
  2048. \verb|table result{(f,t) in S} OUT "...": f~FROM, t~TO, x[f,t]~FLOW;|
  2049. \noindent
  2050. causes writing records, by one record for each pair $(f,t)$ in set
  2051. {\tt S}, to the output table, where each record consists of three
  2052. fields named {\tt FROM}, {\tt TO}, and {\tt FLOW}. The values written
  2053. to fields {\tt FROM} and {\tt TO} are current values of dummy indices
  2054. {\tt f} and {\tt t}, and the value written to field {\tt FLOW} is
  2055. a value of member ${\tt x}[f,t]$ of corresponding subscripted parameter
  2056. or variable.
  2057. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2058. \chapter{Model data}
  2059. {\it Model data} include elemental sets, which are ``values'' of model
  2060. sets, and numeric and symbolic values of model parameters.
  2061. In MathProg there are two different ways to saturate model sets and
  2062. parameters with data. One way is simply providing necessary data using
  2063. the assign attribute. However, in many cases it is more practical to
  2064. separate the model itself and particular data needed for the model. For
  2065. the latter reason in MathProg there is another way, when the model
  2066. description is divided into two parts: model section and data section.
  2067. A {\it model section} is a main part of the model description that
  2068. contains declarations of all model objects and is common for all
  2069. problems based on that model.
  2070. A {\it data section} is an optional part of the model description that
  2071. contains model data specific for a particular problem.
  2072. In MathProg model and data sections can be placed either in one text
  2073. file or in two separate text files.
  2074. 1. If both model and data sections are placed in one file, the file is
  2075. composed as follows:
  2076. \bigskip
  2077. \noindent\hfil
  2078. \framebox{\begin{tabular}{l}
  2079. {\it statement}{\tt;}\\
  2080. {\it statement}{\tt;}\\
  2081. \hfil.\ \ .\ \ .\\
  2082. {\it statement}{\tt;}\\
  2083. {\tt data;}\\
  2084. {\it data block}{\tt;}\\
  2085. {\it data block}{\tt;}\\
  2086. \hfil.\ \ .\ \ .\\
  2087. {\it data block}{\tt;}\\
  2088. {\tt end;}
  2089. \end{tabular}}
  2090. \newpage
  2091. 2. If the model and data sections are placed in two separate files, the
  2092. files are composed as follows:
  2093. \bigskip
  2094. \noindent\hfil
  2095. \begin{tabular}{@{}c@{}}
  2096. \framebox{\begin{tabular}{l}
  2097. {\it statement}{\tt;}\\
  2098. {\it statement}{\tt;}\\
  2099. \hfil.\ \ .\ \ .\\
  2100. {\it statement}{\tt;}\\
  2101. {\tt end;}\\
  2102. \end{tabular}}\\
  2103. \\\\Model file\\
  2104. \end{tabular}
  2105. \hspace{32pt}
  2106. \begin{tabular}{@{}c@{}}
  2107. \framebox{\begin{tabular}{l}
  2108. {\tt data;}\\
  2109. {\it data block}{\tt;}\\
  2110. {\it data block}{\tt;}\\
  2111. \hfil.\ \ .\ \ .\\
  2112. {\it data block}{\tt;}\\
  2113. {\tt end;}\\
  2114. \end{tabular}}\\
  2115. \\Data file\\
  2116. \end{tabular}
  2117. \bigskip
  2118. Note: If the data section is placed in a separate file, the keyword
  2119. {\tt data} is optional and may be omitted along with the semicolon that
  2120. follows it.
  2121. \section{Coding data section}
  2122. The {\it data section} is a sequence of data blocks in various formats,
  2123. which are discussed in following sections. The order, in which data
  2124. blocks follow in the data section, may be arbitrary, not necessarily
  2125. the same, in which corresponding model objects follow in the model
  2126. section.
  2127. The rules of coding the data section are commonly the same as the rules
  2128. of coding the model description (see Section \ref{coding}, page
  2129. \pageref{coding}), i.e. data blocks are composed from basic lexical
  2130. units such as symbolic names, numeric and string literals, keywords,
  2131. delimiters, and comments. However, for the sake of convenience and for
  2132. improving readability there is one deviation from the common rule: if
  2133. a string literal consists of only alphanumeric characters (including
  2134. the underscore character), the signs {\tt+} and {\tt-}, and/or the
  2135. decimal point, it may be coded without bordering by (single or double)
  2136. quotes.
  2137. All numeric and symbolic material provided in the data section is coded
  2138. in the form of numbers and symbols, i.e. unlike the model section
  2139. no expressions are allowed in the data section. Nevertheless, the signs
  2140. {\tt+} and {\tt-} can precede numeric literals to allow coding signed
  2141. numeric quantities, in which case there should be no white-space
  2142. characters between the sign and following numeric literal (if there is
  2143. at least one white-space, the sign and following numeric literal are
  2144. recognized as two different lexical units).
  2145. \newpage
  2146. \section{Set data block}
  2147. \noindent
  2148. \framebox[468pt][l]{
  2149. \parbox[c][44pt]{468pt}{
  2150. \hspace{6pt} {\tt set} {\it name} {\tt,} {\it record} {\tt,} \dots
  2151. {\tt,} {\it record} {\tt;}
  2152. \medskip
  2153. \hspace{6pt} {\tt set} {\it name} {\tt[} {\it symbol} {\tt,} \dots
  2154. {\tt,} {\it symbol} {\tt]} {\tt,} {\it record} {\tt,} \dots {\tt,}
  2155. {\it record} {\tt;}
  2156. }}
  2157. \medskip
  2158. \noindent
  2159. {\it name} is a symbolic name of the set;
  2160. \noindent
  2161. {\it symbol}, \dots, {\it symbol} are subscripts, which specify
  2162. a particular member of the set (if the set is an array, i.e. a set of
  2163. sets);
  2164. \noindent
  2165. {\it record}, \dots, {\it record} are data records.
  2166. \noindent
  2167. Commae preceding data records may be omitted.
  2168. \para{Data records}
  2169. \vspace*{-8pt}
  2170. \begin{description}
  2171. \item[{\tt :=}]\hspace*{0pt}\\
  2172. is a non-significant data record, which may be used freely to improve
  2173. readability;
  2174. \item[{\tt(} {\it slice} {\tt)}]\hspace*{0pt}\\
  2175. specifies a slice;
  2176. \item[{\it simple-data}]\hspace*{0pt}\\
  2177. specifies set data in the simple format;
  2178. \item[{\tt:} {\it matrix-data}]\hspace*{0pt}\\
  2179. specifies set data in the matrix format;
  2180. \item[{\tt(tr)} {\tt:} {\it matrix-data}]\hspace*{0pt}\\
  2181. specifies set data in the transposed matrix format. (In this case the
  2182. colon following the keyword {\tt(tr)} may be omitted.)
  2183. \end{description}
  2184. \vspace*{-8pt}
  2185. \para{Examples}
  2186. \begin{verbatim}
  2187. set month := Jan Feb Mar Apr May Jun;
  2188. set month "Jan", "Feb", "Mar", "Apr", "May", "Jun";
  2189. set A[3,Mar] := (1,2) (2,3) (4,2) (3,1) (2,2) (4,4) (3,4);
  2190. set A[3,'Mar'] := 1 2 2 3 4 2 3 1 2 2 4 4 3 4;
  2191. set A[3,'Mar'] : 1 2 3 4 :=
  2192. 1 - + - -
  2193. 2 - + + -
  2194. 3 + - - +
  2195. 4 - + - + ;
  2196. set B := (1,2,3) (1,3,2) (2,3,1) (2,1,3) (1,2,2) (1,1,1) (2,1,1);
  2197. set B := (*,*,*) 1 2 3, 1 3 2, 2 3 1, 2 1 3, 1 2 2, 1 1 1, 2 1 1;
  2198. set B := (1,*,2) 3 2 (2,*,1) 3 1 (1,2,3) (2,1,3) (1,1,1);
  2199. set B := (1,*,*) : 1 2 3 :=
  2200. 1 + - -
  2201. 2 - + +
  2202. 3 - + -
  2203. (2,*,*) : 1 2 3 :=
  2204. 1 + - +
  2205. 2 - - -
  2206. 3 + - - ;
  2207. \end{verbatim}
  2208. \noindent(In these examples {\tt month} is a simple set of singlets,
  2209. {\tt A} is a 2-dimensional array of doublets, and {\tt B} is a simple
  2210. set of triplets. Data blocks for the same set are equivalent in the
  2211. sense that they specify the same data in different formats.)
  2212. The {\it set data block} is used to specify a complete elemental set,
  2213. which is assigned to a set (if it is a simple set) or one of its
  2214. members (if the set is an array of sets).\footnote{There is another way
  2215. to specify data for a simple set along with data for parameters. This
  2216. feature is discussed in the next section.}
  2217. Data blocks can be specified only for non-computable sets, i.e. for
  2218. sets, which have no assign attribute ({\tt:=}) in the corresponding set
  2219. statements.
  2220. If the set is a simple set, only its symbolic name should be specified
  2221. in the header of the data block. Otherwise, if the set is a
  2222. $n$-dimensional array, its symbolic name should be provided with a
  2223. complete list of subscripts separated by commae and enclosed in square
  2224. brackets to specify a particular member of the set array. The number of
  2225. subscripts should be the same as the dimension of the set array, where
  2226. each subscript should be a number or symbol.
  2227. An elemental set defined in the set data block is coded as a sequence
  2228. of data records described below.\footnote{{\it Data record} is simply a
  2229. technical term. It does not mean that data records have any special
  2230. formatting.}
  2231. \subsection{Assign data record}
  2232. The {\it assign data record} ({\tt:=}) is a non-signficant element.
  2233. It may be used for improving readability of data blocks.
  2234. \subsection{Slice data record}
  2235. The {\it slice data record} is a control record, which specifies a
  2236. {\it slice} of the elemental set defined in the data block. It has the
  2237. following syntactic form:
  2238. $$\mbox{{\tt(} $s_1$ {\tt,} $s_2$ {\tt,} \dots {\tt,} $s_n$ {\tt)}}$$
  2239. where $s_1$, $s_2$, \dots, $s_n$ are components of the slice.
  2240. Each component of the slice can be a number or symbol or the asterisk
  2241. ({\tt*}). The number of components in the slice should be the same as
  2242. the dimension of $n$-tuples in the elemental set to be defined. For
  2243. instance, if the elemental set contains 4-tuples (quadruplets), the
  2244. slice should have four components. The number of asterisks in the slice
  2245. is called the {\it slice dimension}.
  2246. The effect of using slices is the following. If a $m$-dimensional slice
  2247. (i.e. a slice having $m$ asterisks) is specified in the data block, all
  2248. subsequent data records should specify tuples of the dimension~$m$.
  2249. Whenever a $m$-tuple is encountered, each asterisk in the slice is
  2250. replaced by corresponding components of the $m$-tuple that gives the
  2251. resultant $n$-tuple, which is included in the elemental set to be
  2252. defined. For example, if the slice $(a,*,1,2,*)$ is in effect, and
  2253. 2-tuple $(3,b)$ is encountered in a subsequent data record, the
  2254. resultant 5-tuple included in the elemental set is $(a,3,1,2,b)$.
  2255. The slice having no asterisks itself defines a complete $n$-tuple,
  2256. which is included in the elemental set.
  2257. Being once specified the slice effects until either a new slice or the
  2258. end of data block is encountered. Note that if no slice is specified in
  2259. the data block, one, components of which are all asterisks, is assumed.
  2260. \subsection{Simple data record}
  2261. The {\it simple data record} defines one $n$-tuple in a simple format
  2262. and has the following syntactic form:
  2263. $$\mbox{$t_1$ {\tt,} $t_2$ {\tt,} \dots {\tt,} $t_n$}$$
  2264. where $t_1$, $t_2$, \dots, $t_n$ are components of the $n$-tuple. Each
  2265. component can be a number or symbol. Commae between components are
  2266. optional and may be omitted.
  2267. \subsection{Matrix data record}
  2268. The {\it matrix data record} defines several 2-tuples (doublets) in
  2269. a matrix format and has the following syntactic form:
  2270. $$\begin{array}{cccccc}
  2271. \mbox{{\tt:}}&c_1&c_2&\dots&c_n&\mbox{{\tt:=}}\\
  2272. r_1&a_{11}&a_{12}&\dots&a_{1n}&\\
  2273. r_2&a_{21}&a_{22}&\dots&a_{2n}&\\
  2274. \multicolumn{5}{c}{.\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .}&\\
  2275. r_m&a_{m1}&a_{m2}&\dots&a_{mn}&\\
  2276. \end{array}$$
  2277. where $r_1$, $r_2$, \dots, $r_m$ are numbers and/or symbols
  2278. corresponding to rows of the matrix; $c_1$, $c_2$, \dots, $c_n$ are
  2279. numbers and/or symbols corresponding to columns of the matrix, $a_{11}$,
  2280. $a_{12}$, \dots, $a_{mn}$ are matrix elements, which can be either
  2281. {\tt+} or {\tt-}. (In this data record the delimiter {\tt:} preceding
  2282. the column list and the delimiter {\tt:=} following the column list
  2283. cannot be omitted.)
  2284. Each element $a_{ij}$ of the matrix data block (where $1\leq i\leq m$,
  2285. $1\leq j\leq n$) corresponds to 2-tuple $(r_i,c_j)$. If $a_{ij}$ is the
  2286. plus sign ({\tt+}), that 2-tuple (or a longer $n$-tuple, if a slice is
  2287. used) is included in the elemental set. Otherwise, if $a_{ij}$ is the
  2288. minus sign ({\tt-}), that 2-tuple is not included in the elemental set.
  2289. Since the matrix data record defines 2-tuples, either the elemental set
  2290. should consist of 2-tuples or the slice currently used should be
  2291. 2-dimensional.
  2292. \newpage
  2293. \subsection{Transposed matrix data record}
  2294. The {\it transposed matrix data record} has the following syntactic
  2295. form:
  2296. $$\begin{array}{cccccc}
  2297. \mbox{{\tt(tr) :}}&c_1&c_2&\dots&c_n&\mbox{{\tt:=}}\\
  2298. r_1&a_{11}&a_{12}&\dots&a_{1n}&\\
  2299. r_2&a_{21}&a_{22}&\dots&a_{2n}&\\
  2300. \multicolumn{5}{c}{.\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .}&\\
  2301. r_m&a_{m1}&a_{m2}&\dots&a_{mn}&\\
  2302. \end{array}$$
  2303. (In this case the delimiter {\tt:} following the keyword {\tt(tr)} is
  2304. optional and may be omitted.)
  2305. This data record is completely analogous to the matrix data record (see
  2306. above) with only exception that in this case each element $a_{ij}$ of
  2307. the matrix corresponds to 2-tuple $(c_j,r_i)$ rather than $(r_i,c_j)$.
  2308. Being once specified the {\tt(tr)} indicator affects all subsequent
  2309. data records until either a slice or the end of data block is
  2310. encountered.
  2311. \section{Parameter data block}
  2312. \noindent
  2313. \framebox[468pt][l]{
  2314. \parbox[c][88pt]{468pt}{
  2315. \hspace{6pt} {\tt param} {\it name} {\tt,} {\it record} {\tt,} \dots
  2316. {\tt,} {\it record} {\tt;}
  2317. \medskip
  2318. \hspace{6pt} {\tt param} {\it name} {\tt default} {\it value} {\tt,}
  2319. {\it record} {\tt,} \dots {\tt,} {\it record} {\tt;}
  2320. \medskip
  2321. \hspace{6pt} {\tt param} {\tt:} {\it tabbing-data} {\tt;}
  2322. \medskip
  2323. \hspace{6pt} {\tt param} {\tt default} {\it value} {\tt:}
  2324. {\it tabbing-data} {\tt;}
  2325. }}
  2326. \medskip
  2327. \noindent
  2328. {\it name} is a symbolic name of the parameter;
  2329. \noindent
  2330. {\it value} is an optional default value of the parameter;
  2331. \noindent
  2332. {\it record}, \dots, {\it record} are data records;
  2333. \noindent
  2334. {\it tabbing-data} specifies parameter data in the tabbing format.
  2335. \noindent
  2336. Commae preceding data records may be omitted.
  2337. \para{Data records}
  2338. \vspace*{-8pt}
  2339. \begin{description}
  2340. \item[{\tt :=}]\hspace*{0pt}\\
  2341. is a non-significant data record, which may be used freely to improve
  2342. readability;
  2343. \item[{\tt[} {\it slice} {\tt]}]\hspace*{0pt}\\
  2344. specifies a slice;
  2345. \item[{\it plain-data}]\hspace*{0pt}\\
  2346. specifies parameter data in the plain format;
  2347. \item[{\tt:} {\it tabular-data}]\hspace*{0pt}\\
  2348. specifies parameter data in the tabular format;
  2349. \item[{\tt(tr)} {\tt:} {\it tabular-data}]\hspace*{0pt}\\
  2350. specifies set data in the transposed tabular format. (In this case the
  2351. colon following the keyword {\tt(tr)} may be omitted.)
  2352. \end{description}
  2353. \vspace*{-8pt}
  2354. \para{Examples}
  2355. \begin{verbatim}
  2356. param T := 4;
  2357. param month := 1 Jan 2 Feb 3 Mar 4 Apr 5 May;
  2358. param month := [1] 'Jan', [2] 'Feb', [3] 'Mar', [4] 'Apr', [5] 'May';
  2359. param init_stock := iron 7.32 nickel 35.8;
  2360. param init_stock [*] iron 7.32, nickel 35.8;
  2361. param cost [iron] .025 [nickel] .03;
  2362. param value := iron -.1, nickel .02;
  2363. param : init_stock cost value :=
  2364. iron 7.32 .025 -.1
  2365. nickel 35.8 .03 .02 ;
  2366. param : raw : init stock cost value :=
  2367. iron 7.32 .025 -.1
  2368. nickel 35.8 .03 .02 ;
  2369. param demand default 0 (tr)
  2370. : FRA DET LAN WIN STL FRE LAF :=
  2371. bands 300 . 100 75 . 225 250
  2372. coils 500 750 400 250 . 850 500
  2373. plate 100 . . 50 200 . 250 ;
  2374. param trans_cost :=
  2375. [*,*,bands]: FRA DET LAN WIN STL FRE LAF :=
  2376. GARY 30 10 8 10 11 71 6
  2377. CLEV 22 7 10 7 21 82 13
  2378. PITT 19 11 12 10 25 83 15
  2379. [*,*,coils]: FRA DET LAN WIN STL FRE LAF :=
  2380. GARY 39 14 11 14 16 82 8
  2381. CLEV 27 9 12 9 26 95 17
  2382. PITT 24 14 17 13 28 99 20
  2383. [*,*,plate]: FRA DET LAN WIN STL FRE LAF :=
  2384. GARY 41 15 12 16 17 86 8
  2385. CLEV 29 9 13 9 28 99 18
  2386. PITT 26 14 17 13 31 104 20 ;
  2387. \end{verbatim}
  2388. The {\it parameter data block} is used to specify complete data for a
  2389. parameter (or parameters, if data are specified in the tabbing format).
  2390. Data blocks can be specified only for non-computable parameters, i.e.
  2391. for parameters, which have no assign attribute ({\tt:=}) in the
  2392. corresponding parameter statements.
  2393. Data defined in the parameter data block are coded as a sequence of
  2394. data records described below. Additionally the data block can be
  2395. provided with the optional {\tt default} attribute, which specifies a
  2396. default numeric or symbolic value of the parameter (parameters). This
  2397. default value is assigned to the parameter or its members when
  2398. no appropriate value is defined in the parameter data block. The
  2399. {\tt default} attribute cannot be used, if it is already specified in
  2400. the corresponding parameter statement.
  2401. \subsection{Assign data record}
  2402. The {\it assign data record} ({\tt:=}) is a non-signficant element.
  2403. It may be used for improving readability of data blocks.
  2404. \subsection{Slice data record}
  2405. The {\it slice data record} is a control record, which specifies a
  2406. {\it slice} of the parameter array. It has the following syntactic
  2407. form:
  2408. $$\mbox{{\tt[} $s_1$ {\tt,} $s_2$ {\tt,} \dots {\tt,} $s_n$ {\tt]}}$$
  2409. where $s_1$, $s_2$, \dots, $s_n$ are components of the slice.
  2410. Each component of the slice can be a number or symbol or the asterisk
  2411. ({\tt*}). The number of components in the slice should be the same as
  2412. the dimension of the parameter. For instance, if the parameter is a
  2413. 4-dimensional array, the slice should have four components. The number
  2414. of asterisks in the slice is called the {\it slice dimension}.
  2415. The effect of using slices is the following. If a $m$-dimensional slice
  2416. (i.e. a slice having $m$ asterisks) is specified in the data block, all
  2417. subsequent data records should specify subscripts of the parameter
  2418. members as if the parameter were $m$-dimensional, not $n$-dimensional.
  2419. Whenever $m$ subscripts are encountered, each asterisk in the slice is
  2420. replaced by corresponding subscript that gives $n$ subscripts, which
  2421. define the actual parameter member. For example, if the slice
  2422. $[a,*,1,2,*]$ is in effect, and subscripts 3 and $b$ are encountered in
  2423. a subsequent data record, the complete subscript list used to choose a
  2424. parameter member is $[a,3,1,2,b]$.
  2425. It is allowed to specify a slice having no asterisks. Such slice itself
  2426. defines a complete subscript list, in which case the next data record
  2427. should define only a single value of corresponding parameter member.
  2428. Being once specified the slice effects until either a new slice or the
  2429. end of data block is encountered. Note that if no slice is specified in
  2430. the data block, one, components of which are all asterisks, is assumed.
  2431. \subsection{Plain data record}
  2432. The {\it plain data record} defines a subscript list and a single value
  2433. in the plain format. This record has the following syntactic form:
  2434. $$\mbox{$t_1$ {\tt,} $t_2$ {\tt,} \dots {\tt,} $t_n$ {\tt,} $v$}$$
  2435. where $t_1$, $t_2$, \dots, $t_n$ are subscripts, and $v$ is a value.
  2436. Each subscript as well as the value can be a number or symbol. Commae
  2437. following subscripts are optional and may be omitted.
  2438. In case of 0-dimensional parameter or slice the plain data record has
  2439. no subscripts and consists of a single value only.
  2440. \subsection{Tabular data record}
  2441. The {\it tabular data record} defines several values, where each value
  2442. is provided with two subscripts. This record has the following
  2443. syntactic form:
  2444. $$\begin{array}{cccccc}
  2445. \mbox{{\tt:}}&c_1&c_2&\dots&c_n&\mbox{{\tt:=}}\\
  2446. r_1&a_{11}&a_{12}&\dots&a_{1n}&\\
  2447. r_2&a_{21}&a_{22}&\dots&a_{2n}&\\
  2448. \multicolumn{5}{c}{.\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .}&\\
  2449. r_m&a_{m1}&a_{m2}&\dots&a_{mn}&\\
  2450. \end{array}$$
  2451. where $r_1$, $r_2$, \dots, $r_m$ are numbers and/or symbols
  2452. corresponding to rows of the table; $c_1$, $c_2$, \dots, $c_n$ are
  2453. numbers and/or symbols corresponding to columns of the table, $a_{11}$,
  2454. $a_{12}$, \dots, $a_{mn}$ are table elements. Each element can be a
  2455. number or symbol or the single decimal point ({\tt.}). (In this data
  2456. record the delimiter {\tt:} preceding the column list and the delimiter
  2457. {\tt:=} following the column list cannot be omitted.)
  2458. Each element $a_{ij}$ of the tabular data block ($1\leq i\leq m$,
  2459. $1\leq j\leq n$) defines two subscripts, where the first subscript is
  2460. $r_i$, and the second one is $c_j$. These subscripts are used in
  2461. conjunction with the current slice to form the complete subscript list
  2462. that identifies a particular member of the parameter array. If $a_{ij}$
  2463. is a number or symbol, this value is assigned to the parameter member.
  2464. However, if $a_{ij}$ is the single decimal point, the member is
  2465. assigned a default value specified either in the parameter data block
  2466. or in the parameter statement, or, if no default value is specified,
  2467. the member remains undefined.
  2468. Since the tabular data record provides two subscripts for each value,
  2469. either the parameter or the slice currently used should be
  2470. 2-dimensional.
  2471. \subsection{Transposed tabular data record}
  2472. The {\it transposed tabular data record} has the following syntactic
  2473. form:
  2474. $$\begin{array}{cccccc}
  2475. \mbox{{\tt(tr) :}}&c_1&c_2&\dots&c_n&\mbox{{\tt:=}}\\
  2476. r_1&a_{11}&a_{12}&\dots&a_{1n}&\\
  2477. r_2&a_{21}&a_{22}&\dots&a_{2n}&\\
  2478. \multicolumn{5}{c}{.\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .}&\\
  2479. r_m&a_{m1}&a_{m2}&\dots&a_{mn}&\\
  2480. \end{array}$$
  2481. (In this case the delimiter {\tt:} following the keyword {\tt(tr)} is
  2482. optional and may be omitted.)
  2483. This data record is completely analogous to the tabular data record
  2484. (see above) with only exception that the first subscript defined by
  2485. element $a_{ij}$ is $c_j$ while the second one is $r_i$.
  2486. Being once specified the {\tt(tr)} indicator affects all subsequent
  2487. data records until either a slice or the end of data block is
  2488. encountered.
  2489. \newpage
  2490. \subsection{Tabbing data format}
  2491. The parameter data block in the {\it tabbing format} has the following
  2492. syntactic form:
  2493. $$
  2494. \begin{array}{*{8}{l}}
  2495. \multicolumn{4}{l}
  2496. {{\tt param}\ {\tt default}\ value\ {\tt :}\ s\ {\tt :}}&
  2497. p_1\ \ \verb|,|&p_2\ \ \verb|,|&\dots\ \verb|,|&p_r\ \ \verb|:=|\\
  2498. r_{11}\ \verb|,|& r_{12}\ \verb|,|& \dots\ \verb|,|& r_{1n}\ \verb|,|&
  2499. a_{11}\ \verb|,|& a_{12}\ \verb|,|& \dots\ \verb|,|& a_{1r}\ \verb|,|\\
  2500. r_{21}\ \verb|,|& r_{22}\ \verb|,|& \dots\ \verb|,|& r_{2n}\ \verb|,|&
  2501. a_{21}\ \verb|,|& a_{22}\ \verb|,|& \dots\ \verb|,|& a_{2r}\ \verb|,|\\
  2502. \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots \\
  2503. r_{m1}\ \verb|,|& r_{m2}\ \verb|,|& \dots\ \verb|,|& r_{mn}\ \verb|,|&
  2504. a_{m1}\ \verb|,|& a_{m2}\ \verb|,|& \dots\ \verb|,|& a_{mr}\ \verb|;|\\
  2505. \end{array}
  2506. $$
  2507. 1. The keyword {\tt default} may be omitted along with a value
  2508. following it.
  2509. 2. Symbolic name $s$ may be omitted along with the colon following it.
  2510. 3. All commae are optional and may be omitted.
  2511. The data block in the tabbing format shown above is exactly equivalent
  2512. to the following data blocks:
  2513. \verb|set| $s$\ \verb|:=|\ $
  2514. \verb|(|r_{11}\verb|,|r_{12}\verb|,|\dots\verb|,|r_{1n}\verb|) |
  2515. \verb|(|r_{21}\verb|,|r_{22}\verb|,|\dots\verb|,|r_{2n}\verb|) |
  2516. \dots
  2517. \verb| (|r_{m1}\verb|,|r_{m2}\verb|,|\dots\verb|,|r_{mn}\verb|);|$
  2518. \verb|param| $p_1$\ \verb|default|\ $value$\ \verb|:=|
  2519. $\verb| |
  2520. \verb|[|r_{11}\verb|,|r_{12}\verb|,|\dots\verb|,|r_{1n}\verb|] |a_{11}
  2521. \verb| [|r_{21}\verb|,|r_{22}\verb|,|\dots\verb|,|r_{2n}\verb|] |a_{21}
  2522. \verb| |\dots
  2523. \verb| [|r_{m1}\verb|,|r_{m2}\verb|,|\dots\verb|,|r_{mn}\verb|] |a_{m1}
  2524. \verb|;|
  2525. $
  2526. \verb|param| $p_2$\ \verb|default|\ $value$\ \verb|:=|
  2527. $\verb| |
  2528. \verb|[|r_{11}\verb|,|r_{12}\verb|,|\dots\verb|,|r_{1n}\verb|] |a_{12}
  2529. \verb| [|r_{21}\verb|,|r_{22}\verb|,|\dots\verb|,|r_{2n}\verb|] |a_{22}
  2530. \verb| |\dots
  2531. \verb| [|r_{m1}\verb|,|r_{m2}\verb|,|\dots\verb|,|r_{mn}\verb|] |a_{m2}
  2532. \verb|;|
  2533. $
  2534. \verb| |.\ \ \ .\ \ \ .\ \ \ .\ \ \ .\ \ \ .\ \ \ .\ \ \ .\ \ \ .
  2535. \verb|param| $p_r$\ \verb|default|\ $value$\ \verb|:=|
  2536. $\verb| |
  2537. \verb|[|r_{11}\verb|,|r_{12}\verb|,|\dots\verb|,|r_{1n}\verb|] |a_{1r}
  2538. \verb| [|r_{21}\verb|,|r_{22}\verb|,|\dots\verb|,|r_{2n}\verb|] |a_{2r}
  2539. \verb| |\dots
  2540. \verb| [|r_{m1}\verb|,|r_{m2}\verb|,|\dots\verb|,|r_{mn}\verb|] |a_{mr}
  2541. \verb|;|
  2542. $
  2543. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2544. \appendix
  2545. \chapter{Using suffixes}
  2546. \vspace*{-12pt}
  2547. Suffixes can be used to retrieve additional values associated with
  2548. model variables, constraints, and objectives.
  2549. A {\it suffix} consists of a period ({\tt.}) followed by a non-reserved
  2550. keyword. For example, if {\tt x} is a two-dimensional variable,
  2551. {\tt x[i,j].lb} is a numeric value equal to the lower bound of
  2552. elemental variable {\tt x[i,j]}, which (value) can be used everywhere
  2553. in expressions like a numeric parameter.
  2554. For model variables suffixes have the following meaning:
  2555. \begin{tabular}{@{}ll@{}}
  2556. {\tt.lb}&lower bound\\
  2557. {\tt.ub}&upper bound\\
  2558. {\tt.status}&status in the solution:\\
  2559. &0 --- undefined\\
  2560. &1 --- basic\\
  2561. &2 --- non-basic on lower bound\\
  2562. &3 --- non-basic on upper bound\\
  2563. &4 --- non-basic free (unbounded) variable\\
  2564. &5 --- non-basic fixed variable\\
  2565. {\tt.val}&primal value in the solution\\
  2566. {\tt.dual}&dual value (reduced cost) in the solution\\
  2567. \end{tabular}
  2568. For model constraints and objectives suffixes have the following
  2569. meaning:
  2570. \begin{tabular}{@{}ll@{}}
  2571. {\tt.lb}&lower bound of the linear form\\
  2572. {\tt.ub}&upper bound of the linear form\\
  2573. {\tt.status}&status in the solution:\\
  2574. &0 --- undefined\\
  2575. &1 --- non-active\\
  2576. &2 --- active on lower bound\\
  2577. &3 --- active on upper bound\\
  2578. &4 --- active free (unbounded) row\\
  2579. &5 --- active equality constraint\\
  2580. {\tt.val}&primal value of the linear form in the solution\\
  2581. {\tt.dual}&dual value (reduced cost) of the linear form in the
  2582. solution\\
  2583. \end{tabular}
  2584. Note that suffixes {\tt.status}, {\tt.val}, and {\tt.dual} can be used
  2585. only below the solve statement.
  2586. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2587. \chapter{Date and time functions}
  2588. \noindent\hfil
  2589. \begin{tabular}{c}
  2590. by Andrew Makhorin \verb|<mao@gnu.org>|\\
  2591. and Heinrich Schuchardt \verb|<heinrich.schuchardt@gmx.de>|\\
  2592. \end{tabular}
  2593. \section{Obtaining current calendar time}
  2594. \label{gmtime}
  2595. To obtain the current calendar time in MathProg there exists the
  2596. function {\tt gmtime}. It has no arguments and returns the number of
  2597. seconds elapsed since 00:00:00 on January 1, 1970, Coordinated
  2598. Universal Time (UTC). For example:
  2599. \begin{verbatim}
  2600. param utc := gmtime();
  2601. \end{verbatim}
  2602. MathProg has no function to convert UTC time returned by the function
  2603. {\tt gmtime} to {\it local} calendar times. Thus, if you need to
  2604. determine the current local calendar time, you have to add to the UTC
  2605. time returned the time offset from UTC expressed in seconds. For
  2606. example, the time in Berlin during the winter is one hour ahead of UTC
  2607. that corresponds to the time offset +1~hour~= +3600~secs, so the
  2608. current winter calendar time in Berlin may be determined as follows:
  2609. \begin{verbatim}
  2610. param now := gmtime() + 3600;
  2611. \end{verbatim}
  2612. \noindent Similarly, the summer time in Chicago (Central Daylight Time)
  2613. is five hours behind UTC, so the corresponding current local calendar
  2614. time may be determined as follows:
  2615. \begin{verbatim}
  2616. param now := gmtime() - 5 * 3600;
  2617. \end{verbatim}
  2618. Note that the value returned by {\tt gmtime} is volatile, i.e. being
  2619. called several times this function may return different values.
  2620. \section{Converting character string to calendar time}
  2621. \label{str2time}
  2622. The function {\tt str2time(}{\it s}{\tt,} {\it f}{\tt)} converts a
  2623. character string (timestamp) specified by its first argument {\it s},
  2624. which should be a symbolic expression, to the calendar time suitable
  2625. for arithmetic calculations. The conversion is controlled by the
  2626. specified format string {\it f} (the second argument), which also
  2627. should be a symbolic expression.
  2628. \newpage
  2629. The result of conversion returned by {\tt str2time} has the same
  2630. meaning as values returned by the function {\tt gmtime} (see Subsection
  2631. \ref{gmtime}, page \pageref{gmtime}). Note that {\tt str2time} does
  2632. {\tt not} correct the calendar time returned for the local timezone,
  2633. i.e. being applied to 00:00:00 on January 1, 1970 it always returns 0.
  2634. For example, the model statements:
  2635. \begin{verbatim}
  2636. param s, symbolic, := "07/14/98 13:47";
  2637. param t := str2time(s, "%m/%d/%y %H:%M");
  2638. display t;
  2639. \end{verbatim}
  2640. \noindent produce the following printout:
  2641. \begin{verbatim}
  2642. t = 900424020
  2643. \end{verbatim}
  2644. \noindent where the calendar time printed corresponds to 13:47:00 on
  2645. July 14, 1998.
  2646. The format string passed to the function {\tt str2time} consists of
  2647. conversion specifiers and ordinary characters. Each conversion
  2648. specifier begins with a percent ({\tt\%}) character followed by a
  2649. letter.
  2650. The following conversion specifiers may be used in the format string:
  2651. \begin{tabular}{@{}p{20pt}p{421.5pt}@{}}
  2652. {\tt\%b}&The abbreviated month name (case insensitive). At least three
  2653. first letters of the month name should appear in the input string.\\
  2654. \end{tabular}
  2655. \begin{tabular}{@{}p{20pt}p{421.5pt}@{}}
  2656. {\tt\%d}&The day of the month as a decimal number (range 1 to 31).
  2657. Leading zero is permitted, but not required.\\
  2658. \end{tabular}
  2659. \begin{tabular}{@{}p{20pt}p{421.5pt}@{}}
  2660. {\tt\%h}&The same as {\tt\%b}.\\
  2661. \end{tabular}
  2662. \begin{tabular}{@{}p{20pt}p{421.5pt}@{}}
  2663. {\tt\%H}&The hour as a decimal number, using a 24-hour clock (range 0
  2664. to 23). Leading zero is permitted, but not required.\\
  2665. \end{tabular}
  2666. \begin{tabular}{@{}p{20pt}p{421.5pt}@{}}
  2667. {\tt\%m}&The month as a decimal number (range 1 to 12). Leading zero is
  2668. permitted, but not required.\\
  2669. \end{tabular}
  2670. \begin{tabular}{@{}p{20pt}p{421.5pt}@{}}
  2671. {\tt\%M}&The minute as a decimal number (range 0 to 59). Leading zero
  2672. is permitted, but not required.\\
  2673. \end{tabular}
  2674. \begin{tabular}{@{}p{20pt}p{421.5pt}@{}}
  2675. {\tt\%S}&The second as a decimal number (range 0 to 60). Leading zero
  2676. is permitted, but not required.\\
  2677. \end{tabular}
  2678. \begin{tabular}{@{}p{20pt}p{421.5pt}@{}}
  2679. {\tt\%y}&The year without a century as a decimal number (range 0 to 99).
  2680. Leading zero is permitted, but not required. Input values in the range
  2681. 0 to 68 are considered as the years 2000 to 2068 while the values 69 to
  2682. 99 as the years 1969 to 1999.\\
  2683. \end{tabular}
  2684. \begin{tabular}{@{}p{20pt}p{421.5pt}@{}}
  2685. {\tt\%z}&The offset from GMT in ISO 8601 format.\\
  2686. \end{tabular}
  2687. \begin{tabular}{@{}p{20pt}p{421.5pt}@{}}
  2688. {\tt\%\%}&A literal {\tt\%} character.\\
  2689. \end{tabular}
  2690. All other (ordinary) characters in the format string should have a
  2691. matching character in the input string to be converted. Exceptions are
  2692. spaces in the input string which can match zero or more space
  2693. characters in the format string.
  2694. \newpage
  2695. If some date and/or time component(s) are missing in the format and,
  2696. therefore, in the input string, the function {\tt str2time} uses their
  2697. default values corresponding to 00:00:00 on January 1, 1970, that is,
  2698. the default value of the year is 1970, the default value of the month
  2699. is January, etc.
  2700. The function {\tt str2time} is applicable to all calendar times in the
  2701. range 00:00:00 on January 1, 0001 to 23:59:59 on December 31, 4000 of
  2702. the Gregorian calendar.
  2703. \section{Converting calendar time to character string}
  2704. \label{time2str}
  2705. The function {\tt time2str(}{\it t}{\tt,} {\it f}{\tt)} converts the
  2706. calendar time specified by its first argument {\it t}, which should be
  2707. a numeric expression, to a character string (symbolic value). The
  2708. conversion is controlled by the specified format string {\it f} (the
  2709. second argument), which should be a symbolic expression.
  2710. The calendar time passed to {\tt time2str} has the same meaning as
  2711. values returned by the function {\tt gmtime} (see Subsection
  2712. \ref{gmtime}, page \pageref{gmtime}). Note that {\tt time2str} does
  2713. {\it not} correct the specified calendar time for the local timezone,
  2714. i.e. the calendar time 0 always corresponds to 00:00:00 on January 1,
  2715. 1970.
  2716. For example, the model statements:
  2717. \begin{verbatim}
  2718. param s, symbolic, := time2str(gmtime(), "%FT%TZ");
  2719. display s;
  2720. \end{verbatim}
  2721. \noindent may produce the following printout:
  2722. \begin{verbatim}
  2723. s = '2008-12-04T00:23:45Z'
  2724. \end{verbatim}
  2725. \noindent which is a timestamp in the ISO format.
  2726. The format string passed to the function {\tt time2str} consists of
  2727. conversion specifiers and ordinary characters. Each conversion
  2728. specifier begins with a percent ({\tt\%}) character followed by a
  2729. letter.
  2730. The following conversion specifiers may be used in the format string:
  2731. \begin{tabular}{@{}p{20pt}p{421.5pt}@{}}
  2732. {\tt\%a}&The abbreviated (2-character) weekday name.\\
  2733. \end{tabular}
  2734. \begin{tabular}{@{}p{20pt}p{421.5pt}@{}}
  2735. {\tt\%A}&The full weekday name.\\
  2736. \end{tabular}
  2737. \begin{tabular}{@{}p{20pt}p{421.5pt}@{}}
  2738. {\tt\%b}&The abbreviated (3-character) month name.\\
  2739. \end{tabular}
  2740. \begin{tabular}{@{}p{20pt}p{421.5pt}@{}}
  2741. {\tt\%B}&The full month name.\\
  2742. \end{tabular}
  2743. \begin{tabular}{@{}p{20pt}p{421.5pt}@{}}
  2744. {\tt\%C}&The century of the year, that is the greatest integer not
  2745. greater than the year divided by~100.\\
  2746. \end{tabular}
  2747. \begin{tabular}{@{}p{20pt}p{421.5pt}@{}}
  2748. {\tt\%d}&The day of the month as a decimal number (range 01 to 31).\\
  2749. \end{tabular}
  2750. \begin{tabular}{@{}p{20pt}p{421.5pt}@{}}
  2751. {\tt\%D}&The date using the format \verb|%m/%d/%y|.\\
  2752. \end{tabular}
  2753. \begin{tabular}{@{}p{20pt}p{421.5pt}@{}}
  2754. {\tt\%e}&The day of the month like with \verb|%d|, but padded with
  2755. blank rather than zero.\\
  2756. \end{tabular}
  2757. \begin{tabular}{@{}p{20pt}p{421.5pt}@{}}
  2758. {\tt\%F}&The date using the format \verb|%Y-%m-%d|.\\
  2759. \end{tabular}
  2760. \begin{tabular}{@{}p{20pt}p{421.5pt}@{}}
  2761. {\tt\%g}&The year corresponding to the ISO week number, but without the
  2762. century (range 00 to~99). This has the same format and value as
  2763. \verb|%y|, except that if the ISO week number (see \verb|%V|) belongs
  2764. to the previous or next year, that year is used instead.\\
  2765. \end{tabular}
  2766. \begin{tabular}{@{}p{20pt}p{421.5pt}@{}}
  2767. {\tt\%G}&The year corresponding to the ISO week number. This has the
  2768. same format and value as \verb|%Y|, except that if the ISO week number
  2769. (see \verb|%V|) belongs to the previous or next year, that year is used
  2770. instead.
  2771. \end{tabular}
  2772. \begin{tabular}{@{}p{20pt}p{421.5pt}@{}}
  2773. {\tt\%h}&The same as \verb|%b|.\\
  2774. \end{tabular}
  2775. \begin{tabular}{@{}p{20pt}p{421.5pt}@{}}
  2776. {\tt\%H}&The hour as a decimal number, using a 24-hour clock (range 00
  2777. to 23).\\
  2778. \end{tabular}
  2779. \begin{tabular}{@{}p{20pt}p{421.5pt}@{}}
  2780. {\tt\%I}&The hour as a decimal number, using a 12-hour clock (range 01
  2781. to 12).\\
  2782. \end{tabular}
  2783. \begin{tabular}{@{}p{20pt}p{421.5pt}@{}}
  2784. {\tt\%j}&The day of the year as a decimal number (range 001 to 366).\\
  2785. \end{tabular}
  2786. \begin{tabular}{@{}p{20pt}p{421.5pt}@{}}
  2787. {\tt\%k}&The hour as a decimal number, using a 24-hour clock like
  2788. \verb|%H|, but padded with blank rather than zero.\\
  2789. \end{tabular}
  2790. \begin{tabular}{@{}p{20pt}p{421.5pt}@{}}
  2791. {\tt\%l}&The hour as a decimal number, using a 12-hour clock like
  2792. \verb|%I|, but padded with blank rather than zero.
  2793. \end{tabular}
  2794. \begin{tabular}{@{}p{20pt}p{421.5pt}@{}}
  2795. {\tt\%m}&The month as a decimal number (range 01 to 12).\\
  2796. \end{tabular}
  2797. \begin{tabular}{@{}p{20pt}p{421.5pt}@{}}
  2798. {\tt\%M}&The minute as a decimal number (range 00 to 59).\\
  2799. \end{tabular}
  2800. \begin{tabular}{@{}p{20pt}p{421.5pt}@{}}
  2801. {\tt\%p}&Either {\tt AM} or {\tt PM}, according to the given time value.
  2802. Midnight is treated as {\tt AM} and noon as {\tt PM}.\\
  2803. \end{tabular}
  2804. \begin{tabular}{@{}p{20pt}p{421.5pt}@{}}
  2805. {\tt\%P}&Either {\tt am} or {\tt pm}, according to the given time value.
  2806. Midnight is treated as {\tt am} and noon as {\tt pm}.\\
  2807. \end{tabular}
  2808. \begin{tabular}{@{}p{20pt}p{421.5pt}@{}}
  2809. {\tt\%R}&The hour and minute in decimal numbers using the format
  2810. \verb|%H:%M|.\\
  2811. \end{tabular}
  2812. \begin{tabular}{@{}p{20pt}p{421.5pt}@{}}
  2813. {\tt\%S}&The second as a decimal number (range 00 to 59).\\
  2814. \end{tabular}
  2815. \begin{tabular}{@{}p{20pt}p{421.5pt}@{}}
  2816. {\tt\%T}&The time of day in decimal numbers using the format
  2817. \verb|%H:%M:%S|.\\
  2818. \end{tabular}
  2819. \begin{tabular}{@{}p{20pt}p{421.5pt}@{}}
  2820. {\tt\%u}&The day of the week as a decimal number (range 1 to 7), Monday
  2821. being 1.\\
  2822. \end{tabular}
  2823. \begin{tabular}{@{}p{20pt}p{421.5pt}@{}}
  2824. {\tt\%U}&The week number of the current year as a decimal number (range
  2825. 00 to 53), starting with the first Sunday as the first day of the first
  2826. week. Days preceding the first Sunday in the year are considered to be
  2827. in week 00.
  2828. \end{tabular}
  2829. \begin{tabular}{@{}p{20pt}p{421.5pt}@{}}
  2830. {\tt\%V}&The ISO week number as a decimal number (range 01 to 53). ISO
  2831. weeks start with Monday and end with Sunday. Week 01 of a year is the
  2832. first week which has the majority of its days in that year; this is
  2833. equivalent to the week containing January 4. Week 01 of a year can
  2834. contain days from the previous year. The week before week 01 of a year
  2835. is the last week (52 or 53) of the previous year even if it contains
  2836. days from the new year. In other word, if 1 January is Monday, Tuesday,
  2837. Wednesday or Thursday, it is in week 01; if 1 January is Friday,
  2838. Saturday or Sunday, it is in week 52 or 53 of the previous year.\\
  2839. \end{tabular}
  2840. \begin{tabular}{@{}p{20pt}p{421.5pt}@{}}
  2841. {\tt\%w}&The day of the week as a decimal number (range 0 to 6), Sunday
  2842. being 0.\\
  2843. \end{tabular}
  2844. \begin{tabular}{@{}p{20pt}p{421.5pt}@{}}
  2845. {\tt\%W}&The week number of the current year as a decimal number (range
  2846. 00 to 53), starting with the first Monday as the first day of the first
  2847. week. Days preceding the first Monday in the year are considered to be
  2848. in week 00.\\
  2849. \end{tabular}
  2850. \begin{tabular}{@{}p{20pt}p{421.5pt}@{}}
  2851. {\tt\%y}&The year without a century as a decimal number (range 00 to
  2852. 99), that is the year modulo~100.\\
  2853. \end{tabular}
  2854. \begin{tabular}{@{}p{20pt}p{421.5pt}@{}}
  2855. {\tt\%Y}&The year as a decimal number, using the Gregorian calendar.\\
  2856. \end{tabular}
  2857. \begin{tabular}{@{}p{20pt}p{421.5pt}@{}}
  2858. {\tt\%\%}&A literal \verb|%| character.\\
  2859. \end{tabular}
  2860. All other (ordinary) characters in the format string are simply copied
  2861. to the resultant string.
  2862. The first argument (calendar time) passed to the function {\tt time2str}
  2863. should be in the range from $-62135596800$ to $+64092211199$ that
  2864. corresponds to the period from 00:00:00 on January 1, 0001 to 23:59:59
  2865. on December 31, 4000 of the Gregorian calendar.
  2866. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2867. \chapter{Table drivers}
  2868. \label{drivers}
  2869. \noindent\hfil
  2870. \begin{tabular}{c}
  2871. by Andrew Makhorin \verb|<mao@gnu.org>|\\
  2872. and Heinrich Schuchardt \verb|<heinrich.schuchardt@gmx.de>|\\
  2873. \end{tabular}
  2874. \bigskip\bigskip
  2875. The {\it table driver} is a program module which provides transmitting
  2876. data between MathProg model objects and data tables.
  2877. Currently the GLPK package has four table drivers:
  2878. \vspace*{-8pt}
  2879. \begin{itemize}
  2880. \item built-in CSV table driver;
  2881. \item built-in xBASE table driver;
  2882. \item ODBC table driver;
  2883. \item MySQL table driver.
  2884. \end{itemize}
  2885. \vspace*{-8pt}
  2886. \section{CSV table driver}
  2887. The CSV table driver assumes that the data table is represented in the
  2888. form of a plain text file in the CSV (comma-separated values) file
  2889. format as described below.
  2890. To choose the CSV table driver its name in the table statement should
  2891. be specified as \verb|"CSV"|, and the only argument should specify the
  2892. name of a plain text file containing the table. For example:
  2893. \begin{verbatim}
  2894. table data IN "CSV" "data.csv": ... ;
  2895. \end{verbatim}
  2896. The filename suffix may be arbitrary, however, it is recommended to use
  2897. the suffix `\verb|.csv|'.
  2898. On reading input tables the CSV table driver provides an implicit field
  2899. named \verb|RECNO|, which contains the current record number. This
  2900. field can be specified in the input table statement as if there were
  2901. the actual field named \verb|RECNO| in the CSV file. For example:
  2902. \begin{verbatim}
  2903. table list IN "CSV" "list.csv": num <- [RECNO], ... ;
  2904. \end{verbatim}
  2905. \newpage
  2906. \subsection*{CSV format\footnote{This material is based on the RFC
  2907. document 4180.}}
  2908. The CSV (comma-separated values) format is a plain text file format
  2909. defined as follows.
  2910. 1. Each record is located on a separate line, delimited by a line
  2911. break. For example:
  2912. \begin{verbatim}
  2913. aaa,bbb,ccc\n
  2914. xxx,yyy,zzz\n
  2915. \end{verbatim}
  2916. \noindent
  2917. where \verb|\n| means the control character \verb|LF| ({\tt 0x0A}).
  2918. 2. The last record in the file may or may not have an ending line
  2919. break. For example:
  2920. \begin{verbatim}
  2921. aaa,bbb,ccc\n
  2922. xxx,yyy,zzz
  2923. \end{verbatim}
  2924. 3. There should be a header line appearing as the first line of the
  2925. file in the same format as normal record lines. This header should
  2926. contain names corresponding to the fields in the file. The number of
  2927. field names in the header line should be the same as the number of
  2928. fields in the records of the file. For example:
  2929. \begin{verbatim}
  2930. name1,name2,name3\n
  2931. aaa,bbb,ccc\n
  2932. xxx,yyy,zzz\n
  2933. \end{verbatim}
  2934. 4. Within the header and each record there may be one or more fields
  2935. separated by commas. Each line should contain the same number of fields
  2936. throughout the file. Spaces are considered as part of a field and
  2937. therefore not ignored. The last field in the record should not be
  2938. followed by a comma. For example:
  2939. \begin{verbatim}
  2940. aaa,bbb,ccc\n
  2941. \end{verbatim}
  2942. 5. Fields may or may not be enclosed in double quotes. For example:
  2943. \begin{verbatim}
  2944. "aaa","bbb","ccc"\n
  2945. zzz,yyy,xxx\n
  2946. \end{verbatim}
  2947. 6. If a field is enclosed in double quotes, each double quote which is
  2948. part of the field should be coded twice. For example:
  2949. \begin{verbatim}
  2950. "aaa","b""bb","ccc"\n
  2951. \end{verbatim}
  2952. \para{Example}
  2953. \begin{verbatim}
  2954. FROM,TO,DISTANCE,COST
  2955. Seattle,New-York,2.5,0.12
  2956. Seattle,Chicago,1.7,0.08
  2957. Seattle,Topeka,1.8,0.09
  2958. San-Diego,New-York,2.5,0.15
  2959. San-Diego,Chicago,1.8,0.10
  2960. San-Diego,Topeka,1.4,0.07
  2961. \end{verbatim}
  2962. \newpage
  2963. \section{xBASE table driver}
  2964. The xBASE table driver assumes that the data table is stored in the
  2965. .dbf file format.
  2966. To choose the xBASE table driver its name in the table statement should
  2967. be specified as \verb|"xBASE"|, and the first argument should specify
  2968. the name of a .dbf file containing the table. For the output table there
  2969. should be the second argument defining the table format in the form
  2970. \verb|"FF...F"|, where \verb|F| is either {\tt C({\it n})},
  2971. which specifies a character field of length $n$, or
  2972. {\tt N({\it n}{\rm [},{\it p}{\rm ]})}, which specifies a numeric field
  2973. of length $n$ and precision $p$ (by default $p$ is 0).
  2974. The following is a simple example which illustrates creating and
  2975. reading a .dbf file:
  2976. \begin{verbatim}
  2977. table tab1{i in 1..10} OUT "xBASE" "foo.dbf"
  2978. "N(5)N(10,4)C(1)C(10)": 2*i+1 ~ B, Uniform(-20,+20) ~ A,
  2979. "?" ~ FOO, "[" & i & "]" ~ C;
  2980. set S, dimen 4;
  2981. table tab2 IN "xBASE" "foo.dbf": S <- [B, C, RECNO, A];
  2982. display S;
  2983. end;
  2984. \end{verbatim}
  2985. \section{ODBC table driver}
  2986. The ODBC table driver allows connecting to SQL databases using an
  2987. implementation of the ODBC interface based on the Call Level Interface
  2988. (CLI).\footnote{The corresponding software standard is defined in
  2989. ISO/IEC 9075-3:2003.}
  2990. \para{Debian GNU/Linux.}
  2991. Under Debian GNU/Linux the ODBC table driver uses the iODBC
  2992. package,\footnote{See {\tt<http://www.iodbc.org/>}.} which should be
  2993. installed before building the GLPK package. The installation can be
  2994. effected with the following command:
  2995. \begin{verbatim}
  2996. sudo apt-get install libiodbc2-dev
  2997. \end{verbatim}
  2998. Note that on configuring the GLPK package to enable using the iODBC
  2999. library the option `\verb|--enable-odbc|' should be passed to the
  3000. configure script.
  3001. The individual databases should be entered for systemwide usage in
  3002. \verb|/etc/odbc.ini| and\linebreak \verb|/etc/odbcinst.ini|. Database
  3003. connections to be used by a single user are specified by files in the
  3004. home directory (\verb|.odbc.ini| and \verb|.odbcinst.ini|).
  3005. \para{Microsoft Windows.}
  3006. Under Microsoft Windows the ODBC table driver uses the Microsoft ODBC
  3007. library. To enable this feature the symbol:
  3008. \begin{verbatim}
  3009. #define ODBC_DLNAME "odbc32.dll"
  3010. \end{verbatim}
  3011. \noindent
  3012. should be defined in the GLPK configuration file `\verb|config.h|'.
  3013. Data sources can be created via the Administrative Tools from the
  3014. Control Panel.
  3015. To choose the ODBC table driver its name in the table statement should
  3016. be specified as \verb|'ODBC'| or \verb|'iODBC'|.
  3017. \newpage
  3018. The argument list is specified as follows.
  3019. The first argument is the connection string passed to the ODBC library,
  3020. for example:
  3021. \verb|'DSN=glpk;UID=user;PWD=password'|, or
  3022. \verb|'DRIVER=MySQL;DATABASE=glpkdb;UID=user;PWD=password'|.
  3023. Different parts of the string are separated by semicolons. Each part
  3024. consists of a pair {\it fieldname} and {\it value} separated by the
  3025. equal sign. Allowable fieldnames depend on the ODBC library. Typically
  3026. the following fieldnames are allowed:
  3027. \verb|DATABASE | database;
  3028. \verb|DRIVER | ODBC driver;
  3029. \verb|DSN | name of a data source;
  3030. \verb|FILEDSN | name of a file data source;
  3031. \verb|PWD | user password;
  3032. \verb|SERVER | database;
  3033. \verb|UID | user name.
  3034. The second argument and all following are considered to be SQL
  3035. statements
  3036. SQL statements may be spread over multiple arguments. If the last
  3037. character of an argument is a semicolon this indicates the end of
  3038. a SQL statement.
  3039. The arguments of a SQL statement are concatenated separated by space.
  3040. The eventual trailing semicolon will be removed.
  3041. All but the last SQL statement will be executed directly.
  3042. For IN-table the last SQL statement can be a SELECT command starting
  3043. with the capitalized letters \verb|'SELECT '|. If the string does not
  3044. start with \verb|'SELECT '| it is considered to be a table name and a
  3045. SELECT statement is automatically generated.
  3046. For OUT-table the last SQL statement can contain one or multiple
  3047. question marks. If it contains a question mark it is considered a
  3048. template for the write routine. Otherwise the string is considered a
  3049. table name and an INSERT template is automatically generated.
  3050. The writing routine uses the template with the question marks and
  3051. replaces the first question mark by the first output parameter, the
  3052. second question mark by the second output parameter and so forth. Then
  3053. the SQL command is issued.
  3054. The following is an example of the output table statement:
  3055. \begin{verbatim}
  3056. table ta { l in LOCATIONS } OUT
  3057. 'ODBC'
  3058. 'DSN=glpkdb;UID=glpkuser;PWD=glpkpassword'
  3059. 'DROP TABLE IF EXISTS result;'
  3060. 'CREATE TABLE result ( ID INT, LOC VARCHAR(255), QUAN DOUBLE );'
  3061. 'INSERT INTO result 'VALUES ( 4, ?, ? )' :
  3062. l ~ LOC, quantity[l] ~ QUAN;
  3063. \end{verbatim}
  3064. \newpage
  3065. \noindent
  3066. Alternatively it could be written as follows:
  3067. \begin{verbatim}
  3068. table ta { l in LOCATIONS } OUT
  3069. 'ODBC'
  3070. 'DSN=glpkdb;UID=glpkuser;PWD=glpkpassword'
  3071. 'DROP TABLE IF EXISTS result;'
  3072. 'CREATE TABLE result ( ID INT, LOC VARCHAR(255), QUAN DOUBLE );'
  3073. 'result' :
  3074. l ~ LOC, quantity[l] ~ QUAN, 4 ~ ID;
  3075. \end{verbatim}
  3076. Using templates with `\verb|?|' supports not only INSERT, but also
  3077. UPDATE, DELETE, etc. For example:
  3078. \begin{verbatim}
  3079. table ta { l in LOCATIONS } OUT
  3080. 'ODBC'
  3081. 'DSN=glpkdb;UID=glpkuser;PWD=glpkpassword'
  3082. 'UPDATE result SET DATE = ' & date & ' WHERE ID = 4;'
  3083. 'UPDATE result SET QUAN = ? WHERE LOC = ? AND ID = 4' :
  3084. quantity[l], l;
  3085. \end{verbatim}
  3086. \section{MySQL table driver}
  3087. The MySQL table driver allows connecting to MySQL databases.
  3088. \para{Debian GNU/Linux.}
  3089. Under Debian GNU/Linux the MySQL table driver uses the MySQL
  3090. package,\footnote{For download development files see
  3091. {\tt<http://dev.mysql.com/downloads/mysql/>}.} which should be
  3092. installed before building the GLPK package. The installation can be
  3093. effected with the following command:
  3094. \begin{verbatim}
  3095. sudo apt-get install libmysqlclient15-dev
  3096. \end{verbatim}
  3097. Note that on configuring the GLPK package to enable using the MySQL
  3098. library the option `\verb|--enable-mysql|' should be passed to the
  3099. configure script.
  3100. \para{Microsoft Windows.}
  3101. Under Microsoft Windows the MySQL table driver also uses the MySQL
  3102. library. To enable this feature the symbol:
  3103. \begin{verbatim}
  3104. #define MYSQL_DLNAME "libmysql.dll"
  3105. \end{verbatim}
  3106. \noindent
  3107. should be defined in the GLPK configuration file `\verb|config.h|'.
  3108. To choose the MySQL table driver its name in the table statement should
  3109. be specified as \verb|'MySQL'|.
  3110. The argument list is specified as follows.
  3111. The first argument specifies how to connect the data base in the DSN
  3112. style, for example:
  3113. \verb|'Database=glpk;UID=glpk;PWD=gnu'|.
  3114. Different parts of the string are separated by semicolons. Each part
  3115. consists of a pair {\it fieldname} and {\it value} separated by the
  3116. equal sign. The following fieldnames are allowed:
  3117. \newpage
  3118. \verb|Server | server running the database (defaulting to localhost);
  3119. \verb|Database | name of the database;
  3120. \verb|UID | user name;
  3121. \verb|PWD | user password;
  3122. \verb|Port | port used by the server (defaulting to 3306).
  3123. The second argument and all following are considered to be SQL
  3124. statements.
  3125. SQL statements may be spread over multiple arguments. If the last
  3126. character of an argument is a semicolon this indicates the end of
  3127. a SQL statement.
  3128. The arguments of a SQL statement are concatenated separated by space.
  3129. The eventual trailing semicolon will be removed.
  3130. All but the last SQL statement will be executed directly.
  3131. For IN-table the last SQL statement can be a SELECT command starting
  3132. with the capitalized letters \verb|'SELECT '|. If the string does not
  3133. start with \verb|'SELECT '| it is considered to be a table name and a
  3134. SELECT statement is automatically generated.
  3135. For OUT-table the last SQL statement can contain one or multiple
  3136. question marks. If it contains a question mark it is considered a
  3137. template for the write routine. Otherwise the string is considered a
  3138. table name and an INSERT template is automatically generated.
  3139. The writing routine uses the template with the question marks and
  3140. replaces the first question mark by the first output parameter, the
  3141. second question mark by the second output parameter and so forth. Then
  3142. the SQL command is issued.
  3143. The following is an example of the output table statement:
  3144. \begin{verbatim}
  3145. table ta { l in LOCATIONS } OUT
  3146. 'MySQL'
  3147. 'Database=glpkdb;UID=glpkuser;PWD=glpkpassword'
  3148. 'DROP TABLE IF EXISTS result;'
  3149. 'CREATE TABLE result ( ID INT, LOC VARCHAR(255), QUAN DOUBLE );'
  3150. 'INSERT INTO result VALUES ( 4, ?, ? )' :
  3151. l ~ LOC, quantity[l] ~ QUAN;
  3152. \end{verbatim}
  3153. \noindent
  3154. Alternatively it could be written as follows:
  3155. \begin{verbatim}
  3156. table ta { l in LOCATIONS } OUT
  3157. 'MySQL'
  3158. 'Database=glpkdb;UID=glpkuser;PWD=glpkpassword'
  3159. 'DROP TABLE IF EXISTS result;'
  3160. 'CREATE TABLE result ( ID INT, LOC VARCHAR(255), QUAN DOUBLE );'
  3161. 'result' :
  3162. l ~ LOC, quantity[l] ~ QUAN, 4 ~ ID;
  3163. \end{verbatim}
  3164. \newpage
  3165. Using templates with `\verb|?|' supports not only INSERT, but also
  3166. UPDATE, DELETE, etc. For example:
  3167. \begin{verbatim}
  3168. table ta { l in LOCATIONS } OUT
  3169. 'MySQL'
  3170. 'Database=glpkdb;UID=glpkuser;PWD=glpkpassword'
  3171. 'UPDATE result SET DATE = ' & date & ' WHERE ID = 4;'
  3172. 'UPDATE result SET QUAN = ? WHERE LOC = ? AND ID = 4' :
  3173. quantity[l], l;
  3174. \end{verbatim}
  3175. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  3176. \chapter{Solving models with glpsol}
  3177. The GLPK package\footnote{{\tt http://www.gnu.org/software/glpk/}}
  3178. includes the program {\tt glpsol}, a stand-alone LP/MIP solver. This
  3179. program can be launched from the command line or from the shell to
  3180. solve models written in the GNU MathProg modeling language.
  3181. To tell the solver that the input file contains a model description you
  3182. need to specify the option \verb|--model| in the command line.
  3183. For example:
  3184. \begin{verbatim}
  3185. glpsol --model foo.mod
  3186. \end{verbatim}
  3187. Sometimes it is necessary to use the data section placed in a separate
  3188. file, in which case you may use the following command:
  3189. \begin{verbatim}
  3190. glpsol --model foo.mod --data foo.dat
  3191. \end{verbatim}
  3192. \noindent Note that if the model file also contains the data section,
  3193. that section is ignored.
  3194. It is also allowed to specify more than one file containing the data
  3195. section, for example:
  3196. \begin{verbatim}
  3197. glpsol --model foo.mod --data foo1.dat --data foo2.dat
  3198. \end{verbatim}
  3199. If the model description contains some display and/or printf
  3200. statements, by default the output is sent to the terminal. If you need
  3201. to redirect the output to a file, you may use the following command:
  3202. \begin{verbatim}
  3203. glpsol --model foo.mod --display foo.out
  3204. \end{verbatim}
  3205. If you need to look at the problem, which has been generated by the
  3206. model translator, you may use the option \verb|--wlp| as follows:
  3207. \begin{verbatim}
  3208. glpsol --model foo.mod --wlp foo.lp
  3209. \end{verbatim}
  3210. \noindent In this case the problem data is written to file
  3211. \verb|foo.lp| in CPLEX LP format suitable for visual analysis.
  3212. Sometimes it is needed merely to check the model description not
  3213. solving the generated problem instance. In this case you may specify
  3214. the option \verb|--check|, for example:
  3215. \begin{verbatim}
  3216. glpsol --check --model foo.mod --wlp foo.lp
  3217. \end{verbatim}
  3218. \newpage
  3219. If you need to write a numeric solution obtained by the solver to
  3220. a file, you may use the following command:
  3221. \begin{verbatim}
  3222. glpsol --model foo.mod --output foo.sol
  3223. \end{verbatim}
  3224. \noindent in which case the solution is written to file \verb|foo.sol|
  3225. in a plain text format suitable for visual analysis.
  3226. The complete list of the \verb|glpsol| options can be found in the
  3227. GLPK reference manual included in the GLPK distribution.
  3228. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  3229. \chapter{Example model description}
  3230. \section{Model description written in MathProg}
  3231. Below here is a complete example of the model description written in
  3232. the GNU MathProg modeling language.
  3233. \bigskip
  3234. \begin{verbatim}
  3235. # A TRANSPORTATION PROBLEM
  3236. #
  3237. # This problem finds a least cost shipping schedule that meets
  3238. # requirements at markets and supplies at factories.
  3239. #
  3240. # References:
  3241. # Dantzig G B, "Linear Programming and Extensions."
  3242. # Princeton University Press, Princeton, New Jersey, 1963,
  3243. # Chapter 3-3.
  3244. set I;
  3245. /* canning plants */
  3246. set J;
  3247. /* markets */
  3248. param a{i in I};
  3249. /* capacity of plant i in cases */
  3250. param b{j in J};
  3251. /* demand at market j in cases */
  3252. param d{i in I, j in J};
  3253. /* distance in thousands of miles */
  3254. param f;
  3255. /* freight in dollars per case per thousand miles */
  3256. param c{i in I, j in J} := f * d[i,j] / 1000;
  3257. /* transport cost in thousands of dollars per case */
  3258. var x{i in I, j in J} >= 0;
  3259. /* shipment quantities in cases */
  3260. minimize cost: sum{i in I, j in J} c[i,j] * x[i,j];
  3261. /* total transportation costs in thousands of dollars */
  3262. s.t. supply{i in I}: sum{j in J} x[i,j] <= a[i];
  3263. /* observe supply limit at plant i */
  3264. s.t. demand{j in J}: sum{i in I} x[i,j] >= b[j];
  3265. /* satisfy demand at market j */
  3266. data;
  3267. set I := Seattle San-Diego;
  3268. set J := New-York Chicago Topeka;
  3269. param a := Seattle 350
  3270. San-Diego 600;
  3271. param b := New-York 325
  3272. Chicago 300
  3273. Topeka 275;
  3274. param d : New-York Chicago Topeka :=
  3275. Seattle 2.5 1.7 1.8
  3276. San-Diego 2.5 1.8 1.4 ;
  3277. param f := 90;
  3278. end;
  3279. \end{verbatim}
  3280. \newpage
  3281. \section{Generated LP problem instance}
  3282. Below here is the result of the translation of the example model
  3283. produced by the solver \verb|glpsol| and written in CPLEX LP format
  3284. with the option \verb|--wlp|.
  3285. \medskip
  3286. \begin{verbatim}
  3287. \* Problem: transp *\
  3288. Minimize
  3289. cost: + 0.225 x(Seattle,New~York) + 0.153 x(Seattle,Chicago)
  3290. + 0.162 x(Seattle,Topeka) + 0.225 x(San~Diego,New~York)
  3291. + 0.162 x(San~Diego,Chicago) + 0.126 x(San~Diego,Topeka)
  3292. Subject To
  3293. supply(Seattle): + x(Seattle,New~York) + x(Seattle,Chicago)
  3294. + x(Seattle,Topeka) <= 350
  3295. supply(San~Diego): + x(San~Diego,New~York) + x(San~Diego,Chicago)
  3296. + x(San~Diego,Topeka) <= 600
  3297. demand(New~York): + x(Seattle,New~York) + x(San~Diego,New~York) >= 325
  3298. demand(Chicago): + x(Seattle,Chicago) + x(San~Diego,Chicago) >= 300
  3299. demand(Topeka): + x(Seattle,Topeka) + x(San~Diego,Topeka) >= 275
  3300. End
  3301. \end{verbatim}
  3302. \section{Optimal LP solution}
  3303. Below here is the optimal solution of the generated LP problem instance
  3304. found by the solver \verb|glpsol| and written in plain text format
  3305. with the option \verb|--output|.
  3306. \medskip
  3307. \begin{footnotesize}
  3308. \begin{verbatim}
  3309. Problem: transp
  3310. Rows: 6
  3311. Columns: 6
  3312. Non-zeros: 18
  3313. Status: OPTIMAL
  3314. Objective: cost = 153.675 (MINimum)
  3315. No. Row name St Activity Lower bound Upper bound Marginal
  3316. ------ ------------ -- ------------- ------------- ------------- -------------
  3317. 1 cost B 153.675
  3318. 2 supply[Seattle]
  3319. NU 350 350 < eps
  3320. 3 supply[San-Diego]
  3321. B 550 600
  3322. 4 demand[New-York]
  3323. NL 325 325 0.225
  3324. 5 demand[Chicago]
  3325. NL 300 300 0.153
  3326. 6 demand[Topeka]
  3327. NL 275 275 0.126
  3328. No. Column name St Activity Lower bound Upper bound Marginal
  3329. ------ ------------ -- ------------- ------------- ------------- -------------
  3330. 1 x[Seattle,New-York]
  3331. B 50 0
  3332. 2 x[Seattle,Chicago]
  3333. B 300 0
  3334. 3 x[Seattle,Topeka]
  3335. NL 0 0 0.036
  3336. 4 x[San-Diego,New-York]
  3337. B 275 0
  3338. 5 x[San-Diego,Chicago]
  3339. NL 0 0 0.009
  3340. 6 x[San-Diego,Topeka]
  3341. B 275 0
  3342. End of output
  3343. \end{verbatim}
  3344. \end{footnotesize}
  3345. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  3346. \newpage
  3347. \section*{Acknowledgements}
  3348. \addcontentsline{toc}{chapter}{Acknowledgements}
  3349. The authors would like to thank the following people, who kindly read,
  3350. commented, and corrected the draft of this document:
  3351. \noindent Juan Carlos Borras \verb|<borras@cs.helsinki.fi>|
  3352. \noindent Harley Mackenzie \verb|<hjm@bigpond.com>|
  3353. \noindent Robbie Morrison \verb|<robbie@actrix.co.nz>|
  3354. \end{document}