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.

1098 lines
37 KiB

3 months ago
  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. \newpage
  424. \returns
  425. The routine \verb|glp_ios_mip_gap| returns the relative MIP gap.
  426. \para{Comments}
  427. The relative MIP gap is used to measure the quality of the best integer
  428. feasible solution found so far, because the optimal solution value
  429. $z^*$ for the original MIP problem always lies in the range
  430. $${\tt best\_bnd}\leq z^*\leq{\tt best\_mip}$$
  431. in case of minimization, or in the range
  432. $${\tt best\_mip}\leq z^*\leq{\tt best\_bnd}$$
  433. in case of maximization.
  434. To express the relative MIP gap in percents the value returned by the
  435. routine \verb|glp_ios_mip_gap| should be multiplied by 100\%.
  436. \subsection{glp\_ios\_node\_data --- access application-specific data}
  437. \synopsis
  438. \begin{verbatim}
  439. void *glp_ios_node_data(glp_tree *T, int p);
  440. \end{verbatim}
  441. \description
  442. The routine \verb|glp_ios_node_data| allows the application accessing
  443. a memory block allocated for the subproblem (which may be active or
  444. inactive), whose reference number is $p$.
  445. The size of the block is defined by the control parameter
  446. \verb|cb_size| passed to the routine \verb|glp_intopt|. The block is
  447. initialized by binary zeros on creating corresponding subproblem, and
  448. its contents is kept until the subproblem will be removed from the
  449. tree.
  450. The application may use these memory blocks to store specific data for
  451. each subproblem.
  452. \returns
  453. The routine \verb|glp_ios_node_data| returns a pointer to the memory
  454. block for the specified subproblem. Note that if \verb|cb_size| = 0,
  455. the routine returns a null pointer.
  456. \subsection{glp\_ios\_select\_node --- select subproblem to continue
  457. the search}
  458. \synopsis
  459. \begin{verbatim}
  460. void glp_ios_select_node(glp_tree *T, int p);
  461. \end{verbatim}
  462. \description
  463. The routine \verb|glp_ios_select_node| can be called from the
  464. user-defined callback routine in response to the reason
  465. \verb|GLP_ISELECT| to select an active subproblem, whose reference
  466. number\linebreak is $p$. The search will be continued from the
  467. subproblem selected.
  468. \newpage
  469. \subsection{glp\_ios\_heur\_sol --- provide solution found by
  470. heuristic}
  471. \synopsis
  472. \begin{verbatim}
  473. int glp_ios_heur_sol(glp_tree *T, const double x[]);
  474. \end{verbatim}
  475. \description
  476. The routine \verb|glp_ios_heur_sol| can be called from the user-defined
  477. callback routine in response to the reason \verb|GLP_IHEUR| to provide
  478. an integer feasible solution found by a primal heuristic.
  479. Primal values of {\it all} variables (columns) found by the heuristic
  480. should be placed in locations $x[1]$, \dots, $x[n]$, where $n$ is the
  481. number of columns in the original problem object. Note that the routine
  482. \verb|glp_ios_heur_sol| does {\it not} check primal feasibility of the
  483. solution provided.
  484. Using the solution passed in the array $x$ the routine computes value
  485. of the objective function. If the objective value is better than the
  486. best known integer feasible solution, the routine computes values of
  487. auxiliary variables (rows) and stores all solution components in the
  488. problem object.
  489. \returns
  490. If the provided solution is accepted, the routine
  491. \verb|glp_ios_heur_sol| returns zero. Otherwise, if the provided
  492. solution is rejected, the routine returns non-zero.
  493. \vspace*{-5pt}
  494. \subsection{glp\_ios\_can\_branch --- check if can branch upon
  495. specified variable}
  496. \synopsis
  497. \begin{verbatim}
  498. int glp_ios_can_branch(glp_tree *T, int j);
  499. \end{verbatim}
  500. \returns
  501. If $j$-th variable (column) can be used to branch upon, the routine
  502. returns non-zero, otherwise zero.
  503. \vspace*{-5pt}
  504. \subsection{glp\_ios\_branch\_upon --- choose variable to branch upon}
  505. \synopsis
  506. \begin{verbatim}
  507. void glp_ios_branch_upon(glp_tree *T, int j, int sel);
  508. \end{verbatim}
  509. \description
  510. The routine \verb|glp_ios_branch_upon| can be called from the
  511. user-defined callback routine in response to the reason
  512. \verb|GLP_IBRANCH| to choose a branching variable, whose ordinal number
  513. \linebreak is $j$. Should note that only variables, for which the
  514. routine \verb|glp_ios_can_branch| returns non-zero, can be used to
  515. branch upon.
  516. The parameter \verb|sel| is a flag that indicates which branch
  517. (subproblem) should be selected next to continue the search:
  518. \verb|GLP_DN_BRNCH| --- select down-branch;
  519. \verb|GLP_UP_BRNCH| --- select up-branch;
  520. \verb|GLP_NO_BRNCH| --- use general selection technique.
  521. \newpage
  522. \para{Comments}
  523. On branching the solver removes the current active subproblem from the
  524. active list and creates two new subproblems ({\it down-} and {\it
  525. up-branches}), which are added to the end of the active list. Note that
  526. the down-branch is created before the up-branch, so the last active
  527. subproblem will be the up-branch.
  528. The down- and up-branches are identical to the current subproblem with
  529. exception that in the down-branch the upper bound of $x_j$, the variable
  530. chosen to branch upon, is replaced by $\lfloor x_j^*\rfloor$, while in
  531. the up-branch the lower bound of $x_j$ is replaced by
  532. $\lceil x_j^*\rceil$, where $x_j^*$ is the value of $x_j$ in optimal
  533. solution to LP relaxation of the current subproblem. For example, if
  534. $x_j^*=3.14$, the new upper bound of $x_j$ in the down-branch is
  535. $\lfloor 3.14\rfloor=3$, and the new lower bound in the up-branch is
  536. $\lceil 3.14\rceil=4$.)
  537. Additionally the callback routine may select either down- or up-branch,
  538. from which the solver will continue the search. If none of the branches
  539. is selected, a general selection technique will be used.
  540. \subsection{glp\_ios\_terminate --- terminate the solution process}
  541. \synopsis
  542. \begin{verbatim}
  543. void glp_ios_terminate(glp_tree *T);
  544. \end{verbatim}
  545. \description
  546. The routine \verb|glp_ios_terminate| sets a flag indicating that the
  547. MIP solver should prematurely terminate the search.
  548. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  549. \newpage
  550. \section{The search tree exploring routines}
  551. \subsection{glp\_ios\_tree\_size --- determine size of the search tree}
  552. \synopsis
  553. \begin{verbatim}
  554. void glp_ios_tree_size(glp_tree *T, int *a_cnt, int *n_cnt, int *t_cnt);
  555. \end{verbatim}
  556. \description
  557. The routine \verb|glp_ios_tree_size| stores the following three counts
  558. which characterize the current size of the search tree:
  559. \verb|a_cnt| is the current number of active nodes, i.e. the current
  560. size of the active list;
  561. \verb|n_cnt| is the current number of all (active and inactive) nodes;
  562. \verb|t_cnt| is the total number of nodes including those which have
  563. been already removed from the tree. This count is increased whenever
  564. a new node appears in the tree and never decreased.
  565. If some of the parameters \verb|a_cnt|, \verb|n_cnt|, \verb|t_cnt| is
  566. a null pointer, the corresponding count is not stored.
  567. \subsection{glp\_ios\_curr\_node --- determine current active
  568. subproblem}
  569. \synopsis
  570. \begin{verbatim}
  571. int glp_ios_curr_node(glp_tree *T);
  572. \end{verbatim}
  573. \returns
  574. The routine \verb|glp_ios_curr_node| returns the reference number of
  575. the current active subproblem. However, if the current subproblem does
  576. not exist, the routine returns zero.
  577. \subsection{glp\_ios\_next\_node --- determine next active subproblem}
  578. \synopsis
  579. \begin{verbatim}
  580. int glp_ios_next_node(glp_tree *T, int p);
  581. \end{verbatim}
  582. \returns
  583. If the parameter $p$ is zero, the routine \verb|glp_ios_next_node|
  584. returns the reference number of the first active subproblem. However,
  585. if the tree is empty, zero is returned.
  586. If the parameter $p$ is not zero, it must specify the reference number
  587. of some active subproblem, in which case the routine returns the
  588. reference number of the next active subproblem. However, if there is
  589. no next active subproblem in the list, zero is returned.
  590. All subproblems in the active list are ordered chronologically, i.e.
  591. subproblem $A$ precedes subproblem $B$ if $A$ was created before $B$.
  592. \newpage
  593. \subsection{glp\_ios\_prev\_node --- determine previous active
  594. subproblem}
  595. \synopsis
  596. \begin{verbatim}
  597. int glp_ios_prev_node(glp_tree *T, int p);
  598. \end{verbatim}
  599. \returns
  600. If the parameter $p$ is zero, the routine \verb|glp_ios_prev_node|
  601. returns the reference number of the last active subproblem. However, if
  602. the tree is empty, zero is returned.
  603. If the parameter $p$ is not zero, it must specify the reference number
  604. of some active subproblem, in which case the routine returns the
  605. reference number of the previous active subproblem. However, if there
  606. is no previous active subproblem in the list, zero is returned.
  607. All subproblems in the active list are ordered chronologically, i.e.
  608. subproblem $A$ precedes subproblem $B$ if $A$ was created before $B$.
  609. \subsection{glp\_ios\_up\_node --- determine parent subproblem}
  610. \synopsis
  611. \begin{verbatim}
  612. int glp_ios_up_node(glp_tree *T, int p);
  613. \end{verbatim}
  614. \returns
  615. The parameter $p$ must specify the reference number of some (active or
  616. inactive) subproblem, in which case the routine \verb|iet_get_up_node|
  617. returns the reference number of its parent subproblem. However, if the
  618. specified subproblem is the root of the tree and, therefore, has
  619. no parent, the routine returns zero.
  620. \subsection{glp\_ios\_node\_level --- determine subproblem level}
  621. \synopsis
  622. \begin{verbatim}
  623. int glp_ios_node_level(glp_tree *T, int p);
  624. \end{verbatim}
  625. \returns
  626. The routine \verb|glp_ios_node_level| returns the level of the
  627. subproblem, whose reference number is $p$, in the branch-and-bound
  628. tree. (The root subproblem has level 0, and the level of any other
  629. subproblem is the level of its parent plus one.)
  630. \subsection{glp\_ios\_node\_bound --- determine subproblem local bound}
  631. \synopsis
  632. \begin{verbatim}
  633. double glp_ios_node_bound(glp_tree *T, int p);
  634. \end{verbatim}
  635. \returns
  636. The routine \verb|glp_ios_node_bound| returns the local bound for
  637. (active or inactive) subproblem, whose reference number is $p$.
  638. \newpage
  639. \para{Comments}
  640. The local bound for subproblem $p$ is an lower (minimization) or upper
  641. (maximization) bound for integer optimal solution to {\it this}
  642. subproblem (not to the original problem). This bound is local in the
  643. sense that only subproblems in the subtree rooted at node $p$ cannot
  644. have better integer feasible solutions.
  645. On creating a subproblem (due to the branching step) its local bound is
  646. inherited from its parent and then may get only stronger (never weaker).
  647. For the root subproblem its local bound is initially set to
  648. \verb|-DBL_MAX| (minimization) or \verb|+DBL_MAX| (maximization) and
  649. then improved as the root LP relaxation has been solved.
  650. Note that the local bound is not necessarily the optimal objective
  651. value to corresponding LP relaxation.
  652. \subsection{glp\_ios\_best\_node --- find active subproblem with best
  653. local bound}
  654. \synopsis
  655. \begin{verbatim}
  656. int glp_ios_best_node(glp_tree *T);
  657. \end{verbatim}
  658. \returns
  659. The routine \verb|glp_ios_best_node| returns the reference number of
  660. the active subproblem, whose local bound is best (i.e. smallest in case
  661. of minimization or largest in case of maximization). However, if the
  662. tree is empty, the routine returns zero.
  663. \para{Comments}
  664. The best local bound is an lower (minimization) or upper (maximization)
  665. bound for integer optimal solution to the original MIP problem.
  666. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  667. \newpage
  668. \section{The cut pool routines}
  669. \subsection{glp\_ios\_pool\_size --- determine current size of the cut
  670. pool}
  671. \synopsis
  672. \begin{verbatim}
  673. int glp_ios_pool_size(glp_tree *T);
  674. \end{verbatim}
  675. \returns
  676. The routine \verb|glp_ios_pool_size| returns the current size of the
  677. cut pool, that is, the number of cutting plane constraints currently
  678. added to it.
  679. \subsection{glp\_ios\_add\_row --- add constraint to the cut pool}
  680. \synopsis
  681. \begin{verbatim}
  682. int glp_ios_add_row(glp_tree *T, const char *name, int klass, int flags,
  683. int len, const int ind[], const double val[], int type, double rhs);
  684. \end{verbatim}
  685. \description
  686. The routine \verb|glp_ios_add_row| adds specified row (cutting plane
  687. constraint) to the cut pool.
  688. The cutting plane constraint should have the following format:
  689. $$\sum_{j\in J}a_jx_j\left\{\begin{array}{@{}c@{}}\geq\\\leq\\
  690. \end{array}\right\}b,$$
  691. where $J$ is a set of indices (ordinal numbers) of structural
  692. variables, $a_j$ are constraint coefficients, $x_j$ are structural
  693. variables, $b$ is the right-hand side.
  694. The parameter \verb|name| specifies a symbolic name assigned to the
  695. constraint (1 up to 255 characters). If it is \verb|NULL| or an empty
  696. string, no name is assigned.
  697. The parameter \verb|klass| specifies the constraint class, which must
  698. be either zero or a number in the range from 101 to 200.
  699. The application may use this attribute to distinguish between cutting
  700. plane constraints of different classes.\footnote{Constraint classes
  701. numbered from 1 to 100 are reserved for GLPK cutting plane generators.}
  702. The parameter \verb|flags| currently is not used and must be zero.
  703. Ordinal numbers of structural variables (i.e. column indices) $j\in J$
  704. and numerical values of corresponding constraint coefficients $a_j$
  705. should be placed in locations \verb|ind[1]|, \dots, \verb|ind[len]| and
  706. \verb|val[1]|, \dots, \verb|val[len]|, respectively, where
  707. ${\tt len}=|J|$ is the number of constraint coefficients,
  708. $0\leq{\tt len}\leq n$, and $n$ is the number of columns in the problem
  709. object. Coefficients with identical column indices are not allowed.
  710. Zero coefficients are allowed, however, they are ignored.
  711. The parameter \verb|type| specifies the constraint type as follows:
  712. \verb|GLP_LO| means inequality constraint $\Sigma a_jx_j\geq b$;
  713. \verb|GLP_UP| means inequality constraint $\Sigma a_jx_j\leq b$;
  714. \newpage
  715. The parameter \verb|rhs| specifies the right-hand side $b$.
  716. All cutting plane constraints in the cut pool are identified by their
  717. ordinal numbers 1, 2, \dots, $size$, where $size$ is the current size
  718. of the cut pool. New constraints are always added to the end of the cut
  719. pool, thus, ordinal numbers of previously added constraints are not
  720. changed.
  721. \returns
  722. The routine \verb|glp_ios_add_row| returns the ordinal number of the
  723. cutting plane constraint added, which is the new size of the cut pool.
  724. \para{Example}
  725. \begin{verbatim}
  726. /* generate triangle cutting plane:
  727. x[i] + x[j] + x[k] <= 1 */
  728. . . .
  729. /* add the constraint to the cut pool */
  730. ind[1] = i, val[1] = 1.0;
  731. ind[2] = j, val[2] = 1.0;
  732. ind[3] = k, val[3] = 1.0;
  733. glp_ios_add_row(tree, NULL, TRIANGLE_CUT, 0, 3, ind, val, GLP_UP, 1.0);
  734. \end{verbatim}
  735. \para{Comments}
  736. Cutting plane constraints added to the cut pool are intended to be then
  737. added only to the {\it current} subproblem, so these constraints can be
  738. globally as well as locally valid. However, adding a constraint to the
  739. cut pool does not mean that it will be added to the current
  740. subproblem---it depends on the solver's decision: if the constraint
  741. seems to be efficient, it is moved from the pool to the current
  742. subproblem, otherwise it is simply dropped.\footnote{Globally valid
  743. constraints could be saved and then re-used for other subproblems, but
  744. currently such feature is not implemented.}
  745. Normally, every time the callback routine is called for cut generation,
  746. the cut pool is empty. On the other hand, the solver itself can
  747. generate cutting plane constraints (like Gomory's or mixed integer
  748. rounding cuts), in which case the cut pool may be non-empty.
  749. \subsection{glp\_ios\_del\_row --- remove constraint from the cut pool}
  750. \synopsis
  751. \begin{verbatim}
  752. void glp_ios_del_row(glp_tree *T, int i);
  753. \end{verbatim}
  754. \description
  755. The routine \verb|glp_ios_del_row| deletes $i$-th row (cutting plane
  756. constraint) from the cut pool, where $1\leq i\leq size$ is the ordinal
  757. number of the constraint in the pool, $size$ is the current size of the
  758. cut pool.
  759. Note that deleting a constraint from the cut pool leads to changing
  760. ordinal numbers of other constraints remaining in the pool. New ordinal
  761. numbers of the remaining constraints are assigned under assumption that
  762. the original order of constraints is not changed. Let, for example,
  763. there be four constraints $a$, $b$, $c$ and $d$ in the cut pool, which
  764. have ordinal numbers 1, 2, 3 and 4, respectively, and let constraint
  765. $b$ have been deleted. Then after deletion the remaining constraint $a$,
  766. $c$ and $d$ are assigned new ordinal numbers 1, 2 and 3, respectively.
  767. To find the constraint to be deleted the routine \verb|glp_ios_del_row|
  768. uses ``smart'' linear search, so it is recommended to remove
  769. constraints in a natural or reverse order and avoid removing them in
  770. a random order.
  771. \para{Example}
  772. \begin{verbatim}
  773. /* keep first 10 constraints in the cut pool and remove other
  774. constraints */
  775. while (glp_ios_pool_size(tree) > 10)
  776. glp_ios_del_row(tree, glp_ios_pool_size(tree));
  777. \end{verbatim}
  778. \subsection{glp\_ios\_clear\_pool --- remove all constraints from the
  779. cut pool}
  780. \synopsis
  781. \begin{verbatim}
  782. void glp_ios_clear_pool(glp_tree *T);
  783. \end{verbatim}
  784. \description
  785. The routine \verb|glp_ios_clear_pool| makes the cut pool empty deleting
  786. all existing rows (cutting plane constraints) from it.
  787. %* eof *%