glpios03.c 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156
  1. /* glpios03.c (branch-and-cut driver) */
  2. /***********************************************************************
  3. * This code is part of GLPK (GNU Linear Programming Kit).
  4. *
  5. * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
  6. * 2009, 2010 Andrew Makhorin, Department for Applied Informatics,
  7. * Moscow Aviation Institute, Moscow, Russia. All rights reserved.
  8. * E-mail: <mao@gnu.org>.
  9. *
  10. * GLPK is free software: you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * GLPK is distributed in the hope that it will be useful, but WITHOUT
  16. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  17. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
  18. * License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with GLPK. If not, see <http://www.gnu.org/licenses/>.
  22. ***********************************************************************/
  23. #include "glpios.h"
  24. /***********************************************************************
  25. * show_progress - display current progress of the search
  26. *
  27. * This routine displays some information about current progress of the
  28. * search.
  29. *
  30. * The information includes:
  31. *
  32. * the current number of iterations performed by the simplex solver;
  33. *
  34. * the objective value for the best known integer feasible solution,
  35. * which is upper (minimization) or lower (maximization) global bound
  36. * for optimal solution of the original mip problem;
  37. *
  38. * the best local bound for active nodes, which is lower (minimization)
  39. * or upper (maximization) global bound for optimal solution of the
  40. * original mip problem;
  41. *
  42. * the relative mip gap, in percents;
  43. *
  44. * the number of open (active) subproblems;
  45. *
  46. * the number of completely explored subproblems, i.e. whose nodes have
  47. * been removed from the tree. */
  48. static void show_progress(glp_tree *T, int bingo)
  49. { int p;
  50. double temp;
  51. char best_mip[50], best_bound[50], *rho, rel_gap[50];
  52. /* format the best known integer feasible solution */
  53. if (T->mip->mip_stat == GLP_FEAS)
  54. sprintf(best_mip, "%17.9e", T->mip->mip_obj);
  55. else
  56. sprintf(best_mip, "%17s", "not found yet");
  57. /* determine reference number of an active subproblem whose local
  58. bound is best */
  59. p = ios_best_node(T);
  60. /* format the best bound */
  61. if (p == 0)
  62. sprintf(best_bound, "%17s", "tree is empty");
  63. else
  64. { temp = T->slot[p].node->bound;
  65. if (temp == -DBL_MAX)
  66. sprintf(best_bound, "%17s", "-inf");
  67. else if (temp == +DBL_MAX)
  68. sprintf(best_bound, "%17s", "+inf");
  69. else
  70. sprintf(best_bound, "%17.9e", temp);
  71. }
  72. /* choose the relation sign between global bounds */
  73. if (T->mip->dir == GLP_MIN)
  74. rho = ">=";
  75. else if (T->mip->dir == GLP_MAX)
  76. rho = "<=";
  77. else
  78. xassert(T != T);
  79. /* format the relative mip gap */
  80. temp = ios_relative_gap(T);
  81. if (temp == 0.0)
  82. sprintf(rel_gap, " 0.0%%");
  83. else if (temp < 0.001)
  84. sprintf(rel_gap, "< 0.1%%");
  85. else if (temp <= 9.999)
  86. sprintf(rel_gap, "%5.1f%%", 100.0 * temp);
  87. else
  88. sprintf(rel_gap, "%6s", "");
  89. /* display progress of the search */
  90. xprintf("+%6d: %s %s %s %s %s (%d; %d)\n",
  91. T->mip->it_cnt, bingo ? ">>>>>" : "mip =", best_mip, rho,
  92. best_bound, rel_gap, T->a_cnt, T->t_cnt - T->n_cnt);
  93. T->tm_lag = xtime();
  94. return;
  95. }
  96. /***********************************************************************
  97. * is_branch_hopeful - check if specified branch is hopeful
  98. *
  99. * This routine checks if the specified subproblem can have an integer
  100. * optimal solution which is better than the best known one.
  101. *
  102. * The check is based on comparison of the local objective bound stored
  103. * in the subproblem descriptor and the incumbent objective value which
  104. * is the global objective bound.
  105. *
  106. * If there is a chance that the specified subproblem can have a better
  107. * integer optimal solution, the routine returns non-zero. Otherwise, if
  108. * the corresponding branch can pruned, zero is returned. */
  109. static int is_branch_hopeful(glp_tree *T, int p)
  110. { xassert(1 <= p && p <= T->nslots);
  111. xassert(T->slot[p].node != NULL);
  112. return ios_is_hopeful(T, T->slot[p].node->bound);
  113. }
  114. /***********************************************************************
  115. * check_integrality - check integrality of basic solution
  116. *
  117. * This routine checks if the basic solution of LP relaxation of the
  118. * current subproblem satisfies to integrality conditions, i.e. that all
  119. * variables of integer kind have integral primal values. (The solution
  120. * is assumed to be optimal.)
  121. *
  122. * For each variable of integer kind the routine computes the following
  123. * quantity:
  124. *
  125. * ii(x[j]) = min(x[j] - floor(x[j]), ceil(x[j]) - x[j]), (1)
  126. *
  127. * which is a measure of the integer infeasibility (non-integrality) of
  128. * x[j] (for example, ii(2.1) = 0.1, ii(3.7) = 0.3, ii(5.0) = 0). It is
  129. * understood that 0 <= ii(x[j]) <= 0.5, and variable x[j] is integer
  130. * feasible if ii(x[j]) = 0. However, due to floating-point arithmetic
  131. * the routine checks less restrictive condition:
  132. *
  133. * ii(x[j]) <= tol_int, (2)
  134. *
  135. * where tol_int is a given tolerance (small positive number) and marks
  136. * each variable which does not satisfy to (2) as integer infeasible by
  137. * setting its fractionality flag.
  138. *
  139. * In order to characterize integer infeasibility of the basic solution
  140. * in the whole the routine computes two parameters: ii_cnt, which is
  141. * the number of variables with the fractionality flag set, and ii_sum,
  142. * which is the sum of integer infeasibilities (1). */
  143. static void check_integrality(glp_tree *T)
  144. { glp_prob *mip = T->mip;
  145. int j, type, ii_cnt = 0;
  146. double lb, ub, x, temp1, temp2, ii_sum = 0.0;
  147. /* walk through the set of columns (structural variables) */
  148. for (j = 1; j <= mip->n; j++)
  149. { GLPCOL *col = mip->col[j];
  150. T->non_int[j] = 0;
  151. /* if the column is not integer, skip it */
  152. if (col->kind != GLP_IV) continue;
  153. /* if the column is non-basic, it is integer feasible */
  154. if (col->stat != GLP_BS) continue;
  155. /* obtain the type and bounds of the column */
  156. type = col->type, lb = col->lb, ub = col->ub;
  157. /* obtain value of the column in optimal basic solution */
  158. x = col->prim;
  159. /* if the column's primal value is close to the lower bound,
  160. the column is integer feasible within given tolerance */
  161. if (type == GLP_LO || type == GLP_DB || type == GLP_FX)
  162. { temp1 = lb - T->parm->tol_int;
  163. temp2 = lb + T->parm->tol_int;
  164. if (temp1 <= x && x <= temp2) continue;
  165. #if 0
  166. /* the lower bound must not be violated */
  167. xassert(x >= lb);
  168. #else
  169. if (x < lb) continue;
  170. #endif
  171. }
  172. /* if the column's primal value is close to the upper bound,
  173. the column is integer feasible within given tolerance */
  174. if (type == GLP_UP || type == GLP_DB || type == GLP_FX)
  175. { temp1 = ub - T->parm->tol_int;
  176. temp2 = ub + T->parm->tol_int;
  177. if (temp1 <= x && x <= temp2) continue;
  178. #if 0
  179. /* the upper bound must not be violated */
  180. xassert(x <= ub);
  181. #else
  182. if (x > ub) continue;
  183. #endif
  184. }
  185. /* if the column's primal value is close to nearest integer,
  186. the column is integer feasible within given tolerance */
  187. temp1 = floor(x + 0.5) - T->parm->tol_int;
  188. temp2 = floor(x + 0.5) + T->parm->tol_int;
  189. if (temp1 <= x && x <= temp2) continue;
  190. /* otherwise the column is integer infeasible */
  191. T->non_int[j] = 1;
  192. /* increase the number of fractional-valued columns */
  193. ii_cnt++;
  194. /* compute the sum of integer infeasibilities */
  195. temp1 = x - floor(x);
  196. temp2 = ceil(x) - x;
  197. xassert(temp1 > 0.0 && temp2 > 0.0);
  198. ii_sum += (temp1 <= temp2 ? temp1 : temp2);
  199. }
  200. /* store ii_cnt and ii_sum to the current problem descriptor */
  201. xassert(T->curr != NULL);
  202. T->curr->ii_cnt = ii_cnt;
  203. T->curr->ii_sum = ii_sum;
  204. /* and also display these parameters */
  205. if (T->parm->msg_lev >= GLP_MSG_DBG)
  206. { if (ii_cnt == 0)
  207. xprintf("There are no fractional columns\n");
  208. else if (ii_cnt == 1)
  209. xprintf("There is one fractional column, integer infeasibil"
  210. "ity is %.3e\n", ii_sum);
  211. else
  212. xprintf("There are %d fractional columns, integer infeasibi"
  213. "lity is %.3e\n", ii_cnt, ii_sum);
  214. }
  215. return;
  216. }
  217. /***********************************************************************
  218. * record_solution - record better integer feasible solution
  219. *
  220. * This routine records optimal basic solution of LP relaxation of the
  221. * current subproblem, which being integer feasible is better than the
  222. * best known integer feasible solution. */
  223. static void record_solution(glp_tree *T)
  224. { glp_prob *mip = T->mip;
  225. int i, j;
  226. mip->mip_stat = GLP_FEAS;
  227. mip->mip_obj = mip->obj_val;
  228. for (i = 1; i <= mip->m; i++)
  229. { GLPROW *row = mip->row[i];
  230. row->mipx = row->prim;
  231. }
  232. for (j = 1; j <= mip->n; j++)
  233. { GLPCOL *col = mip->col[j];
  234. if (col->kind == GLP_CV)
  235. col->mipx = col->prim;
  236. else if (col->kind == GLP_IV)
  237. { /* value of the integer column must be integral */
  238. col->mipx = floor(col->prim + 0.5);
  239. }
  240. else
  241. xassert(col != col);
  242. }
  243. T->sol_cnt++;
  244. return;
  245. }
  246. /***********************************************************************
  247. * fix_by_red_cost - fix non-basic integer columns by reduced costs
  248. *
  249. * This routine fixes some non-basic integer columns if their reduced
  250. * costs indicate that increasing (decreasing) the column at least by
  251. * one involves the objective value becoming worse than the incumbent
  252. * objective value. */
  253. static void fix_by_red_cost(glp_tree *T)
  254. { glp_prob *mip = T->mip;
  255. int j, stat, fixed = 0;
  256. double obj, lb, ub, dj;
  257. /* the global bound must exist */
  258. xassert(T->mip->mip_stat == GLP_FEAS);
  259. /* basic solution of LP relaxation must be optimal */
  260. xassert(mip->pbs_stat == GLP_FEAS && mip->dbs_stat == GLP_FEAS);
  261. /* determine the objective function value */
  262. obj = mip->obj_val;
  263. /* walk through the column list */
  264. for (j = 1; j <= mip->n; j++)
  265. { GLPCOL *col = mip->col[j];
  266. /* if the column is not integer, skip it */
  267. if (col->kind != GLP_IV) continue;
  268. /* obtain bounds of j-th column */
  269. lb = col->lb, ub = col->ub;
  270. /* and determine its status and reduced cost */
  271. stat = col->stat, dj = col->dual;
  272. /* analyze the reduced cost */
  273. switch (mip->dir)
  274. { case GLP_MIN:
  275. /* minimization */
  276. if (stat == GLP_NL)
  277. { /* j-th column is non-basic on its lower bound */
  278. if (dj < 0.0) dj = 0.0;
  279. if (obj + dj >= mip->mip_obj)
  280. glp_set_col_bnds(mip, j, GLP_FX, lb, lb), fixed++;
  281. }
  282. else if (stat == GLP_NU)
  283. { /* j-th column is non-basic on its upper bound */
  284. if (dj > 0.0) dj = 0.0;
  285. if (obj - dj >= mip->mip_obj)
  286. glp_set_col_bnds(mip, j, GLP_FX, ub, ub), fixed++;
  287. }
  288. break;
  289. case GLP_MAX:
  290. /* maximization */
  291. if (stat == GLP_NL)
  292. { /* j-th column is non-basic on its lower bound */
  293. if (dj > 0.0) dj = 0.0;
  294. if (obj + dj <= mip->mip_obj)
  295. glp_set_col_bnds(mip, j, GLP_FX, lb, lb), fixed++;
  296. }
  297. else if (stat == GLP_NU)
  298. { /* j-th column is non-basic on its upper bound */
  299. if (dj < 0.0) dj = 0.0;
  300. if (obj - dj <= mip->mip_obj)
  301. glp_set_col_bnds(mip, j, GLP_FX, ub, ub), fixed++;
  302. }
  303. break;
  304. default:
  305. xassert(T != T);
  306. }
  307. }
  308. if (T->parm->msg_lev >= GLP_MSG_DBG)
  309. { if (fixed == 0)
  310. /* nothing to say */;
  311. else if (fixed == 1)
  312. xprintf("One column has been fixed by reduced cost\n");
  313. else
  314. xprintf("%d columns have been fixed by reduced costs\n",
  315. fixed);
  316. }
  317. /* fixing non-basic columns on their current bounds does not
  318. change the basic solution */
  319. xassert(mip->pbs_stat == GLP_FEAS && mip->dbs_stat == GLP_FEAS);
  320. return;
  321. }
  322. /***********************************************************************
  323. * branch_on - perform branching on specified variable
  324. *
  325. * This routine performs branching on j-th column (structural variable)
  326. * of the current subproblem. The specified column must be of integer
  327. * kind and must have a fractional value in optimal basic solution of
  328. * LP relaxation of the current subproblem (i.e. only columns for which
  329. * the flag non_int[j] is set are valid candidates to branch on).
  330. *
  331. * Let x be j-th structural variable, and beta be its primal fractional
  332. * value in the current basic solution. Branching on j-th variable is
  333. * dividing the current subproblem into two new subproblems, which are
  334. * identical to the current subproblem with the following exception: in
  335. * the first subproblem that begins the down-branch x has a new upper
  336. * bound x <= floor(beta), and in the second subproblem that begins the
  337. * up-branch x has a new lower bound x >= ceil(beta).
  338. *
  339. * Depending on estimation of local bounds for down- and up-branches
  340. * this routine returns the following:
  341. *
  342. * 0 - both branches have been created;
  343. * 1 - one branch is hopeless and has been pruned, so now the current
  344. * subproblem is other branch;
  345. * 2 - both branches are hopeless and have been pruned; new subproblem
  346. * selection is needed to continue the search. */
  347. static int branch_on(glp_tree *T, int j, int next)
  348. { glp_prob *mip = T->mip;
  349. IOSNPD *node;
  350. int m = mip->m;
  351. int n = mip->n;
  352. int type, dn_type, up_type, dn_bad, up_bad, p, ret, clone[1+2];
  353. double lb, ub, beta, new_ub, new_lb, dn_lp, up_lp, dn_bnd, up_bnd;
  354. /* determine bounds and value of x[j] in optimal solution to LP
  355. relaxation of the current subproblem */
  356. xassert(1 <= j && j <= n);
  357. type = mip->col[j]->type;
  358. lb = mip->col[j]->lb;
  359. ub = mip->col[j]->ub;
  360. beta = mip->col[j]->prim;
  361. /* determine new bounds of x[j] for down- and up-branches */
  362. new_ub = floor(beta);
  363. new_lb = ceil(beta);
  364. switch (type)
  365. { case GLP_FR:
  366. dn_type = GLP_UP;
  367. up_type = GLP_LO;
  368. break;
  369. case GLP_LO:
  370. xassert(lb <= new_ub);
  371. dn_type = (lb == new_ub ? GLP_FX : GLP_DB);
  372. xassert(lb + 1.0 <= new_lb);
  373. up_type = GLP_LO;
  374. break;
  375. case GLP_UP:
  376. xassert(new_ub <= ub - 1.0);
  377. dn_type = GLP_UP;
  378. xassert(new_lb <= ub);
  379. up_type = (new_lb == ub ? GLP_FX : GLP_DB);
  380. break;
  381. case GLP_DB:
  382. xassert(lb <= new_ub && new_ub <= ub - 1.0);
  383. dn_type = (lb == new_ub ? GLP_FX : GLP_DB);
  384. xassert(lb + 1.0 <= new_lb && new_lb <= ub);
  385. up_type = (new_lb == ub ? GLP_FX : GLP_DB);
  386. break;
  387. default:
  388. xassert(type != type);
  389. }
  390. /* compute local bounds to LP relaxation for both branches */
  391. ios_eval_degrad(T, j, &dn_lp, &up_lp);
  392. /* and improve them by rounding */
  393. dn_bnd = ios_round_bound(T, dn_lp);
  394. up_bnd = ios_round_bound(T, up_lp);
  395. /* check local bounds for down- and up-branches */
  396. dn_bad = !ios_is_hopeful(T, dn_bnd);
  397. up_bad = !ios_is_hopeful(T, up_bnd);
  398. if (dn_bad && up_bad)
  399. { if (T->parm->msg_lev >= GLP_MSG_DBG)
  400. xprintf("Both down- and up-branches are hopeless\n");
  401. ret = 2;
  402. goto done;
  403. }
  404. else if (up_bad)
  405. { if (T->parm->msg_lev >= GLP_MSG_DBG)
  406. xprintf("Up-branch is hopeless\n");
  407. glp_set_col_bnds(mip, j, dn_type, lb, new_ub);
  408. T->curr->lp_obj = dn_lp;
  409. if (mip->dir == GLP_MIN)
  410. { if (T->curr->bound < dn_bnd)
  411. T->curr->bound = dn_bnd;
  412. }
  413. else if (mip->dir == GLP_MAX)
  414. { if (T->curr->bound > dn_bnd)
  415. T->curr->bound = dn_bnd;
  416. }
  417. else
  418. xassert(mip != mip);
  419. ret = 1;
  420. goto done;
  421. }
  422. else if (dn_bad)
  423. { if (T->parm->msg_lev >= GLP_MSG_DBG)
  424. xprintf("Down-branch is hopeless\n");
  425. glp_set_col_bnds(mip, j, up_type, new_lb, ub);
  426. T->curr->lp_obj = up_lp;
  427. if (mip->dir == GLP_MIN)
  428. { if (T->curr->bound < up_bnd)
  429. T->curr->bound = up_bnd;
  430. }
  431. else if (mip->dir == GLP_MAX)
  432. { if (T->curr->bound > up_bnd)
  433. T->curr->bound = up_bnd;
  434. }
  435. else
  436. xassert(mip != mip);
  437. ret = 1;
  438. goto done;
  439. }
  440. /* both down- and up-branches seem to be hopeful */
  441. if (T->parm->msg_lev >= GLP_MSG_DBG)
  442. xprintf("Branching on column %d, primal value is %.9e\n",
  443. j, beta);
  444. /* determine the reference number of the current subproblem */
  445. xassert(T->curr != NULL);
  446. p = T->curr->p;
  447. T->curr->br_var = j;
  448. T->curr->br_val = beta;
  449. /* freeze the current subproblem */
  450. ios_freeze_node(T);
  451. /* create two clones of the current subproblem; the first clone
  452. begins the down-branch, the second one begins the up-branch */
  453. ios_clone_node(T, p, 2, clone);
  454. if (T->parm->msg_lev >= GLP_MSG_DBG)
  455. xprintf("Node %d begins down branch, node %d begins up branch "
  456. "\n", clone[1], clone[2]);
  457. /* set new upper bound of j-th column in the down-branch */
  458. node = T->slot[clone[1]].node;
  459. xassert(node != NULL);
  460. xassert(node->up != NULL);
  461. xassert(node->b_ptr == NULL);
  462. node->b_ptr = dmp_get_atom(T->pool, sizeof(IOSBND));
  463. node->b_ptr->k = m + j;
  464. node->b_ptr->type = (unsigned char)dn_type;
  465. node->b_ptr->lb = lb;
  466. node->b_ptr->ub = new_ub;
  467. node->b_ptr->next = NULL;
  468. node->lp_obj = dn_lp;
  469. if (mip->dir == GLP_MIN)
  470. { if (node->bound < dn_bnd)
  471. node->bound = dn_bnd;
  472. }
  473. else if (mip->dir == GLP_MAX)
  474. { if (node->bound > dn_bnd)
  475. node->bound = dn_bnd;
  476. }
  477. else
  478. xassert(mip != mip);
  479. /* set new lower bound of j-th column in the up-branch */
  480. node = T->slot[clone[2]].node;
  481. xassert(node != NULL);
  482. xassert(node->up != NULL);
  483. xassert(node->b_ptr == NULL);
  484. node->b_ptr = dmp_get_atom(T->pool, sizeof(IOSBND));
  485. node->b_ptr->k = m + j;
  486. node->b_ptr->type = (unsigned char)up_type;
  487. node->b_ptr->lb = new_lb;
  488. node->b_ptr->ub = ub;
  489. node->b_ptr->next = NULL;
  490. node->lp_obj = up_lp;
  491. if (mip->dir == GLP_MIN)
  492. { if (node->bound < up_bnd)
  493. node->bound = up_bnd;
  494. }
  495. else if (mip->dir == GLP_MAX)
  496. { if (node->bound > up_bnd)
  497. node->bound = up_bnd;
  498. }
  499. else
  500. xassert(mip != mip);
  501. /* suggest the subproblem to be solved next */
  502. xassert(T->child == 0);
  503. if (next == GLP_NO_BRNCH)
  504. T->child = 0;
  505. else if (next == GLP_DN_BRNCH)
  506. T->child = clone[1];
  507. else if (next == GLP_UP_BRNCH)
  508. T->child = clone[2];
  509. else
  510. xassert(next != next);
  511. ret = 0;
  512. done: return ret;
  513. }
  514. /***********************************************************************
  515. * cleanup_the_tree - prune hopeless branches from the tree
  516. *
  517. * This routine walks through the active list and checks the local
  518. * bound for every active subproblem. If the local bound indicates that
  519. * the subproblem cannot have integer optimal solution better than the
  520. * incumbent objective value, the routine deletes such subproblem that,
  521. * in turn, involves pruning the corresponding branch of the tree. */
  522. static void cleanup_the_tree(glp_tree *T)
  523. { IOSNPD *node, *next_node;
  524. int count = 0;
  525. /* the global bound must exist */
  526. xassert(T->mip->mip_stat == GLP_FEAS);
  527. /* walk through the list of active subproblems */
  528. for (node = T->head; node != NULL; node = next_node)
  529. { /* deleting some active problem node may involve deleting its
  530. parents recursively; however, all its parents being created
  531. *before* it are always *precede* it in the node list, so
  532. the next problem node is never affected by such deletion */
  533. next_node = node->next;
  534. /* if the branch is hopeless, prune it */
  535. if (!is_branch_hopeful(T, node->p))
  536. ios_delete_node(T, node->p), count++;
  537. }
  538. if (T->parm->msg_lev >= GLP_MSG_DBG)
  539. { if (count == 1)
  540. xprintf("One hopeless branch has been pruned\n");
  541. else if (count > 1)
  542. xprintf("%d hopeless branches have been pruned\n", count);
  543. }
  544. return;
  545. }
  546. /**********************************************************************/
  547. static void generate_cuts(glp_tree *T)
  548. { /* generate generic cuts with built-in generators */
  549. if (!(T->parm->mir_cuts == GLP_ON ||
  550. T->parm->gmi_cuts == GLP_ON ||
  551. T->parm->cov_cuts == GLP_ON ||
  552. T->parm->clq_cuts == GLP_ON)) goto done;
  553. #if 1 /* 20/IX-2008 */
  554. { int i, max_cuts, added_cuts;
  555. max_cuts = T->n;
  556. if (max_cuts < 1000) max_cuts = 1000;
  557. added_cuts = 0;
  558. for (i = T->orig_m+1; i <= T->mip->m; i++)
  559. { if (T->mip->row[i]->origin == GLP_RF_CUT)
  560. added_cuts++;
  561. }
  562. /* xprintf("added_cuts = %d\n", added_cuts); */
  563. if (added_cuts >= max_cuts) goto done;
  564. }
  565. #endif
  566. /* generate and add to POOL all cuts violated by x* */
  567. if (T->parm->gmi_cuts == GLP_ON)
  568. { if (T->curr->changed < 5)
  569. ios_gmi_gen(T);
  570. }
  571. if (T->parm->mir_cuts == GLP_ON)
  572. { xassert(T->mir_gen != NULL);
  573. ios_mir_gen(T, T->mir_gen);
  574. }
  575. if (T->parm->cov_cuts == GLP_ON)
  576. { /* cover cuts works well along with mir cuts */
  577. /*if (T->round <= 5)*/
  578. ios_cov_gen(T);
  579. }
  580. if (T->parm->clq_cuts == GLP_ON)
  581. { if (T->clq_gen != NULL)
  582. { if (T->curr->level == 0 && T->curr->changed < 50 ||
  583. T->curr->level > 0 && T->curr->changed < 5)
  584. ios_clq_gen(T, T->clq_gen);
  585. }
  586. }
  587. done: return;
  588. }
  589. /**********************************************************************/
  590. static void remove_cuts(glp_tree *T)
  591. { /* remove inactive cuts (some valueable globally valid cut might
  592. be saved in the global cut pool) */
  593. int i, cnt = 0, *num = NULL;
  594. xassert(T->curr != NULL);
  595. for (i = T->orig_m+1; i <= T->mip->m; i++)
  596. { if (T->mip->row[i]->origin == GLP_RF_CUT &&
  597. T->mip->row[i]->level == T->curr->level &&
  598. T->mip->row[i]->stat == GLP_BS)
  599. { if (num == NULL)
  600. num = xcalloc(1+T->mip->m, sizeof(int));
  601. num[++cnt] = i;
  602. }
  603. }
  604. if (cnt > 0)
  605. { glp_del_rows(T->mip, cnt, num);
  606. #if 0
  607. xprintf("%d inactive cut(s) removed\n", cnt);
  608. #endif
  609. xfree(num);
  610. xassert(glp_factorize(T->mip) == 0);
  611. }
  612. return;
  613. }
  614. /**********************************************************************/
  615. static void display_cut_info(glp_tree *T)
  616. { glp_prob *mip = T->mip;
  617. int i, gmi = 0, mir = 0, cov = 0, clq = 0, app = 0;
  618. for (i = mip->m; i > 0; i--)
  619. { GLPROW *row;
  620. row = mip->row[i];
  621. /* if (row->level < T->curr->level) break; */
  622. if (row->origin == GLP_RF_CUT)
  623. { if (row->klass == GLP_RF_GMI)
  624. gmi++;
  625. else if (row->klass == GLP_RF_MIR)
  626. mir++;
  627. else if (row->klass == GLP_RF_COV)
  628. cov++;
  629. else if (row->klass == GLP_RF_CLQ)
  630. clq++;
  631. else
  632. app++;
  633. }
  634. }
  635. xassert(T->curr != NULL);
  636. if (gmi + mir + cov + clq + app > 0)
  637. { xprintf("Cuts on level %d:", T->curr->level);
  638. if (gmi > 0) xprintf(" gmi = %d;", gmi);
  639. if (mir > 0) xprintf(" mir = %d;", mir);
  640. if (cov > 0) xprintf(" cov = %d;", cov);
  641. if (clq > 0) xprintf(" clq = %d;", clq);
  642. if (app > 0) xprintf(" app = %d;", app);
  643. xprintf("\n");
  644. }
  645. return;
  646. }
  647. /***********************************************************************
  648. * NAME
  649. *
  650. * ios_driver - branch-and-cut driver
  651. *
  652. * SYNOPSIS
  653. *
  654. * #include "glpios.h"
  655. * int ios_driver(glp_tree *T);
  656. *
  657. * DESCRIPTION
  658. *
  659. * The routine ios_driver is a branch-and-cut driver. It controls the
  660. * MIP solution process.
  661. *
  662. * RETURNS
  663. *
  664. * 0 The MIP problem instance has been successfully solved. This code
  665. * does not necessarily mean that the solver has found optimal
  666. * solution. It only means that the solution process was successful.
  667. *
  668. * GLP_EFAIL
  669. * The search was prematurely terminated due to the solver failure.
  670. *
  671. * GLP_EMIPGAP
  672. * The search was prematurely terminated, because the relative mip
  673. * gap tolerance has been reached.
  674. *
  675. * GLP_ETMLIM
  676. * The search was prematurely terminated, because the time limit has
  677. * been exceeded.
  678. *
  679. * GLP_ESTOP
  680. * The search was prematurely terminated by application. */
  681. int ios_driver(glp_tree *T)
  682. { int p, curr_p, p_stat, d_stat, ret;
  683. #if 1 /* carry out to glp_tree */
  684. int pred_p = 0;
  685. /* if the current subproblem has been just created due to
  686. branching, pred_p is the reference number of its parent
  687. subproblem, otherwise pred_p is zero */
  688. #endif
  689. glp_long ttt = T->tm_beg;
  690. #if 0
  691. ((glp_iocp *)T->parm)->msg_lev = GLP_MSG_DBG;
  692. #endif
  693. /* on entry to the B&B driver it is assumed that the active list
  694. contains the only active (i.e. root) subproblem, which is the
  695. original MIP problem to be solved */
  696. loop: /* main loop starts here */
  697. /* at this point the current subproblem does not exist */
  698. xassert(T->curr == NULL);
  699. /* if the active list is empty, the search is finished */
  700. if (T->head == NULL)
  701. { if (T->parm->msg_lev >= GLP_MSG_DBG)
  702. xprintf("Active list is empty!\n");
  703. xassert(dmp_in_use(T->pool).lo == 0);
  704. ret = 0;
  705. goto done;
  706. }
  707. /* select some active subproblem to continue the search */
  708. xassert(T->next_p == 0);
  709. /* let the application program select subproblem */
  710. if (T->parm->cb_func != NULL)
  711. { xassert(T->reason == 0);
  712. T->reason = GLP_ISELECT;
  713. T->parm->cb_func(T, T->parm->cb_info);
  714. T->reason = 0;
  715. if (T->stop)
  716. { ret = GLP_ESTOP;
  717. goto done;
  718. }
  719. }
  720. if (T->next_p != 0)
  721. { /* the application program has selected something */
  722. ;
  723. }
  724. else if (T->a_cnt == 1)
  725. { /* the only active subproblem exists, so select it */
  726. xassert(T->head->next == NULL);
  727. T->next_p = T->head->p;
  728. }
  729. else if (T->child != 0)
  730. { /* select one of branching childs suggested by the branching
  731. heuristic */
  732. T->next_p = T->child;
  733. }
  734. else
  735. { /* select active subproblem as specified by the backtracking
  736. technique option */
  737. T->next_p = ios_choose_node(T);
  738. }
  739. /* the active subproblem just selected becomes current */
  740. ios_revive_node(T, T->next_p);
  741. T->next_p = T->child = 0;
  742. /* invalidate pred_p, if it is not the reference number of the
  743. parent of the current subproblem */
  744. if (T->curr->up != NULL && T->curr->up->p != pred_p) pred_p = 0;
  745. /* determine the reference number of the current subproblem */
  746. p = T->curr->p;
  747. if (T->parm->msg_lev >= GLP_MSG_DBG)
  748. { xprintf("-----------------------------------------------------"
  749. "-------------------\n");
  750. xprintf("Processing node %d at level %d\n", p, T->curr->level);
  751. }
  752. /* if it is the root subproblem, initialize cut generators */
  753. if (p == 1)
  754. { if (T->parm->gmi_cuts == GLP_ON)
  755. { if (T->parm->msg_lev >= GLP_MSG_ALL)
  756. xprintf("Gomory's cuts enabled\n");
  757. }
  758. if (T->parm->mir_cuts == GLP_ON)
  759. { if (T->parm->msg_lev >= GLP_MSG_ALL)
  760. xprintf("MIR cuts enabled\n");
  761. xassert(T->mir_gen == NULL);
  762. T->mir_gen = ios_mir_init(T);
  763. }
  764. if (T->parm->cov_cuts == GLP_ON)
  765. { if (T->parm->msg_lev >= GLP_MSG_ALL)
  766. xprintf("Cover cuts enabled\n");
  767. }
  768. if (T->parm->clq_cuts == GLP_ON)
  769. { xassert(T->clq_gen == NULL);
  770. if (T->parm->msg_lev >= GLP_MSG_ALL)
  771. xprintf("Clique cuts enabled\n");
  772. T->clq_gen = ios_clq_init(T);
  773. }
  774. }
  775. more: /* minor loop starts here */
  776. /* at this point the current subproblem needs either to be solved
  777. for the first time or re-optimized due to reformulation */
  778. /* display current progress of the search */
  779. if (T->parm->msg_lev >= GLP_MSG_DBG ||
  780. T->parm->msg_lev >= GLP_MSG_ON &&
  781. (double)(T->parm->out_frq - 1) <=
  782. 1000.0 * xdifftime(xtime(), T->tm_lag))
  783. show_progress(T, 0);
  784. if (T->parm->msg_lev >= GLP_MSG_ALL &&
  785. xdifftime(xtime(), ttt) >= 60.0)
  786. { glp_long total;
  787. glp_mem_usage(NULL, NULL, &total, NULL);
  788. xprintf("Time used: %.1f secs. Memory used: %.1f Mb.\n",
  789. xdifftime(xtime(), T->tm_beg), xltod(total) / 1048576.0);
  790. ttt = xtime();
  791. }
  792. /* check the mip gap */
  793. if (T->parm->mip_gap > 0.0 &&
  794. ios_relative_gap(T) <= T->parm->mip_gap)
  795. { if (T->parm->msg_lev >= GLP_MSG_DBG)
  796. xprintf("Relative gap tolerance reached; search terminated "
  797. "\n");
  798. ret = GLP_EMIPGAP;
  799. goto done;
  800. }
  801. /* check if the time limit has been exhausted */
  802. if (T->parm->tm_lim < INT_MAX &&
  803. (double)(T->parm->tm_lim - 1) <=
  804. 1000.0 * xdifftime(xtime(), T->tm_beg))
  805. { if (T->parm->msg_lev >= GLP_MSG_DBG)
  806. xprintf("Time limit exhausted; search terminated\n");
  807. ret = GLP_ETMLIM;
  808. goto done;
  809. }
  810. /* let the application program preprocess the subproblem */
  811. if (T->parm->cb_func != NULL)
  812. { xassert(T->reason == 0);
  813. T->reason = GLP_IPREPRO;
  814. T->parm->cb_func(T, T->parm->cb_info);
  815. T->reason = 0;
  816. if (T->stop)
  817. { ret = GLP_ESTOP;
  818. goto done;
  819. }
  820. }
  821. /* perform basic preprocessing */
  822. if (T->parm->pp_tech == GLP_PP_NONE)
  823. ;
  824. else if (T->parm->pp_tech == GLP_PP_ROOT)
  825. { if (T->curr->level == 0)
  826. { if (ios_preprocess_node(T, 100))
  827. goto fath;
  828. }
  829. }
  830. else if (T->parm->pp_tech == GLP_PP_ALL)
  831. { if (ios_preprocess_node(T, T->curr->level == 0 ? 100 : 10))
  832. goto fath;
  833. }
  834. else
  835. xassert(T != T);
  836. /* preprocessing may improve the global bound */
  837. if (!is_branch_hopeful(T, p))
  838. { xprintf("*** not tested yet ***\n");
  839. goto fath;
  840. }
  841. /* solve LP relaxation of the current subproblem */
  842. if (T->parm->msg_lev >= GLP_MSG_DBG)
  843. xprintf("Solving LP relaxation...\n");
  844. ret = ios_solve_node(T);
  845. if (!(ret == 0 || ret == GLP_EOBJLL || ret == GLP_EOBJUL))
  846. { if (T->parm->msg_lev >= GLP_MSG_ERR)
  847. xprintf("ios_driver: unable to solve current LP relaxation;"
  848. " glp_simplex returned %d\n", ret);
  849. ret = GLP_EFAIL;
  850. goto done;
  851. }
  852. /* analyze status of the basic solution to LP relaxation found */
  853. p_stat = T->mip->pbs_stat;
  854. d_stat = T->mip->dbs_stat;
  855. if (p_stat == GLP_FEAS && d_stat == GLP_FEAS)
  856. { /* LP relaxation has optimal solution */
  857. if (T->parm->msg_lev >= GLP_MSG_DBG)
  858. xprintf("Found optimal solution to LP relaxation\n");
  859. }
  860. else if (d_stat == GLP_NOFEAS)
  861. { /* LP relaxation has no dual feasible solution */
  862. /* since the current subproblem cannot have a larger feasible
  863. region than its parent, there is something wrong */
  864. if (T->parm->msg_lev >= GLP_MSG_ERR)
  865. xprintf("ios_driver: current LP relaxation has no dual feas"
  866. "ible solution\n");
  867. ret = GLP_EFAIL;
  868. goto done;
  869. }
  870. else if (p_stat == GLP_INFEAS && d_stat == GLP_FEAS)
  871. { /* LP relaxation has no primal solution which is better than
  872. the incumbent objective value */
  873. xassert(T->mip->mip_stat == GLP_FEAS);
  874. if (T->parm->msg_lev >= GLP_MSG_DBG)
  875. xprintf("LP relaxation has no solution better than incumben"
  876. "t objective value\n");
  877. /* prune the branch */
  878. goto fath;
  879. }
  880. else if (p_stat == GLP_NOFEAS)
  881. { /* LP relaxation has no primal feasible solution */
  882. if (T->parm->msg_lev >= GLP_MSG_DBG)
  883. xprintf("LP relaxation has no feasible solution\n");
  884. /* prune the branch */
  885. goto fath;
  886. }
  887. else
  888. { /* other cases cannot appear */
  889. xassert(T->mip != T->mip);
  890. }
  891. /* at this point basic solution to LP relaxation of the current
  892. subproblem is optimal */
  893. xassert(p_stat == GLP_FEAS && d_stat == GLP_FEAS);
  894. xassert(T->curr != NULL);
  895. T->curr->lp_obj = T->mip->obj_val;
  896. /* thus, it defines a local bound to integer optimal solution of
  897. the current subproblem */
  898. { double bound = T->mip->obj_val;
  899. /* some local bound to the current subproblem could be already
  900. set before, so we should only improve it */
  901. bound = ios_round_bound(T, bound);
  902. if (T->mip->dir == GLP_MIN)
  903. { if (T->curr->bound < bound)
  904. T->curr->bound = bound;
  905. }
  906. else if (T->mip->dir == GLP_MAX)
  907. { if (T->curr->bound > bound)
  908. T->curr->bound = bound;
  909. }
  910. else
  911. xassert(T->mip != T->mip);
  912. if (T->parm->msg_lev >= GLP_MSG_DBG)
  913. xprintf("Local bound is %.9e\n", bound);
  914. }
  915. /* if the local bound indicates that integer optimal solution of
  916. the current subproblem cannot be better than the global bound,
  917. prune the branch */
  918. if (!is_branch_hopeful(T, p))
  919. { if (T->parm->msg_lev >= GLP_MSG_DBG)
  920. xprintf("Current branch is hopeless and can be pruned\n");
  921. goto fath;
  922. }
  923. /* let the application program generate additional rows ("lazy"
  924. constraints) */
  925. xassert(T->reopt == 0);
  926. xassert(T->reinv == 0);
  927. if (T->parm->cb_func != NULL)
  928. { xassert(T->reason == 0);
  929. T->reason = GLP_IROWGEN;
  930. T->parm->cb_func(T, T->parm->cb_info);
  931. T->reason = 0;
  932. if (T->stop)
  933. { ret = GLP_ESTOP;
  934. goto done;
  935. }
  936. if (T->reopt)
  937. { /* some rows were added; re-optimization is needed */
  938. T->reopt = T->reinv = 0;
  939. goto more;
  940. }
  941. if (T->reinv)
  942. { /* no rows were added, however, some inactive rows were
  943. removed */
  944. T->reinv = 0;
  945. xassert(glp_factorize(T->mip) == 0);
  946. }
  947. }
  948. /* check if the basic solution is integer feasible */
  949. check_integrality(T);
  950. /* if the basic solution satisfies to all integrality conditions,
  951. it is a new, better integer feasible solution */
  952. if (T->curr->ii_cnt == 0)
  953. { if (T->parm->msg_lev >= GLP_MSG_DBG)
  954. xprintf("New integer feasible solution found\n");
  955. if (T->parm->msg_lev >= GLP_MSG_ALL)
  956. display_cut_info(T);
  957. record_solution(T);
  958. if (T->parm->msg_lev >= GLP_MSG_ON)
  959. show_progress(T, 1);
  960. /* make the application program happy */
  961. if (T->parm->cb_func != NULL)
  962. { xassert(T->reason == 0);
  963. T->reason = GLP_IBINGO;
  964. T->parm->cb_func(T, T->parm->cb_info);
  965. T->reason = 0;
  966. if (T->stop)
  967. { ret = GLP_ESTOP;
  968. goto done;
  969. }
  970. }
  971. /* since the current subproblem has been fathomed, prune its
  972. branch */
  973. goto fath;
  974. }
  975. /* at this point basic solution to LP relaxation of the current
  976. subproblem is optimal, but integer infeasible */
  977. /* try to fix some non-basic structural variables of integer kind
  978. on their current bounds due to reduced costs */
  979. if (T->mip->mip_stat == GLP_FEAS)
  980. fix_by_red_cost(T);
  981. /* let the application program try to find some solution to the
  982. original MIP with a primal heuristic */
  983. if (T->parm->cb_func != NULL)
  984. { xassert(T->reason == 0);
  985. T->reason = GLP_IHEUR;
  986. T->parm->cb_func(T, T->parm->cb_info);
  987. T->reason = 0;
  988. if (T->stop)
  989. { ret = GLP_ESTOP;
  990. goto done;
  991. }
  992. /* check if the current branch became hopeless */
  993. if (!is_branch_hopeful(T, p))
  994. { if (T->parm->msg_lev >= GLP_MSG_DBG)
  995. xprintf("Current branch became hopeless and can be prune"
  996. "d\n");
  997. goto fath;
  998. }
  999. }
  1000. /* try to find solution with the feasibility pump heuristic */
  1001. if (T->parm->fp_heur)
  1002. { xassert(T->reason == 0);
  1003. T->reason = GLP_IHEUR;
  1004. ios_feas_pump(T);
  1005. T->reason = 0;
  1006. /* check if the current branch became hopeless */
  1007. if (!is_branch_hopeful(T, p))
  1008. { if (T->parm->msg_lev >= GLP_MSG_DBG)
  1009. xprintf("Current branch became hopeless and can be prune"
  1010. "d\n");
  1011. goto fath;
  1012. }
  1013. }
  1014. /* it's time to generate cutting planes */
  1015. xassert(T->local != NULL);
  1016. xassert(T->local->size == 0);
  1017. /* let the application program generate some cuts; note that it
  1018. can add cuts either to the local cut pool or directly to the
  1019. current subproblem */
  1020. if (T->parm->cb_func != NULL)
  1021. { xassert(T->reason == 0);
  1022. T->reason = GLP_ICUTGEN;
  1023. T->parm->cb_func(T, T->parm->cb_info);
  1024. T->reason = 0;
  1025. if (T->stop)
  1026. { ret = GLP_ESTOP;
  1027. goto done;
  1028. }
  1029. }
  1030. /* try to generate generic cuts with built-in generators
  1031. (as suggested by Matteo Fischetti et al. the built-in cuts
  1032. are not generated at each branching node; an intense attempt
  1033. of generating new cuts is only made at the root node, and then
  1034. a moderate effort is spent after each backtracking step) */
  1035. if (T->curr->level == 0 || pred_p == 0)
  1036. { xassert(T->reason == 0);
  1037. T->reason = GLP_ICUTGEN;
  1038. generate_cuts(T);
  1039. T->reason = 0;
  1040. }
  1041. /* if the local cut pool is not empty, select useful cuts and add
  1042. them to the current subproblem */
  1043. if (T->local->size > 0)
  1044. { xassert(T->reason == 0);
  1045. T->reason = GLP_ICUTGEN;
  1046. ios_process_cuts(T);
  1047. T->reason = 0;
  1048. }
  1049. /* clear the local cut pool */
  1050. ios_clear_pool(T, T->local);
  1051. /* perform re-optimization, if necessary */
  1052. if (T->reopt)
  1053. { T->reopt = 0;
  1054. T->curr->changed++;
  1055. goto more;
  1056. }
  1057. /* no cuts were generated; remove inactive cuts */
  1058. remove_cuts(T);
  1059. if (T->parm->msg_lev >= GLP_MSG_ALL && T->curr->level == 0)
  1060. display_cut_info(T);
  1061. /* update history information used on pseudocost branching */
  1062. if (T->pcost != NULL) ios_pcost_update(T);
  1063. /* it's time to perform branching */
  1064. xassert(T->br_var == 0);
  1065. xassert(T->br_sel == 0);
  1066. /* let the application program choose variable to branch on */
  1067. if (T->parm->cb_func != NULL)
  1068. { xassert(T->reason == 0);
  1069. xassert(T->br_var == 0);
  1070. xassert(T->br_sel == 0);
  1071. T->reason = GLP_IBRANCH;
  1072. T->parm->cb_func(T, T->parm->cb_info);
  1073. T->reason = 0;
  1074. if (T->stop)
  1075. { ret = GLP_ESTOP;
  1076. goto done;
  1077. }
  1078. }
  1079. /* if nothing has been chosen, choose some variable as specified
  1080. by the branching technique option */
  1081. if (T->br_var == 0)
  1082. T->br_var = ios_choose_var(T, &T->br_sel);
  1083. /* perform actual branching */
  1084. curr_p = T->curr->p;
  1085. ret = branch_on(T, T->br_var, T->br_sel);
  1086. T->br_var = T->br_sel = 0;
  1087. if (ret == 0)
  1088. { /* both branches have been created */
  1089. pred_p = curr_p;
  1090. goto loop;
  1091. }
  1092. else if (ret == 1)
  1093. { /* one branch is hopeless and has been pruned, so now the
  1094. current subproblem is other branch */
  1095. /* the current subproblem should be considered as a new one,
  1096. since one bound of the branching variable was changed */
  1097. T->curr->solved = T->curr->changed = 0;
  1098. goto more;
  1099. }
  1100. else if (ret == 2)
  1101. { /* both branches are hopeless and have been pruned; new
  1102. subproblem selection is needed to continue the search */
  1103. goto fath;
  1104. }
  1105. else
  1106. xassert(ret != ret);
  1107. fath: /* the current subproblem has been fathomed */
  1108. if (T->parm->msg_lev >= GLP_MSG_DBG)
  1109. xprintf("Node %d fathomed\n", p);
  1110. /* freeze the current subproblem */
  1111. ios_freeze_node(T);
  1112. /* and prune the corresponding branch of the tree */
  1113. ios_delete_node(T, p);
  1114. /* if a new integer feasible solution has just been found, other
  1115. branches may become hopeless and therefore must be pruned */
  1116. if (T->mip->mip_stat == GLP_FEAS) cleanup_the_tree(T);
  1117. /* new subproblem selection is needed due to backtracking */
  1118. pred_p = 0;
  1119. goto loop;
  1120. done: /* display progress of the search on exit from the solver */
  1121. if (T->parm->msg_lev >= GLP_MSG_ON)
  1122. show_progress(T, 0);
  1123. if (T->mir_gen != NULL)
  1124. ios_mir_term(T->mir_gen), T->mir_gen = NULL;
  1125. if (T->clq_gen != NULL)
  1126. ios_clq_term(T->clq_gen), T->clq_gen = NULL;
  1127. /* return to the calling program */
  1128. return ret;
  1129. }
  1130. /* eof */