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.

3428 lines
105 KiB

  1. %* glpk02.tex *%
  2. \chapter{Basic API Routines}
  3. \section{General conventions}
  4. \subsection{Library header}
  5. All GLPK API data types and routines are defined in the header file
  6. \verb|glpk.h|. It should be included in all source files which use
  7. GLPK API, either directly or indirectly through some other header file
  8. as follows:
  9. \begin{verbatim}
  10. #include <glpk.h>
  11. \end{verbatim}
  12. \subsection{Error handling}
  13. If some GLPK API routine detects erroneous or incorrect data passed by
  14. the application program, it writes appropriate diagnostic messages to
  15. the terminal and then abnormally terminates the application program.
  16. In most practical cases this allows to simplify programming by avoiding
  17. numerous checks of return codes. Thus, in order to prevent crashing the
  18. application program should check all data, which are suspected to be
  19. incorrect, before calling GLPK API routines.
  20. Should note that this kind of error handling is used only in cases of
  21. incorrect data passed by the application program. If, for example, the
  22. application program calls some GLPK API routine to read data from an
  23. input file and these data are incorrect, the GLPK API routine reports
  24. about error in the usual way by means of the return code.
  25. \subsection{Thread safety}
  26. The standard version of GLPK API is {\it not} thread safe and therefore
  27. should not be used in multi-threaded programs.
  28. \subsection{Array indexing}
  29. Normally all GLPK API routines start array indexing from 1, not from 0
  30. (except the specially stipulated cases). This means, for example, that
  31. if some vector $x$ of the length $n$ is passed as an array to some GLPK
  32. API routine, the latter expects vector components to be placed in
  33. locations \verb|x[1]|, \verb|x[2]|, \dots, \verb|x[n]|, and the
  34. location \verb|x[0]| normally is not used.
  35. To avoid indexing errors it is most convenient and most reliable to
  36. declare the array \verb|x| as follows:
  37. \begin{verbatim}
  38. double x[1+n];
  39. \end{verbatim}
  40. \noindent
  41. or to allocate it as follows:
  42. \begin{verbatim}
  43. double *x;
  44. . . .
  45. x = calloc(1+n, sizeof(double));
  46. . . .
  47. \end{verbatim}
  48. \noindent
  49. In both cases one extra location \verb|x[0]| is reserved that allows
  50. passing the array to GLPK routines in a usual way.
  51. \section{Problem object}
  52. All GLPK API routines deal with so called {\it problem object}, which
  53. is a program object of type \verb|glp_prob| and intended to represent
  54. a particular LP or MIP instance.
  55. The type \verb|glp_prob| is a data structure declared in the header
  56. file \verb|glpk.h| as follows:
  57. \begin{verbatim}
  58. typedef struct glp_prob glp_prob;
  59. \end{verbatim}
  60. Problem objects (i.e. program objects of the \verb|glp_prob| type) are
  61. allocated and managed internally by the GLPK API routines. The
  62. application program should never use any members of the \verb|glp_prob|
  63. structure directly and should deal only with pointers to these objects
  64. (that is, \verb|glp_prob *| values).
  65. The problem object consists of the following segments:
  66. \vspace*{-8pt}
  67. \begin{itemize}\setlength{\itemsep}{0pt}
  68. \item problem segment,
  69. \item basis segment,
  70. \item interior-point segment, and
  71. \item MIP segment.
  72. \end{itemize}
  73. \subsection{Problem segment}
  74. The {\it problem segment} contains original LP/MIP data, which
  75. corresponds to the problem formulation (1.1)---(1.3) (see Section
  76. \ref{seclp}, page \pageref{seclp}). This segment includes the following
  77. components:
  78. \vspace*{-8pt}
  79. \begin{itemize}\setlength{\itemsep}{0pt}
  80. \item rows (auxiliary variables),
  81. \item columns (structural variables),
  82. \item objective function, and
  83. \item constraint matrix.
  84. \end{itemize}
  85. \vspace*{-7pt}
  86. Rows and columns have the same set of the following attributes:
  87. \vspace*{-7pt}
  88. \begin{itemize}\setlength{\itemsep}{0pt}
  89. \item ordinal number,
  90. \item symbolic name (1 up to 255 arbitrary graphic characters),
  91. \item type (free, lower bound, upper bound, double bound, fixed),
  92. \item numerical values of lower and upper bounds,
  93. \item scale factor.
  94. \end{itemize}
  95. \vspace*{-7pt}
  96. {\it Ordinal numbers} are intended for referencing rows and columns.
  97. Row ordinal numbers are integers $1, 2, \dots, m$, and column ordinal
  98. numbers are integers $1, 2, \dots, n$, where $m$ and $n$ are,
  99. respectively, the current number of rows and columns in the problem
  100. object.
  101. {\it Symbolic names} are intended for informational purposes. They also
  102. can be used for referencing rows and columns.
  103. {\it Types and bounds} of rows (auxiliary variables) and columns
  104. (structural variables) are explained above (see Section \ref{seclp},
  105. page \pageref{seclp}).
  106. {\it Scale factors} are used internally for scaling rows and columns of
  107. the constraint matrix.
  108. Information about the {\it objective function} includes numerical
  109. values of objective coefficients and a flag, which defines the
  110. optimization direction (i.e. minimization or maximization).
  111. The {\it constraint matrix} is a $m \times n$ rectangular matrix built
  112. of constraint coefficients $a_{ij}$, which defines the system of linear
  113. constraints (1.2) (see Section \ref{seclp}, page \pageref{seclp}). This
  114. matrix is stored in the problem object in both row-wise and column-wise
  115. sparse formats.
  116. Once the problem object has been created, the application program can
  117. access and modify any components of the problem segment in arbitrary
  118. order.
  119. \subsection{Basis segment}
  120. The {\it basis segment} of the problem object keeps information related
  121. to the current basic solution. It includes:
  122. \vspace*{-8pt}
  123. \begin{itemize}\setlength{\itemsep}{0pt}
  124. \item row and column statuses,
  125. \item basic solution statuses,
  126. \item factorization of the current basis matrix, and
  127. \item basic solution components.
  128. \end{itemize}
  129. \vspace*{-8pt}
  130. The {\it row and column statuses} define which rows and columns are
  131. basic and which are non-basic. These statuses may be assigned either by
  132. the application program of by some API routines. Note that these
  133. statuses are always defined independently on whether the corresponding
  134. basis is valid or not.
  135. The {\it basic solution statuses} include the {\it primal status} and
  136. the {\it dual status}, which are set by the simplex-based solver once
  137. the problem has been solved. The primal status shows whether a primal
  138. basic solution is feasible, infeasible, or undefined. The dual status
  139. shows the same for a dual basic solution.
  140. The {\it factorization of the basis matrix} is some factorized form
  141. (like {\it LU}-factorization) of the current basis matrix (defined by
  142. the current row and column statuses). The factorization is used by
  143. simplex-based solvers and kept when the solver terminates the search.
  144. This feature allows efficiently reoptimizing the problem after some
  145. modifications (for example, after changing some bounds or objective
  146. coefficients). It also allows performing the post-optimal analysis (for
  147. example, computing components of the simplex table, etc.).
  148. The {\it basic solution components} include primal and dual values of
  149. all auxiliary and structural variables for the most recently obtained
  150. basic solution.
  151. \subsection{Interior-point segment}
  152. The {\it interior-point segment} contains interior-point solution
  153. components, which include the solution status, and primal and dual
  154. values of all auxiliary and structural variables.
  155. \subsection{MIP segment}
  156. The {\it MIP segment} is used only for MIP problems. This segment
  157. includes:
  158. \vspace*{-8pt}
  159. \begin{itemize}\setlength{\itemsep}{0pt}
  160. \item column kinds,
  161. \item MIP solution status, and
  162. \item MIP solution components.
  163. \end{itemize}
  164. \vspace*{-8pt}
  165. The {\it column kinds} define which columns (i.e. structural variables)
  166. are integer and which are continuous.
  167. The {\it MIP solution status} is set by the MIP solver and shows whether
  168. a MIP solution is integer optimal, integer feasible (non-optimal), or
  169. undefined.
  170. The {\it MIP solution components} are computed by the MIP solver and
  171. include primal values of all auxiliary and structural variables for the
  172. most recently obtained MIP solution.
  173. Note that in case of MIP problem the basis segment corresponds to
  174. the optimal solution of LP relaxation, which is also available to the
  175. application program.
  176. Currently the search tree is not kept in the MIP segment, so if the
  177. search has been terminated, it cannot be continued.
  178. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  179. \newpage
  180. \section{Problem creating and modifying routines}
  181. \subsection{glp\_create\_prob --- create problem object}
  182. \synopsis
  183. \begin{verbatim}
  184. glp_prob *glp_create_prob(void);
  185. \end{verbatim}
  186. \description
  187. The routine \verb|glp_create_prob| creates a new problem object, which
  188. initially is ``empty'', i.e. has no rows and columns.
  189. \returns
  190. The routine returns a pointer to the created object, which should be
  191. used in any subsequent operations on this object.
  192. \subsection{glp\_set\_prob\_name --- assign (change) problem name}
  193. \synopsis
  194. \begin{verbatim}
  195. void glp_set_prob_name(glp_prob *P, const char *name);
  196. \end{verbatim}
  197. \description
  198. The routine \verb|glp_set_prob_name| assigns a given symbolic
  199. \verb|name| (1 up to 255 characters) to the specified problem object.
  200. If the parameter \verb|name| is \verb|NULL| or empty string, the
  201. routine erases an existing symbolic name of the problem object.
  202. \subsection{glp\_set\_obj\_name --- assign (change) objective function
  203. name}
  204. \synopsis
  205. \begin{verbatim}
  206. void glp_set_obj_name(glp_prob *P, const char *name);
  207. \end{verbatim}
  208. \description
  209. The routine \verb|glp_set_obj_name| assigns a given symbolic
  210. \verb|name| (1 up to 255 characters) to the objective function of the
  211. specified problem object.
  212. If the parameter \verb|name| is \verb|NULL| or empty string, the
  213. routine erases an existing symbolic name of the objective function.
  214. \newpage
  215. \subsection{glp\_set\_obj\_dir --- set (change) optimization direction
  216. flag}
  217. \synopsis
  218. \begin{verbatim}
  219. void glp_set_obj_dir(glp_prob *P, int dir);
  220. \end{verbatim}
  221. \description
  222. The routine \verb|glp_set_obj_dir| sets (changes) the optimization
  223. direction flag (i.e. ``sense'' of the objective function) as specified
  224. by the parameter \verb|dir|:
  225. \verb|GLP_MIN| means minimization;
  226. \verb|GLP_MAX| means maximization.
  227. \noindent
  228. (Note that by default the problem is minimization.)
  229. \subsection{glp\_add\_rows --- add new rows to problem object}
  230. \synopsis
  231. \begin{verbatim}
  232. int glp_add_rows(glp_prob *P, int nrs);
  233. \end{verbatim}
  234. \description
  235. The routine \verb|glp_add_rows| adds \verb|nrs| rows (constraints) to
  236. the specified problem object. New rows are always added to the end of
  237. the row list, so the ordinal numbers of existing rows are not changed.
  238. Being added each new row is initially free (unbounded) and has empty
  239. list of the constraint coefficients.
  240. \returns
  241. The routine \verb|glp_add_rows| returns the ordinal number of the first
  242. new row added to the problem object.
  243. \subsection{glp\_add\_cols --- add new columns to problem object}
  244. \synopsis
  245. \begin{verbatim}
  246. int glp_add_cols(glp_prob *P, int ncs);
  247. \end{verbatim}
  248. \description
  249. The routine \verb|glp_add_cols| adds \verb|ncs| columns (structural
  250. variables) to the specified problem object. New columns are always
  251. added to the end of the column list, so the ordinal numbers of existing
  252. columns are not changed.
  253. Being added each new column is initially fixed at zero and has empty
  254. list of the constraint coefficients.
  255. \returns
  256. The routine \verb|glp_add_cols| returns the ordinal number of the first
  257. new column added to the problem object.
  258. \subsection{glp\_set\_row\_name --- assign (change) row name}
  259. \synopsis
  260. \begin{verbatim}
  261. void glp_set_row_name(glp_prob *P, int i, const char *name);
  262. \end{verbatim}
  263. \description
  264. The routine \verb|glp_set_row_name| assigns a given symbolic
  265. \verb|name| (1 up to 255 characters) to \verb|i|-th row (auxiliary
  266. variable) of the specified problem object.
  267. If the parameter \verb|name| is \verb|NULL| or empty string, the
  268. routine erases an existing name of $i$-th row.
  269. \subsection{glp\_set\_col\_name --- assign (change) column name}
  270. \synopsis
  271. \begin{verbatim}
  272. void glp_set_col_name(glp_prob *P, int j, const char *name);
  273. \end{verbatim}
  274. \description
  275. The routine \verb|glp_set_col_name| assigns a given symbolic
  276. \verb|name| (1 up to 255 characters) to \verb|j|-th column (structural
  277. variable) of the specified problem object.
  278. If the parameter \verb|name| is \verb|NULL| or empty string, the
  279. routine erases an existing name of $j$-th column.
  280. \subsection{glp\_set\_row\_bnds --- set (change) row bounds}
  281. \synopsis
  282. {\tt void glp\_set\_row\_bnds(glp\_prob *P, int i, int type,
  283. double lb, double ub);}
  284. \description
  285. The routine \verb|glp_set_row_bnds| sets (changes) the type and bounds
  286. of \verb|i|-th row (auxiliary variable) of the specified problem
  287. object.
  288. The parameters \verb|type|, \verb|lb|, and \verb|ub| specify the type,
  289. lower bound, and upper bound, respectively, as follows:
  290. \begin{center}
  291. \begin{tabular}{cr@{}c@{}ll}
  292. Type & \multicolumn{3}{c}{Bounds} & Comment \\
  293. \hline
  294. \verb|GLP_FR| & $-\infty <$ &$\ x\ $& $< +\infty$
  295. & Free (unbounded) variable \\
  296. \verb|GLP_LO| & $lb \leq$ &$\ x\ $& $< +\infty$
  297. & Variable with lower bound \\
  298. \verb|GLP_UP| & $-\infty <$ &$\ x\ $& $\leq ub$
  299. & Variable with upper bound \\
  300. \verb|GLP_DB| & $lb \leq$ &$\ x\ $& $\leq ub$
  301. & Double-bounded variable \\
  302. \verb|GLP_FX| & $lb =$ &$\ x\ $& $= ub$
  303. & Fixed variable \\
  304. \end{tabular}
  305. \end{center}
  306. \noindent
  307. where $x$ is the auxiliary variable associated with $i$-th row.
  308. If the row has no lower bound, the parameter \verb|lb| is ignored. If
  309. the row has no upper bound, the parameter \verb|ub| is ignored. If the
  310. row is an equality constraint (i.e. the corresponding auxiliary
  311. variable is of fixed type), only the parameter \verb|lb| is used while
  312. the parameter \verb|ub| is ignored.
  313. Being added to the problem object each row is initially free, i.e. its
  314. type is \verb|GLP_FR|.
  315. \subsection{glp\_set\_col\_bnds --- set (change) column bounds}
  316. \synopsis
  317. {\tt void glp\_set\_col\_bnds(glp\_prob *P, int j, int type,
  318. double lb, double ub);}
  319. \description
  320. The routine \verb|glp_set_col_bnds| sets (changes) the type and bounds
  321. of \verb|j|-th column (structural variable) of the specified problem
  322. object.
  323. The parameters \verb|type|, \verb|lb|, and \verb|ub| specify the type,
  324. lower bound, and upper bound, respectively, as follows:
  325. \begin{center}
  326. \begin{tabular}{cr@{}c@{}ll}
  327. Type & \multicolumn{3}{c}{Bounds} & Comment \\
  328. \hline
  329. \verb|GLP_FR| & $-\infty <$ &$\ x\ $& $< +\infty$
  330. & Free (unbounded) variable \\
  331. \verb|GLP_LO| & $lb \leq$ &$\ x\ $& $< +\infty$
  332. & Variable with lower bound \\
  333. \verb|GLP_UP| & $-\infty <$ &$\ x\ $& $\leq ub$
  334. & Variable with upper bound \\
  335. \verb|GLP_DB| & $lb \leq$ &$\ x\ $& $\leq ub$
  336. & Double-bounded variable \\
  337. \verb|GLP_FX| & $lb =$ &$\ x\ $& $= ub$
  338. & Fixed variable \\
  339. \end{tabular}
  340. \end{center}
  341. \noindent
  342. where $x$ is the structural variable associated with $j$-th column.
  343. If the column has no lower bound, the parameter \verb|lb| is ignored.
  344. If the column has no upper bound, the parameter \verb|ub| is ignored.
  345. If the column is of fixed type, only the parameter \verb|lb| is used
  346. while the parameter \verb|ub| is ignored.
  347. Being added to the problem object each column is initially fixed at
  348. zero, i.e. its type is \verb|GLP_FX| and both bounds are 0.
  349. \subsection{glp\_set\_obj\_coef --- set (change) objective coefficient
  350. or constant term}
  351. \synopsis
  352. \begin{verbatim}
  353. void glp_set_obj_coef(glp_prob *P, int j, double coef);
  354. \end{verbatim}
  355. \description
  356. The routine \verb|glp_set_obj_coef| sets (changes) the objective
  357. coefficient at \verb|j|-th column (structural variable). A new value of
  358. the objective coefficient is specified by the parameter \verb|coef|.
  359. If the parameter \verb|j| is 0, the routine sets (changes) the constant
  360. term (``shift'') of the objective function.
  361. \newpage
  362. \subsection{glp\_set\_mat\_row --- set (replace) row of the constraint
  363. matrix}
  364. \synopsis
  365. \begin{verbatim}
  366. void glp_set_mat_row(glp_prob *P, int i, int len, const int ind[],
  367. const double val[]);
  368. \end{verbatim}
  369. \description
  370. The routine \verb|glp_set_mat_row| stores (replaces) the contents of
  371. \verb|i|-th row of the constraint matrix of the specified problem
  372. object.
  373. Column indices and numerical values of new row elements should be
  374. placed in locations\linebreak \verb|ind[1]|, \dots, \verb|ind[len]| and
  375. \verb|val[1]|, \dots, \verb|val[len]|, respectively, where
  376. $0 \leq$ \verb|len| $\leq n$ is the new length of $i$-th row, $n$ is
  377. the current number of columns in the problem object. Elements with
  378. identical column indices are not allowed. Zero elements are allowed,
  379. but they are not stored in the constraint matrix.
  380. If the parameter \verb|len| is 0, the parameters \verb|ind| and/or
  381. \verb|val| can be specified as \verb|NULL|.
  382. \subsection{glp\_set\_mat\_col --- set (replace) column of the
  383. constr\-aint matrix}
  384. \synopsis
  385. \begin{verbatim}
  386. void glp_set_mat_col(glp_prob *P, int j, int len, const int ind[],
  387. const double val[]);
  388. \end{verbatim}
  389. \description
  390. The routine \verb|glp_set_mat_col| stores (replaces) the contents of
  391. \verb|j|-th column of the constraint matrix of the specified problem
  392. object.
  393. Row indices and numerical values of new column elements should be
  394. placed in locations\linebreak \verb|ind[1]|, \dots, \verb|ind[len]| and
  395. \verb|val[1]|, \dots, \verb|val[len]|, respectively, where
  396. $0 \leq$ \verb|len| $\leq m$ is the new length of $j$-th column, $m$ is
  397. the current number of rows in the problem object. Elements with
  398. identical row indices are not allowed. Zero elements are allowed, but
  399. they are not stored in the constraint matrix.
  400. If the parameter \verb|len| is 0, the parameters \verb|ind| and/or
  401. \verb|val| can be specified as \verb|NULL|.
  402. \subsection{glp\_load\_matrix --- load (replace) the whole constraint
  403. matrix}
  404. \synopsis
  405. \begin{verbatim}
  406. void glp_load_matrix(glp_prob *P, int ne, const int ia[],
  407. const int ja[], const double ar[]);
  408. \end{verbatim}
  409. \description
  410. The routine \verb|glp_load_matrix| loads the constraint matrix passed
  411. in the arrays \verb|ia|, \verb|ja|, and \verb|ar| into the specified
  412. problem object. Before loading the current contents of the constraint
  413. matrix is destroyed.
  414. Constraint coefficients (elements of the constraint matrix) should be
  415. specified as triplets (\verb|ia[k]|, \verb|ja[k]|, \verb|ar[k]|) for
  416. $k=1,\dots,ne$, where \verb|ia[k]| is the row index, \verb|ja[k]| is
  417. the column index, and \verb|ar[k]| is a numeric value of corresponding
  418. constraint coefficient. The parameter \verb|ne| specifies the total
  419. number of (non-zero) elements in the matrix to be loaded. Coefficients
  420. with identical indices are not allowed. Zero coefficients are allowed,
  421. however, they are not stored in the constraint matrix.
  422. If the parameter \verb|ne| is 0, the parameters \verb|ia|, \verb|ja|,
  423. and/or \verb|ar| can be specified as \verb|NULL|.
  424. \subsection{glp\_check\_dup --- check for duplicate elements in sparse
  425. matrix}
  426. \synopsis
  427. {\tt int glp\_check\_dup(int m, int n, int ne, const int ia[],
  428. const int ja[]);}
  429. \description
  430. The routine \verb|glp_check_dup checks| for duplicate elements (that
  431. is, elements with identical indices) in a sparse matrix specified in
  432. the coordinate format.
  433. The parameters $m$ and $n$ specifies, respectively, the number of rows
  434. and columns in the matrix, $m\geq 0$, $n\geq 0$.
  435. The parameter {\it ne} specifies the number of (structurally) non-zero
  436. elements in the matrix,\linebreak {\it ne} $\geq 0$.
  437. Elements of the matrix are specified as doublets $(ia[k],ja[k])$ for
  438. $k=1,\dots,ne$, where $ia[k]$ is a row index, $ja[k]$ is a column
  439. index.
  440. The routine \verb|glp_check_dup| can be used prior to a call to the
  441. routine \verb|glp_load_matrix| to check that the constraint matrix to
  442. be loaded has no duplicate elements.
  443. \returns
  444. \begin{retlist}
  445. 0& the matrix representation is correct;\\
  446. $-k$& indices $ia[k]$ or/and $ja[k]$ are out of range;\\
  447. $+k$& element $(ia[k],ja[k])$ is duplicate.\\
  448. \end{retlist}
  449. \subsection{glp\_sort\_matrix --- sort elements of the constraint
  450. matrix}
  451. \synopsis
  452. \begin{verbatim}
  453. void glp_sort_matrix(glp_prob *P);
  454. \end{verbatim}
  455. \description
  456. The routine \verb|glp_sort_matrix| sorts elements of the constraint
  457. matrix by rebuilding its row and column linked lists.
  458. On exit from the routine the constraint matrix is not changed, however,
  459. elements in the row linked lists become ordered by ascending column
  460. indices, and the elements in the column linked lists become ordered by
  461. ascending row indices.
  462. \subsection{glp\_del\_rows --- delete rows from problem object}
  463. \synopsis
  464. \begin{verbatim}
  465. void glp_del_rows(glp_prob *P, int nrs, const int num[]);
  466. \end{verbatim}
  467. \description
  468. The routine \verb|glp_del_rows| deletes rows from the specified problem
  469. object. Ordinal numbers of rows to be deleted should be placed in
  470. locations \verb|num[1]|, \dots, \verb|num[nrs]|, where ${\tt nrs}>0$.
  471. Note that deleting rows involves changing ordinal numbers of other
  472. rows remaining in the problem object. New ordinal numbers of the
  473. remaining rows are assigned under the assumption that the original
  474. order of rows is not changed. Let, for example, before deletion there
  475. be five rows $a$, $b$, $c$, $d$, $e$ with ordinal numbers 1, 2, 3, 4,
  476. 5, and let rows $b$ and $d$ have been deleted. Then after deletion the
  477. remaining rows $a$, $c$, $e$ are assigned new oridinal numbers 1, 2, 3.
  478. \subsection{glp\_del\_cols --- delete columns from problem object}
  479. \synopsis
  480. \begin{verbatim}
  481. void glp_del_cols(glp_prob *P, int ncs, const int num[]);
  482. \end{verbatim}
  483. \description
  484. The routine \verb|glp_del_cols| deletes columns from the specified
  485. problem object. Ordinal numbers of columns to be deleted should be
  486. placed in locations \verb|num[1]|, \dots, \verb|num[ncs]|, where
  487. ${\tt ncs}>0$.
  488. Note that deleting columns involves changing ordinal numbers of other
  489. columns remaining in\linebreak the problem object. New ordinal numbers
  490. of the remaining columns are assigned under the assumption that the
  491. original order of columns is not changed. Let, for example, before
  492. deletion there be six columns $p$, $q$, $r$, $s$, $t$, $u$ with
  493. ordinal numbers 1, 2, 3, 4, 5, 6, and let columns $p$, $q$, $s$ have
  494. been deleted. Then after deletion the remaining columns $r$, $t$, $u$
  495. are assigned new ordinal numbers 1, 2, 3.
  496. \subsection{glp\_copy\_prob --- copy problem object content}
  497. \synopsis
  498. \begin{verbatim}
  499. void glp_copy_prob(glp_prob *dest, glp_prob *prob, int names);
  500. \end{verbatim}
  501. \description
  502. The routine \verb|glp_copy_prob| copies the content of the problem
  503. object \verb|prob| to the problem object \verb|dest|.
  504. The parameter \verb|names| is a flag. If it is \verb|GLP_ON|,
  505. the routine also copies all symbolic names; otherwise, if it is
  506. \verb|GLP_OFF|, no symbolic names are copied.
  507. \newpage
  508. \subsection{glp\_erase\_prob --- erase problem object content}
  509. \synopsis
  510. \begin{verbatim}
  511. void glp_erase_prob(glp_prob *P);
  512. \end{verbatim}
  513. \description
  514. The routine \verb|glp_erase_prob| erases the content of the specified
  515. problem object. The effect of this operation is the same as if the
  516. problem object would be deleted with the routine \verb|glp_delete_prob|
  517. and then created anew with the routine \verb|glp_create_prob|, with the
  518. only exception that the pointer to the problem object remains valid.
  519. \subsection{glp\_delete\_prob --- delete problem object}
  520. \synopsis
  521. \begin{verbatim}
  522. void glp_delete_prob(glp_prob *P);
  523. \end{verbatim}
  524. \description
  525. The routine \verb|glp_delete_prob| deletes a problem object, which the
  526. parameter \verb|lp| points to, freeing all the memory allocated to this
  527. object.
  528. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  529. \newpage
  530. \section{Problem retrieving routines}
  531. \subsection{glp\_get\_prob\_name --- retrieve problem name}
  532. \synopsis
  533. \begin{verbatim}
  534. const char *glp_get_prob_name(glp_prob *P);
  535. \end{verbatim}
  536. \returns
  537. The routine \verb|glp_get_prob_name| returns a pointer to an internal
  538. buffer, which contains symbolic name of the problem. However, if the
  539. problem has no assigned name, the routine returns \verb|NULL|.
  540. \subsection{glp\_get\_obj\_name --- retrieve objective function name}
  541. \synopsis
  542. \begin{verbatim}
  543. const char *glp_get_obj_name(glp_prob *P);
  544. \end{verbatim}
  545. \returns
  546. The routine \verb|glp_get_obj_name| returns a pointer to an internal
  547. buffer, which contains symbolic name assigned to the objective
  548. function. However, if the objective function has no assigned name, the
  549. routine returns \verb|NULL|.
  550. \subsection{glp\_get\_obj\_dir --- retrieve optimization direction
  551. flag}
  552. \synopsis
  553. \begin{verbatim}
  554. int glp_get_obj_dir(glp_prob *P);
  555. \end{verbatim}
  556. \returns
  557. The routine \verb|glp_get_obj_dir| returns the optimization direction
  558. flag (i.e. ``sense'' of the objective function):
  559. \verb|GLP_MIN| means minimization;
  560. \verb|GLP_MAX| means maximization.
  561. \subsection{glp\_get\_num\_rows --- retrieve number of rows}
  562. \synopsis
  563. \begin{verbatim}
  564. int glp_get_num_rows(glp_prob *P);
  565. \end{verbatim}
  566. \returns
  567. The routine \verb|glp_get_num_rows| returns the current number of rows
  568. in the specified problem object.
  569. \subsection{glp\_get\_num\_cols --- retrieve number of columns}
  570. \synopsis
  571. \begin{verbatim}
  572. int glp_get_num_cols(glp_prob *P);
  573. \end{verbatim}
  574. \returns
  575. The routine \verb|glp_get_num_cols| returns the current number of
  576. columns in the specified problem object.
  577. \subsection{glp\_get\_row\_name --- retrieve row name}
  578. \synopsis
  579. \begin{verbatim}
  580. const char *glp_get_row_name(glp_prob *P, int i);
  581. \end{verbatim}
  582. \returns
  583. The routine \verb|glp_get_row_name| returns a pointer to an internal
  584. buffer, which contains a symbolic name assigned to \verb|i|-th row.
  585. However, if the row has no assigned name, the routine returns
  586. \verb|NULL|.
  587. \subsection{glp\_get\_col\_name --- retrieve column name}
  588. \synopsis
  589. \begin{verbatim}
  590. const char *glp_get_col_name(glp_prob *P, int j);
  591. \end{verbatim}
  592. \returns
  593. The routine \verb|glp_get_col_name| returns a pointer to an internal
  594. buffer, which contains a symbolic name assigned to \verb|j|-th column.
  595. However, if the column has no assigned name, the routine returns
  596. \verb|NULL|.
  597. \subsection{glp\_get\_row\_type --- retrieve row type}
  598. \synopsis
  599. \begin{verbatim}
  600. int glp_get_row_type(glp_prob *P, int i);
  601. \end{verbatim}
  602. \returns
  603. The routine \verb|glp_get_row_type| returns the type of \verb|i|-th
  604. row, i.e. the type of corresponding auxiliary variable, as follows:
  605. \verb|GLP_FR| --- free (unbounded) variable;
  606. \verb|GLP_LO| --- variable with lower bound;
  607. \verb|GLP_UP| --- variable with upper bound;
  608. \verb|GLP_DB| --- double-bounded variable;
  609. \verb|GLP_FX| --- fixed variable.
  610. \subsection{glp\_get\_row\_lb --- retrieve row lower bound}
  611. \synopsis
  612. \begin{verbatim}
  613. double glp_get_row_lb(glp_prob *P, int i);
  614. \end{verbatim}
  615. \returns
  616. The routine \verb|glp_get_row_lb| returns the lower bound of
  617. \verb|i|-th row, i.e. the lower bound of corresponding auxiliary
  618. variable. However, if the row has no lower bound, the routine returns
  619. \verb|-DBL_MAX|.
  620. \vspace*{-4pt}
  621. \subsection{glp\_get\_row\_ub --- retrieve row upper bound}
  622. \synopsis
  623. \begin{verbatim}
  624. double glp_get_row_ub(glp_prob *P, int i);
  625. \end{verbatim}
  626. \returns
  627. The routine \verb|glp_get_row_ub| returns the upper bound of
  628. \verb|i|-th row, i.e. the upper bound of corresponding auxiliary
  629. variable. However, if the row has no upper bound, the routine returns
  630. \verb|+DBL_MAX|.
  631. \vspace*{-4pt}
  632. \subsection{glp\_get\_col\_type --- retrieve column type}
  633. \synopsis
  634. \begin{verbatim}
  635. int glp_get_col_type(glp_prob *P, int j);
  636. \end{verbatim}
  637. \returns
  638. The routine \verb|glp_get_col_type| returns the type of \verb|j|-th
  639. column, i.e. the type of corresponding structural variable, as follows:
  640. \verb|GLP_FR| --- free (unbounded) variable;
  641. \verb|GLP_LO| --- variable with lower bound;
  642. \verb|GLP_UP| --- variable with upper bound;
  643. \verb|GLP_DB| --- double-bounded variable;
  644. \verb|GLP_FX| --- fixed variable.
  645. \vspace*{-4pt}
  646. \subsection{glp\_get\_col\_lb --- retrieve column lower bound}
  647. \synopsis
  648. \begin{verbatim}
  649. double glp_get_col_lb(glp_prob *P, int j);
  650. \end{verbatim}
  651. \returns
  652. The routine \verb|glp_get_col_lb| returns the lower bound of
  653. \verb|j|-th column, i.e. the lower bound of corresponding structural
  654. variable. However, if the column has no lower bound, the routine
  655. returns \verb|-DBL_MAX|.
  656. \subsection{glp\_get\_col\_ub --- retrieve column upper bound}
  657. \synopsis
  658. \begin{verbatim}
  659. double glp_get_col_ub(glp_prob *P, int j);
  660. \end{verbatim}
  661. \returns
  662. The routine \verb|glp_get_col_ub| returns the upper bound of
  663. \verb|j|-th column, i.e. the upper bound of corresponding structural
  664. variable. However, if the column has no upper bound, the routine
  665. returns \verb|+DBL_MAX|.
  666. \subsection{glp\_get\_obj\_coef --- retrieve objective coefficient or
  667. constant term}
  668. \synopsis
  669. \begin{verbatim}
  670. double glp_get_obj_coef(glp_prob *P, int j);
  671. \end{verbatim}
  672. \returns
  673. The routine \verb|glp_get_obj_coef| returns the objective coefficient
  674. at \verb|j|-th structural variable (column).
  675. If the parameter \verb|j| is 0, the routine returns the constant term
  676. (``shift'') of the objective function.
  677. \subsection{glp\_get\_num\_nz --- retrieve number of constraint
  678. coefficients}
  679. \synopsis
  680. \begin{verbatim}
  681. int glp_get_num_nz(glp_prob *P);
  682. \end{verbatim}
  683. \returns
  684. The routine \verb|glp_get_num_nz| returns the number of non-zero
  685. elements in the constraint matrix of the specified problem object.
  686. \subsection{glp\_get\_mat\_row --- retrieve row of the constraint
  687. matrix}
  688. \synopsis
  689. \begin{verbatim}
  690. int glp_get_mat_row(glp_prob *P, int i, int ind[], double val[]);
  691. \end{verbatim}
  692. \description
  693. The routine \verb|glp_get_mat_row| scans (non-zero) elements of
  694. \verb|i|-th row of the constraint matrix of the specified problem
  695. object and stores their column indices and numeric values to locations
  696. \verb|ind[1]|, \dots, \verb|ind[len]| and \verb|val[1]|, \dots,
  697. \verb|val[len]|, respectively, where $0\leq{\tt len}\leq n$ is the
  698. number of elements in $i$-th row, $n$ is the number of columns.
  699. The parameter \verb|ind| and/or \verb|val| can be specified as
  700. \verb|NULL|, in which case corresponding information is not stored.
  701. \newpage
  702. \returns
  703. The routine \verb|glp_get_mat_row| returns the length \verb|len|, i.e.
  704. the number of (non-zero) elements in \verb|i|-th row.
  705. \subsection{glp\_get\_mat\_col --- retrieve column of the constraint
  706. matrix}
  707. \synopsis
  708. \begin{verbatim}
  709. int glp_get_mat_col(glp_prob *P, int j, int ind[], double val[]);
  710. \end{verbatim}
  711. \description
  712. The routine \verb|glp_get_mat_col| scans (non-zero) elements of
  713. \verb|j|-th column of the constraint matrix of the specified problem
  714. object and stores their row indices and numeric values to locations
  715. \linebreak \verb|ind[1]|, \dots, \verb|ind[len]| and \verb|val[1]|,
  716. \dots, \verb|val[len]|, respectively, where $0\leq{\tt len}\leq m$ is
  717. the number of elements in $j$-th column, $m$ is the number of rows.
  718. The parameter \verb|ind| and/or \verb|val| can be specified as
  719. \verb|NULL|, in which case corresponding information is not stored.
  720. \returns
  721. The routine \verb|glp_get_mat_col| returns the length \verb|len|, i.e.
  722. the number of (non-zero) elements in \verb|j|-th column.
  723. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  724. \newpage
  725. \section{Row and column searching routines}
  726. Sometimes it may be necessary to find rows and/or columns by their
  727. names (assigned with the routines \verb|glp_set_row_name| and
  728. \verb|glp_set_col_name|). Though a particular row/column can be found
  729. by its name using simple enumeration of all rows/columns, in case of
  730. large instances such a {\it linear} search may take too long time.
  731. To significantly reduce the search time the application program may
  732. create the row/column name index, which is an auxiliary data structure
  733. implementing a {\it binary} search. Even in worst cases the search
  734. takes logarithmic time, i.e. the time needed to find a particular row
  735. (or column) by its name is $O(\log_2m)$ (or $O(\log_2n)$), where $m$
  736. and $n$ are, resp., the number of rows and columns in the problem
  737. object.
  738. It is important to note that:
  739. 1. On creating the problem object with the routine
  740. \verb|glp_create_prob| the name index is {\it not} created.
  741. 2. The name index can be created (destroyed) at any time with the
  742. routine \verb|glp_create_index| (\verb|glp_delete_index|). Having been
  743. created the name index becomes part of the corresponding problem
  744. object.
  745. 3. The time taken to create the name index is $O[(m+n)\log_2(m+n)]$,
  746. so it is recommended to create the index only once, for example, just
  747. after the problem object was created.
  748. 4. If the name index exists, it is automatically updated every time
  749. the name of a row/column is assigned/changed. The update operation
  750. takes logarithmic time.
  751. 5. If the name index does not exist, the application should not call
  752. the routines \verb|glp_find_row| and \verb|glp_find_col|. Otherwise,
  753. an error message will be issued and abnormal program termination will
  754. occur.
  755. 6. On destroying the problem object with the routine
  756. \verb|glp_delete_prob|, the name index, if exists, is automatically
  757. destroyed.
  758. \subsection{glp\_create\_index --- create the name index}
  759. \synopsis
  760. \begin{verbatim}
  761. void glp_create_index(glp_prob *P);
  762. \end{verbatim}
  763. \description
  764. The routine \verb|glp_create_index| creates the name index for the
  765. specified problem object. The name index is an auxiliary data
  766. structure, which is intended to quickly (i.e. for logarithmic time)
  767. find rows and columns by their names.
  768. This routine can be called at any time. If the name index already
  769. exists, the routine does nothing.
  770. \newpage
  771. \subsection{glp\_find\_row --- find row by its name}
  772. \synopsis
  773. \begin{verbatim}
  774. int glp_find_row(glp_prob *P, const char *name);
  775. \end{verbatim}
  776. \returns
  777. The routine \verb|glp_find_row| returns the ordinal number of a row,
  778. which is assigned the specified symbolic \verb|name|. If no such row
  779. exists, the routine returns 0.
  780. \subsection{glp\_find\_col --- find column by its name}
  781. \synopsis
  782. \begin{verbatim}
  783. int glp_find_col(glp_prob *P, const char *name);
  784. \end{verbatim}
  785. \returns
  786. The routine \verb|glp_find_col| returns the ordinal number of a column,
  787. which is assigned the specified symbolic \verb|name|. If no such column
  788. exists, the routine returns 0.
  789. \subsection{glp\_delete\_index --- delete the name index}
  790. \synopsis
  791. \begin{verbatim}
  792. void glp_delete_index(glp_prob *P);
  793. \end{verbatim}
  794. \description
  795. The routine \verb|glp_delete_index| deletes the name index previously
  796. created by the routine\linebreak \verb|glp_create_index| and frees the
  797. memory allocated to this auxiliary data structure.
  798. This routine can be called at any time. If the name index does not
  799. exist, the routine does nothing.
  800. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  801. \newpage
  802. \section{Problem scaling routines}
  803. \subsection{Background}
  804. In GLPK the {\it scaling} means a linear transformation applied to the
  805. constraint matrix to improve its numerical properties.\footnote{In many
  806. cases a proper scaling allows making the constraint matrix to be better
  807. conditioned, i.e. decreasing its condition number, that makes
  808. computations numerically more stable.}
  809. The main equality is the following:
  810. $$\widetilde{A}=RAS,\eqno(2.1)$$
  811. where $A=(a_{ij})$ is the original constraint matrix, $R=(r_{ii})>0$ is
  812. a diagonal matrix used to scale rows (constraints), $S=(s_{jj})>0$ is a
  813. diagonal matrix used to scale columns (variables), $\widetilde{A}$ is
  814. the scaled constraint matrix.
  815. From (2.1) it follows that in the {\it scaled} problem instance each
  816. original constraint coefficient $a_{ij}$ is replaced by corresponding
  817. scaled constraint coefficient:
  818. $$\widetilde{a}_{ij}=r_{ii}a_{ij}s_{jj}.\eqno(2.2)$$
  819. Note that the scaling is performed internally and therefore
  820. transparently to the user. This means that on API level the user always
  821. deal with unscaled data.
  822. Scale factors $r_{ii}$ and $s_{jj}$ can be set or changed at any time
  823. either directly by the application program in a problem specific way
  824. (with the routines \verb|glp_set_rii| and \verb|glp_set_sjj|), or by
  825. some API routines intended for automatic scaling.
  826. \subsection{glp\_set\_rii --- set (change) row scale factor}
  827. \synopsis
  828. \begin{verbatim}
  829. void glp_set_rii(glp_prob *P, int i, double rii);
  830. \end{verbatim}
  831. \description
  832. The routine \verb|glp_set_rii| sets (changes) the scale factor $r_{ii}$
  833. for $i$-th row of the specified problem object.
  834. \subsection{glp\_set\_sjj --- set (change) column scale factor}
  835. \synopsis
  836. \begin{verbatim}
  837. void glp_set_sjj(glp_prob *P, int j, double sjj);
  838. \end{verbatim}
  839. \description
  840. The routine \verb|glp_set_sjj| sets (changes) the scale factor $s_{jj}$
  841. for $j$-th column of the specified problem object.
  842. \subsection{glp\_get\_rii --- retrieve row scale factor}
  843. \synopsis
  844. \begin{verbatim}
  845. double glp_get_rii(glp_prob *P, int i);
  846. \end{verbatim}
  847. \returns
  848. The routine \verb|glp_get_rii| returns current scale factor $r_{ii}$
  849. for $i$-th row of the specified problem object.
  850. \vspace*{-6pt}
  851. \subsection{glp\_get\_sjj --- retrieve column scale factor}
  852. \vspace*{-4pt}
  853. \synopsis
  854. \begin{verbatim}
  855. double glp_get_sjj(glp_prob *P, int j);
  856. \end{verbatim}
  857. \returns
  858. The routine \verb|glp_get_sjj| returns current scale factor $s_{jj}$
  859. for $j$-th column of the specified problem object.
  860. \vspace*{-6pt}
  861. \subsection{glp\_scale\_prob --- scale problem data}
  862. \vspace*{-4pt}
  863. \synopsis
  864. \begin{verbatim}
  865. void glp_scale_prob(glp_prob *P, int flags);
  866. \end{verbatim}
  867. \description
  868. The routine \verb|glp_scale_prob| performs automatic scaling of problem
  869. data for the specified problem object.
  870. The parameter \verb|flags| specifies scaling options used by the
  871. routine. The options can be combined with the bitwise OR operator and
  872. may be the following:
  873. \verb|GLP_SF_GM | --- perform geometric mean scaling;
  874. \verb|GLP_SF_EQ | --- perform equilibration scaling;
  875. \verb|GLP_SF_2N | --- round scale factors to nearest power of two;
  876. \verb|GLP_SF_SKIP| --- skip scaling, if the problem is well scaled.
  877. The parameter \verb|flags| may be also specified as \verb|GLP_SF_AUTO|,
  878. in which case the routine chooses the scaling options automatically.
  879. \vspace*{-6pt}
  880. \subsection{glp\_unscale\_prob --- unscale problem data}
  881. \vspace*{-4pt}
  882. \synopsis
  883. \begin{verbatim}
  884. void glp_unscale_prob(glp_prob *P);
  885. \end{verbatim}
  886. The routine \verb|glp_unscale_prob| performs unscaling of problem data
  887. for the specified problem object.
  888. ``Unscaling'' means replacing the current scaling matrices $R$ and $S$
  889. by unity matrices that cancels the scaling effect.
  890. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  891. \newpage
  892. \section{LP basis constructing routines}
  893. \subsection{Background}
  894. To start the search the simplex method needs a valid initial basis.
  895. In GLPK the basis is completely defined by a set of {\it statuses}
  896. assigned to {\it all} (auxiliary and structural) variables, where the
  897. status may be one of the following:
  898. \verb|GLP_BS| --- basic variable;
  899. \verb|GLP_NL| --- non-basic variable having active lower bound;
  900. \verb|GLP_NU| --- non-basic variable having active upper bound;
  901. \verb|GLP_NF| --- non-basic free variable;
  902. \verb|GLP_NS| --- non-basic fixed variable.
  903. The basis is {\it valid}, if the basis matrix, which is a matrix built
  904. of columns of the augmented constraint matrix $(I\:|-A)$ corresponding
  905. to basic variables, is non-singular. This, in particular, means that
  906. the number of basic variables must be the same as the number of rows in
  907. the problem object. (For more details see Section \ref{lpbasis}, page
  908. \pageref{lpbasis}.)
  909. Any initial basis may be constructed (or restored) with the API
  910. routines \verb|glp_set_row_stat| and \verb|glp_set_col_stat| by
  911. assigning appropriate statuses to auxiliary and structural variables.
  912. Another way to construct an initial basis is to use API routines like
  913. \verb|glp_adv_basis|, which implement so called
  914. {\it crashing}.\footnote{This term is from early linear programming
  915. systems and means a heuristic to construct a valid initial basis.} Note
  916. that on normal exit the simplex solver remains the basis valid, so in
  917. case of reoptimization there is no need to construct an initial basis
  918. from scratch.
  919. \subsection{glp\_set\_row\_stat --- set (change) row status}
  920. \synopsis
  921. \begin{verbatim}
  922. void glp_set_row_stat(glp_prob *P, int i, int stat);
  923. \end{verbatim}
  924. \description
  925. The routine \verb|glp_set_row_stat| sets (changes) the current status
  926. of \verb|i|-th row (auxiliary variable) as specified by the parameter
  927. \verb|stat|:
  928. \verb|GLP_BS| --- make the row basic (make the constraint inactive);
  929. \verb|GLP_NL| --- make the row non-basic (make the constraint active);
  930. \verb|GLP_NU| --- make the row non-basic and set it to the upper bound;
  931. if the row is not double-bounded, this status is equivalent to
  932. \verb|GLP_NL| (only in case of this routine);
  933. \verb|GLP_NF| --- the same as \verb|GLP_NL| (only in case of this
  934. routine);
  935. \verb|GLP_NS| --- the same as \verb|GLP_NL| (only in case of this
  936. routine).
  937. \newpage
  938. \subsection{glp\_set\_col\_stat --- set (change) column status}
  939. \synopsis
  940. \begin{verbatim}
  941. void glp_set_col_stat(glp_prob *P, int j, int stat);
  942. \end{verbatim}
  943. \description
  944. The routine \verb|glp_set_col_stat sets| (changes) the current status
  945. of \verb|j|-th column (structural variable) as specified by the
  946. parameter \verb|stat|:
  947. \verb|GLP_BS| --- make the column basic;
  948. \verb|GLP_NL| --- make the column non-basic;
  949. \verb|GLP_NU| --- make the column non-basic and set it to the upper
  950. bound; if the column is not double-bounded, this status is equivalent
  951. to \verb|GLP_NL| (only in case of this routine);
  952. \verb|GLP_NF| --- the same as \verb|GLP_NL| (only in case of this
  953. routine);
  954. \verb|GLP_NS| --- the same as \verb|GLP_NL| (only in case of this
  955. routine).
  956. \subsection{glp\_std\_basis --- construct standard initial LP basis}
  957. \synopsis
  958. \begin{verbatim}
  959. void glp_std_basis(glp_prob *P);
  960. \end{verbatim}
  961. \description
  962. The routine \verb|glp_std_basis| constructs the ``standard'' (trivial)
  963. initial LP basis for the specified problem object.
  964. In the ``standard'' LP basis all auxiliary variables (rows) are basic,
  965. and all structural variables (columns) are non-basic (so the
  966. corresponding basis matrix is unity).
  967. \subsection{glp\_adv\_basis --- construct advanced initial LP basis}
  968. \synopsis
  969. \begin{verbatim}
  970. void glp_adv_basis(glp_prob *P, int flags);
  971. \end{verbatim}
  972. \description
  973. The routine \verb|glp_adv_basis| constructs an advanced initial LP
  974. basis for the specified problem object.
  975. The parameter \verb|flags| is reserved for use in the future and must
  976. be specified as zero.
  977. In order to construct the advanced initial LP basis the routine does
  978. the following:
  979. 1) includes in the basis all non-fixed auxiliary variables;
  980. 2) includes in the basis as many non-fixed structural variables as
  981. possible keeping the triangular form of the basis matrix;
  982. 3) includes in the basis appropriate (fixed) auxiliary variables to
  983. complete the basis.
  984. As a result the initial LP basis has as few fixed variables as possible
  985. and the corresponding basis matrix is triangular.
  986. \subsection{glp\_cpx\_basis --- construct Bixby's initial LP basis}
  987. \synopsis
  988. \begin{verbatim}
  989. void glp_cpx_basis(glp_prob *P);
  990. \end{verbatim}
  991. \description
  992. The routine \verb|glp_cpx_basis| constructs an initial basis for the
  993. specified problem object with the algorithm proposed by
  994. R.~Bixby.\footnote{Robert E. Bixby, ``Implementing the Simplex Method:
  995. The Initial Basis.'' ORSA Journal on Computing, Vol. 4, No. 3, 1992,
  996. pp. 267-84.}
  997. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  998. \newpage
  999. \section{Simplex method routines}
  1000. The {\it simplex method} is a well known efficient numerical procedure
  1001. to solve LP problems.
  1002. On each iteration the simplex method transforms the original system of
  1003. equaility constraints (1.2) resolving them through different sets of
  1004. variables to an equivalent system called {\it the simplex table} (or
  1005. sometimes {\it the simplex tableau}), which has the following form:
  1006. $$
  1007. \begin{array}{r@{\:}c@{\:}r@{\:}c@{\:}r@{\:}c@{\:}r}
  1008. z&=&d_1(x_N)_1&+&d_2(x_N)_2&+ \dots +&d_n(x_N)_n \\
  1009. (x_B)_1&=&\xi_{11}(x_N)_1& +& \xi_{12}(x_N)_2& + \dots +&
  1010. \xi_{1n}(x_N)_n \\
  1011. (x_B)_2&=& \xi_{21}(x_N)_1& +& \xi_{22}(x_N)_2& + \dots +&
  1012. \xi_{2n}(x_N)_n \\
  1013. \multicolumn{7}{c}
  1014. {.\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .} \\
  1015. (x_B)_m&=&\xi_{m1}(x_N)_1& +& \xi_{m2}(x_N)_2& + \dots +&
  1016. \xi_{mn}(x_N)_n \\
  1017. \end{array} \eqno (2.3)
  1018. $$
  1019. where: $(x_B)_1, (x_B)_2, \dots, (x_B)_m$ are basic variables;
  1020. $(x_N)_1, (x_N)_2, \dots, (x_N)_n$ are non-basic variables;
  1021. $d_1, d_2, \dots, d_n$ are reduced costs;
  1022. $\xi_{11}, \xi_{12}, \dots, \xi_{mn}$ are coefficients of the
  1023. simplex table. (May note that the original LP problem (1.1)---(1.3)
  1024. also has the form of a simplex table, where all equalities are resolved
  1025. through auxiliary variables.)
  1026. From the linear programming theory it is known that if an optimal
  1027. solution of the LP problem (1.1)---(1.3) exists, it can always be
  1028. written in the form (2.3), where non-basic variables are set on their
  1029. bounds while values of the objective function and basic variables are
  1030. determined by the corresponding equalities of the simplex table.
  1031. A set of values of all basic and non-basic variables determined by the
  1032. simplex table is called {\it basic solution}. If all basic variables
  1033. are within their bounds, the basic solution is called {\it (primal)
  1034. feasible}, otherwise it is called {\it (primal) infeasible}. A feasible
  1035. basic solution, which provides a smallest (in case of minimization) or
  1036. a largest (in case of maximization) value of the objective function is
  1037. called {\it optimal}. Therefore, for solving LP problem the simplex
  1038. method tries to find its optimal basic solution.
  1039. Primal feasibility of some basic solution may be stated by simple
  1040. checking if all basic variables are within their bounds. Basic solution
  1041. is optimal if additionally the following optimality conditions are
  1042. satisfied for all non-basic variables:
  1043. \begin{center}
  1044. \begin{tabular}{lcc}
  1045. Status of $(x_N)_j$ & Minimization & Maximization \\
  1046. \hline
  1047. $(x_N)_j$ is free & $d_j = 0$ & $d_j = 0$ \\
  1048. $(x_N)_j$ is on its lower bound & $d_j \geq 0$ & $d_j \leq 0$ \\
  1049. $(x_N)_j$ is on its upper bound & $d_j \leq 0$ & $d_j \geq 0$ \\
  1050. \end{tabular}
  1051. \end{center}
  1052. In other words, basic solution is optimal if there is no non-basic
  1053. variable, which changing in the feasible direction (i.e. increasing if
  1054. it is free or on its lower bound, or decreasing if it is free or on its
  1055. upper bound) can improve (i.e. decrease in case of minimization or
  1056. increase in case of maximization) the objective function.
  1057. If all non-basic variables satisfy to the optimality conditions shown
  1058. above (independently on whether basic variables are within their bounds
  1059. or not), the basic solution is called {\it dual feasible}, otherwise it
  1060. is called {\it dual infeasible}.
  1061. It may happen that some LP problem has no primal feasible solution due
  1062. to incorrect\linebreak formulation --- this means that its constraints
  1063. conflict with each other. It also may happen that some LP problem has
  1064. unbounded solution again due to incorrect formulation --- this means
  1065. that some non-basic variable can improve the objective function, i.e.
  1066. the optimality conditions are violated, and at the same time this
  1067. variable can infinitely change in the feasible direction meeting
  1068. no resistance from basic variables. (May note that in the latter case
  1069. the LP problem has no dual feasible solution.)
  1070. \subsection{glp\_simplex --- solve LP problem with the primal or dual
  1071. simplex method}
  1072. \synopsis
  1073. \begin{verbatim}
  1074. int glp_simplex(glp_prob *P, const glp_smcp *parm);
  1075. \end{verbatim}
  1076. \description
  1077. The routine \verb|glp_simplex| is a driver to the LP solver based on
  1078. the simplex method. This routine retrieves problem data from the
  1079. specified problem object, calls the solver to solve the problem
  1080. instance, and stores results of computations back into the problem
  1081. object.
  1082. The simplex solver has a set of control parameters. Values of the
  1083. control parameters can be passed in the structure \verb|glp_smcp|,
  1084. which the parameter \verb|parm| points to. For detailed description of
  1085. this structure see paragraph ``Control parameters'' below.
  1086. Before specifying some control parameters the application program
  1087. should initialize the structure \verb|glp_smcp| by default values of
  1088. all control parameters using the routine \verb|glp_init_smcp| (see the
  1089. next subsection). This is needed for backward compatibility, because in
  1090. the future there may appear new members in the structure
  1091. \verb|glp_smcp|.
  1092. The parameter \verb|parm| can be specified as \verb|NULL|, in which
  1093. case the solver uses default settings.
  1094. \returns
  1095. \begin{retlist}
  1096. 0 & The LP problem instance has been successfully solved. (This code
  1097. does {\it not} necessarily mean that the solver has found optimal
  1098. solution. It only means that the solution process was successful.) \\
  1099. \verb|GLP_EBADB| & Unable to start the search, because the initial
  1100. basis specified in the problem object is invalid---the number of basic
  1101. (auxiliary and structural) variables is not the same as the number of
  1102. rows in the problem object.\\
  1103. \verb|GLP_ESING| & Unable to start the search, because the basis matrix
  1104. corresponding to the initial basis is singular within the working
  1105. precision.\\
  1106. \verb|GLP_ECOND| & Unable to start the search, because the basis matrix
  1107. corresponding to the initial basis is ill-conditioned, i.e. its
  1108. condition number is too large.\\
  1109. \verb|GLP_EBOUND| & Unable to start the search, because some
  1110. double-bounded (auxiliary or structural) variables have incorrect
  1111. bounds.\\
  1112. \verb|GLP_EFAIL| & The search was prematurely terminated due to the
  1113. solver failure.\\
  1114. \verb|GLP_EOBJLL| & The search was prematurely terminated, because the
  1115. objective function being maximized has reached its lower limit and
  1116. continues decreasing (the dual simplex only).\\
  1117. \end{retlist}
  1118. \begin{retlist}
  1119. \verb|GLP_EOBJUL| & The search was prematurely terminated, because the
  1120. objective function being minimized has reached its upper limit and
  1121. continues increasing (the dual simplex only).\\
  1122. \verb|GLP_EITLIM| & The search was prematurely terminated, because the
  1123. simplex iteration limit has been exceeded.\\
  1124. \verb|GLP_ETMLIM| & The search was prematurely terminated, because the
  1125. time limit has been exceeded.\\
  1126. \verb|GLP_ENOPFS| & The LP problem instance has no primal feasible
  1127. solution (only if the LP presolver is used).\\
  1128. \verb|GLP_ENODFS| & The LP problem instance has no dual feasible
  1129. solution (only if the LP presolver is used).\\
  1130. \end{retlist}
  1131. \para{Built-in LP presolver}
  1132. The simplex solver has {\it built-in LP presolver}. It is a subprogram
  1133. that transforms the original LP problem specified in the problem object
  1134. to an equivalent LP problem, which may be easier for solving with the
  1135. simplex method than the original one. This is attained mainly due to
  1136. reducing the problem size and improving its numeric properties (for
  1137. example, by removing some inactive constraints or by fixing some
  1138. non-basic variables). Once the transformed LP problem has been solved,
  1139. the presolver transforms its basic solution back to the corresponding
  1140. basic solution of the original problem.
  1141. Presolving is an optional feature of the routine \verb|glp_simplex|,
  1142. and by default it is disabled. In order to enable the LP presolver the
  1143. control parameter \verb|presolve| should be set to \verb|GLP_ON| (see
  1144. paragraph ``Control parameters'' below). Presolving may be used when
  1145. the problem instance is solved for the first time. However, on
  1146. performing re-optimization the presolver should be disabled.
  1147. The presolving procedure is transparent to the API user in the sense
  1148. that all necessary processing is performed internally, and a basic
  1149. solution of the original problem recovered by the presolver is the same
  1150. as if it were computed directly, i.e. without presolving.
  1151. Note that the presolver is able to recover only optimal solutions. If
  1152. a computed solution is infeasible or non-optimal, the corresponding
  1153. solution of the original problem cannot be recovered and therefore
  1154. remains undefined. If you need to know a basic solution even if it is
  1155. infeasible or non-optimal, the presolver should be disabled.
  1156. \para{Terminal output}
  1157. Solving large problem instances may take a long time, so the solver
  1158. reports some information about the current basic solution, which is sent
  1159. to the terminal. This information has the following format:
  1160. \begin{verbatim}
  1161. nnn: obj = xxx infeas = yyy (ddd)
  1162. \end{verbatim}
  1163. \noindent
  1164. where: `\verb|nnn|' is the iteration number, `\verb|xxx|' is the
  1165. current value of the objective function (it is is unscaled and has
  1166. correct sign); `\verb|yyy|' is the current sum of primal or dual
  1167. infeasibilities (it is scaled and therefore may be used only for visual
  1168. estimating), `\verb|ddd|' is the current number of fixed basic
  1169. variables.
  1170. The symbol preceding the iteration number indicates which phase of the
  1171. simplex method is in effect:
  1172. {\it Blank} means that the solver is searching for primal feasible
  1173. solution using the primal simplex or for dual feasible solution using
  1174. the dual simplex;
  1175. {\it Asterisk} (\verb|*|) means that the solver is searching for
  1176. optimal solution using the primal simplex;
  1177. {\it Vertical dash} (\verb/|/) means that the solver is searching for
  1178. optimal solution using the dual simplex.
  1179. \para{Control parameters}
  1180. This paragraph describes all control parameters currently used in the
  1181. simplex solver. Symbolic names of control parameters are names of
  1182. corresponding members in the structure \verb|glp_smcp|.
  1183. \bigskip
  1184. {\tt int msg\_lev} (default: {\tt GLP\_MSG\_ALL})
  1185. Message level for terminal output:
  1186. \verb|GLP_MSG_OFF| --- no output;
  1187. \verb|GLP_MSG_ERR| --- error and warning messages only;
  1188. \verb|GLP_MSG_ON | --- normal output;
  1189. \verb|GLP_MSG_ALL| --- full output (including informational messages).
  1190. \bigskip
  1191. {\tt int meth} (default: {\tt GLP\_PRIMAL})
  1192. Simplex method option:
  1193. \verb|GLP_PRIMAL| --- use two-phase primal simplex;
  1194. \verb|GLP_DUAL | --- use two-phase dual simplex;
  1195. \verb|GLP_DUALP | --- use two-phase dual simplex, and if it fails,
  1196. switch to the primal simplex.
  1197. \bigskip
  1198. {\tt int pricing} (default: {\tt GLP\_PT\_PSE})
  1199. Pricing technique:
  1200. \verb|GLP_PT_STD| --- standard (``textbook'');
  1201. \verb|GLP_PT_PSE| --- projected steepest edge.
  1202. \bigskip
  1203. {\tt int r\_test} (default: {\tt GLP\_RT\_HAR})
  1204. Ratio test technique:
  1205. \verb|GLP_RT_STD| --- standard (``textbook'');
  1206. \verb|GLP_RT_HAR| --- Harris' two-pass ratio test.
  1207. \bigskip
  1208. {\tt double tol\_bnd} (default: {\tt 1e-7})
  1209. Tolerance used to check if the basic solution is primal feasible.
  1210. (Do not change this parameter without detailed understanding its
  1211. purpose.)
  1212. \newpage
  1213. {\tt double tol\_dj} (default: {\tt 1e-7})
  1214. Tolerance used to check if the basic solution is dual feasible.
  1215. (Do not change this parameter without detailed understanding its
  1216. purpose.)
  1217. \bigskip
  1218. {\tt double tol\_piv} (default: {\tt 1e-10})
  1219. Tolerance used to choose eligble pivotal elements of the simplex table.
  1220. (Do not change this parameter without detailed understanding its
  1221. purpose.)
  1222. \bigskip
  1223. {\tt double obj\_ll} (default: {\tt -DBL\_MAX})
  1224. Lower limit of the objective function. If the objective function
  1225. reaches this limit and continues decreasing, the solver terminates the
  1226. search. (Used in the dual simplex only.)
  1227. \bigskip
  1228. {\tt double obj\_ul} (default: {\tt +DBL\_MAX})
  1229. Upper limit of the objective function. If the objective function
  1230. reaches this limit and continues increasing, the solver terminates the
  1231. search. (Used in the dual simplex only.)
  1232. \bigskip
  1233. {\tt int it\_lim} (default: {\tt INT\_MAX})
  1234. Simplex iteration limit.
  1235. \bigskip
  1236. {\tt int tm\_lim} (default: {\tt INT\_MAX})
  1237. Searching time limit, in milliseconds.
  1238. \bigskip
  1239. {\tt int out\_frq} (default: {\tt 500})
  1240. Output frequency, in iterations. This parameter specifies how
  1241. frequently the solver sends information about the solution process to
  1242. the terminal.
  1243. \bigskip
  1244. {\tt int out\_dly} (default: {\tt 0})
  1245. Output delay, in milliseconds. This parameter specifies how long the
  1246. solver should delay sending information about the solution process to
  1247. the terminal.
  1248. \bigskip
  1249. {\tt int presolve} (default: {\tt GLP\_OFF})
  1250. LP presolver option:
  1251. \verb|GLP_ON | --- enable using the LP presolver;
  1252. \verb|GLP_OFF| --- disable using the LP presolver.
  1253. \newpage
  1254. \para{Example 1}
  1255. The following example main program reads LP problem instance in fixed
  1256. MPS format from file \verb|25fv47.mps|,\footnote{This instance in fixed
  1257. MPS format can be found in the Netlib LP collection; see
  1258. {\tt ftp://ftp.netlib.org/lp/data/}.} constructs an advanced initial
  1259. basis, solves the instance with the primal simplex method (by default),
  1260. and writes the solution to file \verb|25fv47.txt|.
  1261. \begin{footnotesize}
  1262. \begin{verbatim}
  1263. /* spxsamp1.c */
  1264. #include <stdio.h>
  1265. #include <stdlib.h>
  1266. #include <glpk.h>
  1267. int main(void)
  1268. { glp_prob *P;
  1269. P = glp_create_prob();
  1270. glp_read_mps(P, GLP_MPS_DECK, NULL, "25fv47.mps");
  1271. glp_adv_basis(P, 0);
  1272. glp_simplex(P, NULL);
  1273. glp_print_sol(P, "25fv47.txt");
  1274. glp_delete_prob(P);
  1275. return 0;
  1276. }
  1277. /* eof */
  1278. \end{verbatim}
  1279. \end{footnotesize}
  1280. Below here is shown the terminal output from this example program.
  1281. \begin{footnotesize}
  1282. \begin{verbatim}
  1283. Reading problem data from `25fv47.mps'...
  1284. Problem: 25FV47
  1285. Objective: R0000
  1286. 822 rows, 1571 columns, 11127 non-zeros
  1287. 6919 records were read
  1288. Crashing...
  1289. Size of triangular part = 799
  1290. 0: obj = 1.627307307e+04 infeas = 5.194e+04 (23)
  1291. 200: obj = 1.474901610e+04 infeas = 1.233e+04 (19)
  1292. 400: obj = 1.343909995e+04 infeas = 3.648e+03 (13)
  1293. 600: obj = 1.756052217e+04 infeas = 4.179e+02 (7)
  1294. * 775: obj = 1.789251591e+04 infeas = 4.982e-14 (1)
  1295. * 800: obj = 1.663354510e+04 infeas = 2.857e-14 (1)
  1296. * 1000: obj = 1.024935068e+04 infeas = 1.958e-12 (1)
  1297. * 1200: obj = 7.860174791e+03 infeas = 2.810e-29 (1)
  1298. * 1400: obj = 6.642378184e+03 infeas = 2.036e-16 (1)
  1299. * 1600: obj = 6.037014568e+03 infeas = 0.000e+00 (1)
  1300. * 1800: obj = 5.662171307e+03 infeas = 6.447e-15 (1)
  1301. * 2000: obj = 5.528146165e+03 infeas = 9.764e-13 (1)
  1302. * 2125: obj = 5.501845888e+03 infeas = 0.000e+00 (1)
  1303. OPTIMAL SOLUTION FOUND
  1304. Writing basic solution to `25fv47.txt'...
  1305. \end{verbatim}
  1306. \end{footnotesize}
  1307. \newpage
  1308. \para{Example 2}
  1309. The following example main program solves the same LP problem instance
  1310. as in Example 1 above, however, it uses the dual simplex method, which
  1311. starts from the standard initial basis.
  1312. \begin{footnotesize}
  1313. \begin{verbatim}
  1314. /* spxsamp2.c */
  1315. #include <stdio.h>
  1316. #include <stdlib.h>
  1317. #include <glpk.h>
  1318. int main(void)
  1319. { glp_prob *P;
  1320. glp_smcp parm;
  1321. P = glp_create_prob();
  1322. glp_read_mps(P, GLP_MPS_DECK, NULL, "25fv47.mps");
  1323. glp_init_smcp(&parm);
  1324. parm.meth = GLP_DUAL;
  1325. glp_simplex(P, &parm);
  1326. glp_print_sol(P, "25fv47.txt");
  1327. glp_delete_prob(P);
  1328. return 0;
  1329. }
  1330. /* eof */
  1331. \end{verbatim}
  1332. \end{footnotesize}
  1333. Below here is shown the terminal output from this example program.
  1334. \begin{footnotesize}
  1335. \begin{verbatim}
  1336. Reading problem data from `25fv47.mps'...
  1337. Problem: 25FV47
  1338. Objective: R0000
  1339. 822 rows, 1571 columns, 11127 non-zeros
  1340. 6919 records were read
  1341. 0: infeas = 1.223e+03 (516)
  1342. 200: infeas = 7.000e+00 (471)
  1343. 240: infeas = 1.106e-14 (461)
  1344. | 400: obj = -5.394267152e+03 infeas = 5.571e-16 (391)
  1345. | 600: obj = -4.586395752e+03 infeas = 1.389e-15 (340)
  1346. | 800: obj = -4.158268146e+03 infeas = 1.640e-15 (264)
  1347. | 1000: obj = -3.725320045e+03 infeas = 5.181e-15 (245)
  1348. | 1200: obj = -3.104802163e+03 infeas = 1.019e-14 (210)
  1349. | 1400: obj = -2.584190499e+03 infeas = 8.865e-15 (178)
  1350. | 1600: obj = -2.073852927e+03 infeas = 7.867e-15 (142)
  1351. | 1800: obj = -1.164037407e+03 infeas = 8.792e-15 (109)
  1352. | 2000: obj = -4.370590250e+02 infeas = 2.591e-14 (85)
  1353. | 2200: obj = 1.068240144e+03 infeas = 1.025e-13 (70)
  1354. | 2400: obj = 1.607481126e+03 infeas = 3.272e-14 (67)
  1355. | 2600: obj = 3.038230551e+03 infeas = 4.850e-14 (52)
  1356. | 2800: obj = 4.316238187e+03 infeas = 2.622e-14 (36)
  1357. | 3000: obj = 5.443842629e+03 infeas = 3.976e-15 (11)
  1358. | 3060: obj = 5.501845888e+03 infeas = 8.806e-15 (2)
  1359. OPTIMAL SOLUTION FOUND
  1360. Writing basic solution to `25fv47.txt'...
  1361. \end{verbatim}
  1362. \end{footnotesize}
  1363. \newpage
  1364. \subsection{glp\_exact --- solve LP problem in exact arithmetic}
  1365. \synopsis
  1366. \begin{verbatim}
  1367. int glp_exact(glp_prob *P, const glp_smcp *parm);
  1368. \end{verbatim}
  1369. \description
  1370. The routine \verb|glp_exact| is a tentative implementation of the
  1371. primal two-phase simplex method based on exact (rational) arithmetic.
  1372. It is similar to the routine \verb|glp_simplex|, however, for all
  1373. internal computations it uses arithmetic of rational numbers, which is
  1374. exact in mathematical sense, i.e. free of round-off errors unlike
  1375. floating-point arithmetic.
  1376. Note that the routine \verb|glp_exact| uses only two control parameters
  1377. passed in the structure \verb|glp_smcp|, namely, \verb|it_lim| and
  1378. \verb|tm_lim|.
  1379. \returns
  1380. \begin{retlist}
  1381. 0 & The LP problem instance has been successfully solved. (This code
  1382. does {\it not} necessarily mean that the solver has found optimal
  1383. solution. It only means that the solution process was successful.) \\
  1384. \verb|GLP_EBADB| & Unable to start the search, because the initial basis
  1385. specified in the problem object is invalid---the number of basic
  1386. (auxiliary and structural) variables is not the same as the number of
  1387. rows in the problem object.\\
  1388. \verb|GLP_ESING| & Unable to start the search, because the basis matrix
  1389. corresponding to the initial basis is exactly singular.\\
  1390. \verb|GLP_EBOUND| & Unable to start the search, because some
  1391. double-bounded (auxiliary or structural) variables have incorrect
  1392. bounds.\\
  1393. \verb|GLP_EFAIL| & The problem instance has no rows/columns.\\
  1394. \verb|GLP_EITLIM| & The search was prematurely terminated, because the
  1395. simplex iteration limit has been exceeded.\\
  1396. \verb|GLP_ETMLIM| & The search was prematurely terminated, because the
  1397. time limit has been exceeded.\\
  1398. \end{retlist}
  1399. \para{Note}
  1400. Computations in exact arithmetic are very time-consuming, so solving
  1401. LP problem with the routine \verb|glp_exact| from the very beginning is
  1402. not a good idea. It is much better at first to find an optimal basis
  1403. with the routine \verb|glp_simplex| and only then to call
  1404. \verb|glp_exact|, in which case only a few simplex iterations need to
  1405. be performed in exact arithmetic.
  1406. \newpage
  1407. \subsection{glp\_init\_smcp --- initialize simplex solver control
  1408. parameters}
  1409. \synopsis
  1410. \begin{verbatim}
  1411. int glp_init_smcp(glp_smcp *parm);
  1412. \end{verbatim}
  1413. \description
  1414. The routine \verb|glp_init_smcp| initializes control parameters, which
  1415. are used by the simplex solver, with default values.
  1416. Default values of the control parameters are stored in
  1417. a \verb|glp_smcp| structure, which the parameter \verb|parm| points to.
  1418. \subsection{glp\_get\_status --- determine generic status of basic
  1419. solution}
  1420. \synopsis
  1421. \begin{verbatim}
  1422. int glp_get_status(glp_prob *P);
  1423. \end{verbatim}
  1424. \returns
  1425. The routine \verb|glp_get_status| reports the generic status of the
  1426. current basic solution for the specified problem object as follows:
  1427. \verb|GLP_OPT | --- solution is optimal;
  1428. \verb|GLP_FEAS | --- solution is feasible;
  1429. \verb|GLP_INFEAS| --- solution is infeasible;
  1430. \verb|GLP_NOFEAS| --- problem has no feasible solution;
  1431. \verb|GLP_UNBND | --- problem has unbounded solution;
  1432. \verb|GLP_UNDEF | --- solution is undefined.
  1433. More detailed information about the status of basic solution can be
  1434. retrieved with the routines \verb|glp_get_prim_stat| and
  1435. \verb|glp_get_dual_stat|.
  1436. \subsection{glp\_get\_prim\_stat --- retrieve status of primal basic
  1437. solution}
  1438. \synopsis
  1439. \begin{verbatim}
  1440. int glp_get_prim_stat(glp_prob *P);
  1441. \end{verbatim}
  1442. \returns
  1443. The routine \verb|glp_get_prim_stat| reports the status of the primal
  1444. basic solution for the specified problem object as follows:
  1445. \verb|GLP_UNDEF | --- primal solution is undefined;
  1446. \verb|GLP_FEAS | --- primal solution is feasible;
  1447. \verb|GLP_INFEAS| --- primal solution is infeasible;
  1448. \verb|GLP_NOFEAS| --- no primal feasible solution exists.
  1449. \subsection{glp\_get\_dual\_stat --- retrieve status of dual basic
  1450. solution}
  1451. \synopsis
  1452. \begin{verbatim}
  1453. int glp_get_dual_stat(glp_prob *P);
  1454. \end{verbatim}
  1455. \returns
  1456. The routine \verb|glp_get_dual_stat| reports the status of the dual
  1457. basic solution for the specified problem object as follows:
  1458. \verb|GLP_UNDEF | --- dual solution is undefined;
  1459. \verb|GLP_FEAS | --- dual solution is feasible;
  1460. \verb|GLP_INFEAS| --- dual solution is infeasible;
  1461. \verb|GLP_NOFEAS| --- no dual feasible solution exists.
  1462. \subsection{glp\_get\_obj\_val --- retrieve objective value}
  1463. \synopsis
  1464. \begin{verbatim}
  1465. double glp_get_obj_val(glp_prob *P);
  1466. \end{verbatim}
  1467. \returns
  1468. The routine \verb|glp_get_obj_val| returns current value of the
  1469. objective function.
  1470. \subsection{glp\_get\_row\_stat --- retrieve row status}
  1471. \synopsis
  1472. \begin{verbatim}
  1473. int glp_get_row_stat(glp_prob *P, int i);
  1474. \end{verbatim}
  1475. \returns
  1476. The routine \verb|glp_get_row_stat| returns current status assigned to
  1477. the auxiliary variable associated with \verb|i|-th row as follows:
  1478. \verb|GLP_BS| --- basic variable;
  1479. \verb|GLP_NL| --- non-basic variable on its lower bound;
  1480. \verb|GLP_NU| --- non-basic variable on its upper bound;
  1481. \verb|GLP_NF| --- non-basic free (unbounded) variable;
  1482. \verb|GLP_NS| --- non-basic fixed variable.
  1483. \newpage
  1484. \subsection{glp\_get\_row\_prim --- retrieve row primal value}
  1485. \synopsis
  1486. \begin{verbatim}
  1487. double glp_get_row_prim(glp_prob *P, int i);
  1488. \end{verbatim}
  1489. \returns
  1490. The routine \verb|glp_get_row_prim| returns primal value of the
  1491. auxiliary variable associated with \verb|i|-th row.
  1492. \subsection{glp\_get\_row\_dual --- retrieve row dual value}
  1493. \synopsis
  1494. \begin{verbatim}
  1495. double glp_get_row_dual(glp_prob *P, int i);
  1496. \end{verbatim}
  1497. \returns
  1498. The routine \verb|glp_get_row_dual| returns dual value (i.e. reduced
  1499. cost) of the auxiliary variable associated with \verb|i|-th row.
  1500. \subsection{glp\_get\_col\_stat --- retrieve column status}
  1501. \synopsis
  1502. \begin{verbatim}
  1503. int glp_get_col_stat(glp_prob *P, int j);
  1504. \end{verbatim}
  1505. \returns
  1506. The routine \verb|glp_get_col_stat| returns current status assigned to
  1507. the structural variable associated with \verb|j|-th column as follows:
  1508. \verb|GLP_BS| --- basic variable;
  1509. \verb|GLP_NL| --- non-basic variable on its lower bound;
  1510. \verb|GLP_NU| --- non-basic variable on its upper bound;
  1511. \verb|GLP_NF| --- non-basic free (unbounded) variable;
  1512. \verb|GLP_NS| --- non-basic fixed variable.
  1513. \subsection{glp\_get\_col\_prim --- retrieve column primal value}
  1514. \synopsis
  1515. \begin{verbatim}
  1516. double glp_get_col_prim(glp_prob *P, int j);
  1517. \end{verbatim}
  1518. \returns
  1519. The routine \verb|glp_get_col_prim| returns primal value of the
  1520. structural variable associated with \verb|j|-th column.
  1521. \newpage
  1522. \subsection{glp\_get\_col\_dual --- retrieve column dual value}
  1523. \synopsis
  1524. \begin{verbatim}
  1525. double glp_get_col_dual(glp_prob *P, int j);
  1526. \end{verbatim}
  1527. \returns
  1528. The routine \verb|glp_get_col_dual| returns dual value (i.e. reduced
  1529. cost) of the structural variable associated with \verb|j|-th column.
  1530. \subsection{glp\_get\_unbnd\_ray --- determine variable causing
  1531. unboundedness}
  1532. \synopsis
  1533. \begin{verbatim}
  1534. int glp_get_unbnd_ray(glp_prob *P);
  1535. \end{verbatim}
  1536. \returns
  1537. The routine \verb|glp_get_unbnd_ray| returns the number $k$ of
  1538. a variable, which causes primal or dual unboundedness.
  1539. If $1\leq k\leq m$, it is $k$-th auxiliary variable, and if
  1540. $m+1\leq k\leq m+n$, it is $(k-m)$-th structural variable, where $m$ is
  1541. the number of rows, $n$ is the number of columns in the problem object.
  1542. If such variable is not defined, the routine returns 0.
  1543. \para{Note}
  1544. If it is not exactly known which version of the simplex solver
  1545. detected unboundedness, i.e. whether the unboundedness is primal or
  1546. dual, it is sufficient to check the status of the variable
  1547. with the routine \verb|glp_get_row_stat| or \verb|glp_get_col_stat|.
  1548. If the variable is non-basic, the unboundedness is primal, otherwise,
  1549. if the variable is basic, the unboundedness is dual (the latter case
  1550. means that the problem has no primal feasible dolution).
  1551. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1552. \newpage
  1553. \section{Interior-point method routines}
  1554. {\it Interior-point methods} (also known as {\it barrier methods}) are
  1555. more modern and powerful numerical methods for large-scale linear
  1556. programming. Such methods are especially efficient for very sparse LP
  1557. problems and allow solving such problems much faster than the simplex
  1558. method.
  1559. In brief, the GLPK interior-point solver works as follows.
  1560. At first, the solver transforms the original LP to a {\it working} LP
  1561. in the standard format:
  1562. \medskip
  1563. \noindent
  1564. \hspace{.5in} minimize
  1565. $$z = c_1x_{m+1} + c_2x_{m+2} + \dots + c_nx_{m+n} + c_0 \eqno (2.4)$$
  1566. \hspace{.5in} subject to linear constraints
  1567. $$
  1568. \begin{array}{r@{\:}c@{\:}r@{\:}c@{\:}r@{\:}c@{\:}l}
  1569. a_{11}x_{m+1}&+&a_{12}x_{m+2}&+ \dots +&a_{1n}x_{m+n}&=&b_1 \\
  1570. a_{21}x_{m+1}&+&a_{22}x_{m+2}&+ \dots +&a_{2n}x_{m+n}&=&b_2 \\
  1571. \multicolumn{7}{c}
  1572. {.\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .\ \ .} \\
  1573. a_{m1}x_{m+1}&+&a_{m2}x_{m+2}&+ \dots +&a_{mn}x_{m+n}&=&b_m \\
  1574. \end{array} \eqno (2.5)
  1575. $$
  1576. \hspace{.5in} and non-negative variables
  1577. $$x_1\geq 0,\ \ x_2\geq 0,\ \ \dots,\ \ x_n\geq 0 \eqno(2.6)$$
  1578. where: $z$ is the objective function; $x_1$, \dots, $x_n$ are variables;
  1579. $c_1$, \dots, $c_n$ are objective coefficients; $c_0$ is a constant term
  1580. of the objective function; $a_{11}$, \dots, $a_{mn}$ are constraint
  1581. coefficients; $b_1$, \dots, $b_m$ are right-hand sides.
  1582. Using vector and matrix notations the working LP (2.4)---(2.6) can be
  1583. written as follows:
  1584. $$z=c^Tx+c_0\ \rightarrow\ \min,\eqno(2.7)$$
  1585. $$Ax=b,\eqno(2.8)$$
  1586. $$x\geq 0,\eqno(2.9)$$
  1587. where: $x=(x_j)$ is $n$-vector of variables, $c=(c_j)$ is $n$-vector of
  1588. objective coefficients, $A=(a_{ij})$ is $m\times n$-matrix of
  1589. constraint coefficients, and $b=(b_i)$ is $m$-vector of right-hand
  1590. sides.
  1591. Karush--Kuhn--Tucker optimality conditions for LP (2.7)---(2.9) are the
  1592. following:
  1593. $$Ax=b,\eqno(2.10)$$
  1594. $$A^T\pi+\lambda=c,\eqno(2.11)$$
  1595. $$\lambda^Tx=0,\eqno(2.12)$$
  1596. $$x\geq 0,\ \ \lambda\geq 0,\eqno(2.13)$$
  1597. where:
  1598. $\pi$ is $m$-vector of Lagrange multipliers (dual variables) for
  1599. equality constraints (2.8),\linebreak $\lambda$ is $n$-vector of
  1600. Lagrange multipliers (dual variables) for non-negativity constraints
  1601. (2.9),\linebreak (2.10) is the primal feasibility condition, (2.11) is
  1602. the dual feasibility condition, (2.12) is the primal-dual
  1603. complementarity condition, and (2.13) is the non-negativity conditions.
  1604. The main idea of the primal-dual interior-point method is based on
  1605. finding a point in the primal-dual space (i.e. in the space of all
  1606. primal and dual variables $x$, $\pi$, and $\lambda$), which satisfies
  1607. to all optimality conditions (2.10)---(2.13). Obviously, $x$-component
  1608. of such point then provides an optimal solution to the working LP
  1609. (2.7)---(2.9).
  1610. To find the optimal point $(x^*,\pi^*,\lambda^*)$ the interior-point
  1611. method attempts to solve the system of equations (2.10)---(2.12), which
  1612. is closed in the sense that the number of variables $x_j$, $\pi_i$, and
  1613. $\lambda_j$ and the number equations are the same and equal to $m+2n$.
  1614. Due to condition (2.12) this system of equations is non-linear, so it
  1615. can be solved with a version of {\it Newton's method} provided with
  1616. additional rules to keep the current point within the positive orthant
  1617. as required by the non-negativity conditions (2.13).
  1618. Finally, once the optimal point $(x^*,\pi^*,\lambda^*)$ has been found,
  1619. the solver performs inverse transformations to recover corresponding
  1620. solution to the original LP passed to the solver from the application
  1621. program.
  1622. \subsection{glp\_interior --- solve LP problem with the interior-point
  1623. method}
  1624. \synopsis
  1625. \begin{verbatim}
  1626. int glp_interior(glp_prob *P, const glp_iptcp *parm);
  1627. \end{verbatim}
  1628. \description
  1629. The routine \verb|glp_interior| is a driver to the LP solver based on
  1630. the primal-dual interior-point method. This routine retrieves problem
  1631. data from the specified problem object, calls the solver to solve the
  1632. problem instance, and stores results of computations back into the
  1633. problem object.
  1634. The interior-point solver has a set of control parameters. Values of
  1635. the control parameters can be passed in the structure \verb|glp_iptcp|,
  1636. which the parameter \verb|parm| points to. For detailed description of
  1637. this structure see paragraph ``Control parameters'' below. Before
  1638. specifying some control parameters the application program should
  1639. initialize the structure \verb|glp_iptcp| by default values of all
  1640. control parameters using the routine \verb|glp_init_iptcp| (see the
  1641. next subsection). This is needed for backward compatibility, because in
  1642. the future there may appear new members in the structure
  1643. \verb|glp_iptcp|.
  1644. The parameter \verb|parm| can be specified as \verb|NULL|, in which
  1645. case the solver uses default settings.
  1646. \returns
  1647. \begin{retlist}
  1648. 0 & The LP problem instance has been successfully solved. (This code
  1649. does {\it not} necessarily mean that the solver has found optimal
  1650. solution. It only means that the solution process was successful.) \\
  1651. \verb|GLP_EFAIL| & The problem has no rows/columns.\\
  1652. \verb|GLP_ENOCVG| & Very slow convergence or divergence.\\
  1653. \verb|GLP_EITLIM| & Iteration limit exceeded.\\
  1654. \verb|GLP_EINSTAB| & Numerical instability on solving Newtonian
  1655. system.\\
  1656. \end{retlist}
  1657. \newpage
  1658. \para{Comments}
  1659. The routine \verb|glp_interior| implements an easy version of
  1660. the primal-dual interior-point method based on Mehrotra's
  1661. technique.\footnote{S. Mehrotra. On the implementation of a primal-dual
  1662. interior point method. SIAM J. on Optim., 2(4), pp. 575-601, 1992.}
  1663. Note that currently the GLPK interior-point solver does not include
  1664. many important features, in particular:
  1665. \vspace*{-8pt}
  1666. \begin{itemize}
  1667. \item it is not able to process dense columns. Thus, if the constraint
  1668. matrix of the LP problem has dense columns, the solving process may be
  1669. inefficient;
  1670. \item it has no features against numerical instability. For some LP
  1671. problems premature termination may happen if the matrix $ADA^T$ becomes
  1672. singular or ill-conditioned;
  1673. \item it is not able to identify the optimal basis, which corresponds
  1674. to the interior-point solution found.
  1675. \end{itemize}
  1676. \vspace*{-8pt}
  1677. \para{Terminal output}
  1678. Solving large LP problems may take a long time, so the solver reports
  1679. some information about every interior-point iteration,\footnote{Unlike
  1680. the simplex method the interior point method usually needs 30---50
  1681. iterations (independently on the problem size) in order to find an
  1682. optimal solution.} which is sent to the terminal. This information has
  1683. the following format:
  1684. \begin{verbatim}
  1685. nnn: obj = fff; rpi = ppp; rdi = ddd; gap = ggg
  1686. \end{verbatim}
  1687. \noindent where: \verb|nnn| is iteration number, \verb|fff| is the
  1688. current value of the objective function (in the case of maximization it
  1689. has wrong sign), \verb|ppp| is the current relative primal
  1690. infeasibility (cf. (2.10)):
  1691. $$\frac{\|Ax^{(k)}-b\|}{1+\|b\|},\eqno(2.14)$$
  1692. \verb|ddd| is the current relative dual infeasibility (cf. (2.11)):
  1693. $$\frac{\|A^T\pi^{(k)}+\lambda^{(k)}-c\|}{1+\|c\|},\eqno(2.15)$$
  1694. \verb|ggg| is the current primal-dual gap (cf. (2.12)):
  1695. $$\frac{|c^Tx^{(k)}-b^T\pi^{(k)}|}{1+|c^Tx^{(k)}|},\eqno(2.16)$$
  1696. and $[x^{(k)},\pi^{(k)},\lambda^{(k)}]$ is the current point on $k$-th
  1697. iteration, $k=0,1,2,\dots$\ . Note that all solution components are
  1698. internally scaled, so information sent to the terminal is suitable only
  1699. for visual inspection.
  1700. \newpage
  1701. \para{Control parameters}
  1702. This paragraph describes all control parameters currently used in the
  1703. interior-point solver. Symbolic names of control parameters are names of
  1704. corresponding members in the structure \verb|glp_iptcp|.
  1705. \bigskip
  1706. {\tt int msg\_lev} (default: {\tt GLP\_MSG\_ALL})
  1707. Message level for terminal output:
  1708. \verb|GLP_MSG_OFF|---no output;
  1709. \verb|GLP_MSG_ERR|---error and warning messages only;
  1710. \verb|GLP_MSG_ON |---normal output;
  1711. \verb|GLP_MSG_ALL|---full output (including informational messages).
  1712. \bigskip
  1713. {\tt int ord\_alg} (default: {\tt GLP\_ORD\_AMD})
  1714. Ordering algorithm used prior to Cholesky factorization:
  1715. \verb|GLP_ORD_NONE |---use natural (original) ordering;
  1716. \verb|GLP_ORD_QMD |---quotient minimum degree (QMD);
  1717. \verb|GLP_ORD_AMD |---approximate minimum degree (AMD);
  1718. \verb|GLP_ORD_SYMAMD|---approximate minimum degree (SYMAMD).
  1719. \bigskip
  1720. \para{Example}
  1721. The following main program reads LP problem instance in fixed MPS
  1722. format from file\linebreak \verb|25fv47.mps|,\footnote{This instance in
  1723. fixed MPS format can be found in the Netlib LP collection; see
  1724. {\tt ftp://ftp.netlib.org/lp/data/}.} solves it with the interior-point
  1725. solver, and writes the solution to file \verb|25fv47.txt|.
  1726. \begin{footnotesize}
  1727. \begin{verbatim}
  1728. /* iptsamp.c */
  1729. #include <stdio.h>
  1730. #include <stdlib.h>
  1731. #include <glpk.h>
  1732. int main(void)
  1733. { glp_prob *P;
  1734. P = glp_create_prob();
  1735. glp_read_mps(P, GLP_MPS_DECK, NULL, "25fv47.mps");
  1736. glp_interior(P, NULL);
  1737. glp_print_ipt(P, "25fv47.txt");
  1738. glp_delete_prob(P);
  1739. return 0;
  1740. }
  1741. /* eof */
  1742. \end{verbatim}
  1743. \end{footnotesize}
  1744. \newpage
  1745. Below here is shown the terminal output from this example program.
  1746. \begin{footnotesize}
  1747. \begin{verbatim}
  1748. Reading problem data from `25fv47.mps'...
  1749. Problem: 25FV47
  1750. Objective: R0000
  1751. 822 rows, 1571 columns, 11127 non-zeros
  1752. 6919 records were read
  1753. Original LP has 822 row(s), 1571 column(s), and 11127 non-zero(s)
  1754. Working LP has 821 row(s), 1876 column(s), and 10705 non-zero(s)
  1755. Matrix A has 10705 non-zeros
  1756. Matrix S = A*A' has 11895 non-zeros (upper triangle)
  1757. Minimal degree ordering...
  1758. Computing Cholesky factorization S = L'*L...
  1759. Matrix L has 35411 non-zeros
  1760. Guessing initial point...
  1761. Optimization begins...
  1762. 0: obj = 1.823377629e+05; rpi = 1.3e+01; rdi = 1.4e+01; gap = 9.3e-01
  1763. 1: obj = 9.260045192e+04; rpi = 5.3e+00; rdi = 5.6e+00; gap = 6.8e+00
  1764. 2: obj = 3.596999742e+04; rpi = 1.5e+00; rdi = 1.2e+00; gap = 1.8e+01
  1765. 3: obj = 1.989627568e+04; rpi = 4.7e-01; rdi = 3.0e-01; gap = 1.9e+01
  1766. 4: obj = 1.430215557e+04; rpi = 1.1e-01; rdi = 8.6e-02; gap = 1.4e+01
  1767. 5: obj = 1.155716505e+04; rpi = 2.3e-02; rdi = 2.4e-02; gap = 6.8e+00
  1768. 6: obj = 9.660273208e+03; rpi = 6.7e-03; rdi = 4.6e-03; gap = 3.9e+00
  1769. 7: obj = 8.694348283e+03; rpi = 3.7e-03; rdi = 1.7e-03; gap = 2.0e+00
  1770. 8: obj = 8.019543639e+03; rpi = 2.4e-03; rdi = 3.9e-04; gap = 1.0e+00
  1771. 9: obj = 7.122676293e+03; rpi = 1.2e-03; rdi = 1.5e-04; gap = 6.6e-01
  1772. 10: obj = 6.514534518e+03; rpi = 6.1e-04; rdi = 4.3e-05; gap = 4.1e-01
  1773. 11: obj = 6.361572203e+03; rpi = 4.8e-04; rdi = 2.2e-05; gap = 3.0e-01
  1774. 12: obj = 6.203355508e+03; rpi = 3.2e-04; rdi = 1.7e-05; gap = 2.6e-01
  1775. 13: obj = 6.032943411e+03; rpi = 2.0e-04; rdi = 9.3e-06; gap = 2.1e-01
  1776. 14: obj = 5.796553021e+03; rpi = 9.8e-05; rdi = 3.2e-06; gap = 1.0e-01
  1777. 15: obj = 5.667032431e+03; rpi = 4.4e-05; rdi = 1.1e-06; gap = 5.6e-02
  1778. 16: obj = 5.613911867e+03; rpi = 2.5e-05; rdi = 4.1e-07; gap = 3.5e-02
  1779. 17: obj = 5.560572626e+03; rpi = 9.9e-06; rdi = 2.3e-07; gap = 2.1e-02
  1780. 18: obj = 5.537276001e+03; rpi = 5.5e-06; rdi = 8.4e-08; gap = 1.1e-02
  1781. 19: obj = 5.522746942e+03; rpi = 2.2e-06; rdi = 4.0e-08; gap = 6.7e-03
  1782. 20: obj = 5.509956679e+03; rpi = 7.5e-07; rdi = 1.8e-08; gap = 2.9e-03
  1783. 21: obj = 5.504571733e+03; rpi = 1.6e-07; rdi = 5.8e-09; gap = 1.1e-03
  1784. 22: obj = 5.502576367e+03; rpi = 3.4e-08; rdi = 1.0e-09; gap = 2.5e-04
  1785. 23: obj = 5.502057119e+03; rpi = 8.1e-09; rdi = 3.0e-10; gap = 7.7e-05
  1786. 24: obj = 5.501885996e+03; rpi = 9.4e-10; rdi = 1.2e-10; gap = 2.4e-05
  1787. 25: obj = 5.501852464e+03; rpi = 1.4e-10; rdi = 1.2e-11; gap = 3.0e-06
  1788. 26: obj = 5.501846549e+03; rpi = 1.4e-11; rdi = 1.2e-12; gap = 3.0e-07
  1789. 27: obj = 5.501845954e+03; rpi = 1.4e-12; rdi = 1.2e-13; gap = 3.0e-08
  1790. 28: obj = 5.501845895e+03; rpi = 1.5e-13; rdi = 1.2e-14; gap = 3.0e-09
  1791. OPTIMAL SOLUTION FOUND
  1792. Writing interior-point solution to `25fv47.txt'...
  1793. \end{verbatim}
  1794. \end{footnotesize}
  1795. \newpage
  1796. \subsection{glp\_init\_iptcp --- initialize interior-point solver
  1797. control parameters}
  1798. \synopsis
  1799. \begin{verbatim}
  1800. int glp_init_iptcp(glp_iptcp *parm);
  1801. \end{verbatim}
  1802. \description
  1803. The routine \verb|glp_init_iptcp| initializes control parameters, which
  1804. are used by the interior-point solver, with default values.
  1805. Default values of the control parameters are stored in the structure
  1806. \verb|glp_iptcp|, which the parameter \verb|parm| points to.
  1807. \subsection{glp\_ipt\_status --- determine solution status}
  1808. \synopsis
  1809. \begin{verbatim}
  1810. int glp_ipt_status(glp_prob *P);
  1811. \end{verbatim}
  1812. \returns
  1813. The routine \verb|glp_ipt_status| reports the status of a solution
  1814. found by the interior-point solver as follows:
  1815. \verb|GLP_UNDEF | --- interior-point solution is undefined;
  1816. \verb|GLP_OPT | --- interior-point solution is optimal;
  1817. \verb|GLP_INFEAS| --- interior-point solution is infeasible;
  1818. \verb|GLP_NOFEAS| --- no feasible primal-dual solution exists.
  1819. \subsection{glp\_ipt\_obj\_val --- retrieve objective value}
  1820. \synopsis
  1821. \begin{verbatim}
  1822. double glp_ipt_obj_val(glp_prob *P);
  1823. \end{verbatim}
  1824. \returns
  1825. The routine \verb|glp_ipt_obj_val| returns value of the objective
  1826. function for interior-point solution.
  1827. \subsection{glp\_ipt\_row\_prim --- retrieve row primal value}
  1828. \synopsis
  1829. \begin{verbatim}
  1830. double glp_ipt_row_prim(glp_prob *P, int i);
  1831. \end{verbatim}
  1832. \returns
  1833. The routine \verb|glp_ipt_row_prim| returns primal value of the
  1834. auxiliary variable associated with \verb|i|-th row.
  1835. \newpage
  1836. \subsection{glp\_ipt\_row\_dual --- retrieve row dual value}
  1837. \synopsis
  1838. \begin{verbatim}
  1839. double glp_ipt_row_dual(glp_prob *P, int i);
  1840. \end{verbatim}
  1841. \returns
  1842. The routine \verb|glp_ipt_row_dual| returns dual value (i.e. reduced
  1843. cost) of the auxiliary variable associated with \verb|i|-th row.
  1844. \subsection{glp\_ipt\_col\_prim --- retrieve column primal value}
  1845. \synopsis
  1846. \begin{verbatim}
  1847. double glp_ipt_col_prim(glp_prob *P, int j);
  1848. \end{verbatim}
  1849. \returns
  1850. The routine \verb|glp_ipt_col_prim| returns primal value of the
  1851. structural variable associated with \verb|j|-th column.
  1852. \subsection{glp\_ipt\_col\_dual --- retrieve column dual value}
  1853. \synopsis
  1854. \begin{verbatim}
  1855. double glp_ipt_col_dual(glp_prob *P, int j);
  1856. \end{verbatim}
  1857. \returns
  1858. The routine \verb|glp_ipt_col_dual| returns dual value (i.e. reduced
  1859. cost) of the structural variable associated with \verb|j|-th column.
  1860. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1861. \newpage
  1862. \section{Mixed integer programming routines}
  1863. \subsection{glp\_set\_col\_kind --- set (change) column kind}
  1864. \synopsis
  1865. \begin{verbatim}
  1866. void glp_set_col_kind(glp_prob *P, int j, int kind);
  1867. \end{verbatim}
  1868. \description
  1869. The routine \verb|glp_set_col_kind| sets (changes) the kind of
  1870. \verb|j|-th column (structural variable) as specified by the parameter
  1871. \verb|kind|:
  1872. \verb|GLP_CV| --- continuous variable;
  1873. \verb|GLP_IV| --- integer variable;
  1874. \verb|GLP_BV| --- binary variable.
  1875. Setting a column to \verb|GLP_BV| has the same effect as if it were
  1876. set to \verb|GLP_IV|, its lower bound were set 0, and its upper bound
  1877. were set to 1.
  1878. \subsection{glp\_get\_col\_kind --- retrieve column kind}
  1879. \synopsis
  1880. \begin{verbatim}
  1881. int glp_get_col_kind(glp_prob *P, int j);
  1882. \end{verbatim}
  1883. \returns
  1884. The routine \verb|glp_get_col_kind| returns the kind of \verb|j|-th
  1885. column (structural variable) as follows:
  1886. \verb|GLP_CV| --- continuous variable;
  1887. \verb|GLP_IV| --- integer variable;
  1888. \verb|GLP_BV| --- binary variable.
  1889. \subsection{glp\_get\_num\_int --- retrieve number of integer columns}
  1890. \synopsis
  1891. \begin{verbatim}
  1892. int glp_get_num_int(glp_prob *P);
  1893. \end{verbatim}
  1894. \returns
  1895. The routine \verb|glp_get_num_int| returns the number of columns
  1896. (structural variables), which are marked as integer. Note that this
  1897. number {\it does} include binary columns.
  1898. \newpage
  1899. \subsection{glp\_get\_num\_bin --- retrieve number of binary columns}
  1900. \synopsis
  1901. \begin{verbatim}
  1902. int glp_get_num_bin(glp_prob *P);
  1903. \end{verbatim}
  1904. \returns
  1905. The routine \verb|glp_get_num_bin| returns the number of columns
  1906. (structural variables), which are marked as integer and whose lower
  1907. bound is zero and upper bound is one.
  1908. \subsection{glp\_intopt --- solve MIP problem with the branch-and-cut
  1909. method}
  1910. \synopsis
  1911. \begin{verbatim}
  1912. int glp_intopt(glp_prob *P, const glp_iocp *parm);
  1913. \end{verbatim}
  1914. \description
  1915. The routine \verb|glp_intopt| is a driver to the MIP solver based on
  1916. the branch-and-cut method, which is a hybrid of branch-and-bound and
  1917. cutting plane methods.
  1918. If the presolver is disabled (see paragraph ``Control parameters''
  1919. below), on entry to the routine \verb|glp_intopt| the problem object,
  1920. which the parameter \verb|mip| points to, should contain optimal
  1921. solution to LP relaxation (it can be obtained, for example, with the
  1922. routine \verb|glp_simplex|). Otherwise, if the presolver is enabled, it
  1923. is not necessary.
  1924. The MIP solver has a set of control parameters. Values of the control
  1925. parameters can be passed in the structure \verb|glp_iocp|, which the
  1926. parameter \verb|parm| points to. For detailed description of this
  1927. structure see paragraph ``Control parameters'' below. Before specifying
  1928. some control parameters the application program should initialize the
  1929. structure \verb|glp_iocp| by default values of all control parameters
  1930. using the routine \verb|glp_init_iocp| (see the next subsection). This
  1931. is needed for backward compatibility, because in the future there may
  1932. appear new members in the structure \verb|glp_iocp|.
  1933. The parameter \verb|parm| can be specified as \verb|NULL|, in which case
  1934. the solver uses default settings.
  1935. Note that the GLPK branch-and-cut solver is not perfect, so it is
  1936. unable to solve hard or very large scale MIP instances for a reasonable
  1937. time.
  1938. \returns
  1939. \begin{retlist}
  1940. 0 & The MIP problem instance has been successfully solved. (This code
  1941. does {\it not} necessarily mean that the solver has found optimal
  1942. solution. It only means that the solution process was successful.) \\
  1943. \verb|GLP_EBOUND| & Unable to start the search, because some
  1944. double-bounded variables have incorrect bounds or some integer
  1945. variables have non-integer (fractional) bounds.\\
  1946. \verb|GLP_EROOT| & Unable to start the search, because optimal basis
  1947. for initial LP relaxation is not provided. (This code may appear only
  1948. if the presolver is disabled.)\\
  1949. \verb|GLP_ENOPFS| & Unable to start the search, because LP relaxation
  1950. of the MIP problem instance has no primal feasible solution. (This code
  1951. may appear only if the presolver is enabled.)\\
  1952. \end{retlist}
  1953. \newpage
  1954. \begin{retlist}
  1955. \verb|GLP_ENODFS| & Unable to start the search, because LP relaxation
  1956. of the MIP problem instance has no dual feasible solution. In other
  1957. word, this code means that if the LP relaxation has at least one primal
  1958. feasible solution, its optimal solution is unbounded, so if the MIP
  1959. problem has at least one integer feasible solution, its (integer)
  1960. optimal solution is also unbounded. (This code may appear only if the
  1961. presolver is enabled.)\\
  1962. \verb|GLP_EFAIL| & The search was prematurely terminated due to the
  1963. solver failure.\\
  1964. \verb|GLP_EMIPGAP| & The search was prematurely terminated, because the
  1965. relative mip gap tolerance has been reached.\\
  1966. \verb|GLP_ETMLIM| & The search was prematurely terminated, because the
  1967. time limit has been exceeded.\\
  1968. \verb|GLP_ESTOP| & The search was prematurely terminated by application.
  1969. (This code may appear only if the advanced solver interface is used.)\\
  1970. \end{retlist}
  1971. \para{Built-in MIP presolver}
  1972. The branch-and-cut solver has {\it built-in MIP presolver}. It is
  1973. a subprogram that transforms the original MIP problem specified in the
  1974. problem object to an equivalent MIP problem, which may be easier for
  1975. solving with the branch-and-cut method than the original one. For
  1976. example, the presolver can remove redundant constraints and variables,
  1977. whose optimal values are known, perform bound and coefficient reduction,
  1978. etc. Once the transformed MIP problem has been solved, the presolver
  1979. transforms its solution back to corresponding solution of the original
  1980. problem.
  1981. Presolving is an optional feature of the routine \verb|glp_intopt|, and
  1982. by default it is disabled. In order to enable the MIP presolver, the
  1983. control parameter \verb|presolve| should be set to \verb|GLP_ON| (see
  1984. paragraph ``Control parameters'' below).
  1985. \para{Advanced solver interface}
  1986. The routine \verb|glp_intopt| allows the user to control the
  1987. branch-and-cut search by passing to the solver a user-defined callback
  1988. routine. For more details see Chapter ``Branch-and-Cut API Routines''.
  1989. \para{Terminal output}
  1990. Solving a MIP problem may take a long time, so the solver reports some
  1991. information about best known solutions, which is sent to the terminal.
  1992. This information has the following format:
  1993. \begin{verbatim}
  1994. +nnn: mip = xxx <rho> yyy gap (ppp; qqq)
  1995. \end{verbatim}
  1996. \noindent
  1997. where: `\verb|nnn|' is the simplex iteration number; `\verb|xxx|' is a
  1998. value of the objective function for the best known integer feasible
  1999. solution (if no integer feasible solution has been found yet,
  2000. `\verb|xxx|' is the text `\verb|not found yet|'); `\verb|rho|' is the
  2001. string `\verb|>=|' (in case of minimization) or `\verb|<=|' (in case of
  2002. maximization); `\verb|yyy|' is a global bound for exact integer optimum
  2003. (i.e. the exact integer optimum is always in the range from `\verb|xxx|'
  2004. to `\verb|yyy|'); `\verb|gap|' is the relative mip gap, in percents,
  2005. computed as $gap=|xxx-yyy|/(|xxx|+{\tt DBL\_EPSILON})\cdot 100\%$ (if
  2006. $gap$ is greater than $999.9\%$, it is not printed); `\verb|ppp|' is the
  2007. number of subproblems in the active list, `\verb|qqq|' is the number of
  2008. subproblems which have been already fathomed and therefore removed from
  2009. the branch-and-bound search tree.
  2010. \newpage
  2011. \subsubsection{Control parameters}
  2012. This paragraph describes all control parameters currently used in the
  2013. MIP solver. Symbolic names of control parameters are names of
  2014. corresponding members in the structure \verb|glp_iocp|.
  2015. \bigskip\vspace*{-2pt}
  2016. {\tt int msg\_lev} (default: {\tt GLP\_MSG\_ALL})
  2017. Message level for terminal output:
  2018. \verb|GLP_MSG_OFF| --- no output;
  2019. \verb|GLP_MSG_ERR| --- error and warning messages only;
  2020. \verb|GLP_MSG_ON | --- normal output;
  2021. \verb|GLP_MSG_ALL| --- full output (including informational messages).
  2022. \bigskip\vspace*{-2pt}
  2023. {\tt int br\_tech} (default: {\tt GLP\_BR\_DTH})
  2024. Branching technique option:
  2025. \verb|GLP_BR_FFV| --- first fractional variable;
  2026. \verb|GLP_BR_LFV| --- last fractional variable;
  2027. \verb|GLP_BR_MFV| --- most fractional variable;
  2028. \verb|GLP_BR_DTH| --- heuristic by Driebeck and Tomlin;
  2029. \verb|GLP_BR_PCH| --- hybrid pseudo-cost heuristic.
  2030. \bigskip\vspace*{-2pt}
  2031. {\tt int bt\_tech} (default: {\tt GLP\_BT\_BLB})
  2032. Backtracking technique option:
  2033. \verb|GLP_BT_DFS| --- depth first search;
  2034. \verb|GLP_BT_BFS| --- breadth first search;
  2035. \verb|GLP_BT_BLB| --- best local bound;
  2036. \verb|GLP_BT_BPH| --- best projection heuristic.
  2037. \bigskip\vspace*{-2pt}
  2038. {\tt int pp\_tech} (default: {\tt GLP\_PP\_ALL})
  2039. Preprocessing technique option:
  2040. \verb|GLP_PP_NONE| --- disable preprocessing;
  2041. \verb|GLP_PP_ROOT| --- perform preprocessing only on the root level;
  2042. \verb|GLP_PP_ALL | --- perform preprocessing on all levels.
  2043. \bigskip\vspace*{-2pt}
  2044. {\tt int fp\_heur} (default: {\tt GLP\_OFF})
  2045. Feasibility pump heuristic option:
  2046. \verb|GLP_ON | --- enable applying the feasibility pump heuristic;
  2047. \verb|GLP_OFF| --- disable applying the feasibility pump heuristic.
  2048. \newpage
  2049. {\tt int ps\_heur} (default: {\tt GLP\_OFF})
  2050. Proximity search heuristic\footnote{The Fischetti--Monaci Proximity
  2051. Search (a.k.a. Proxy) heuristic. This algorithm is often capable of
  2052. rapidly improving a feasible solution of a MIP problem with binary
  2053. variables. It allows to quickly obtain suboptimal solutions in some
  2054. problems which take too long time to be solved to optimality.} option:
  2055. \verb|GLP_ON | --- enable applying the proximity search heuristic;
  2056. \verb|GLP_OFF| --- disable applying the proximity search pump heuristic.
  2057. \bigskip
  2058. {\tt int ps\_tm\_lim} (default: {\tt 60000})
  2059. Time limit, in milliseconds, for the proximity search heuristic (see
  2060. above).
  2061. \bigskip
  2062. {\tt int gmi\_cuts} (default: {\tt GLP\_OFF})
  2063. Gomory's mixed integer cut option:
  2064. \verb|GLP_ON | --- enable generating Gomory's cuts;
  2065. \verb|GLP_OFF| --- disable generating Gomory's cuts.
  2066. \bigskip
  2067. {\tt int mir\_cuts} (default: {\tt GLP\_OFF})
  2068. Mixed integer rounding (MIR) cut option:
  2069. \verb|GLP_ON | --- enable generating MIR cuts;
  2070. \verb|GLP_OFF| --- disable generating MIR cuts.
  2071. \bigskip
  2072. {\tt int cov\_cuts} (default: {\tt GLP\_OFF})
  2073. Mixed cover cut option:
  2074. \verb|GLP_ON | --- enable generating mixed cover cuts;
  2075. \verb|GLP_OFF| --- disable generating mixed cover cuts.
  2076. \bigskip
  2077. {\tt int clq\_cuts} (default: {\tt GLP\_OFF})
  2078. Clique cut option:
  2079. \verb|GLP_ON | --- enable generating clique cuts;
  2080. \verb|GLP_OFF| --- disable generating clique cuts.
  2081. \bigskip
  2082. {\tt double tol\_int} (default: {\tt 1e-5})
  2083. Absolute tolerance used to check if optimal solution to the current LP
  2084. relaxation is integer feasible. (Do not change this parameter without
  2085. detailed understanding its purpose.)
  2086. \newpage
  2087. {\tt double tol\_obj} (default: {\tt 1e-7})
  2088. Relative tolerance used to check if the objective value in optimal
  2089. solution to the current LP relaxation is not better than in the best
  2090. known integer feasible solution. (Do not change this parameter without
  2091. detailed understanding its purpose.)
  2092. \bigskip
  2093. {\tt double mip\_gap} (default: {\tt 0.0})
  2094. The relative mip gap tolerance. If the relative mip gap for currently
  2095. known best integer feasible solution falls below this tolerance, the
  2096. solver terminates the search. This allows obtainig suboptimal integer
  2097. feasible solutions if solving the problem to optimality takes too long
  2098. time.
  2099. \bigskip
  2100. {\tt int tm\_lim} (default: {\tt INT\_MAX})
  2101. Searching time limit, in milliseconds.
  2102. \bigskip
  2103. {\tt int out\_frq} (default: {\tt 5000})
  2104. Output frequency, in milliseconds. This parameter specifies how
  2105. frequently the solver sends information about the solution process to
  2106. the terminal.
  2107. \bigskip
  2108. {\tt int out\_dly} (default: {\tt 10000})
  2109. Output delay, in milliseconds. This parameter specifies how long the
  2110. solver should delay sending information about solution of the current
  2111. LP relaxation with the simplex method to the terminal.
  2112. \bigskip
  2113. {\tt void (*cb\_func)(glp\_tree *tree, void *info)}
  2114. (default: {\tt NULL})
  2115. Entry point to the user-defined callback routine. \verb|NULL| means
  2116. the advanced solver interface is not used. For more details see Chapter
  2117. ``Branch-and-Cut API Routines''.
  2118. \bigskip
  2119. {\tt void *cb\_info} (default: {\tt NULL})
  2120. Transit pointer passed to the routine \verb|cb_func| (see above).
  2121. \bigskip
  2122. {\tt int cb\_size} (default: {\tt 0})
  2123. The number of extra (up to 256) bytes allocated for each node of the
  2124. branch-and-bound tree to store application-specific data. On creating
  2125. a node these bytes are initialized by binary zeros.
  2126. \bigskip
  2127. {\tt int presolve} (default: {\tt GLP\_OFF})
  2128. MIP presolver option:
  2129. \verb|GLP_ON | --- enable using the MIP presolver;
  2130. \verb|GLP_OFF| --- disable using the MIP presolver.
  2131. \newpage
  2132. {\tt int binarize} (default: {\tt GLP\_OFF})
  2133. Binarization option (used only if the presolver is enabled):
  2134. \verb|GLP_ON | --- replace general integer variables by binary ones;
  2135. \verb|GLP_OFF| --- do not use binarization.
  2136. \subsection{glp\_init\_iocp --- initialize integer optimizer control
  2137. parameters}
  2138. \synopsis
  2139. \begin{verbatim}
  2140. void glp_init_iocp(glp_iocp *parm);
  2141. \end{verbatim}
  2142. \description
  2143. The routine \verb|glp_init_iocp| initializes control parameters, which
  2144. are used by the branch-and-cut solver, with default values.
  2145. Default values of the control parameters are stored in
  2146. a \verb|glp_iocp| structure, which the parameter \verb|parm| points to.
  2147. \subsection{glp\_mip\_status --- determine status of MIP solution}
  2148. \synopsis
  2149. \begin{verbatim}
  2150. int glp_mip_status(glp_prob *P);
  2151. \end{verbatim}
  2152. \returns
  2153. The routine \verb|glp_mip_status| reports the status of a MIP solution
  2154. found by the MIP solver as follows:
  2155. \verb|GLP_UNDEF | --- MIP solution is undefined;
  2156. \verb|GLP_OPT | --- MIP solution is integer optimal;
  2157. \verb|GLP_FEAS | --- MIP solution is integer feasible, however, its
  2158. optimality (or non-optimality) has not been proven, perhaps due to
  2159. premature termination of the search;
  2160. \verb|GLP_NOFEAS| --- problem has no integer feasible solution (proven
  2161. by the solver).
  2162. \subsection{glp\_mip\_obj\_val --- retrieve objective value}
  2163. \synopsis
  2164. \begin{verbatim}
  2165. double glp_mip_obj_val(glp_prob *P);
  2166. \end{verbatim}
  2167. \returns
  2168. The routine \verb|glp_mip_obj_val| returns value of the objective
  2169. function for MIP solution.
  2170. \subsection{glp\_mip\_row\_val --- retrieve row value}
  2171. \synopsis
  2172. \begin{verbatim}
  2173. double glp_mip_row_val(glp_prob *P, int i);
  2174. \end{verbatim}
  2175. \returns
  2176. The routine \verb|glp_mip_row_val| returns value of the auxiliary
  2177. variable associated with \verb|i|-th row for MIP solution.
  2178. \subsection{glp\_mip\_col\_val --- retrieve column value}
  2179. \synopsis
  2180. \begin{verbatim}
  2181. double glp_mip_col_val(glp_prob *P, int j);
  2182. \end{verbatim}
  2183. \returns
  2184. The routine \verb|glp_mip_col_val| returns value of the structural
  2185. variable associated with \verb|j|-th column for MIP solution.
  2186. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2187. \newpage
  2188. \section{Additional routines}
  2189. \subsection{glp\_check\_kkt --- check feasibility/optimality
  2190. conditions}
  2191. \synopsis
  2192. {\parskip=0pt
  2193. \tt void glp\_check\_kkt(glp\_prob *P, int sol, int cond,
  2194. double *ae\_max, int *ae\_ind,
  2195. \hspace{105pt}double *re\_max, int *re\_ind);}
  2196. \description
  2197. The routine \verb|glp_check_kkt| allows to check
  2198. feasibility/optimality conditions for the current solution stored in
  2199. the specified problem object. (For basic and interior-point solutions
  2200. these conditions are known as {\it Karush--Kuhn--Tucker optimality
  2201. conditions}.)
  2202. The parameter \verb|sol| specifies which solution should be checked:
  2203. \verb|GLP_SOL| --- basic solution;
  2204. \verb|GLP_IPT| --- interior-point solution;
  2205. \verb|GLP_MIP| --- mixed integer solution.
  2206. The parameter \verb|cond| specifies which condition should be checked:
  2207. \verb|GLP_KKT_PE| --- check primal equality constraints (KKT.PE);
  2208. \verb|GLP_KKT_PB| --- check primal bound constraints (KKT.PB);
  2209. \verb|GLP_KKT_DE| --- check dual equality constraints (KKT.DE). This
  2210. conditions can be checked only for basic or interior-point solution;
  2211. \verb|GLP_KKT_DB| --- check dual bound constraints (KKT.DB). This
  2212. conditions can be checked only for basic or interior-point solution.
  2213. Detailed explanations of these conditions are given below in paragraph
  2214. ``Background''.
  2215. On exit the routine stores the following information to locations
  2216. specified by parameters \verb|ae_max|, \verb|ae_ind|, \verb|re_max|,
  2217. and \verb|re_ind| (if some parameter is a null pointer, corresponding
  2218. information is not stored):
  2219. \verb|ae_max| --- largest absolute error;
  2220. \verb|ae_ind| --- number of row (KKT.PE), column (KKT.DE), or variable
  2221. (KKT.PB, KKT.DB) with the largest absolute error;
  2222. \verb|re_max| --- largest relative error;
  2223. \verb|re_ind| --- number of row (KKT.PE), column (KKT.DE), or variable
  2224. (KKT.PB, KKT.DB) with the largest relative error.
  2225. Row (auxiliary variable) numbers are in the range 1 to $m$, where $m$
  2226. is the number of rows in the problem object. Column (structural
  2227. variable) numbers are in the range 1 to $n$, where $n$ is the number
  2228. of columns in the problem object. Variable numbers are in the range
  2229. 1 to $m+n$, where variables with numbers 1 to $m$ correspond to rows,
  2230. and variables with numbers $m+1$ to $m+n$ correspond to columns. If
  2231. the error reported is exact zero, corresponding row, column or variable
  2232. number is set to zero.
  2233. \para{Background}
  2234. \def\arraystretch{1.5}
  2235. The first condition checked by the routine is the following:
  2236. $$x_R - A x_S = 0, \eqno{\rm (KKT.PE)}$$
  2237. where $x_R$ is the subvector of auxiliary variables (rows), $x_S$ is
  2238. the subvector of structural variables (columns), $A$ is the constraint
  2239. matrix. This condition expresses the requirement that all primal
  2240. variables should satisfy to the system of equality constraints of the
  2241. original LP problem. In case of exact arithmetic this condition would
  2242. be satisfied for any basic solution; however, in case of inexact
  2243. (floating-point) arithmetic, this condition shows how accurate the
  2244. primal solution is, that depends on accuracy of a representation of the
  2245. basis matrix used by the simplex method, or on accuracy provided by the
  2246. interior-point method.
  2247. To check the condition (KKT.PE) the routine computes the vector of
  2248. residuals:
  2249. $$g = x_R - A x_S,$$
  2250. and determines component of this vector that correspond to largest
  2251. absolute and relative errors:
  2252. $${\tt ae\_max}=\max_{1\leq i\leq m}|g_i|,$$
  2253. $${\tt re\_max}=\max_{1\leq i\leq m}\frac{|g_i|}{1+|(x_R)_i|}.$$
  2254. The second condition checked by the routine is the following:
  2255. $$l_k \leq x_k \leq u_k {\rm \ \ \ for\ all}\ k=1,\dots,m+n,
  2256. \eqno{\rm (KKT.PB)}$$
  2257. where $x_k$ is auxiliary ($1\leq k\leq m$) or structural
  2258. ($m+1\leq k\leq m+n$) variable, $l_k$ and $u_k$ are, respectively,
  2259. lower and upper bounds of the variable $x_k$ (including cases of
  2260. infinite bounds). This condition expresses the requirement that all
  2261. primal variables shoudl satisfy to bound constraints of the original
  2262. LP problem. In case of basic solution all non-basic variables are
  2263. placed on their active bounds, so actually the condition (KKT.PB) needs
  2264. to be checked for basic variables only. If the primal solution has
  2265. sufficient accuracy, this condition shows its primal feasibility.
  2266. To check the condition (KKT.PB) the routine computes a vector of
  2267. residuals:
  2268. $$
  2269. h_k = \left\{
  2270. \begin{array}{ll}
  2271. 0, & {\rm if}\ l_k \leq x_k \leq u_k \\
  2272. x_k - l_k, & {\rm if}\ x_k < l_k \\
  2273. x_k - u_k, & {\rm if}\ x_k > u_k \\
  2274. \end{array}
  2275. \right.
  2276. $$
  2277. for all $k=1,\dots,m+n$, and determines components of this vector that
  2278. correspond to largest absolute and relative errors:
  2279. $${\tt ae\_max}=\max_{1\leq k \leq m+n}|h_k|,$$
  2280. $${\tt re\_max}=\max_{1\leq k \leq m+n}\frac{|h_k|}{1+|x_k|}.$$
  2281. The third condition checked by the routine is:
  2282. $${\rm grad}\;Z = c = (\tilde{A})^T \pi + d,$$
  2283. where $Z$ is the objective function, $c$ is the vector of objective
  2284. coefficients, $(\tilde{A})^T$ is a matrix transposed to the expanded
  2285. constraint matrix $\tilde{A} = (I|-A)$, $\pi$ is a vector of Lagrange
  2286. multipliers that correspond to equality constraints of the original LP
  2287. problem, $d$ is a vector of Lagrange multipliers that correspond to
  2288. bound constraints for all (auxiliary and structural) variables of the
  2289. original LP problem. Geometrically the third condition expresses the
  2290. requirement that the gradient of the objective function should belong
  2291. to the orthogonal complement of a linear subspace defined by the
  2292. equality and active bound constraints, i.e. that the gradient is
  2293. a linear combination of normals to the constraint hyperplanes, where
  2294. Lagrange multipliers $\pi$ and $d$ are coefficients of that linear
  2295. combination.
  2296. To eliminate the vector $\pi$ rewrite the third condition as:
  2297. $$
  2298. \left(\begin{array}{@{}c@{}}I \\ -A^T\end{array}\right) \pi =
  2299. \left(\begin{array}{@{}c@{}}d_R \\ d_S\end{array}\right) +
  2300. \left(\begin{array}{@{}c@{}}c_R \\ c_S\end{array}\right),
  2301. $$
  2302. or, equivalently,
  2303. $$
  2304. \left\{
  2305. \begin{array}{r@{}c@{}c}
  2306. \pi + d_R&\ =\ &c_R, \\
  2307. -A^T\pi + d_S&\ =\ &c_S. \\
  2308. \end{array}
  2309. \right.
  2310. $$
  2311. Then substituting the vector $\pi$ from the first equation into the
  2312. second we finally have:
  2313. $$A^T (d_R - c_R) + (d_S - c_S) = 0, \eqno{\rm(KKT.DE)}$$
  2314. where $d_R$ is the subvector of reduced costs of auxiliary variables
  2315. (rows), $d_S$ is the subvector of reduced costs of structural variables
  2316. (columns), $c_R$ and $c_S$ are subvectors of objective coefficients at,
  2317. respectively, auxiliary and structural variables, $A^T$ is a matrix
  2318. transposed to the constraint matrix of the original LP problem. In case
  2319. of exact arithmetic this condition would be satisfied for any basic
  2320. solution; however, in case of inexact (floating-point) arithmetic, this
  2321. condition shows how accurate the dual solution is, that depends on
  2322. accuracy of a representation of the basis matrix used by the simplex
  2323. method, or on accuracy provided by the interior-point method.
  2324. To check the condition (KKT.DE) the routine computes a vector of
  2325. residuals:
  2326. $$u = A^T (d_R - c_R) + (d_S - c_S),$$
  2327. and determines components of this vector that correspond to largest
  2328. absolute and relative errors:
  2329. $${\tt ae\_max}=\max_{1\leq j\leq n}|u_j|,$$
  2330. $${\tt re\_max}=\max_{1\leq j\leq n}\frac{|u_j|}{1+|(d_S)_j-(c_S)_j|}.$$
  2331. \newpage
  2332. The fourth condition checked by the routine is the following:
  2333. $$
  2334. \left\{
  2335. \begin{array}{l@{\ }r@{\ }c@{\ }c@{\ }c@{\ }l@{\ }c@{\ }c@{\ }c@{\ }l}
  2336. {\rm if} & -\infty & < & x_k & < & +\infty,
  2337. & {\rm then} & d_k & = & 0 \\
  2338. {\rm if} & l_k & \leq & x_k & < & +\infty,
  2339. & {\rm then} & d_k & \geq & 0\ {\rm(minimization)} \\
  2340. &&&&&& & d_k & \leq & 0\ {\rm(maximization)} \\
  2341. {\rm if} & -\infty & < & x_k & \leq & u_k,
  2342. & {\rm then} & d_k & \leq & 0\ {\rm(minimization)} \\
  2343. &&&&&& & d_k & \geq & 0\ {\rm(maximization)} \\
  2344. {\rm if} & l_k & \leq & x_k & \leq & u_k,
  2345. & {\rm then} & d_k & {\rm is} & {\rm of\ any\ sign} \\
  2346. \end{array}\right.\eqno{\rm(KKT.DB)}
  2347. $$
  2348. for all $k=1,\dots,m+n$, where $d_k$ is a reduced cost (Lagrange
  2349. multiplier) of auxiliary ($1\leq k\leq m$) or structural
  2350. ($m+1\leq k\leq m+n$) variable $x_k$. Geometrically this condition
  2351. expresses the requirement that constraints of the original problem must
  2352. ``hold'' the point preventing its movement along the anti-gradient (in
  2353. case of minimization) or the gradient (in case of maximization) of the
  2354. objective function. In case of basic solution reduced costs of all
  2355. basic variables are placed on their active (zero) bounds, so actually
  2356. the condition (KKT.DB) needs to be checked for non-basic variables
  2357. only. If the dual solution has sufficient accuracy, this condition
  2358. shows the dual feasibility of the solution.
  2359. To check the condition (KKT.DB) the routine computes a vector of
  2360. residuals:
  2361. $$
  2362. v_k = \left\{
  2363. \begin{array}{ll}
  2364. 0, & {\rm if}\ d_k\ {\rm has\ correct\ sign} \\
  2365. |d_k|, & {\rm if}\ d_k\ {\rm has\ wrong\ sign} \\
  2366. \end{array}
  2367. \right.
  2368. $$
  2369. for all $k=1,\dots,m+n$, and determines components of this vector that
  2370. correspond to largest absolute and relative errors:
  2371. $${\tt ae\_max}=\max_{1\leq k\leq m+n}|v_k|,$$
  2372. $${\tt re\_max}=\max_{1\leq k\leq m+n}\frac{|v_k|}{1+|d_k - c_k|}.$$
  2373. Note that the complete set of Karush-Kuhn-Tucker optimality conditions
  2374. also includes the fifth, so called {\it complementary slackness
  2375. condition}, which expresses the requirement that at least either
  2376. a primal variable $x_k$ or its dual counterpart $d_k$ should be on its
  2377. bound for all $k=1,\dots,m+n$. Currently checking this condition is
  2378. not implemented yet.
  2379. \def\arraystretch{1}
  2380. %* eof *%