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.

3470 lines
106 KiB

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