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.

4295 lines
145 KiB

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