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.

1090 lines
37 KiB

  1. %* glpk05.tex *%
  2. \chapter{Branch-and-Cut API Routines}
  3. \section{Introduction}
  4. \subsection{Using the callback routine}
  5. The GLPK MIP solver based on the branch-and-cut method allows the
  6. application program to control the solution process. This is attained
  7. by means of the user-defined callback routine, which is called by the
  8. solver at various points of the branch-and-cut algorithm.
  9. The callback routine passed to the MIP solver should be written by the
  10. user and has the following specification:\footnote{The name
  11. {\tt foo\_bar} used here is a placeholder for the callback routine
  12. name.}
  13. \begin{verbatim}
  14. void foo_bar(glp_tree *T, void *info);
  15. \end{verbatim}
  16. \noindent
  17. where \verb|tree| is a pointer to the data structure \verb|glp_tree|,
  18. which should be used on subsequent calls to branch-and-cut interface
  19. routines, and \verb|info| is a transit pointer passed to the routine
  20. \verb|glp_intopt|, which may be used by the application program to pass
  21. some external data to the callback routine.
  22. The callback routine is passed to the MIP solver through the control
  23. parameter structure \verb|glp_iocp| (see Chapter ``Basic API
  24. Routines'', Section ``Mixed integer programming routines'', Subsection
  25. ``Solve MIP problem with the branch-and-cut method'') as follows:
  26. \begin{verbatim}
  27. glp_prob *mip;
  28. glp_iocp parm;
  29. . . .
  30. glp_init_iocp(&parm);
  31. . . .
  32. parm.cb_func = foo_bar;
  33. parm.cb_info = ... ;
  34. ret = glp_intopt(mip, &parm);
  35. . . .
  36. \end{verbatim}
  37. To determine why it is being called by the MIP solver the callback
  38. routine should use the routine \verb|glp_ios_reason| (described in this
  39. section below), which returns a code indicating the reason for calling.
  40. Depending on the reason the callback routine may perform necessary
  41. actions to control the solution process.
  42. The reason codes, which correspond to various point of the
  43. branch-and-cut algorithm implemented in the MIP solver, are described
  44. in Subsection ``Reasons for calling the callback routine'' below.
  45. To ignore calls for reasons, which are not processed by the callback
  46. routine, it should simply return to the MIP solver doing nothing. For
  47. example:
  48. \begin{verbatim}
  49. void foo_bar(glp_tree *T, void *info)
  50. { . . .
  51. switch (glp_ios_reason(T))
  52. { case GLP_IBRANCH:
  53. . . .
  54. break;
  55. case GLP_ISELECT:
  56. . . .
  57. break;
  58. default:
  59. /* ignore call for other reasons */
  60. break;
  61. }
  62. return;
  63. }
  64. \end{verbatim}
  65. To control the solution process as well as to obtain necessary
  66. information the callback routine may use the branch-and-cut API
  67. routines described in this chapter. Names of all these routines begin
  68. with `\verb|glp_ios_|'.
  69. \subsection{Branch-and-cut algorithm}
  70. This section gives a schematic description of the branch-and-cut
  71. algorithm as it is implemented in the GLPK MIP solver.
  72. {\it 1. Initialization}
  73. Set $L:=\{P_0\}$, where $L$ is the {\it active list} (i.e. the list of
  74. active subproblems), $P_0$ is the original MIP problem to be solved.
  75. Set $z^{\it best}:=+\infty$ (in case of minimization) or
  76. $z^{\it best}:=-\infty$ (in case of maximization), where $z^{\it best}$
  77. is {\it incumbent value}, i.e. an upper (minimization) or lower
  78. (maximization) global bound for $z^{\it opt}$, the optimal objective
  79. value for $P^0$.
  80. {\it 2. Subproblem selection}
  81. If $L=\varnothing$ then GO TO 9.
  82. Select $P\in L$, i.e. make active subproblem $P$ current.
  83. \newpage
  84. {\it 3. Solving LP relaxation}
  85. Solve $P^{\it LP}$, which is LP relaxation of $P$.
  86. If $P^{\it LP}$ has no primal feasible solution then GO TO 8.
  87. Let $z^{\it LP}$ be the optimal objective value for $P^{\it LP}$.
  88. If $z^{\it LP}\geq z^{\it best}$ (minimization) or
  89. $z^{\it LP}\leq z^{\rm best}$ (), GO TO 8.
  90. {\it 4. Adding ``lazy'' constraints}
  91. Let $x^{\it LP}$ be the optimal solution to $P^{\it LP}$.
  92. If there are ``lazy'' constraints (i.e. essential constraints not
  93. included in the original MIP problem $P_0$), which are violated at the
  94. optimal point $x^{\it LP}$, add them to $P$, and GO TO 3.
  95. {\it 5. Check for integrality}
  96. Let $x_j$ be a variable, which is required to be integer, and let
  97. $x^{\it LP}_j\in x^{\it LP}$ be its value in the optimal solution to
  98. $P^{\it LP}$.
  99. If $x^{\it LP}_j$ are integral for all integer variables, then a better
  100. integer feasible solution is found. Store its components, set
  101. $z^{\it best}:=z^{\it LP}$, and GO TO 8.
  102. {\it 6. Adding cutting planes}
  103. If there are cutting planes (i.e. valid constraints for $P$),
  104. which are violated at the optimal point $x^{\it LP}$, add them to $P$,
  105. and GO TO 3.
  106. {\it 7. Branching}
  107. Select {\it branching variable} $x_j$, i.e. a variable, which is
  108. required to be integer, and whose value $x^{\it LP}_j\in x^{\it LP}$ is
  109. fractional in the optimal solution to $P^{\it LP}$.
  110. Create new subproblem $P^D$ (so called {\it down branch}), which is
  111. identical to the current subproblem $P$ with exception that the upper
  112. bound of $x_j$ is replaced by $\lfloor x^{\it LP}_j\rfloor$. (For
  113. example, if $x^{\it LP}_j=3.14$, the new upper bound of $x_j$ in the
  114. down branch will be $\lfloor 3.14\rfloor=3$.)
  115. Create new subproblem $P^U$ (so called {\it up branch}), which is
  116. identical to the current subproblem $P$ with exception that the lower
  117. bound of $x_j$ is replaced by $\lceil x^{\it LP}_j\rceil$. (For example,
  118. if $x^{\it LP}_j=3.14$, the new lower bound of $x_j$ in the up branch
  119. will be $\lceil 3.14\rceil=4$.)
  120. Set $L:=(L\backslash\{P\})\cup\{P^D,P^U\}$, i.e. remove the current
  121. subproblem $P$ from the active list $L$ and add two new subproblems
  122. $P^D$ and $P^U$ to it. Then GO TO 2.
  123. {\it 8. Pruning}
  124. Remove from the active list $L$ all subproblems (including the current
  125. one), whose local bound $\widetilde{z}$ is not better than the global
  126. bound $z^{\it best}$, i.e. set $L:=L\backslash\{P\}$ for all $P$, where
  127. $\widetilde{z}\geq z^{\it best}$ (in case of minimization) or
  128. $\widetilde{z}\leq z^{\it best}$ (in case of maximization), and then
  129. GO TO 2.
  130. The local bound $\widetilde{z}$ for subproblem $P$ is an lower
  131. (minimization) or upper (maximization) bound for integer optimal
  132. solution to {\it this} subproblem (not to the original problem). This
  133. bound is local in the sense that only subproblems in the subtree rooted
  134. at node $P$ cannot have better integer feasible solutions. Note that
  135. the local bound is not necessarily the optimal objective value to LP
  136. relaxation $P^{\it LP}$.
  137. {\it 9. Termination}
  138. If $z^{\it best}=+\infty$ (in case of minimization) or
  139. $z^{\it best}=-\infty$ (in case of maximization), the original problem
  140. $P_0$ has no integer feasible solution. Otherwise, the last integer
  141. feasible solution stored on step 5 is the integer optimal solution to
  142. the original problem $P_0$ with $z^{\it opt}=z^{\it best}$. STOP.
  143. \subsection{The search tree}
  144. On the branching step of the branch-and-cut algorithm the current
  145. subproblem is divided into two\footnote{In more general cases the
  146. current subproblem may be divided into more than two subproblems.
  147. However, currently such feature is not used in GLPK.} new subproblems,
  148. so the set of all subproblems can be represented in the form of a rooted
  149. tree, which is called the {\it search} or {\it branch-and-bound} tree.
  150. An example of the search tree is shown on Fig.~1. Each node of the
  151. search tree corresponds to a subproblem, so the terms `node' and
  152. `subproblem' may be used synonymously.
  153. \begin{figure}[t]
  154. \noindent\hfil
  155. \xymatrix @R=20pt @C=10pt
  156. {&&&&&&*+<14pt>[o][F=]{A}\ar@{-}[dllll]\ar@{-}[dr]\ar@{-}[drrrr]&&&&\\
  157. &&*+<14pt>[o][F=]{B}\ar@{-}[dl]\ar@{-}[dr]&&&&&*+<14pt>[o][F=]{C}
  158. \ar@{-}[dll]\ar@{-}[dr]\ar@{-}[drrr]&&&*+<14pt>[o][F-]{\times}\\
  159. &*+<14pt>[o][F-]{\times}\ar@{-}[dl]\ar@{-}[d]\ar@{-}[dr]&&
  160. *+<14pt>[o][F-]{D}&&*+<14pt>[o][F=]{E}\ar@{-}[dl]\ar@{-}[dr]&&&
  161. *+<14pt>[o][F=]{F}\ar@{-}[dl]\ar@{-}[dr]&&*+<14pt>[o][F-]{G}\\
  162. *+<14pt>[o][F-]{\times}&*+<14pt>[o][F-]{\times}&*+<14pt>[o][F-]{\times}
  163. &&*+<14pt>[][F-]{H}&&*+<14pt>[o][F-]{I}&*+<14pt>[o][F-]{\times}&&
  164. *+<14pt>[o][F-]{J}&\\}
  165. \bigskip
  166. \noindent\hspace{.8in}
  167. \xymatrix @R=11pt
  168. {*+<20pt>[][F-]{}&*\txt{\makebox[1in][l]{Current}}&&
  169. *+<20pt>[o][F-]{}&*\txt{\makebox[1in][l]{Active}}\\
  170. *+<20pt>[o][F=]{}&*\txt{\makebox[1in][l]{Non-active}}&&
  171. *+<14pt>[o][F-]{\times}&*\txt{\makebox[1in][l]{Fathomed}}\\
  172. }
  173. \bigskip
  174. \begin{center}
  175. Fig. 1. An example of the search tree.
  176. \end{center}
  177. \end{figure}
  178. In GLPK each node may have one of the following four statuses:
  179. \vspace*{-8pt}
  180. \begin{itemize}
  181. \item {\it current node} is the active node currently being
  182. processed;
  183. \item {\it active node} is a leaf node, which still has to be
  184. processed;
  185. \item {\it non-active node} is a node, which has been processed,
  186. but not fathomed;
  187. \item {\it fathomed node} is a node, which has been processed and
  188. fathomed.
  189. \end{itemize}
  190. \vspace*{-8pt}
  191. In the data structure representing the search tree GLPK keeps only
  192. current, active, and non-active nodes. Once a node has been fathomed,
  193. it is removed from the tree data structure.
  194. Being created each node of the search tree is assigned a distinct
  195. positive integer called the {\it subproblem reference number}, which
  196. may be used by the application program to specify a particular node of
  197. the tree. The root node corresponding to the original problem to be
  198. solved is always assigned the reference number 1.
  199. \subsection{Current subproblem}
  200. The current subproblem is a MIP problem corresponding to the current
  201. node of the search tree. It is represented as the GLPK problem object
  202. (\verb|glp_prob|) that allows the application program using API
  203. routines to access its content in the standard way. If the MIP
  204. presolver is not used, it is the original problem object passed to the
  205. routine \verb|glp_intopt|; otherwise, it is an internal problem object
  206. built by the MIP presolver.
  207. Note that the problem object is used by the MIP solver itself during
  208. the solution process for various purposes (to solve LP relaxations, to
  209. perfom branching, etc.), and even if the MIP presolver is not used, the
  210. current content of the problem object may differ from its original
  211. content. For example, it may have additional rows, bounds of some rows
  212. and columns may be changed, etc. In particular, LP segment of the
  213. problem object corresponds to LP relaxation of the current subproblem.
  214. However, on exit from the MIP solver the content of the problem object
  215. is restored to its original state.
  216. To obtain information from the problem object the application program
  217. may use any API routines, which do not change the object. Using API
  218. routines, which change the problem object, is restricted to stipulated
  219. cases.
  220. \subsection{The cut pool}
  221. The {\it cut pool} is a set of cutting plane constraints maintained by
  222. the MIP solver. It is used by the GLPK cut generation routines and may
  223. be used by the application program in the same way, i.e. rather than
  224. to add cutting plane constraints directly to the problem object the
  225. application program may store them to the cut pool. In the latter case
  226. the solver looks through the cut pool, selects efficient constraints,
  227. and adds them to the problem object.
  228. \subsection{Reasons for calling the callback routine}
  229. The callback routine may be called by the MIP solver for the following
  230. reasons.
  231. \para{Request for subproblem selection}
  232. The callback routine is called with the reason code \verb|GLP_ISELECT|
  233. if the current subproblem has been fathomed and therefore there is no
  234. current subproblem.
  235. In response the callback routine may select some subproblem from the
  236. active list and pass its reference number to the solver using the
  237. routine \verb|glp_ios_select_node|, in which case the solver continues
  238. the search from the specified active subproblem. If no selection is
  239. made by the callback routine, the solver uses a backtracking technique
  240. specified by the control parameter \verb|bt_tech|.
  241. To explore the active list (i.e. active nodes of the branch-and-bound
  242. tree) the callback routine may use the routines \verb|glp_ios_next_node|
  243. and \verb|glp_ios_prev_node|.
  244. \para{Request for preprocessing}
  245. The callback routine is called with the reason code \verb|GLP_IPREPRO|
  246. if the current subproblem has just been selected from the active list
  247. and its LP relaxation is not solved yet.
  248. In response the callback routine may perform some preprocessing of the
  249. current subproblem like tightening bounds of some variables or removing
  250. bounds of some redundant constraints.
  251. \para{Request for row generation}
  252. The callback routine is called with the reason code \verb|GLP_IROWGEN|
  253. if LP relaxation of the current subproblem has just been solved to
  254. optimality and its objective value is better than the best known
  255. integer feasible solution.
  256. In response the callback routine may add one or more ``lazy''
  257. constraints (rows), which are violated by the current optimal solution
  258. of LP relaxation, using API routines \verb|glp_add_rows|,
  259. \verb|glp_set_row_name|, \verb|glp_set_row_bnds|, and
  260. \verb|glp_set_mat_row|, in which case the solver will perform
  261. re-optimization of LP relaxation. If there are no violated constraints,
  262. the callback routine should just return.
  263. Note that components of optimal solution to LP relaxation can be
  264. obtained with API\linebreak routines \verb|glp_get_obj_val|,
  265. \verb|glp_get_row_prim|, \verb|glp_get_row_dual|,
  266. \verb|glp_get_col_prim|, and\linebreak \verb|glp_get_col_dual|.
  267. \para{Request for heuristic solution}
  268. The callback routine is called with the reason code \verb|GLP_IHEUR|
  269. if LP relaxation of the current subproblem being solved to optimality
  270. is integer infeasible (i.e. values of some structural variables of
  271. integer kind are fractional), though its objective value is better than
  272. the best known integer feasible solution.
  273. In response the callback routine may try applying a primal heuristic
  274. to find an integer feasible solution,\footnote{Integer feasible to the
  275. original MIP problem, not to the current subproblem.} which is better
  276. than the best known one. In case of success the callback routine may
  277. store such better solution in the problem object using the routine
  278. \verb|glp_ios_heur_sol|.
  279. \para{Request for cut generation}
  280. The callback routine is called with the reason code \verb|GLP_ICUTGEN|
  281. if LP relaxation of the current subproblem being solved to optimality
  282. is integer infeasible (i.e. values of some structural variables of
  283. integer kind are fractional), though its objective value is better than
  284. the best known integer feasible solution.
  285. In response the callback routine may reformulate the {\it current}
  286. subproblem (before it will be splitted up due to branching) by adding
  287. to the problem object one or more {\it cutting plane constraints},
  288. which cut off the fractional optimal point from the MIP
  289. polytope.\footnote{Since these constraints are added to the current
  290. subproblem, they may be globally as well as locally valid.}
  291. Adding cutting plane constraints may be performed in two ways.
  292. One way is the same as for the reason code \verb|GLP_IROWGEN| (see
  293. above), in which case the callback routine adds new rows corresponding
  294. to cutting plane constraints directly to the current subproblem.
  295. The other way is to add cutting plane constraints to the
  296. {\it cut pool}, a set of cutting plane constraints maintained by the
  297. solver, rather than directly to the current subproblem. In this case
  298. after return from the callback routine the solver looks through the
  299. cut pool, selects efficient cutting plane constraints, adds them to the
  300. current subproblem, drops other constraints, and then performs
  301. re-optimization.
  302. \para{Request for branching}
  303. The callback routine is called with the reason code \verb|GLP_IBRANCH|
  304. if LP relaxation of the current subproblem being solved to optimality
  305. is integer infeasible (i.e. values of some structural variables of
  306. integer kind are fractional), though its objective value is better than
  307. the best known integer feasible solution.
  308. In response the callback routine may choose some variable suitable for
  309. branching (i.e. integer variable, whose value in optimal solution to
  310. LP relaxation of the current subproblem is fractional) and pass its
  311. ordinal number to the solver using the routine
  312. \verb|glp_ios_branch_upon|, in which case the solver splits the current
  313. subproblem in two new subproblems and continues the search.
  314. If no choice is made by the callback routine, the solver uses
  315. a branching technique specified by the control parameter \verb|br_tech|.
  316. \para{Better integer solution found}
  317. The callback routine is called with the reason code \verb|GLP_IBINGO|
  318. if LP relaxation of the current subproblem being solved to optimality
  319. is integer feasible (i.e. values of all structural variables of integer
  320. kind are integral within the working precision) and its objective value
  321. is better than the best known integer feasible solution.
  322. Optimal solution components for LP relaxation can be obtained in the
  323. same way as for the reason code \verb|GLP_IROWGEN| (see above).
  324. Components of the new MIP solution can be obtained with API routines
  325. \verb|glp_mip_obj_val|, \verb|glp_mip_row_val|, and
  326. \verb|glp_mip_col_val|. Note, however, that due to row/cut generation
  327. there may be additional rows in the problem object.
  328. The difference between optimal solution to LP relaxation and
  329. corresponding MIP solution is that in the former case some structural
  330. variables of integer kind (namely, basic variables) may have values,
  331. which are close to nearest integers within the working precision, while
  332. in the latter case all such variables have exact integral values.
  333. The reason \verb|GLP_IBINGO| is intended only for informational
  334. purposes, so the callback routine should not modify the problem object
  335. in this case.
  336. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  337. \newpage
  338. \section{Basic routines}
  339. \subsection{glp\_ios\_reason --- determine reason for calling the
  340. callback routine}
  341. \synopsis
  342. \begin{verbatim}
  343. int glp_ios_reason(glp_tree *T);
  344. \end{verbatim}
  345. \returns
  346. The routine \verb|glp_ios_reason| returns a code, which indicates why
  347. the user-defined callback routine is being called:
  348. \verb|GLP_ISELECT| --- request for subproblem selection;
  349. \verb|GLP_IPREPRO| --- request for preprocessing;
  350. \verb|GLP_IROWGEN| --- request for row generation;
  351. \verb|GLP_IHEUR | --- request for heuristic solution;
  352. \verb|GLP_ICUTGEN| --- request for cut generation;
  353. \verb|GLP_IBRANCH| --- request for branching;
  354. \verb|GLP_IBINGO | --- better integer solution found.
  355. \subsection{glp\_ios\_get\_prob --- access the problem object}
  356. \synopsis
  357. \begin{verbatim}
  358. glp_prob *glp_ios_get_prob(glp_tree *T);
  359. \end{verbatim}
  360. \description
  361. The routine \verb|glp_ios_get_prob| can be called from the user-defined
  362. callback routine to access the problem object, which is used by the MIP
  363. solver. It is the original problem object passed to the routine
  364. \verb|glp_intopt| if the MIP presolver is not used; otherwise it is an
  365. internal problem object built by the presolver.
  366. \returns
  367. The routine \verb|glp_ios_get_prob| returns a pointer to the problem
  368. object used by the MIP solver.
  369. \para{Comments}
  370. To obtain various information about the problem instance the callback
  371. routine can access the problem object (i.e. the object of type
  372. \verb|glp_prob|) using the routine \verb|glp_ios_get_prob|. It is the
  373. original problem object passed to the routine \verb|glp_intopt| if the
  374. MIP presolver is not used; otherwise it is an internal problem object
  375. built by the presolver.
  376. \newpage
  377. \subsection{glp\_ios\_row\_attr --- determine additional row
  378. attributes}
  379. \synopsis
  380. \begin{verbatim}
  381. void glp_ios_row_attr(glp_tree *T, int i, glp_attr *attr);
  382. \end{verbatim}
  383. \description
  384. The routine \verb|glp_ios_row_attr| retrieves additional attributes of
  385. $i$-th row of the current subproblem and stores them in the structure
  386. \verb|glp_attr|, which the parameter \verb|attr| points to.
  387. The structure \verb|glp_attr| has the following fields:
  388. \medskip
  389. {\tt int level}
  390. Subproblem level at which the row was created. (If \verb|level| = 0,
  391. the row was added either to the original problem object passed to the
  392. routine \verb|glp_intopt| or to the root subproblem on generating
  393. ``lazy'' or/and cutting plane constraints.)
  394. \medskip
  395. {\tt int origin}
  396. The row origin flag:
  397. \verb|GLP_RF_REG | --- regular constraint;
  398. \verb|GLP_RF_LAZY| --- ``lazy'' constraint;
  399. \verb|GLP_RF_CUT | --- cutting plane constraint.
  400. \medskip
  401. {\tt int klass}
  402. The row class descriptor, which is a number passed to the routine
  403. \verb|glp_ios_add_row| as its third parameter. If the row is a cutting
  404. plane constraint generated by the solver, its class may be the
  405. following:
  406. \verb|GLP_RF_GMI | --- Gomory's mixed integer cut;
  407. \verb|GLP_RF_MIR | --- mixed integer rounding cut;
  408. \verb|GLP_RF_COV | --- mixed cover cut;
  409. \verb|GLP_RF_CLQ | --- clique cut.
  410. \subsection{glp\_ios\_mip\_gap --- compute relative MIP gap}
  411. \synopsis
  412. \begin{verbatim}
  413. double glp_ios_mip_gap(glp_tree *T);
  414. \end{verbatim}
  415. \description
  416. The routine \verb|glp_ios_mip_gap| computes the relative MIP gap (also
  417. called {\it duality gap}) with the following formula:
  418. $${\tt gap} = \frac{|{\tt best\_mip} - {\tt best\_bnd}|}
  419. {|{\tt best\_mip}| + {\tt DBL\_EPSILON}}$$
  420. where \verb|best_mip| is the best integer feasible solution found so
  421. far, \verb|best_bnd| is the best (global) bound. If no integer feasible
  422. solution has been found yet, \verb|gap| is set to \verb|DBL_MAX|.
  423. \returns
  424. The routine \verb|glp_ios_mip_gap| returns the relative MIP gap.
  425. \para{Comments}
  426. The relative MIP gap is used to measure the quality of the best integer
  427. feasible solution found so far, because the optimal solution value
  428. $z^*$ for the original MIP problem always lies in the range
  429. $${\tt best\_bnd}\leq z^*\leq{\tt best\_mip}$$
  430. in case of minimization, or in the range
  431. $${\tt best\_mip}\leq z^*\leq{\tt best\_bnd}$$
  432. in case of maximization.
  433. To express the relative MIP gap in percents the value returned by the
  434. routine \verb|glp_ios_mip_gap| should be multiplied by 100\%.
  435. \subsection{glp\_ios\_node\_data --- access application-specific data}
  436. \synopsis
  437. \begin{verbatim}
  438. void *glp_ios_node_data(glp_tree *T, int p);
  439. \end{verbatim}
  440. \description
  441. The routine \verb|glp_ios_node_data| allows the application accessing
  442. a memory block allocated for the subproblem (which may be active or
  443. inactive), whose reference number is $p$.
  444. The size of the block is defined by the control parameter
  445. \verb|cb_size| passed to the routine \verb|glp_intopt|. The block is
  446. initialized by binary zeros on creating corresponding subproblem, and
  447. its contents is kept until the subproblem will be removed from the
  448. tree.
  449. The application may use these memory blocks to store specific data for
  450. each subproblem.
  451. \returns
  452. The routine \verb|glp_ios_node_data| returns a pointer to the memory
  453. block for the specified subproblem. Note that if \verb|cb_size| = 0,
  454. the routine returns a null pointer.
  455. \subsection{glp\_ios\_select\_node --- select subproblem to continue
  456. the search}
  457. \synopsis
  458. \begin{verbatim}
  459. void glp_ios_select_node(glp_tree *T, int p);
  460. \end{verbatim}
  461. \description
  462. The routine \verb|glp_ios_select_node| can be called from the
  463. user-defined callback routine in response to the reason
  464. \verb|GLP_ISELECT| to select an active subproblem, whose reference
  465. number\linebreak is $p$. The search will be continued from the
  466. subproblem selected.
  467. \newpage
  468. \subsection{glp\_ios\_heur\_sol --- provide solution found by
  469. heuristic}
  470. \synopsis
  471. \begin{verbatim}
  472. int glp_ios_heur_sol(glp_tree *T, const double x[]);
  473. \end{verbatim}
  474. \description
  475. The routine \verb|glp_ios_heur_sol| can be called from the user-defined
  476. callback routine in response to the reason \verb|GLP_IHEUR| to provide
  477. an integer feasible solution found by a primal heuristic.
  478. Primal values of {\it all} variables (columns) found by the heuristic
  479. should be placed in locations $x[1]$, \dots, $x[n]$, where $n$ is the
  480. number of columns in the original problem object. Note that the routine
  481. \verb|glp_ios_heur_sol| does {\it not} check primal feasibility of the
  482. solution provided.
  483. Using the solution passed in the array $x$ the routine computes value
  484. of the objective function. If the objective value is better than the
  485. best known integer feasible solution, the routine computes values of
  486. auxiliary variables (rows) and stores all solution components in the
  487. problem object.
  488. \returns
  489. If the provided solution is accepted, the routine
  490. \verb|glp_ios_heur_sol| returns zero. Otherwise, if the provided
  491. solution is rejected, the routine returns non-zero.
  492. \vspace*{-5pt}
  493. \subsection{glp\_ios\_can\_branch --- check if can branch upon
  494. specified variable}
  495. \synopsis
  496. \begin{verbatim}
  497. int glp_ios_can_branch(glp_tree *T, int j);
  498. \end{verbatim}
  499. \returns
  500. If $j$-th variable (column) can be used to branch upon, the routine
  501. returns non-zero, otherwise zero.
  502. \vspace*{-5pt}
  503. \subsection{glp\_ios\_branch\_upon --- choose variable to branch upon}
  504. \synopsis
  505. \begin{verbatim}
  506. void glp_ios_branch_upon(glp_tree *T, int j, int sel);
  507. \end{verbatim}
  508. \description
  509. The routine \verb|glp_ios_branch_upon| can be called from the
  510. user-defined callback routine in response to the reason
  511. \verb|GLP_IBRANCH| to choose a branching variable, whose ordinal number
  512. \linebreak is $j$. Should note that only variables, for which the
  513. routine \verb|glp_ios_can_branch| returns non-zero, can be used to
  514. branch upon.
  515. The parameter \verb|sel| is a flag that indicates which branch
  516. (subproblem) should be selected next to continue the search:
  517. \verb|GLP_DN_BRNCH| --- select down-branch;
  518. \verb|GLP_UP_BRNCH| --- select up-branch;
  519. \verb|GLP_NO_BRNCH| --- use general selection technique.
  520. \para{Comments}
  521. On branching the solver removes the current active subproblem from the
  522. active list and creates two new subproblems ({\it down-} and {\it
  523. up-branches}), which are added to the end of the active list. Note that
  524. the down-branch is created before the up-branch, so the last active
  525. subproblem will be the up-branch.
  526. The down- and up-branches are identical to the current subproblem with
  527. exception that in the down-branch the upper bound of $x_j$, the variable
  528. chosen to branch upon, is replaced by $\lfloor x_j^*\rfloor$, while in
  529. the up-branch the lower bound of $x_j$ is replaced by
  530. $\lceil x_j^*\rceil$, where $x_j^*$ is the value of $x_j$ in optimal
  531. solution to LP relaxation of the current subproblem. For example, if
  532. $x_j^*=3.14$, the new upper bound of $x_j$ in the down-branch is
  533. $\lfloor 3.14\rfloor=3$, and the new lower bound in the up-branch is
  534. $\lceil 3.14\rceil=4$.)
  535. Additionally the callback routine may select either down- or up-branch,
  536. from which the solver will continue the search. If none of the branches
  537. is selected, a general selection technique will be used.
  538. \subsection{glp\_ios\_terminate --- terminate the solution process}
  539. \synopsis
  540. \begin{verbatim}
  541. void glp_ios_terminate(glp_tree *T);
  542. \end{verbatim}
  543. \description
  544. The routine \verb|glp_ios_terminate| sets a flag indicating that the
  545. MIP solver should prematurely terminate the search.
  546. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  547. \newpage
  548. \section{The search tree exploring routines}
  549. \subsection{glp\_ios\_tree\_size --- determine size of the search tree}
  550. \synopsis
  551. \begin{verbatim}
  552. void glp_ios_tree_size(glp_tree *T, int *a_cnt, int *n_cnt, int *t_cnt);
  553. \end{verbatim}
  554. \description
  555. The routine \verb|glp_ios_tree_size| stores the following three counts
  556. which characterize the current size of the search tree:
  557. \verb|a_cnt| is the current number of active nodes, i.e. the current
  558. size of the active list;
  559. \verb|n_cnt| is the current number of all (active and inactive) nodes;
  560. \verb|t_cnt| is the total number of nodes including those which have
  561. been already removed from the tree. This count is increased whenever
  562. a new node appears in the tree and never decreased.
  563. If some of the parameters \verb|a_cnt|, \verb|n_cnt|, \verb|t_cnt| is
  564. a null pointer, the corresponding count is not stored.
  565. \subsection{glp\_ios\_curr\_node --- determine current active
  566. subproblem}
  567. \synopsis
  568. \begin{verbatim}
  569. int glp_ios_curr_node(glp_tree *T);
  570. \end{verbatim}
  571. \returns
  572. The routine \verb|glp_ios_curr_node| returns the reference number of
  573. the current active subproblem. However, if the current subproblem does
  574. not exist, the routine returns zero.
  575. \subsection{glp\_ios\_next\_node --- determine next active subproblem}
  576. \synopsis
  577. \begin{verbatim}
  578. int glp_ios_next_node(glp_tree *T, int p);
  579. \end{verbatim}
  580. \returns
  581. If the parameter $p$ is zero, the routine \verb|glp_ios_next_node|
  582. returns the reference number of the first active subproblem. However,
  583. if the tree is empty, zero is returned.
  584. If the parameter $p$ is not zero, it must specify the reference number
  585. of some active subproblem, in which case the routine returns the
  586. reference number of the next active subproblem. However, if there is
  587. no next active subproblem in the list, zero is returned.
  588. All subproblems in the active list are ordered chronologically, i.e.
  589. subproblem $A$ precedes subproblem $B$ if $A$ was created before $B$.
  590. \newpage
  591. \subsection{glp\_ios\_prev\_node --- determine previous active
  592. subproblem}
  593. \synopsis
  594. \begin{verbatim}
  595. int glp_ios_prev_node(glp_tree *T, int p);
  596. \end{verbatim}
  597. \returns
  598. If the parameter $p$ is zero, the routine \verb|glp_ios_prev_node|
  599. returns the reference number of the last active subproblem. However, if
  600. the tree is empty, zero is returned.
  601. If the parameter $p$ is not zero, it must specify the reference number
  602. of some active subproblem, in which case the routine returns the
  603. reference number of the previous active subproblem. However, if there
  604. is no previous active subproblem in the list, zero is returned.
  605. All subproblems in the active list are ordered chronologically, i.e.
  606. subproblem $A$ precedes subproblem $B$ if $A$ was created before $B$.
  607. \subsection{glp\_ios\_up\_node --- determine parent subproblem}
  608. \synopsis
  609. \begin{verbatim}
  610. int glp_ios_up_node(glp_tree *T, int p);
  611. \end{verbatim}
  612. \returns
  613. The parameter $p$ must specify the reference number of some (active or
  614. inactive) subproblem, in which case the routine \verb|iet_get_up_node|
  615. returns the reference number of its parent subproblem. However, if the
  616. specified subproblem is the root of the tree and, therefore, has
  617. no parent, the routine returns zero.
  618. \subsection{glp\_ios\_node\_level --- determine subproblem level}
  619. \synopsis
  620. \begin{verbatim}
  621. int glp_ios_node_level(glp_tree *T, int p);
  622. \end{verbatim}
  623. \returns
  624. The routine \verb|glp_ios_node_level| returns the level of the
  625. subproblem, whose reference number is $p$, in the branch-and-bound
  626. tree. (The root subproblem has level 0, and the level of any other
  627. subproblem is the level of its parent plus one.)
  628. \subsection{glp\_ios\_node\_bound --- determine subproblem local bound}
  629. \synopsis
  630. \begin{verbatim}
  631. double glp_ios_node_bound(glp_tree *T, int p);
  632. \end{verbatim}
  633. \returns
  634. The routine \verb|glp_ios_node_bound| returns the local bound for
  635. (active or inactive) subproblem, whose reference number is $p$.
  636. \para{Comments}
  637. The local bound for subproblem $p$ is an lower (minimization) or upper
  638. (maximization) bound for integer optimal solution to {\it this}
  639. subproblem (not to the original problem). This bound is local in the
  640. sense that only subproblems in the subtree rooted at node $p$ cannot
  641. have better integer feasible solutions.
  642. On creating a subproblem (due to the branching step) its local bound is
  643. inherited from its parent and then may get only stronger (never weaker).
  644. For the root subproblem its local bound is initially set to
  645. \verb|-DBL_MAX| (minimization) or \verb|+DBL_MAX| (maximization) and
  646. then improved as the root LP relaxation has been solved.
  647. Note that the local bound is not necessarily the optimal objective
  648. value to corresponding LP relaxation.
  649. \subsection{glp\_ios\_best\_node --- find active subproblem with best
  650. local bound}
  651. \synopsis
  652. \begin{verbatim}
  653. int glp_ios_best_node(glp_tree *T);
  654. \end{verbatim}
  655. \returns
  656. The routine \verb|glp_ios_best_node| returns the reference number of
  657. the active subproblem, whose local bound is best (i.e. smallest in case
  658. of minimization or largest in case of maximization). However, if the
  659. tree is empty, the routine returns zero.
  660. \para{Comments}
  661. The best local bound is an lower (minimization) or upper (maximization)
  662. bound for integer optimal solution to the original MIP problem.
  663. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  664. \newpage
  665. \section{The cut pool routines}
  666. \subsection{glp\_ios\_pool\_size --- determine current size of the cut
  667. pool}
  668. \synopsis
  669. \begin{verbatim}
  670. int glp_ios_pool_size(glp_tree *T);
  671. \end{verbatim}
  672. \returns
  673. The routine \verb|glp_ios_pool_size| returns the current size of the
  674. cut pool, that is, the number of cutting plane constraints currently
  675. added to it.
  676. \subsection{glp\_ios\_add\_row --- add constraint to the cut pool}
  677. \synopsis
  678. \begin{verbatim}
  679. int glp_ios_add_row(glp_tree *T, const char *name, int klass, int flags,
  680. int len, const int ind[], const double val[], int type, double rhs);
  681. \end{verbatim}
  682. \description
  683. The routine \verb|glp_ios_add_row| adds specified row (cutting plane
  684. constraint) to the cut pool.
  685. The cutting plane constraint should have the following format:
  686. $$\sum_{j\in J}a_jx_j\left\{\begin{array}{@{}c@{}}\geq\\\leq\\
  687. \end{array}\right\}b,$$
  688. where $J$ is a set of indices (ordinal numbers) of structural
  689. variables, $a_j$ are constraint coefficients, $x_j$ are structural
  690. variables, $b$ is the right-hand side.
  691. The parameter \verb|name| specifies a symbolic name assigned to the
  692. constraint (1 up to 255 characters). If it is \verb|NULL| or an empty
  693. string, no name is assigned.
  694. The parameter \verb|klass| specifies the constraint class, which must
  695. be either zero or a number in the range from 101 to 200.
  696. The application may use this attribute to distinguish between cutting
  697. plane constraints of different classes.\footnote{Constraint classes
  698. numbered from 1 to 100 are reserved for GLPK cutting plane generators.}
  699. The parameter \verb|flags| currently is not used and must be zero.
  700. Ordinal numbers of structural variables (i.e. column indices) $j\in J$
  701. and numerical values of corresponding constraint coefficients $a_j$
  702. should be placed in locations \verb|ind[1]|, \dots, \verb|ind[len]| and
  703. \verb|val[1]|, \dots, \verb|val[len]|, respectively, where
  704. ${\tt len}=|J|$ is the number of constraint coefficients,
  705. $0\leq{\tt len}\leq n$, and $n$ is the number of columns in the problem
  706. object. Coefficients with identical column indices are not allowed.
  707. Zero coefficients are allowed, however, they are ignored.
  708. The parameter \verb|type| specifies the constraint type as follows:
  709. \verb|GLP_LO| means inequality constraint $\Sigma a_jx_j\geq b$;
  710. \verb|GLP_UP| means inequality constraint $\Sigma a_jx_j\leq b$;
  711. The parameter \verb|rhs| specifies the right-hand side $b$.
  712. All cutting plane constraints in the cut pool are identified by their
  713. ordinal numbers 1, 2, \dots, $size$, where $size$ is the current size
  714. of the cut pool. New constraints are always added to the end of the cut
  715. pool, thus, ordinal numbers of previously added constraints are not
  716. changed.
  717. \returns
  718. The routine \verb|glp_ios_add_row| returns the ordinal number of the
  719. cutting plane constraint added, which is the new size of the cut pool.
  720. \para{Example}
  721. \begin{verbatim}
  722. /* generate triangle cutting plane:
  723. x[i] + x[j] + x[k] <= 1 */
  724. . . .
  725. /* add the constraint to the cut pool */
  726. ind[1] = i, val[1] = 1.0;
  727. ind[2] = j, val[2] = 1.0;
  728. ind[3] = k, val[3] = 1.0;
  729. glp_ios_add_row(tree, NULL, TRIANGLE_CUT, 0, 3, ind, val, GLP_UP, 1.0);
  730. \end{verbatim}
  731. \para{Comments}
  732. Cutting plane constraints added to the cut pool are intended to be then
  733. added only to the {\it current} subproblem, so these constraints can be
  734. globally as well as locally valid. However, adding a constraint to the
  735. cut pool does not mean that it will be added to the current
  736. subproblem---it depends on the solver's decision: if the constraint
  737. seems to be efficient, it is moved from the pool to the current
  738. subproblem, otherwise it is simply dropped.\footnote{Globally valid
  739. constraints could be saved and then re-used for other subproblems, but
  740. currently such feature is not implemented.}
  741. Normally, every time the callback routine is called for cut generation,
  742. the cut pool is empty. On the other hand, the solver itself can
  743. generate cutting plane constraints (like Gomory's or mixed integer
  744. rounding cuts), in which case the cut pool may be non-empty.
  745. \subsection{glp\_ios\_del\_row --- remove constraint from the cut pool}
  746. \synopsis
  747. \begin{verbatim}
  748. void glp_ios_del_row(glp_tree *T, int i);
  749. \end{verbatim}
  750. \description
  751. The routine \verb|glp_ios_del_row| deletes $i$-th row (cutting plane
  752. constraint) from the cut pool, where $1\leq i\leq size$ is the ordinal
  753. number of the constraint in the pool, $size$ is the current size of the
  754. cut pool.
  755. Note that deleting a constraint from the cut pool leads to changing
  756. ordinal numbers of other constraints remaining in the pool. New ordinal
  757. numbers of the remaining constraints are assigned under assumption that
  758. the original order of constraints is not changed. Let, for example,
  759. there be four constraints $a$, $b$, $c$ and $d$ in the cut pool, which
  760. have ordinal numbers 1, 2, 3 and 4, respectively, and let constraint
  761. $b$ have been deleted. Then after deletion the remaining constraint $a$,
  762. $c$ and $d$ are assigned new ordinal numbers 1, 2 and 3, respectively.
  763. To find the constraint to be deleted the routine \verb|glp_ios_del_row|
  764. uses ``smart'' linear search, so it is recommended to remove
  765. constraints in a natural or reverse order and avoid removing them in
  766. a random order.
  767. \para{Example}
  768. \begin{verbatim}
  769. /* keep first 10 constraints in the cut pool and remove other
  770. constraints */
  771. while (glp_ios_pool_size(tree) > 10)
  772. glp_ios_del_row(tree, glp_ios_pool_size(tree));
  773. \end{verbatim}
  774. \subsection{glp\_ios\_clear\_pool --- remove all constraints from the
  775. cut pool}
  776. \synopsis
  777. \begin{verbatim}
  778. void glp_ios_clear_pool(glp_tree *T);
  779. \end{verbatim}
  780. \description
  781. The routine \verb|glp_ios_clear_pool| makes the cut pool empty deleting
  782. all existing rows (cutting plane constraints) from it.
  783. %* eof *%