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.

1936 lines
66 KiB

  1. %* glpk03.tex *%
  2. \chapter{Utility API routines}
  3. \section{Problem data reading/writing routines}
  4. \subsection{glp\_read\_mps --- read problem data in MPS format}
  5. \synopsis
  6. \begin{verbatim}
  7. int glp_read_mps(glp_prob *P, int fmt, const glp_mpscp *parm,
  8. const char *fname);
  9. \end{verbatim}
  10. \description
  11. The routine \verb|glp_read_mps| reads problem data in MPS format from a
  12. text file. (The MPS format is described in Appendix \ref{champs}, page
  13. \pageref{champs}.)
  14. The parameter \verb|fmt| specifies the MPS format version as follows:
  15. \verb|GLP_MPS_DECK| --- fixed (ancient) MPS format;
  16. \verb|GLP_MPS_FILE| --- free (modern) MPS format.
  17. The parameter \verb|parm| is reserved for use in the future and should
  18. be specified as \verb|NULL|.
  19. The character string \verb|fname| specifies a name of the text file to
  20. be read in. (If the file name ends with suffix `\verb|.gz|', the file
  21. is assumed to be compressed, in which case the routine
  22. \verb|glp_read_mps| decompresses it ``on the fly''.)
  23. Note that before reading data the current content of the problem object
  24. is completely erased with the routine \verb|glp_erase_prob|.
  25. \returns
  26. If the operation was successful, the routine \verb|glp_read_mps|
  27. returns zero. Otherwise, it prints an error message and returns
  28. non-zero.
  29. \newpage
  30. \subsection{glp\_write\_mps --- write problem data in MPS format}
  31. \synopsis
  32. \begin{verbatim}
  33. int glp_write_mps(glp_prob *P, int fmt, const glp_mpscp *parm,
  34. const char *fname);
  35. \end{verbatim}
  36. \description
  37. The routine \verb|glp_write_mps| writes problem data in MPS format to
  38. a text file. (The MPS format is described in Appendix \ref{champs},
  39. page \pageref{champs}.)
  40. The parameter \verb|fmt| specifies the MPS format version as follows:
  41. \verb|GLP_MPS_DECK| --- fixed (ancient) MPS format;
  42. \verb|GLP_MPS_FILE| --- free (modern) MPS format.
  43. The parameter \verb|parm| is reserved for use in the future and should
  44. be specified as \verb|NULL|.
  45. The character string \verb|fname| specifies a name of the text file to
  46. be written out. (If the file name ends with suffix `\verb|.gz|', the
  47. file is assumed to be compressed, in which case the routine
  48. \verb|glp_write_mps| performs automatic compression on writing it.)
  49. \returns
  50. If the operation was successful, the routine \verb|glp_write_mps|
  51. returns zero. Otherwise, it prints an error message and returns
  52. non-zero.
  53. \subsection{glp\_read\_lp --- read problem data in CPLEX LP format}
  54. \synopsis
  55. {\tt int glp\_read\_lp(glp\_prob *P, const glp\_cpxcp *parm,
  56. const char *fname);}
  57. \description
  58. The routine \verb|glp_read_lp| reads problem data in CPLEX LP format
  59. from a text file. (The CPLEX LP format is described in Appendix
  60. \ref{chacplex}, page \pageref{chacplex}.)
  61. The parameter \verb|parm| is reserved for use in the future and should
  62. be specified as \verb|NULL|.
  63. The character string \verb|fname| specifies a name of the text file to
  64. be read in. (If the file name ends with suffix `\verb|.gz|', the file
  65. is assumed to be compressed, in which case the routine
  66. \verb|glp_read_lp| decompresses it ``on the fly''.)
  67. Note that before reading data the current content of the problem object
  68. is completely erased with the routine \verb|glp_erase_prob|.
  69. \returns
  70. If the operation was successful, the routine \verb|glp_read_lp| returns
  71. zero. Otherwise, it prints an error message and returns non-zero.
  72. \newpage
  73. \subsection{glp\_write\_lp --- write problem data in CPLEX LP format}
  74. \synopsis
  75. {\tt int glp\_write\_lp(glp\_prob *P, const glp\_cpxcp *parm,
  76. const char *fname);}
  77. \description
  78. The routine \verb|glp_write_lp| writes problem data in CPLEX LP format
  79. to a text file. (The CPLEX LP format is described in Appendix
  80. \ref{chacplex}, page \pageref{chacplex}.)
  81. The parameter \verb|parm| is reserved for use in the future and should
  82. be specified as \verb|NULL|.
  83. The character string \verb|fname| specifies a name of the text file to
  84. be written out. (If the file name ends with suffix `\verb|.gz|', the
  85. file is assumed to be compressed, in which case the routine
  86. \verb|glp_write_lp| performs automatic compression on writing it.)
  87. \returns
  88. If the operation was successful, the routine \verb|glp_write_lp|
  89. returns zero. Otherwise, it prints an error message and returns
  90. non-zero.
  91. \subsection{glp\_read\_prob --- read problem data in GLPK format}
  92. \synopsis
  93. \begin{verbatim}
  94. int glp_read_prob(glp_prob *P, int flags, const char *fname);
  95. \end{verbatim}
  96. \description
  97. The routine \verb|glp_read_prob| reads problem data in the GLPK LP/MIP
  98. format from a text file. (For description of the GLPK LP/MIP format see
  99. below.)
  100. The parameter \verb|flags| is reserved for use in the future and should
  101. be specified as zero.
  102. The character string \verb|fname| specifies a name of the text file to
  103. be read in. (If the file name ends with suffix `\verb|.gz|', the file
  104. is assumed to be compressed, in which case the routine
  105. \verb|glp_read_prob| decompresses it ``on the fly''.)
  106. Note that before reading data the current content of the problem object
  107. is completely erased with the routine \verb|glp_erase_prob|.
  108. \returns
  109. If the operation was successful, the routine \verb|glp_read_prob|
  110. returns zero. Otherwise, it prints an error message and returns
  111. non-zero.
  112. %\newpage
  113. \para{GLPK LP/MIP format}
  114. The GLPK LP/MIP format is a DIMACS-like format.\footnote{The DIMACS
  115. formats were developed by the Center for Discrete Mathematics and
  116. Theoretical Computer Science (DIMACS) to facilitate exchange of problem
  117. data. For details see: {\tt <http://dimacs.rutgers.edu/Challenges/>}. }
  118. The file in this format is a plain ASCII text file containing lines of
  119. several types described below. A line is terminated with the
  120. end-of-line character. Fields in each line are separated by at least
  121. one blank space. Each line begins with a one-character designator to
  122. identify the line type.
  123. \newpage
  124. The first line of the data file must be the problem line (except
  125. optional comment lines, which may precede the problem line). The last
  126. line of the data file must be the end line. Other lines may follow in
  127. arbitrary order, however, duplicate lines are not allowed.
  128. \para{Comment lines.} Comment lines give human-readable
  129. information about the data file and are ignored by GLPK routines.
  130. Comment lines can appear anywhere in the data file. Each comment line
  131. begins with the lower-case character \verb|c|.
  132. \begin{verbatim}
  133. c This is an example of comment line
  134. \end{verbatim}
  135. \para{Problem line.} There must be exactly one problem line in the
  136. data file. This line must appear before any other lines except comment
  137. lines and has the following format:
  138. \begin{verbatim}
  139. p CLASS DIR ROWS COLS NONZ
  140. \end{verbatim}
  141. The lower-case letter \verb|p| specifies that this is the problem line.
  142. The \verb|CLASS| field defines the problem class and can contain either
  143. the keyword \verb|lp| (that means linear programming problem) or
  144. \verb|mip| (that means mixed integer programming problem).
  145. The \verb|DIR| field defines the optimization direction (that is, the
  146. objective function sense) and can contain either the keyword \verb|min|
  147. (that means minimization) or \verb|max| (that means maximization).
  148. The \verb|ROWS|, \verb|COLS|, and \verb|NONZ| fields contain
  149. non-negative integer values specifying, respectively, the number of
  150. rows (constraints), columns (variables), and non-zero constraint
  151. coefficients in the problem instance. Note that \verb|NONZ| value does
  152. not account objective coefficients.
  153. \para{Row descriptors.} There must be at most one row descriptor line
  154. in the data file for each row (constraint). This line has one of the
  155. following formats:
  156. \begin{verbatim}
  157. i ROW f
  158. i ROW l RHS
  159. i ROW u RHS
  160. i ROW d RHS1 RHS2
  161. i ROW s RHS
  162. \end{verbatim}
  163. The lower-case letter \verb|i| specifies that this is the row
  164. descriptor line.
  165. The \verb|ROW| field specifies the row ordinal number, an integer
  166. between 1 and $m$, where $m$ is the number of rows in the problem
  167. instance.
  168. The next lower-case letter specifies the row type as follows:
  169. \verb|f| --- free (unbounded) row: $-\infty<\sum a_jx_j<+\infty$;
  170. \verb|l| --- inequality constraint of `$\geq$' type:
  171. $\sum a_jx_j\geq b$;
  172. \verb|u| --- inequality constraint of `$\leq$' type:
  173. $\sum a_jx_j\leq b$;
  174. \verb|d| --- double-sided inequality constraint:
  175. $b_1\leq\sum a_jx_j\leq b_2$;
  176. \verb|s| --- equality constraint: $\sum a_jx_j=b$.
  177. The \verb|RHS| field contains a floaing-point value specifying the
  178. row right-hand side. The \verb|RHS1| and \verb|RHS2| fields contain
  179. floating-point values specifying, respectively, the lower and upper
  180. right-hand sides for the double-sided row.
  181. If for some row its descriptor line does not appear in the data file,
  182. by default that row is assumed to be an equality constraint with zero
  183. right-hand side.
  184. \para{Column descriptors.} There must be at most one column descriptor
  185. line in the data file for each column (variable). This line has one of
  186. the following formats depending on the problem class specified in the
  187. problem line:
  188. \begin{tabular}{@{}l@{\hspace*{40pt}}l}
  189. LP class & MIP class \\
  190. \hline
  191. \verb|j COL f| & \verb|j COL KIND f| \\
  192. \verb|j COL l BND| & \verb|j COL KIND l BND| \\
  193. \verb|j COL u BND| & \verb|j COL KIND u BND| \\
  194. \verb|j COL d BND1 BND2| & \verb|j COL KIND d BND1 BND2| \\
  195. \verb|j COL s BND| & \verb|j COL KIND s BND| \\
  196. \end{tabular}
  197. The lower-case letter \verb|j| specifies that this is the column
  198. descriptor line.
  199. The \verb|COL| field specifies the column ordinal number, an integer
  200. between 1 and $n$, where $n$ is the number of columns in the problem
  201. instance.
  202. The \verb|KIND| field is used only for MIP problems and specifies the
  203. column kind as follows:
  204. \verb|c| --- continuous column;
  205. \verb|i| --- integer column;
  206. \verb|b| --- binary column (in this case all remaining fields must be
  207. omitted).
  208. The next lower-case letter specifies the column type as follows:
  209. \verb|f| --- free (unbounded) column: $-\infty<x<+\infty$;
  210. \verb|l| --- column with lower bound: $x\geq l$;
  211. \verb|u| --- column with upper bound: $x\leq u$;
  212. \verb|d| --- double-bounded column: $l\leq x\leq u$;
  213. \verb|s| --- fixed column: $x=s$.
  214. The \verb|BND| field contains a floating-point value that specifies the
  215. column bound. The \verb|BND1| and \verb|BND2| fields contain
  216. floating-point values specifying, respectively, the lower and upper
  217. bounds for the double-bounded column.
  218. If for some column its descriptor line does not appear in the file, by
  219. default that column is assumed to be non-negative (in case of LP class)
  220. or binary (in case of MIP class).
  221. \para{Coefficient descriptors.} There must be exactly one coefficient
  222. descriptor line in the data file for each non-zero objective or
  223. constraint coefficient. This line has the following format:
  224. \begin{verbatim}
  225. a ROW COL VAL
  226. \end{verbatim}
  227. The lower-case letter \verb|a| specifies that this is the coefficient
  228. descriptor line.
  229. For objective coefficients the \verb|ROW| field must contain 0. For
  230. constraint coefficients the \verb|ROW| field specifies the row ordinal
  231. number, an integer between 1 and $m$, where $m$ is the number of rows
  232. in the problem instance.
  233. The \verb|COL| field specifies the column ordinal number, an integer
  234. between 1 and $n$, where $n$ is the number of columns in the problem
  235. instance.
  236. If both the \verb|ROW| and \verb|COL| fields contain 0, the line
  237. specifies the constant term (``shift'') of the objective function
  238. rather than objective coefficient.
  239. The \verb|VAL| field contains a floating-point coefficient value (it is
  240. allowed to specify zero value in this field).
  241. The number of constraint coefficient descriptor lines must be exactly
  242. the same as specified in the field \verb|NONZ| of the problem line.
  243. \para{Symbolic name descriptors.} There must be at most one symbolic
  244. name descriptor line for the problem instance, objective function, each
  245. row (constraint), and each column (variable). This line has one of the
  246. following formats:
  247. \begin{verbatim}
  248. n p NAME
  249. n z NAME
  250. n i ROW NAME
  251. n j COL NAME
  252. \end{verbatim}
  253. The lower-case letter \verb|n| specifies that this is the symbolic name
  254. descriptor line.
  255. The next lower-case letter specifies which object should be assigned a
  256. symbolic name:
  257. \verb|p| --- problem instance;
  258. \verb|z| --- objective function;
  259. \verb|i| --- row (constraint);
  260. \verb|j| --- column (variable).
  261. The \verb|ROW| field specifies the row ordinal number, an integer
  262. between 1 and $m$, where $m$ is the number of rows in the problem
  263. instance.
  264. The \verb|COL| field specifies the column ordinal number, an integer
  265. between 1 and $n$, where $n$ is the number of columns in the problem
  266. instance.
  267. The \verb|NAME| field contains the symbolic name, a sequence from 1 to
  268. 255 arbitrary graphic ASCII characters, assigned to corresponding
  269. object.
  270. \para{End line.} There must be exactly one end line in the data file.
  271. This line must appear last in the file and has the following format:
  272. \begin{verbatim}
  273. e
  274. \end{verbatim}
  275. The lower-case letter \verb|e| specifies that this is the end line.
  276. Anything that follows the end line is ignored by GLPK routines.
  277. \newpage
  278. \para{Example of data file in GLPK LP/MIP format}
  279. The following example of a data file in GLPK LP/MIP format specifies
  280. the same LP problem as in Subsection ``Example of MPS file''.
  281. \bigskip
  282. \begin{center}
  283. \footnotesize\tt
  284. \begin{tabular}{l@{\hspace*{50pt}}}
  285. p lp min 8 7 48 \\
  286. n p PLAN \\
  287. n z VALUE \\
  288. i 1 f \\
  289. n i 1 VALUE \\
  290. i 2 s 2000 \\
  291. n i 2 YIELD \\
  292. i 3 u 60 \\
  293. n i 3 FE \\
  294. i 4 u 100 \\
  295. n i 4 CU \\
  296. i 5 u 40 \\
  297. n i 5 MN \\
  298. i 6 u 30 \\
  299. n i 6 MG \\
  300. i 7 l 1500 \\
  301. n i 7 AL \\
  302. i 8 d 250 300 \\
  303. n i 8 SI \\
  304. j 1 d 0 200 \\
  305. n j 1 BIN1 \\
  306. j 2 d 0 2500 \\
  307. n j 2 BIN2 \\
  308. j 3 d 400 800 \\
  309. n j 3 BIN3 \\
  310. j 4 d 100 700 \\
  311. n j 4 BIN4 \\
  312. j 5 d 0 1500 \\
  313. n j 5 BIN5 \\
  314. n j 6 ALUM \\
  315. n j 7 SILICON \\
  316. a 0 1 0.03 \\
  317. a 0 2 0.08 \\
  318. a 0 3 0.17 \\
  319. a 0 4 0.12 \\
  320. a 0 5 0.15 \\
  321. a 0 6 0.21 \\
  322. a 0 7 0.38 \\
  323. a 1 1 0.03 \\
  324. a 1 2 0.08 \\
  325. a 1 3 0.17 \\
  326. a 1 4 0.12 \\
  327. a 1 5 0.15 \\
  328. a 1 6 0.21 \\
  329. \end{tabular}
  330. \begin{tabular}{|@{\hspace*{80pt}}l}
  331. a 1 7 0.38 \\
  332. a 2 1 1 \\
  333. a 2 2 1 \\
  334. a 2 3 1 \\
  335. a 2 4 1 \\
  336. a 2 5 1 \\
  337. a 2 6 1 \\
  338. a 2 7 1 \\
  339. a 3 1 0.15 \\
  340. a 3 2 0.04 \\
  341. a 3 3 0.02 \\
  342. a 3 4 0.04 \\
  343. a 3 5 0.02 \\
  344. a 3 6 0.01 \\
  345. a 3 7 0.03 \\
  346. a 4 1 0.03 \\
  347. a 4 2 0.05 \\
  348. a 4 3 0.08 \\
  349. a 4 4 0.02 \\
  350. a 4 5 0.06 \\
  351. a 4 6 0.01 \\
  352. a 5 1 0.02 \\
  353. a 5 2 0.04 \\
  354. a 5 3 0.01 \\
  355. a 5 4 0.02 \\
  356. a 5 5 0.02 \\
  357. a 6 1 0.02 \\
  358. a 6 2 0.03 \\
  359. a 6 5 0.01 \\
  360. a 7 1 0.7 \\
  361. a 7 2 0.75 \\
  362. a 7 3 0.8 \\
  363. a 7 4 0.75 \\
  364. a 7 5 0.8 \\
  365. a 7 6 0.97 \\
  366. a 8 1 0.02 \\
  367. a 8 2 0.06 \\
  368. a 8 3 0.08 \\
  369. a 8 4 0.12 \\
  370. a 8 5 0.02 \\
  371. a 8 6 0.01 \\
  372. a 8 7 0.97 \\
  373. e o f \\
  374. \\
  375. \end{tabular}
  376. \end{center}
  377. \newpage
  378. \subsection{glp\_write\_prob --- write problem data in GLPK format}
  379. \synopsis
  380. \begin{verbatim}
  381. int glp_write_prob(glp_prob *P, int flags, const char *fname);
  382. \end{verbatim}
  383. \description
  384. The routine \verb|glp_write_prob| writes problem data in the GLPK
  385. LP/MIP format to a text file. (For description of the GLPK LP/MIP
  386. format see Subsection ``Read problem data in GLPK format''.)
  387. The parameter \verb|flags| is reserved for use in the future and should
  388. be specified as zero.
  389. The character string \verb|fname| specifies a name of the text file to
  390. be written out. (If the file name ends with suffix `\verb|.gz|', the
  391. file is assumed to be compressed, in which case the routine
  392. \verb|glp_write_prob| performs automatic compression on writing it.)
  393. \returns
  394. If the operation was successful, the routine \verb|glp_read_prob|
  395. returns zero. Otherwise, it prints an error message and returns
  396. non-zero.
  397. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  398. \newpage
  399. \section{Routines for processing MathProg models}
  400. \subsection{Introduction}
  401. GLPK supports the {\it GNU MathProg modeling language}.\footnote{The
  402. GNU MathProg modeling language is a subset of the AMPL language. For
  403. its detailed description see the document ``Modeling Language GNU
  404. MathProg: Language Reference'' included in the GLPK distribution.}
  405. As a rule, models written in MathProg are solved with the GLPK LP/MIP
  406. stand-alone solver \verb|glpsol| (see Appendix D) and do not need any
  407. programming with API routines. However, for various reasons the user
  408. may need to process MathProg models directly in his/her application
  409. program, in which case he/she may use API routines described in this
  410. section. These routines provide an interface to the {\it MathProg
  411. translator}, a component of GLPK, which translates MathProg models into
  412. an internal code and then interprets (executes) this code.
  413. The processing of a model written in GNU MathProg includes several
  414. steps, which should be performed in the following order:
  415. %\vspace*{-8pt}
  416. %\begin{enumerate}
  417. \Item{1.}{\it Allocating the workspace.}
  418. The translator allocates the workspace, an internal data structure used
  419. on all subsequent steps.
  420. \Item{2.}{\it Reading model section.} The translator reads model
  421. section and, optionally, data section from a specified text file and
  422. translates them into the internal code. If necessary, on this step data
  423. section may be ignored.
  424. \Item{3.}{\it Reading data section(s).} The translator reads one or
  425. more data sections from specified text file(s) and translates them into
  426. the internal code.
  427. \Item{4.}{\it Generating the model.} The translator executes the
  428. internal code to evaluate the content of the model objects such as sets,
  429. parameters, variables, constraints, and objectives. On this step the
  430. execution is suspended at the solve statement.
  431. \Item{5.}{\it Building the problem object.} The translator obtains all
  432. necessary information from the workspace and builds the standard
  433. problem object (that is, the program object of type \verb|glp_prob|).
  434. \Item{6.}{\it Solving the problem.} On this step the problem object
  435. built on the previous step is passed to a solver, which solves the
  436. problem instance and stores its solution back to the problem object.
  437. \Item{7.}{\it Postsolving the model.} The translator copies the
  438. solution from the problem object to the workspace and then executes the
  439. internal code from the solve statement to the end of the model.
  440. (If model has no solve statement, the translator does nothing on this
  441. step.)
  442. \Item{8.}{\it Freeing the workspace.} The translator frees all the
  443. memory allocated to the workspace.
  444. %\end{enumerate}
  445. %\vspace*{-8pt}
  446. Note that the MathProg translator performs no error correction, so if
  447. any of steps 2 to 7 fails (due to errors in the model), the application
  448. program should terminate processing and go to\linebreak step 8.
  449. \newpage
  450. \para{Example 1}
  451. In this example the program reads model and data sections from input
  452. file \verb|egypt.mod|\footnote{This is an example model included in
  453. the GLPK distribution.} and writes the model to output file
  454. \verb|egypt.mps| in free MPS format (see Appendix B). No solution is
  455. performed.
  456. \bigskip
  457. \begin{small}
  458. \begin{verbatim}
  459. /* mplsamp1.c */
  460. #include <stdio.h>
  461. #include <stdlib.h>
  462. #include <glpk.h>
  463. int main(void)
  464. { glp_prob *lp;
  465. glp_tran *tran;
  466. int ret;
  467. lp = glp_create_prob();
  468. tran = glp_mpl_alloc_wksp();
  469. ret = glp_mpl_read_model(tran, "egypt.mod", 0);
  470. if (ret != 0)
  471. { fprintf(stderr, "Error on translating model\n");
  472. goto skip;
  473. }
  474. ret = glp_mpl_generate(tran, NULL);
  475. if (ret != 0)
  476. { fprintf(stderr, "Error on generating model\n");
  477. goto skip;
  478. }
  479. glp_mpl_build_prob(tran, lp);
  480. ret = glp_write_mps(lp, GLP_MPS_FILE, NULL, "egypt.mps");
  481. if (ret != 0)
  482. fprintf(stderr, "Error on writing MPS file\n");
  483. skip: glp_mpl_free_wksp(tran);
  484. glp_delete_prob(lp);
  485. return 0;
  486. }
  487. /* eof */
  488. \end{verbatim}
  489. \end{small}
  490. \newpage
  491. \subsubsection*{Example 2}
  492. In this example the program reads model section from file
  493. \verb|sudoku.mod|\footnote{This is an example model which is included
  494. in the GLPK distribution along with alternative data file
  495. {\tt sudoku.dat}.} ignoring data section in this file, reads alternative
  496. data section from file \verb|sudoku.dat|, solves the problem instance
  497. and passes the solution found back to the model.
  498. \bigskip
  499. \begin{small}
  500. \begin{verbatim}
  501. /* mplsamp2.c */
  502. #include <stdio.h>
  503. #include <stdlib.h>
  504. #include <glpk.h>
  505. int main(void)
  506. { glp_prob *mip;
  507. glp_tran *tran;
  508. int ret;
  509. mip = glp_create_prob();
  510. tran = glp_mpl_alloc_wksp();
  511. ret = glp_mpl_read_model(tran, "sudoku.mod", 1);
  512. if (ret != 0)
  513. { fprintf(stderr, "Error on translating model\n");
  514. goto skip;
  515. }
  516. ret = glp_mpl_read_data(tran, "sudoku.dat");
  517. if (ret != 0)
  518. { fprintf(stderr, "Error on translating data\n");
  519. goto skip;
  520. }
  521. ret = glp_mpl_generate(tran, NULL);
  522. if (ret != 0)
  523. { fprintf(stderr, "Error on generating model\n");
  524. goto skip;
  525. }
  526. glp_mpl_build_prob(tran, mip);
  527. glp_simplex(mip, NULL);
  528. glp_intopt(mip, NULL);
  529. ret = glp_mpl_postsolve(tran, mip, GLP_MIP);
  530. if (ret != 0)
  531. fprintf(stderr, "Error on postsolving model\n");
  532. skip: glp_mpl_free_wksp(tran);
  533. glp_delete_prob(mip);
  534. return 0;
  535. }
  536. /* eof */
  537. \end{verbatim}
  538. \end{small}
  539. \newpage
  540. \subsection{glp\_mpl\_alloc\_wksp --- allocate the translator
  541. workspace}
  542. \synopsis
  543. \begin{verbatim}
  544. glp_tran *glp_mpl_alloc_wksp(void);
  545. \end{verbatim}
  546. \description
  547. The routine \verb|glp_mpl_alloc_wksp| allocates the MathProg translator
  548. work\-space. (Note that multiple instances of the workspace may be
  549. allocated, if necessary.)
  550. \returns
  551. The routine returns a pointer to the workspace, which should be used in
  552. all subsequent operations.
  553. \subsection{glp\_mpl\_init\_rand --- initialize pseudo-random number
  554. generator}
  555. \synopsis
  556. \begin{verbatim}
  557. void glp_mpl_init_rand(glp_tran *tran, int seed);
  558. \end{verbatim}
  559. \description
  560. The routine \verb|glp_mpl_init_rand| initializes a pseudo-random number
  561. generator used by the MathProg translator, where the parameter
  562. \verb|seed| may be any integer number.
  563. A call to the routine \verb|glp_mpl_init_rand| should immediately
  564. follow the call to the routine \verb|glp_mpl_alloc_wksp|. However,
  565. using of this routine is optional. If it is not called, the effect is
  566. the same as if it were called with \verb|seed| equal to 1.
  567. \subsection{glp\_mpl\_read\_model --- read and translate model section}
  568. \synopsis
  569. \begin{verbatim}
  570. int glp_mpl_read_model(glp_tran *tran, const char *fname, int skip);
  571. \end{verbatim}
  572. \description
  573. The routine \verb|glp_mpl_read_model| reads model section and,
  574. optionally, data section, which may follow the model section, from a
  575. text file, whose name is the character string \verb|fname|, performs
  576. translation of model statements and data blocks, and stores all the
  577. information in the workspace.
  578. The parameter \verb|skip| is a flag. If the input file contains the
  579. data section and this flag is non-zero, the data section is not read as
  580. if there were no data section and a warning message is printed. This
  581. allows reading data section(s) from other file(s).
  582. \returns
  583. If the operation is successful, the routine returns zero. Otherwise
  584. the routine prints an error message and returns non-zero.
  585. \newpage
  586. \subsection{glp\_mpl\_read\_data --- read and translate data section}
  587. \synopsis
  588. \begin{verbatim}
  589. int glp_mpl_read_data(glp_tran *tran, const char *fname);
  590. \end{verbatim}
  591. \description
  592. The routine \verb|glp_mpl_read_data| reads data section from a text
  593. file, whose name is the character string \verb|fname|, performs
  594. translation of data blocks, and stores the data read in the translator
  595. workspace. If necessary, this routine may be called more than once.
  596. \returns
  597. If the operation is successful, the routine returns zero. Otherwise
  598. the routine prints an error message and returns non-zero.
  599. \subsection{glp\_mpl\_generate --- generate the model}
  600. \synopsis
  601. \begin{verbatim}
  602. int glp_mpl_generate(glp_tran *tran, const char *fname);
  603. \end{verbatim}
  604. \description
  605. The routine \verb|glp_mpl_generate| generates the model using its
  606. description stored in the translator workspace. This operation means
  607. generating all variables, constraints, and objectives, executing check
  608. and display statements, which precede the solve statement (if it is
  609. presented).
  610. The character string \verb|fname| specifies the name of an output text
  611. file, to which output produced by display statements should be written.
  612. If \verb|fname| is \verb|NULL|, the output is sent to the terminal.
  613. \returns
  614. If the operation is successful, the routine returns zero. Otherwise
  615. the routine prints an error message and returns non-zero.
  616. \vspace*{-6pt}
  617. \subsection{glp\_mpl\_build\_prob --- build problem instance from the
  618. model}
  619. \synopsis
  620. \begin{verbatim}
  621. void glp_mpl_build_prob(glp_tran *tran, glp_prob *P);
  622. \end{verbatim}
  623. \description
  624. The routine \verb|glp_mpl_build_prob| obtains all necessary information
  625. from the translator work\-space and stores it in the specified problem
  626. object \verb|P|. Note that before building the current content of the
  627. problem object is erased with the routine \verb|glp_erase_prob|.
  628. \newpage
  629. \subsection{glp\_mpl\_postsolve --- postsolve the model}
  630. \synopsis
  631. \begin{verbatim}
  632. int glp_mpl_postsolve(glp_tran *tran, glp_prob *P, int sol);
  633. \end{verbatim}
  634. \description
  635. The routine \verb|glp_mpl_postsolve| copies the solution from the
  636. specified problem object \verb|prob| to the translator workspace and
  637. then executes all the remaining model statements, which follow the
  638. solve statement.
  639. The parameter \verb|sol| specifies which solution should be copied
  640. from the problem object to the workspace as follows:
  641. \verb|GLP_SOL| --- basic solution;
  642. \verb|GLP_IPT| --- interior-point solution;
  643. \verb|GLP_MIP| --- mixed integer solution.
  644. \returns
  645. If the operation is successful, the routine returns zero. Otherwise
  646. the routine prints an error message and returns non-zero.
  647. \subsection{glp\_mpl\_free\_wksp --- free the translator workspace}
  648. \synopsis
  649. \begin{verbatim}
  650. void glp_mpl_free_wksp(glp_tran *tran);
  651. \end{verbatim}
  652. \description
  653. The routine \verb|glp_mpl_free_wksp| frees all the memory allocated to
  654. the translator workspace. It also frees all other resources, which are
  655. still used by the translator.
  656. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  657. \newpage
  658. \section{Problem solution reading/writing routines}
  659. \subsection{glp\_print\_sol --- write basic solution in printable
  660. format}
  661. \synopsis
  662. \begin{verbatim}
  663. int glp_print_sol(glp_prob *P, const char *fname);
  664. \end{verbatim}
  665. \description
  666. The routine \verb|glp_print_sol writes| the current basic solution to
  667. an LP problem, which is specified by the pointer \verb|P|, to a text
  668. file, whose name is the character string \verb|fname|, in printable
  669. format.
  670. Information reported by the routine \verb|glp_print_sol| is intended
  671. mainly for visual analysis.
  672. \returns
  673. If no errors occurred, the routine returns zero. Otherwise the routine
  674. prints an error message and returns non-zero.
  675. \subsection{glp\_read\_sol --- read basic solution in GLPK format}
  676. \synopsis
  677. \begin{verbatim}
  678. int glp_read_sol(glp_prob *P, const char *fname);
  679. \end{verbatim}
  680. \description
  681. The routine \verb|glp_read_sol| reads basic solution from a text file
  682. in the GLPK format. (For description of the format see below.)
  683. The character string \verb|fname| specifies the name of the text file
  684. to be read in. (If the file name ends with suffix `\verb|.gz|', the
  685. file is assumed to be compressed, in which case the routine
  686. \verb|glp_read_sol| decompresses it "on the fly".)
  687. \returns
  688. If the operation was successful, the routine \verb|glp_read_sol|
  689. returns zero. Otherwise, it prints an error message and returns
  690. non-zero.
  691. \para{GLPK basic solution format}
  692. The GLPK basic solution format is a DIMACS-like format.\footnote{The
  693. DIMACS formats were developed by the Center for Discrete Mathematics
  694. and Theoretical Computer Science (DIMACS) to facilitate exchange of
  695. problem data.
  696. For details see: {\tt <http://dimacs.rutgers.edu/Challenges/>}. }
  697. The file in this format is a plain ASCII text file containing lines of
  698. several types described below. A line is terminated with the
  699. end-of-line character. Fields in each line are separated by at least
  700. one blank space. Each line begins with a one-character designator to
  701. identify the line type.
  702. The first line of the solution file must be the solution line (except
  703. optional comment lines, which may precede the problem line). The last
  704. line of the data file must be the end line. Other lines may follow in
  705. arbitrary order, however, duplicate lines are not allowed.
  706. \newpage
  707. \para{Comment lines.} Comment lines give human-readable information
  708. about the solution file and are ignored by GLPK routines. Comment lines
  709. can appear anywhere in the data file. Each comment line begins with the
  710. lower-case character \verb|c|.
  711. \begin{verbatim}
  712. c This is an example of comment line
  713. \end{verbatim}
  714. \para{Solution line.} There must be exactly one solution line in the
  715. solution file. This line must appear before any other lines except
  716. comment lines and has the following format:
  717. \begin{verbatim}
  718. s bas ROWS COLS PST DST OBJ
  719. \end{verbatim}
  720. The lower-case letter \verb|s| specifies that this is the solution
  721. line.
  722. The three-character solution designator \verb|bas| identifies the file
  723. as containing a basic solution to the LP problem instance.
  724. The \verb|ROWS| and \verb|COLS| fields contain non-negative integer
  725. values that specify the number of rows (constraints) and columns
  726. (variables), resp., in the LP problem instance.
  727. The \verb|PST| and \verb|DST| fields contain lower-case letters that
  728. specify the primal and dual solution status, resp., as follows:
  729. \verb|u| --- solution is undefined;
  730. \verb|f| --- solution is feasible;
  731. \verb|i| --- solution is infeasible;
  732. \verb|n| --- no feasible solution exists.
  733. The \verb|OBJ| field contains a floating-point number that specifies
  734. the objective function value in the basic solution.
  735. \para{Row solution descriptors.} There must be exactly one row solution
  736. descriptor line in the solution file for each row (constraint). This
  737. line has the following format:
  738. \begin{verbatim}
  739. i ROW ST PRIM DUAL
  740. \end{verbatim}
  741. The lower-case letter \verb|i| specifies that this is the row solution
  742. descriptor line.
  743. The \verb|ROW| field specifies the row ordinal number, an integer
  744. between 1 and $m$, where $m$ is the number of rows in the problem
  745. instance.
  746. The \verb|ST| field contains one of the following lower-case letters
  747. that specifies the row status in the basic solution:\footnote{The row
  748. status is the status of the associated auxiliary variable.}
  749. \verb|b| --- inactive constraint;
  750. \verb|l| --- inequality constraint active on its lower bound;
  751. \verb|u| --- inequality constraint active on its upper bound;
  752. \verb|f| --- active free (unounded) row;
  753. \verb|s| --- active equality constraint.
  754. The \verb|PRIM| field contains a floating-point number that specifies
  755. the row primal value (the value of the corresponding linear form).
  756. The \verb|DUAL| field contains a floating-point number that specifies
  757. the row dual value (the Lagrangian multiplier for active bound).
  758. \para{Column solution descriptors.} There must be exactly one column
  759. solution descriptor line in the solution file for each column
  760. (variable). This line has the following format:
  761. \begin{verbatim}
  762. j COL ST PRIM DUAL
  763. \end{verbatim}
  764. The lower-case letter \verb|j| specifies that this is the column
  765. solution descriptor line.
  766. The \verb|COL| field specifies the column ordinal number, an integer
  767. between 1 and $n$, where $n$ is the number of columns in the problem
  768. instance.
  769. The \verb|ST| field contains one of the following lower-case letters
  770. that specifies the column status in the basic solution:
  771. \verb|b| --- basic variable;
  772. \verb|l| --- non-basic variable having its lower bound active;
  773. \verb|u| --- non-basic variable having its upper bound active;
  774. \verb|f| --- non-basic free (unounded) variable;
  775. \verb|s| --- non-basic fixed variable.
  776. The \verb|PRIM| field contains a floating-point number that specifies
  777. the column primal value.
  778. The \verb|DUAL| field contains a floating-point number that specifies
  779. the column dual value (the Lagrangian multiplier for active bound).
  780. \para{End line.} There must be exactly one end line in the solution
  781. file. This line must appear last in the file and has the following
  782. format:
  783. \begin{verbatim}
  784. e
  785. \end{verbatim}
  786. The lower-case letter \verb|e| specifies that this is the end line.
  787. Anything that follows the end line is ignored by GLPK routines.
  788. \para{Example of solution file in GLPK basic solution format}
  789. The following example of a solution file in GLPK basic solution format
  790. specifies the optimal basic solution to the LP problem instance from
  791. Subsection ``Example of MPS file''.
  792. \bigskip
  793. \begin{center}
  794. \footnotesize\tt
  795. \begin{tabular}{l@{\hspace*{50pt}}}
  796. s bas 7 7 f f 296.216606498195 \\
  797. i 1 s 2000 -0.0135956678700369 \\
  798. i 2 u 60 -2.56823104693141 \\
  799. i 3 b 83.9675090252707 0 \\
  800. i 4 u 40 -0.544404332129962 \\
  801. i 5 b 19.9602888086643 0 \\
  802. i 6 l 1500 0.251985559566788 \\
  803. i 7 l 250 0.48519855595668 \\
  804. \end{tabular}
  805. \begin{tabular}{|@{\hspace*{50pt}}l}
  806. j 1 l 0 0.253624548736462 \\
  807. j 2 b 665.342960288809 0 \\
  808. j 3 b 490.252707581226 0 \\
  809. j 4 b 424.187725631769 0 \\
  810. j 5 l 0 0.0145559566787004 \\
  811. j 6 b 299.638989169676 0 \\
  812. j 7 b 120.57761732852 0 \\
  813. e o f \\
  814. \end{tabular}
  815. \end{center}
  816. \newpage
  817. \subsection{glp\_write\_sol --- write basic solution in GLPK format}
  818. \synopsis
  819. \begin{verbatim}
  820. int glp_write_sol(glp_prob *P, const char *fname);
  821. \end{verbatim}
  822. \description
  823. The routine \verb|glp_write_sol| writes the current basic solution to
  824. a text file in the GLPK format. (For description of the GLPK basic
  825. solution format see Subsection ``Read basic solution in GLPK format.'')
  826. The character string \verb|fname| specifies the name of the text file
  827. to be written. (If the file name ends with suffix `\verb|.gz|', the
  828. routine \verb|glp_write_sol| compresses it "on the fly".)
  829. \returns
  830. If the operation was successful, the routine \verb|glp_write_sol|
  831. returns zero. Otherwise, it prints an error message and returns
  832. non-zero.
  833. \subsection{glp\_print\_ipt --- write interior-point solution in
  834. printable format}
  835. \synopsis
  836. \begin{verbatim}
  837. int glp_print_ipt(glp_prob *P, const char *fname);
  838. \end{verbatim}
  839. \description
  840. The routine \verb|glp_print_ipt| writes the current interior point
  841. solution to an LP problem, which the parameter \verb|P| points to, to
  842. a text file, whose name is the character string \verb|fname|, in
  843. printable format.
  844. Information reported by the routine \verb|glp_print_ipt| is intended
  845. mainly for visual analysis.
  846. \returns
  847. If no errors occurred, the routine returns zero. Otherwise the routine
  848. prints an error message and returns non-zero.
  849. \subsection{glp\_read\_ipt --- read interior-point solution in GLPK
  850. format}
  851. \synopsis
  852. \begin{verbatim}
  853. int glp_read_ipt(glp_prob *P, const char *fname);
  854. \end{verbatim}
  855. \description
  856. The routine \verb|glp_read_ipt| reads interior-point solution from
  857. a text file in the GLPK format. (For description of the format see
  858. below.)
  859. The character string \verb|fname| specifies the name of the text file
  860. to be read in. (If the file name ends with suffix `\verb|.gz|', the
  861. file is assumed to be compressed, in which case the routine
  862. \verb|glp_read_ipt| decompresses it "on the fly".)
  863. %\newpage
  864. \returns
  865. If the operation was successful, the routine \verb|glp_read_ipt|
  866. returns zero. Otherwise, it prints an error message and returns
  867. non-zero.
  868. \para{GLPK interior-point solution format}
  869. The GLPK interior-point solution format is a DIMACS-like
  870. format.\footnote{The DIMACS formats were developed by the Center for
  871. Discrete Mathematics and Theoretical Computer Science (DIMACS) to
  872. facilitate exchange of problem data. For details see:
  873. {\tt <http://dimacs.rutgers.edu/Challenges/>}. }
  874. The file in this format is a plain ASCII text file containing lines of
  875. several types described below. A line is terminated with the
  876. end-of-line character. Fields in each line are separated by at least
  877. one blank space. Each line begins with a one-character designator to
  878. identify the line type.
  879. The first line of the solution file must be the solution line (except
  880. optional comment lines, which may precede the problem line). The last
  881. line of the data file must be the end line. Other lines may follow in
  882. arbitrary order, however, duplicate lines are not allowed.
  883. \para{Comment lines.} Comment lines give human-readable information
  884. about the solution file and are ignored by GLPK routines. Comment lines
  885. can appear anywhere in the data file. Each comment line begins with the
  886. lower-case character \verb|c|.
  887. \begin{verbatim}
  888. c This is an example of comment line
  889. \end{verbatim}
  890. \para{Solution line.} There must be exactly one solution line in the
  891. solution file. This line must appear before any other lines except
  892. comment lines and has the following format:
  893. \begin{verbatim}
  894. s ipt ROWS COLS SST OBJ
  895. \end{verbatim}
  896. The lower-case letter \verb|s| specifies that this is the solution
  897. line.
  898. The three-character solution designator \verb|ipt| identifies the file
  899. as containing an interior-point solution to the LP problem instance.
  900. The \verb|ROWS| and \verb|COLS| fields contain non-negative integer
  901. values that specify the number of rows (constraints) and columns
  902. (variables), resp., in the LP problem instance.
  903. The \verb|SST| field contains one of the following lower-case letters
  904. that specifies the solution status:
  905. \verb|o| --- solution is optimal;
  906. \verb|i| --- solution is infeasible;
  907. \verb|n| --- no feasible solution exists;
  908. \verb|u| --- solution is undefined.
  909. The \verb|OBJ| field contains a floating-point number that specifies
  910. the objective function value in the interior-point solution.
  911. \para{Row solution descriptors.} There must be exactly one row solution
  912. descriptor line in the solution file for each row (constraint). This
  913. line has the following format:
  914. \begin{verbatim}
  915. i ROW PRIM DUAL
  916. \end{verbatim}
  917. The lower-case letter \verb|i| specifies that this is the row solution
  918. descriptor line.
  919. %\newpage
  920. The \verb|ROW| field specifies the row ordinal number, an integer
  921. between 1 and $m$, where $m$ is the number of rows in the problem
  922. instance.
  923. The \verb|PRIM| field contains a floating-point number that specifies
  924. the row primal value (the value of the corresponding linear form).
  925. The \verb|DUAL| field contains a floating-point number that specifies
  926. the row dual value (the Lagrangian multiplier for active bound).
  927. \para{Column solution descriptors.} There must be exactly one column
  928. solution descriptor line in the solution file for each column
  929. (variable). This line has the following format:
  930. \begin{verbatim}
  931. j COL PRIM DUAL
  932. \end{verbatim}
  933. The lower-case letter \verb|j| specifies that this is the column
  934. solution descriptor line.
  935. The \verb|COL| field specifies the column ordinal number, an integer
  936. between 1 and $n$, where $n$ is the number of columns in the problem
  937. instance.
  938. The \verb|PRIM| field contains a floating-point number that specifies
  939. the column primal value.
  940. The \verb|DUAL| field contains a floating-point number that specifies
  941. the column dual value (the Lagrangian multiplier for active bound).
  942. \para{End line.} There must be exactly one end line in the solution
  943. file. This line must appear last in the file and has the following
  944. format:
  945. \begin{verbatim}
  946. e
  947. \end{verbatim}
  948. The lower-case letter \verb|e| specifies that this is the end line.
  949. Anything that follows the end line is ignored by GLPK routines.
  950. \para{Example of solution file in GLPK interior-point solution format}
  951. The following example of a solution file in GLPK interior-point
  952. solution format specifies the optimal interior-point solution to the LP
  953. problem instance from Subsection ``Example of MPS file''.
  954. \bigskip
  955. \begin{center}
  956. \footnotesize\tt
  957. \begin{tabular}{l@{\hspace*{10pt}}}
  958. s ipt 7 7 o 296.216606851403 \\
  959. i 1 2000.00000290369 -0.0135956757623443 \\
  960. i 2 60.0000001302903 -2.568231024875 \\
  961. i 3 83.9675094251819 -8.85591445202383e-10 \\
  962. i 4 39.9999999985064 -0.544404310443766 \\
  963. i 5 19.9602886941262 -2.24817803513554e-09 \\
  964. i 6 1500.00000199013 0.251985567257828 \\
  965. i 7 250.000000244896 0.48519856304979 \\
  966. \end{tabular}
  967. \begin{tabular}{|@{\hspace*{10pt}}l}
  968. j 1 3.3482079213784e-07 0.253624547432525 \\
  969. j 2 665.342955760768 6.04613825351601e-11 \\
  970. j 3 490.25271366802 5.8488360240978e-10 \\
  971. j 4 424.187729774275 -2.54144550490434e-11 \\
  972. j 5 1.46067738492801e-06 0.0145559574770786 \\
  973. j 6 299.638985053112 1.49359074902927e-10 \\
  974. j 7 120.577616852015 3.50297708781545e-10 \\
  975. e o f
  976. \end{tabular}
  977. \end{center}
  978. \subsection{glp\_write\_ipt --- write interior-point solution in GLPK
  979. format}
  980. \synopsis
  981. \begin{verbatim}
  982. int glp_write_ipt(glp_prob *P, const char *fname);
  983. \end{verbatim}
  984. \description
  985. The routine \verb|glp_write_ipt| writes the current interior-point
  986. solution to a text file in the GLPK format. (For description of the
  987. GLPK interior-point solution format see Subsection ``Read
  988. interior-point solution in GLPK format.'')
  989. The character string \verb|fname| specifies the name of the text file
  990. to be written. (If the file name ends with suffix `\verb|.gz|', the
  991. routine \verb|glp_write_ipt| compresses it "on the fly".)
  992. \returns
  993. If the operation was successful, the routine \verb|glp_write_ipt|
  994. returns zero. Otherwise, it prints an error message and returns
  995. non-zero.
  996. \subsection{glp\_print\_mip --- write MIP solution in printable format}
  997. \synopsis
  998. \begin{verbatim}
  999. int glp_print_mip(glp_prob *P, const char *fname);
  1000. \end{verbatim}
  1001. \description
  1002. The routine \verb|glp_print_mip| writes the current solution to a MIP
  1003. problem, which is specified by the pointer \verb|P|, to a text file,
  1004. whose name is the character string \verb|fname|, in printable format.
  1005. Information reported by the routine \verb|glp_print_mip| is intended
  1006. mainly for visual analysis.
  1007. \returns
  1008. If no errors occurred, the routine returns zero. Otherwise the routine
  1009. prints an error message and returns non-zero.
  1010. \subsection{glp\_read\_mip --- read MIP solution in GLPK format}
  1011. \synopsis
  1012. \begin{verbatim}
  1013. int glp_read_mip(glp_prob *P, const char *fname);
  1014. \end{verbatim}
  1015. \description
  1016. The routine \verb|glp_read_mip| reads MIP solution from a text file in
  1017. the GLPK format. (For description of the format see below.)
  1018. The character string \verb|fname| specifies the name of the text file
  1019. to be read in. (If the file name ends with suffix `\verb|.gz|', the
  1020. file is assumed to be compressed, in which case the routine
  1021. \verb|glp_read_mip| decompresses it "on the fly".)
  1022. \returns
  1023. If the operation was successful, the routine \verb|glp_read_mip|
  1024. returns zero. Otherwise, it prints an error message and returns
  1025. non-zero.
  1026. \para{GLPK MIP solution format}
  1027. The GLPK MIP solution format is a DIMACS-like format.\footnote{The
  1028. DIMACS formats were developed by the Center for Discrete Mathematics
  1029. and Theoretical Computer Science (DIMACS) to facilitate exchange of
  1030. problem data. For details see:
  1031. {\tt <http://dimacs.rutgers.edu/Challenges/>}. }
  1032. The file in this format is a plain ASCII text file containing lines of
  1033. several types described below. A line is terminated with the
  1034. end-of-line character. Fields in each line are separated by at least
  1035. one blank space. Each line begins with a one-character designator to
  1036. identify the line type.
  1037. The first line of the solution file must be the solution line (except
  1038. optional comment lines, which may precede the problem line). The last
  1039. line of the data file must be the end line. Other lines may follow in
  1040. arbitrary order, however, duplicate lines are not allowed.
  1041. \para{Comment lines.} Comment lines give human-readable information
  1042. about the solution file and are ignored by GLPK routines. Comment lines
  1043. can appear anywhere in the data file. Each comment line begins with the
  1044. lower-case character \verb|c|.
  1045. \begin{verbatim}
  1046. c This is an example of comment line
  1047. \end{verbatim}
  1048. \para{Solution line.} There must be exactly one solution line in the
  1049. solution file. This line must appear before any other lines except
  1050. comment lines and has the following format:
  1051. \begin{verbatim}
  1052. s mip ROWS COLS SST OBJ
  1053. \end{verbatim}
  1054. The lower-case letter \verb|s| specifies that this is the solution
  1055. line.
  1056. The three-character solution designator \verb|mip| identifies the file
  1057. as containing a solution to the MIP problem instance.
  1058. The \verb|ROWS| and \verb|COLS| fields contain non-negative integer
  1059. values that specify the number of rows (constraints) and columns
  1060. (variables), resp., in the LP problem instance.
  1061. The \verb|SST| field contains one of the following lower-case letters
  1062. that specifies the solution status:
  1063. \verb|o| --- solution is integer optimal;
  1064. \verb|f| --- solution is integer feasible (non-optimal);
  1065. \verb|n| --- no integer feasible solution exists;
  1066. \verb|u| --- solution is undefined.
  1067. The \verb|OBJ| field contains a floating-point number that specifies
  1068. the objective function value in the MIP solution.
  1069. \para{Row solution descriptors.} There must be exactly one row solution
  1070. descriptor line in the solution file for each row (constraint). This
  1071. line has the following format:
  1072. \begin{verbatim}
  1073. i ROW VAL
  1074. \end{verbatim}
  1075. The lower-case letter \verb|i| specifies that this is the row solution
  1076. descriptor line.
  1077. The \verb|ROW| field specifies the row ordinal number, an integer
  1078. between 1 and $m$, where $m$ is the number of rows in the problem
  1079. instance.
  1080. The \verb|VAL| field contains a floating-point number that specifies
  1081. the row value (the value of the corresponding linear form).
  1082. \para{Column solution descriptors.} There must be exactly one column
  1083. solution descriptor line in the solution file for each column
  1084. (variable). This line has the following format:
  1085. \begin{verbatim}
  1086. j COL VAL
  1087. \end{verbatim}
  1088. The lower-case letter \verb|j| specifies that this is the column
  1089. solution descriptor line.
  1090. The \verb|COL| field specifies the column ordinal number, an integer
  1091. between 1 and $n$, where $n$ is the number of columns in the problem
  1092. instance.
  1093. The \verb|VAL| field contains a floating-point number that specifies
  1094. the column value.
  1095. \para{End line.} There must be exactly one end line in the solution
  1096. file. This line must appear last in the file and has the following
  1097. format:
  1098. \begin{verbatim}
  1099. e
  1100. \end{verbatim}
  1101. The lower-case letter \verb|e| specifies that this is the end line.
  1102. Anything that follows the end line is ignored by GLPK routines.
  1103. \para{Example of solution file in GLPK MIP solution format}
  1104. The following example of a solution file in GLPK MIP solution format
  1105. specifies an optimal solution to a MIP problem instance.
  1106. \bigskip
  1107. \begin{center}
  1108. \footnotesize\tt
  1109. \begin{tabular}{l@{\hspace*{50pt}}}
  1110. s mip 8 8 o 1201500 \\
  1111. i 1 60 \\
  1112. i 2 8400 \\
  1113. i 3 -1200 \\
  1114. i 4 0 \\
  1115. i 5 9000 \\
  1116. i 6 -600 \\
  1117. i 7 0 \\
  1118. i 8 8000 \\
  1119. \end{tabular}
  1120. \begin{tabular}{|@{\hspace*{80pt}}l}
  1121. j 1 60 \\
  1122. j 2 6 \\
  1123. j 3 0 \\
  1124. j 4 60 \\
  1125. j 5 6 \\
  1126. j 6 600 \\
  1127. j 7 60 \\
  1128. j 8 16 \\
  1129. e o f \\
  1130. \end{tabular}
  1131. \end{center}
  1132. \subsection{glp\_write\_mip --- write MIP solution in GLPK format}
  1133. \synopsis
  1134. \begin{verbatim}
  1135. int glp_write_mip(glp_prob *P, const char *fname);
  1136. \end{verbatim}
  1137. \description
  1138. The routine \verb|glp_write_mip| writes the current MIP solution to
  1139. a text file in the GLPK format. (For description of the GLPK MIP
  1140. solution format see Subsection ``Read MIP solution in GLPK format.'')
  1141. The character string \verb|fname| specifies the name of the text file
  1142. to be written. (If the file name ends with suffix `\verb|.gz|', the
  1143. routine \verb|glp_write_mip| compresses it "on the fly".)
  1144. \returns
  1145. If the operation was successful, the routine \verb|glp_write_mip|
  1146. returns zero. Otherwise, it prints an error message and returns
  1147. non-zero.
  1148. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1149. \newpage
  1150. \section{Post-optimal analysis routines}
  1151. \subsection{glp\_print\_ranges --- print sensitivity analysis report}
  1152. \synopsis
  1153. {\tt int glp\_print\_ranges(glp\_prob *P, int len, const int list[],
  1154. int flags,\\
  1155. \hspace*{134pt}const char *fname);}
  1156. \description
  1157. The routine \verb|glp_print_ranges| performs sensitivity analysis of
  1158. current optimal basic solution and writes the analysis report in
  1159. human-readable format to a text file, whose name is the character
  1160. string {\it fname}. (Detailed description of the report structure is
  1161. given below.)
  1162. The parameter {\it len} specifies the length of the row/column list.
  1163. The array {\it list} specifies ordinal number of rows and columns to be
  1164. analyzed. The ordinal numbers should be passed in locations
  1165. {\it list}[1], {\it list}[2], \dots, {\it list}[{\it len}]. Ordinal
  1166. numbers from 1 to $m$ refer to rows, and ordinal numbers from $m+1$ to
  1167. $m+n$ refer to columns, where $m$ and $n$ are, resp., the total number
  1168. of rows and columns in the problem object. Rows and columns appear in
  1169. the analysis report in the same order as they follow in the array list.
  1170. It is allowed to specify $len=0$, in which case the array {\it list} is
  1171. not used (so it can be specified as \verb|NULL|), and the routine
  1172. performs analysis for all rows and columns of the problem object.
  1173. The parameter {\it flags} is reserved for use in the future and must be
  1174. specified as zero.
  1175. On entry to the routine \verb|glp_print_ranges| the current basic
  1176. solution must be optimal and the basis factorization must exist.
  1177. The application program can check that with the routine
  1178. \verb|glp_bf_exists|, and if the factorization does
  1179. not exist, compute it with the routine \verb|glp_factorize|. Note that
  1180. if the LP preprocessor is not used, on normal exit from the simplex
  1181. solver routine \verb|glp_simplex| the basis factorization always exists.
  1182. \returns
  1183. If the operation was successful, the routine \verb|glp_print_ranges|
  1184. returns zero. Otherwise, it prints an error message and returns
  1185. non-zero.
  1186. \para{Analysis report example}
  1187. An example of the sensitivity analysis report is shown on the next two
  1188. pages. This example corresponds to the example of LP problem described
  1189. in Subsection ``Example of MPS file''.
  1190. \para{Structure of the analysis report}
  1191. For each row and column specified in the array {\it list} the routine
  1192. prints two lines containing generic information and analysis
  1193. information, which depends on the status of corresponding row or column.
  1194. Note that analysis of a row is analysis of its auxiliary variable,
  1195. which is equal to the row linear form $\sum a_jx_j$, and analysis of
  1196. a column is analysis of corresponding structural variable. Therefore,
  1197. formally, on performing the sensitivity analysis there is no difference
  1198. between rows and columns.
  1199. \newpage
  1200. \begin{landscape}
  1201. \begin{footnotesize}
  1202. \begin{verbatim}
  1203. GLPK 4.42 - SENSITIVITY ANALYSIS REPORT Page 1
  1204. Problem: PLAN
  1205. Objective: VALUE = 296.2166065 (MINimum)
  1206. No. Row name St Activity Slack Lower bound Activity Obj coef Obj value at Limiting
  1207. Marginal Upper bound range range break point variable
  1208. ------ ------------ -- ------------- ------------- ------------- ------------- ------------- ------------- ------------
  1209. 1 VALUE BS 296.21661 -296.21661 -Inf 299.25255 -1.00000 . MN
  1210. . +Inf 296.21661 +Inf +Inf
  1211. 2 YIELD NS 2000.00000 . 2000.00000 1995.06864 -Inf 296.28365 BIN3
  1212. -.01360 2000.00000 2014.03479 +Inf 296.02579 CU
  1213. 3 FE NU 60.00000 . -Inf 55.89016 -Inf 306.77162 BIN4
  1214. -2.56823 60.00000 62.69978 2.56823 289.28294 BIN3
  1215. 4 CU BS 83.96751 16.03249 -Inf 93.88467 -.30613 270.51157 MN
  1216. . 100.00000 79.98213 .21474 314.24798 BIN5
  1217. 5 MN NU 40.00000 . -Inf 34.42336 -Inf 299.25255 BIN4
  1218. -.54440 40.00000 41.68691 .54440 295.29825 BIN3
  1219. 6 MG BS 19.96029 10.03971 -Inf 24.74427 -1.79618 260.36433 BIN1
  1220. . 30.00000 9.40292 .28757 301.95652 MN
  1221. 7 AL NL 1500.00000 . 1500.00000 1485.78425 -.25199 292.63444 CU
  1222. .25199 +Inf 1504.92126 +Inf 297.45669 BIN3
  1223. 8 SI NL 250.00000 50.00000 250.00000 235.32871 -.48520 289.09812 CU
  1224. .48520 300.00000 255.06073 +Inf 298.67206 BIN3
  1225. \end{verbatim}
  1226. \end{footnotesize}
  1227. \end{landscape}
  1228. \newpage
  1229. \begin{landscape}
  1230. \begin{footnotesize}
  1231. \begin{verbatim}
  1232. GLPK 4.42 - SENSITIVITY ANALYSIS REPORT Page 2
  1233. Problem: PLAN
  1234. Objective: VALUE = 296.2166065 (MINimum)
  1235. No. Column name St Activity Obj coef Lower bound Activity Obj coef Obj value at Limiting
  1236. Marginal Upper bound range range break point variable
  1237. ------ ------------ -- ------------- ------------- ------------- ------------- ------------- ------------- ------------
  1238. 1 BIN1 NL . .03000 . -28.82475 -.22362 288.90594 BIN4
  1239. .25362 200.00000 33.88040 +Inf 304.80951 BIN4
  1240. 2 BIN2 BS 665.34296 .08000 . 802.22222 .01722 254.44822 BIN1
  1241. . 2500.00000 313.43066 .08863 301.95652 MN
  1242. 3 BIN3 BS 490.25271 .17000 400.00000 788.61314 .15982 291.22807 MN
  1243. . 800.00000 -347.42857 .17948 300.86548 BIN5
  1244. 4 BIN4 BS 424.18773 .12000 100.00000 710.52632 .10899 291.54745 MN
  1245. . 700.00000 -256.15524 .14651 307.46010 BIN1
  1246. 5 BIN5 NL . .15000 . -201.78739 .13544 293.27940 BIN3
  1247. .01456 1500.00000 58.79586 +Inf 297.07244 BIN3
  1248. 6 ALUM BS 299.63899 .21000 . 358.26772 .18885 289.87879 AL
  1249. . +Inf 112.40876 .22622 301.07527 MN
  1250. 7 SILICON BS 120.57762 .38000 . 124.27093 .14828 268.27586 BIN5
  1251. . +Inf 85.54745 .46667 306.66667 MN
  1252. End of report
  1253. \end{verbatim}
  1254. \end{footnotesize}
  1255. \end{landscape}
  1256. \newpage
  1257. \noindent
  1258. {\it Generic information}
  1259. {\tt No.} is the row or column ordinal number in the problem object.
  1260. Rows are numbered from 1 to $m$, and columns are numbered from 1 to $n$,
  1261. where $m$ and $n$ are, resp., the total number of rows and columns in
  1262. the problem object.
  1263. {\tt Row name} is the symbolic name assigned to the row. If the row has
  1264. no name assigned, this field contains blanks.
  1265. {\tt Column name} is the symbolic name assigned to the column. If the
  1266. column has no name assigned, this field contains blanks.
  1267. {\tt St} is the status of the row or column in the optimal solution:
  1268. {\tt BS} --- non-active constraint (row), basic column;
  1269. {\tt NL} --- inequality constraint having its lower right-hand side
  1270. active (row), non-basic column having its lower bound active;
  1271. {\tt NU} --- inequality constraint having its upper right-hand side
  1272. active (row), non-basic column having its upper bound active;
  1273. {\tt NS} --- active equality constraint (row), non-basic fixed column.
  1274. {\tt NF} --- active free row, non-basic free (unbounded) column. (This
  1275. case means that the optimal solution is dual degenerate.)
  1276. {\tt Activity} is the (primal) value of the auxiliary variable (row) or
  1277. structural variable (column) in the optimal solution.
  1278. {\tt Slack} is the (primal) value of the row slack variable.
  1279. {\tt Obj coef} is the objective coefficient of the column (structural
  1280. variable).
  1281. {\tt Marginal} is the reduced cost (dual activity) of the auxiliary
  1282. variable (row) or structural variable (column).
  1283. {\tt Lower bound} is the lower right-hand side (row) or lower bound
  1284. (column). If the row or column has no lower bound, this field contains
  1285. {\tt -Inf}.
  1286. {\tt Upper bound} is the upper right-hand side (row) or upper bound
  1287. (column). If the row or column has no upper bound, this field contains
  1288. {\tt +Inf}.
  1289. \noindent
  1290. {\it Sensitivity analysis of active bounds}
  1291. The sensitivity analysis of active bounds is performed only for rows,
  1292. which are active constraints, and only for non-basic columns, because
  1293. inactive constraints and basic columns have no active bounds.
  1294. For every auxiliary (row) or structural (column) non-basic variable the
  1295. routine starts changing its active bound in both direction. The first
  1296. of the two lines in the report corresponds to decreasing, and the
  1297. second line corresponds to increasing of the active bound. Since the
  1298. variable being analyzed is non-basic, its activity, which is equal to
  1299. its active bound, also starts changing. This changing leads to changing
  1300. of basic (auxiliary and structural) variables, which depend on the
  1301. non-basic variable. The current basis remains primal feasible and
  1302. therefore optimal while values of all basic variables are primal
  1303. feasible, i.e. are within their bounds. Therefore, if some basic
  1304. variable called the {\it limiting variable} reaches its (lower or
  1305. upper) bound first, before any other basic variables, it thereby limits
  1306. further changing of the non-basic variable, because otherwise the
  1307. current basis would become primal infeasible. The point, at which this
  1308. happens, is called the {\it break point}. Note that there are two break
  1309. points: the lower break point, which corresponds to decreasing of the
  1310. non-basic variable, and the upper break point, which corresponds to
  1311. increasing of the non-basic variable.
  1312. In the analysis report values of the non-basic variable (i.e. of its
  1313. active bound) being analyzed at both lower and upper break points are
  1314. printed in the field `{\tt Activity range}'. Corresponding values of
  1315. the objective function are printed in the field `{\tt Obj value at
  1316. break point}', and symbolic names of corresponding limiting basic
  1317. variables are printed in the field `{\tt Limiting variable}'.
  1318. If the active bound can decrease or/and increase unlimitedly, the field
  1319. `{\tt Activity range}' contains {\tt -Inf} or/and {\tt +Inf}, resp.
  1320. For example (see the example report above), row SI is a double-sided
  1321. constraint, which is active on its lower bound (right-hand side), and
  1322. its activity in the optimal solution being equal to the lower bound is
  1323. 250. The activity range for this row is $[235.32871,255.06073]$. This
  1324. means that the basis remains optimal while the lower bound is
  1325. increasing up to 255.06073, and further increasing is limited by
  1326. (structural) variable BIN3. If the lower bound reaches this upper break
  1327. point, the objective value becomes equal to 298.67206.
  1328. Note that if the basis does not change, the objective function depends
  1329. on the non-basic variable linearly, and the per-unit change of the
  1330. objective function is the reduced cost (marginal value) of the
  1331. non-basic variable.
  1332. \noindent
  1333. {\it Sensitivity analysis of objective coefficients at non-basic
  1334. variables}
  1335. The sensitivity analysis of the objective coefficient at a non-basic
  1336. variable is quite simple, because in this case change in the objective
  1337. coefficient leads to equivalent change in the reduced cost (marginal
  1338. value).
  1339. For every auxiliary (row) or structural (column) non-basic variable the
  1340. routine starts changing its objective coefficient in both direction.
  1341. (Note that auxiliary variables are not included in the objective
  1342. function and therefore always have zero objective coefficients.) The
  1343. first of the two lines in the report corresponds to decreasing, and the
  1344. second line corresponds to increasing of the objective coefficient.
  1345. This changing leads to changing of the reduced cost of the non-basic
  1346. variable to be analyzed and does affect reduced costs of all other
  1347. non-basic variables. The current basis remains dual feasible and
  1348. therefore optimal while the reduced cost keeps its sign. Therefore, if
  1349. the reduced cost reaches zero, it limits further changing of the
  1350. objective coefficient (if only the non-basic variable is non-fixed).
  1351. In the analysis report minimal and maximal values of the objective
  1352. coefficient, on which the basis remains optimal, are printed in the
  1353. field `\verb|Obj coef range|'. If the objective coefficient can
  1354. decrease or/and increase unlimitedly, this field contains {\tt -Inf}
  1355. or/and {\tt +Inf}, resp.
  1356. For example (see the example report above), column BIN5 is non-basic
  1357. having its lower bound active. Its objective coefficient is 0.15, and
  1358. reduced cost in the optimal solution 0.01456. The column lower bound
  1359. remains active while the column reduced cost remains non-negative,
  1360. thus, minimal value of the objective coefficient, on which the current
  1361. basis still remains optimal, is $0.15-0.01456=0.13644$, that is
  1362. indicated in the field `\verb|Obj coef range|'.
  1363. %\newpage
  1364. %{\parskip=0pt
  1365. \noindent
  1366. {\it Sensitivity analysis of objective coefficients at basic variables}
  1367. %\medskip
  1368. To perform sensitivity analysis for every auxiliary (row) or structural
  1369. (column) variable the routine starts changing its objective coefficient
  1370. in both direction. (Note that auxiliary variables are not included in
  1371. the objective function and therefore always have zero objective
  1372. coefficients.) The first of the two lines in the report corresponds to
  1373. decreasing, and the second line corresponds to increasing of the
  1374. objective coefficient. This changing leads to changing of reduced costs
  1375. of non-basic variables. The current basis remains dual feasible and
  1376. therefore optimal while reduced costs of all non-basic variables
  1377. (except fixed variables) keep their signs. Therefore, if the reduced
  1378. cost of some non-basic non-fixed variable called the {\it limiting
  1379. variable} reaches zero first, before reduced cost of any other
  1380. non-basic non-fixed variable, it thereby limits further changing of the
  1381. objective coefficient, because otherwise the current basis would become
  1382. dual infeasible (non-optimal). The point, at which this happens, is
  1383. called the {\it break point}. Note that there are two break points: the
  1384. lower break point, which corresponds to decreasing of the objective
  1385. coefficient, and the upper break point, which corresponds to increasing
  1386. of the objective coefficient. Let the objective coefficient reach its
  1387. limit value and continue changing a bit further in the same direction
  1388. that makes the current basis dual infeasible (non-optimal). Then the
  1389. reduced cost of the non-basic limiting variable becomes ``a bit'' dual
  1390. infeasible that forces the limiting variable to enter the basis
  1391. replacing there some basic variable, which leaves the basis to keep its
  1392. primal feasibility. It should be understood that if we change the
  1393. current basis in this way exactly at the break point, both the current
  1394. and adjacent bases will be optimal with the same objective value,
  1395. because at the break point the limiting variable has zero reduced cost.
  1396. On the other hand, in the adjacent basis the value of the limiting
  1397. variable changes, because there it becomes basic, that leads to
  1398. changing of the value of the basic variable being analyzed. Note that
  1399. on determining the adjacent basis the bounds of the analyzed basic
  1400. variable are ignored as if it were a free (unbounded) variable, so it
  1401. cannot leave the current basis.
  1402. In the analysis report lower and upper limits of the objective
  1403. coefficient at the basic variable being analyzed, when the basis
  1404. remains optimal, are printed in the field `{\tt Obj coef range}'.
  1405. Corresponding values of the objective function at both lower and upper
  1406. break points are printed in the field `{\tt Obj value at break point}',
  1407. symbolic names of corresponding non-basic limiting variables are
  1408. printed in the field `{\tt Limiting variable}', and values of the basic
  1409. variable, which it would take on in the adjacent bases (as was
  1410. explained above) are printed in the field `{\tt Activity range}'.
  1411. If the objective coefficient can increase or/and decrease unlimitedly,
  1412. the field `{\tt Obj coef range}' contains {\tt -Inf} and/or {\tt +Inf},
  1413. resp. It also may happen that no dual feasible adjacent basis exists
  1414. (i.e. on entering the basis the limiting variable can increase or
  1415. decrease unlimitedly), in which case the field `{\tt Activity range}'
  1416. contains {\tt -Inf} and/or {\tt +Inf}.
  1417. For example (see the example report above), structural variable
  1418. (column) BIN3 is basic, its optimal value is 490.25271, and its
  1419. objective coefficient is 0.17. The objective coefficient range for this
  1420. column is $[0.15982,0.17948]$. This means that the basis remains
  1421. optimal while the objective coefficient is decreasing down to 0.15982,
  1422. and further decreasing is limited by (auxiliary) variable MN. If we
  1423. make the objective coefficient a bit less than 0.15982, the limiting
  1424. variable MN will enter the basis, and in that adjacent basis the
  1425. structural variable BIN3 will take on new optimal value 788.61314. At
  1426. the lower break point, where the objective coefficient is exactly
  1427. 0.15982, the objective function takes on the value 291.22807 in both
  1428. the current and adjacent bases.
  1429. Note that if the basis does not change, the objective function depends
  1430. on the objective coefficient at the basic variable linearly, and the
  1431. per-unit change of the objective function is the value of the basic
  1432. variable.
  1433. %}
  1434. %* eof *%