The source code and dockerfile for the GSW2024 AI Lab.
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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

3480 lines
106 KiB

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