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.

424 lines
13 KiB

  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:
  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 arbitrary
  85. 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\ 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. {\it constraint}$_2$ \\
  129. \hspace{20pt}\dots \\
  130. {\it constraint}$_m$ \\
  131. \end{tabular}
  132. \end{center}
  133. \noindent where {\it constraint}$_i, i=1,\dots,m,$ is a particular
  134. constraint definition.
  135. Each constraint definition can be continued on as many text lines as
  136. desired. However, each constraint definition must begin on a new line
  137. except the very first constraint definition which can begin on the same
  138. line as the keyword `\verb|subject to|'.
  139. Constraint definitions have the following form:
  140. $$
  141. r\ {\tt:}\ s\ c\ x\ s\ c\ x\ \dots\ s\ c\ x
  142. \ \left\{
  143. \begin{array}{@{}c@{}}
  144. \mbox{\tt<=} \\ \mbox{\tt>=} \\ \mbox{\tt=}
  145. \end{array}
  146. \right\}\ b
  147. $$
  148. where $r$ is a symbolic name of a constraint, $s$ is a sign \verb|+| or
  149. \verb|-|, $c$ is a numeric constant that denotes a constraint
  150. coefficient, $x$ is a symbolic name of a variable, $b$ is a right-hand
  151. side.
  152. The name $r$ of a constraint (which is the name of the corresponding
  153. auxiliary variable) is optional and may be omitted (together with the
  154. semicolon that follows it). In this case the default names like
  155. `\verb|r.nnn|' are assigned to unnamed constraints.
  156. The linear form $s\ c\ x\ s\ c\ x\ \dots\ s\ c\ x$ in the left-hand
  157. side of a constraint definition has exactly the same meaning as in the
  158. case of the objective function definition (see above).
  159. After the linear form one of the following delimiters that indicates
  160. the constraint sense must be specified:
  161. \verb|<=| \ means `less than or equal to'
  162. \verb|>=| \ means `greater than or equal to'
  163. \verb|= | \ means `equal to'
  164. The right hand side $b$ is a numeric constant with an optional sign.
  165. Here is an example of the constraints section:
  166. \begin{verbatim}
  167. Subject To
  168. one: y1 + 3 a1 - a2 - b >= 1.5
  169. y2 + 2 a3 + 2
  170. a4 - b >= -1.5
  171. two : y4 + 3 a1 + 4 a5 - b <= +1
  172. .20y5 + 5 a2 - b = 0
  173. 1.7 y6 - a6 + 5 a777 - b >= 1
  174. \end{verbatim}
  175. Should note that it is impossible to express ranged constraints in the
  176. CPLEX LP format. Each a ranged constraint can be coded as two
  177. constraints with identical linear forms in the left-hand side, one of
  178. which specifies a lower bound and other does an upper one of the
  179. original ranged constraint. Another way is to introduce a slack
  180. double-bounded variable; for example, the
  181. constraint
  182. $$10\leq x+2y+3z\leq 50$$
  183. can be written as follows:
  184. $$x+2y+3z+t=50,$$
  185. where $0\leq t\leq 40$ is a slack variable.
  186. \section{Bounds section}
  187. The bounds section is intended to define bounds of variables. This
  188. section is optional; if it is specified, it must follow the constraints
  189. section. If the bound section is omitted, all variables are assumed to
  190. be non-negative (i.e. that they have zero lower bound and no upper
  191. bound).
  192. The bounds section has the following form:
  193. \begin{center}
  194. \begin{tabular}{l}
  195. \verb|bounds| \\
  196. {\it definition}$_1$ \\
  197. {\it definition}$_2$ \\
  198. \hspace{20pt}\dots \\
  199. {\it definition}$_p$ \\
  200. \end{tabular}
  201. \end{center}
  202. \noindent
  203. where {\it definition}$_k, k=1,\dots,p,$ is a particular bound
  204. definition.
  205. Each bound definition must begin on a new line\footnote{The GLPK
  206. implementation allows several bound definitions to be placed on the
  207. same line.} except the very first bound definition which can begin on
  208. the same line as the keyword `\verb|bounds|'.
  209. \newpage
  210. Syntactically constraint definitions can have one of the following six
  211. forms:
  212. \begin{center}
  213. \begin{tabular}{ll}
  214. $x$ \verb|>=| $l$ & specifies a lower bound \\
  215. $l$ \verb|<=| $x$ & specifies a lower bound \\
  216. $x$ \verb|<=| $u$ & specifies an upper bound \\
  217. $l$ \verb|<=| $x$ \verb|<=| $u$ &specifies both lower and upper bounds\\
  218. $x$ \verb|=| $t$ &specifies a fixed value \\
  219. $x$ \verb|free| &specifies free variable
  220. \end{tabular}
  221. \end{center}
  222. \noindent
  223. where $x$ is a symbolic name of a variable, $l$ is a numeric constant
  224. with an optional sign that defines a lower bound of the variable or
  225. \verb|-inf| that means that the variable has no lower bound, $u$ is a
  226. numeric constant with an optional sign that defines an upper bound of
  227. the variable or \verb|+inf| that means that the variable has no upper
  228. bound, $t$ is a numeric constant with an optional sign that defines a
  229. fixed value of the variable.
  230. By default all variables are non-negative, i.e. have zero lower bound
  231. and no upper bound. Therefore definitions of these default bounds can
  232. be omitted in the bounds section.
  233. Here is an example of the bounds section:
  234. \begin{verbatim}
  235. Bounds
  236. -inf <= a1 <= 100
  237. -100 <= a2
  238. b <= 100
  239. x2 = +123.456
  240. x3 free
  241. \end{verbatim}
  242. \section{General, integer, and binary sections}
  243. The general, integer, and binary sections are intended to define
  244. some variables as integer or binary. All these sections are optional
  245. and needed only in case of MIP problems. If they are specified, they
  246. must follow the bounds section or, if the latter is omitted, the
  247. constraints section.
  248. All the general, integer, and binary sections have the same form as
  249. follows:
  250. \begin{center}
  251. \begin{tabular}{l}
  252. $
  253. \left\{
  254. \begin{array}{@{}l@{}}
  255. \verb|general| \\
  256. \verb|integer| \\
  257. \verb|binary | \\
  258. \end{array}
  259. \right\}
  260. $ \\
  261. \hspace{10pt}$x_1$ \\
  262. \hspace{10pt}$x_2$ \\
  263. \hspace{10pt}\dots \\
  264. \hspace{10pt}$x_q$ \\
  265. \end{tabular}
  266. \end{center}
  267. \noindent
  268. where $x_k$ is a symbolic name of variable, $k=1,\dots,q$.
  269. Each symbolic name must begin on a new line\footnote{The GLPK
  270. implementation allows several symbolic names to be placed on the same
  271. line.} except the very first symbolic name which can begin on the same
  272. line as the keyword `\verb|general|', `\verb|integer|', or
  273. `\verb|binary|'.
  274. \newpage
  275. If a variable appears in the general or the integer section, it is
  276. assumed to be general integer variable. If a variable appears in the
  277. binary section, it is assumed to be binary variable, i.e. an integer
  278. variable whose lower bound is zero and upper bound is one. (Note that
  279. if bounds of a variable are specified in the bounds section and then
  280. the variable appears in the binary section, its previously specified
  281. bounds are ignored.)
  282. Here is an example of the integer section:
  283. \begin{verbatim}
  284. Integer
  285. z12
  286. z22
  287. z35
  288. \end{verbatim}
  289. \section{End keyword}
  290. The keyword `\verb|end|' is intended to end the LP file. It must begin
  291. on a separate line and no other elements (except comments and blank
  292. lines) must follow it. Although this keyword is optional, it is strongly
  293. recommended to include it in the LP file.
  294. \section{Example of CPLEX LP file}
  295. Here is a complete example of CPLEX LP file that corresponds to the
  296. example given in Section \ref{secmpsex}, page \pageref{secmpsex}.
  297. \medskip
  298. \begin{footnotesize}
  299. \begin{verbatim}
  300. \* plan.lp *\
  301. Minimize
  302. value: .03 bin1 + .08 bin2 + .17 bin3 + .12 bin4 + .15 bin5 +
  303. .21 alum + .38 silicon
  304. Subject To
  305. yield: bin1 + bin2 + bin3 + bin4 + bin5 +
  306. alum + silicon = 2000
  307. fe: .15 bin1 + .04 bin2 + .02 bin3 + .04 bin4 + .02 bin5 +
  308. .01 alum + .03 silicon <= 60
  309. cu: .03 bin1 + .05 bin2 + .08 bin3 + .02 bin4 + .06 bin5 +
  310. .01 alum <= 100
  311. mn: .02 bin1 + .04 bin2 + .01 bin3 + .02 bin4 + .02 bin5 <= 40
  312. mg: .02 bin1 + .03 bin2 + .01 bin5 <= 30
  313. al: .70 bin1 + .75 bin2 + .80 bin3 + .75 bin4 + .80 bin5 +
  314. .97 alum >= 1500
  315. si1: .02 bin1 + .06 bin2 + .08 bin3 + .12 bin4 + .02 bin5 +
  316. .01 alum + .97 silicon >= 250
  317. si2: .02 bin1 + .06 bin2 + .08 bin3 + .12 bin4 + .02 bin5 +
  318. .01 alum + .97 silicon <= 300
  319. Bounds
  320. bin1 <= 200
  321. bin2 <= 2500
  322. 400 <= bin3 <= 800
  323. 100 <= bin4 <= 700
  324. bin5 <= 1500
  325. End
  326. \* eof *\
  327. \end{verbatim}
  328. \end{footnotesize}
  329. %* eof *%