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.

423 lines
13 KiB

2 months ago
  1. %* glpk09.tex *%
  2. \chapter{CPLEX LP Format}
  3. \label{chacplex}
  4. \section{Prelude}
  5. The CPLEX LP format\footnote{The CPLEX LP format was developed in
  6. the end of 1980's by CPLEX Optimization, Inc. as an input format for
  7. the CPLEX linear programming system. Although the CPLEX LP format is
  8. not as widely used as the MPS format, being row-oriented it is more
  9. convenient for coding mathematical programming models by human. This
  10. appendix describes only the features of the CPLEX LP format which are
  11. implemented in the GLPK package.} is intended for coding LP/MIP problem
  12. data. It is a row-oriented format that assumes the formulation of
  13. LP/MIP problem (1.1)---(1.3) (see Section \ref{seclp}, page
  14. \pageref{seclp}).
  15. CPLEX LP file is a plain text file written in CPLEX LP format. Each
  16. text line of this file may contain up to 255 characters\footnote{GLPK
  17. allows text lines of arbitrary length.}. Blank lines are ignored.
  18. If a line contains the backslash character ($\backslash$), this
  19. character and everything that follows it until the end of line are
  20. considered as a comment and also ignored.
  21. An LP file is coded by the user using the following elements: keywords,
  22. symbolic names, numeric constants, delimiters, and blanks.
  23. {\it Keywords} which may be used in the LP file are the following:
  24. \begin{verbatim}
  25. minimize minimum min
  26. maximize maximum max
  27. subject to such that s.t. st. st
  28. bounds bound
  29. general generals gen
  30. integer integers int
  31. binary binaries bin
  32. infinity inf
  33. free
  34. end
  35. \end{verbatim}
  36. \noindent
  37. All the keywords are case insensitive. Keywords given above on the same
  38. line are equivalent. Any keyword (except \verb|infinity|, \verb|inf|,
  39. and \verb|free|) being used in the LP file must start at the beginning
  40. of a text line.
  41. \newpage
  42. {\it Symbolic names} are used to identify the objective function,
  43. constraints (rows), and variables (columns). All symbolic names are case
  44. sensitive and may contain up to 16 alphanumeric characters\footnote{GLPK
  45. allows symbolic names having up to 255 characters.} (\verb|a|, \dots,
  46. \verb|z|, \verb|A|, \dots, \verb|Z|, \verb|0|, \dots, \verb|9|) as well
  47. as the following characters:
  48. \begin{verbatim}
  49. ! " # $ % & ( ) / , . ; ? @ _ ` ' { } | ~
  50. \end{verbatim}
  51. \noindent
  52. with exception that no symbolic name can begin with a digit or
  53. a period.
  54. {\it Numeric constants} are used to denote constraint and objective
  55. coefficients, right-hand sides of constraints, and bounds of variables.
  56. They are coded in the standard form $xx$\verb|E|$syy$, where $xx$ is
  57. a real number with optional decimal point, $s$ is a sign (\verb|+| or
  58. \verb|-|), $yy$ is an integer decimal exponent. Numeric constants may
  59. contain arbitrary number of characters. The exponent part is optional.
  60. The letter `\verb|E|' can be coded as `\verb|e|'. If the sign $s$ is
  61. omitted, plus is assumed.
  62. {\it Delimiters} that may be used in the LP file are the following:
  63. \begin{verbatim}
  64. :
  65. +
  66. -
  67. < <= =<
  68. > >= =>
  69. =
  70. \end{verbatim}
  71. \noindent
  72. Delimiters given above on the same line are equivalent. The meaning of
  73. the delimiters will be explained below.
  74. {\it Blanks} are non-significant characters. They may be used freely to
  75. improve readability of the LP file. Besides, blanks should be used to
  76. separate elements from each other if there is no other way to do that
  77. (for example, to separate a keyword from a following symbolic name).
  78. The order of an LP file is the following:
  79. %\vspace*{-8pt}
  80. %\begin{itemize}
  81. \Item{---}objective function definition;
  82. \Item{---}constraints section;
  83. \Item{---}bounds section;
  84. \Item{---}general, integer, and binary sections (can appear in
  85. arbitrary order);
  86. \Item{---}end keyword.
  87. %\end{itemize}
  88. %\vspace*{-8pt}
  89. These components are discussed in following sections.
  90. \section{Objective function definition}
  91. The objective function definition must appear first in the LP file.
  92. It defines the objective function and specifies the optimization
  93. direction.
  94. The objective function definition has the following form:
  95. $$
  96. \left\{
  97. \begin{array}{@{}c@{}}
  98. {\tt minimize} \\ {\tt maximize}
  99. \end{array}
  100. \right\}\ f\ {\tt :}\ s\ c\ x\ \dots\ s\ c\ x
  101. $$
  102. where $f$ is a symbolic name of the objective function, $s$ is a sign
  103. \verb|+| or \verb|-|, $c$ is a numeric constant that denotes an
  104. objective coefficient, $x$ is a symbolic name of a variable.
  105. If necessary, the objective function definition can be continued on as
  106. many text lines as desired.
  107. The name of the objective function is optional and may be omitted
  108. (together with the semicolon that follows it). In this case the default
  109. name `\verb|obj|' is assigned to the objective function.
  110. If the very first sign $s$ is omitted, the sign plus is assumed. Other
  111. signs cannot be omitted.
  112. If some objective coefficient $c$ is omitted, 1 is assumed.
  113. Symbolic names $x$ used to denote variables are recognized by context
  114. and therefore needn't to be declared somewhere else.
  115. Here is an example of the objective function definition:
  116. \begin{verbatim}
  117. Minimize Z : - x1 + 2 x2 - 3.5 x3 + 4.997e3x(4) + x5 + x6 +
  118. x7 - .01x8
  119. \end{verbatim}
  120. \section{Constraints section}
  121. The constraints section must follow the objective function definition.
  122. It defines a system of equality and/or inequality constraints.
  123. The constraint section has the following form:
  124. \begin{center}
  125. \begin{tabular}{l}
  126. \verb|subject to| \\
  127. {\it constraint}$_1$ \\
  128. \hspace{20pt}\dots \\
  129. {\it constraint}$_m$ \\
  130. \end{tabular}
  131. \end{center}
  132. \noindent where {\it constraint}$_i, i=1,\dots,m,$ is a particular
  133. constraint definition.
  134. Each constraint definition can be continued on as many text lines as
  135. desired. However, each constraint definition must begin on a new line
  136. except the very first constraint definition which can begin on the same
  137. line as the keyword `\verb|subject to|'.
  138. Constraint definitions have the following form:
  139. $$
  140. r\ {\tt:}\ s\ c\ x\ \dots\ s\ c\ x
  141. \ \left\{
  142. \begin{array}{@{}c@{}}
  143. \mbox{\tt<=} \\ \mbox{\tt>=} \\ \mbox{\tt=}
  144. \end{array}
  145. \right\}\ b
  146. $$
  147. where $r$ is a symbolic name of a constraint, $s$ is a sign \verb|+| or
  148. \verb|-|, $c$ is a numeric constant that denotes a constraint
  149. coefficient, $x$ is a symbolic name of a variable, $b$ is a right-hand
  150. side.
  151. The name $r$ of a constraint (which is the name of the corresponding
  152. auxiliary variable) is optional and may be omitted together with the
  153. semicolon that follows it. In the latter case the default names like
  154. `\verb|r.nnn|' are assigned to unnamed constraints.
  155. The linear form $s\ c\ x\ \dots\ s\ c\ x$ in the left-hand side of
  156. a constraint definition has exactly the same meaning as in the case of
  157. the objective function definition (see above).
  158. After the linear form one of the following delimiters that indicates
  159. the constraint sense must be specified:
  160. \verb|<=| \ means `less than or equal to'
  161. \verb|>=| \ means `greater than or equal to'
  162. \verb|= | \ means `equal to'
  163. The right hand side $b$ is a numeric constant with an optional sign.
  164. Here is an example of the constraints section:
  165. \begin{verbatim}
  166. Subject To
  167. one: y1 + 3 a1 - a2 - b >= 1.5
  168. y2 + 2 a3 + 2
  169. a4 - b >= -1.5
  170. two : y4 + 3 a1 + 4 a5 - b <= +1
  171. .20y5 + 5 a2 - b = 0
  172. 1.7 y6 - a6 + 5 a777 - b >= 1
  173. \end{verbatim}
  174. Should note that it is impossible to express ranged constraints in the
  175. CPLEX LP format. Each a ranged constraint can be coded as two
  176. constraints with identical linear forms in the left-hand side, one of
  177. which specifies a lower bound and other does an upper one of the
  178. original ranged constraint. Another way is to introduce a slack
  179. double-bounded variable; for example, the
  180. constraint
  181. $$10\leq x+2y+3z\leq 50$$
  182. can be written as follows:
  183. $$x+2y+3z+t=50,$$
  184. where $0\leq t\leq 40$ is a slack variable.
  185. \section{Bounds section}
  186. The bounds section is intended to define bounds of variables. This
  187. section is optional; if it is specified, it must follow the constraints
  188. section. If the bound section is omitted, all variables are assumed to
  189. be non-negative (i.e. that they have zero lower bound and no upper
  190. bound).
  191. The bounds section has the following form:
  192. \begin{center}
  193. \begin{tabular}{l}
  194. \verb|bounds| \\
  195. {\it definition}$_1$ \\
  196. \hspace{20pt}\dots \\
  197. {\it definition}$_p$ \\
  198. \end{tabular}
  199. \end{center}
  200. \noindent
  201. where {\it definition}$_k, k=1,\dots,p,$ is a particular bound
  202. definition.
  203. Each bound definition must begin on a new line\footnote{The GLPK
  204. implementation allows several bound definitions to be placed on the
  205. same line.} except the very first bound definition which can begin on
  206. the same line as the keyword `\verb|bounds|'.
  207. %\newpage
  208. Syntactically constraint definitions can have one of the following six
  209. forms:
  210. \begin{center}
  211. \begin{tabular}{ll}
  212. $x$ \verb|>=| $l$ & specifies a lower bound \\
  213. $l$ \verb|<=| $x$ & specifies a lower bound \\
  214. $x$ \verb|<=| $u$ & specifies an upper bound \\
  215. $l$ \verb|<=| $x$ \verb|<=| $u$ &specifies both lower and upper bounds\\
  216. $x$ \verb|=| $t$ &specifies a fixed value \\
  217. $x$ \verb|free| &specifies free variable
  218. \end{tabular}
  219. \end{center}
  220. \noindent
  221. where $x$ is a symbolic name of a variable, $l$ is a numeric constant
  222. with an optional sign that defines a lower bound of the variable or
  223. \verb|-inf| that means that the variable has no lower bound, $u$ is
  224. a~numeric constant with an optional sign that defines an upper bound of
  225. the variable or \verb|+inf| that means that the variable has no upper
  226. bound, $t$ is a numeric constant with an optional sign that defines a
  227. fixed value of the variable.
  228. By default all variables are non-negative, i.e. have zero lower bound
  229. and no upper bound. Therefore definitions of these default bounds can
  230. be omitted in the bounds section.
  231. Here is an example of the bounds section:
  232. \begin{verbatim}
  233. Bounds
  234. -inf <= a1 <= 100
  235. -100 <= a2
  236. b <= 100
  237. x2 = +123.456
  238. x3 free
  239. \end{verbatim}
  240. \section{General, integer, and binary sections}
  241. The general, integer, and binary sections are intended to define
  242. some variables as integer or binary. All these sections are optional
  243. and needed only in case of MIP problems. If they are specified, they
  244. must follow the bounds section or, if the latter is omitted, the
  245. constraints section.
  246. All the general, integer, and binary sections have the same form as
  247. follows:
  248. \begin{center}
  249. \begin{tabular}{l}
  250. $
  251. \left\{
  252. \begin{array}{@{}l@{}}
  253. \verb|general| \\
  254. \verb|integer| \\
  255. \verb|binary | \\
  256. \end{array}
  257. \right\}
  258. $ \\
  259. \hspace{10pt}$x_1$ \\
  260. \hspace{10pt}\dots \\
  261. \hspace{10pt}$x_q$ \\
  262. \end{tabular}
  263. \end{center}
  264. \noindent
  265. where $x_k$ is a symbolic name of variable, $k=1,\dots,q$.
  266. Each symbolic name must begin on a new line\footnote{The GLPK
  267. implementation allows several symbolic names to be placed on the same
  268. line.} except the very first symbolic name which can begin on the same
  269. line as the keyword `\verb|general|', `\verb|integer|', or
  270. `\verb|binary|'.
  271. %\newpage
  272. If a variable appears in the general or the integer section, it is
  273. assumed to be general integer variable. If a variable appears in the
  274. binary section, it is assumed to be binary variable, i.e. an integer
  275. variable whose lower bound is zero and upper bound is one. (Note that
  276. if bounds of a variable are specified in the bounds section and then
  277. the variable appears in the binary section, its previously specified
  278. bounds are ignored.)
  279. Here is an example of the integer section:
  280. \begin{verbatim}
  281. Integer
  282. z12
  283. z22
  284. z35
  285. \end{verbatim}
  286. \newpage
  287. \section{End keyword}
  288. The keyword `\verb|end|' is intended to end the LP file. It must begin
  289. on a separate line and no other elements (except comments and blank
  290. lines) must follow it. Although this keyword is optional, it is strongly
  291. recommended to include it in the LP file.
  292. \section{Example of CPLEX LP file}
  293. Here is a complete example of CPLEX LP file that corresponds to the
  294. example given in Section \ref{secmpsex}, page \pageref{secmpsex}.
  295. \medskip
  296. \begin{footnotesize}
  297. \begin{verbatim}
  298. \* plan.lp *\
  299. Minimize
  300. value: .03 bin1 + .08 bin2 + .17 bin3 + .12 bin4 + .15 bin5 +
  301. .21 alum + .38 silicon
  302. Subject To
  303. yield: bin1 + bin2 + bin3 + bin4 + bin5 +
  304. alum + silicon = 2000
  305. fe: .15 bin1 + .04 bin2 + .02 bin3 + .04 bin4 + .02 bin5 +
  306. .01 alum + .03 silicon <= 60
  307. cu: .03 bin1 + .05 bin2 + .08 bin3 + .02 bin4 + .06 bin5 +
  308. .01 alum <= 100
  309. mn: .02 bin1 + .04 bin2 + .01 bin3 + .02 bin4 + .02 bin5 <= 40
  310. mg: .02 bin1 + .03 bin2 + .01 bin5 <= 30
  311. al: .70 bin1 + .75 bin2 + .80 bin3 + .75 bin4 + .80 bin5 +
  312. .97 alum >= 1500
  313. si1: .02 bin1 + .06 bin2 + .08 bin3 + .12 bin4 + .02 bin5 +
  314. .01 alum + .97 silicon >= 250
  315. si2: .02 bin1 + .06 bin2 + .08 bin3 + .12 bin4 + .02 bin5 +
  316. .01 alum + .97 silicon <= 300
  317. Bounds
  318. bin1 <= 200
  319. bin2 <= 2500
  320. 400 <= bin3 <= 800
  321. 100 <= bin4 <= 700
  322. bin5 <= 1500
  323. End
  324. \* eof *\
  325. \end{verbatim}
  326. \end{footnotesize}
  327. %* eof *%