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.

826 lines
26 KiB

  1. /* glpios02.c (preprocess current subproblem) */
  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, 2011, 2013 Andrew Makhorin, Department for Applied
  7. * Informatics, Moscow Aviation Institute, Moscow, Russia. All rights
  8. * reserved. 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 "env.h"
  24. #include "glpios.h"
  25. /***********************************************************************
  26. * prepare_row_info - prepare row info to determine implied bounds
  27. *
  28. * Given a row (linear form)
  29. *
  30. * n
  31. * sum a[j] * x[j] (1)
  32. * j=1
  33. *
  34. * and bounds of columns (variables)
  35. *
  36. * l[j] <= x[j] <= u[j] (2)
  37. *
  38. * this routine computes f_min, j_min, f_max, j_max needed to determine
  39. * implied bounds.
  40. *
  41. * ALGORITHM
  42. *
  43. * Let J+ = {j : a[j] > 0} and J- = {j : a[j] < 0}.
  44. *
  45. * Parameters f_min and j_min are computed as follows:
  46. *
  47. * 1) if there is no x[k] such that k in J+ and l[k] = -inf or k in J-
  48. * and u[k] = +inf, then
  49. *
  50. * f_min := sum a[j] * l[j] + sum a[j] * u[j]
  51. * j in J+ j in J-
  52. * (3)
  53. * j_min := 0
  54. *
  55. * 2) if there is exactly one x[k] such that k in J+ and l[k] = -inf
  56. * or k in J- and u[k] = +inf, then
  57. *
  58. * f_min := sum a[j] * l[j] + sum a[j] * u[j]
  59. * j in J+\{k} j in J-\{k}
  60. * (4)
  61. * j_min := k
  62. *
  63. * 3) if there are two or more x[k] such that k in J+ and l[k] = -inf
  64. * or k in J- and u[k] = +inf, then
  65. *
  66. * f_min := -inf
  67. * (5)
  68. * j_min := 0
  69. *
  70. * Parameters f_max and j_max are computed in a similar way as follows:
  71. *
  72. * 1) if there is no x[k] such that k in J+ and u[k] = +inf or k in J-
  73. * and l[k] = -inf, then
  74. *
  75. * f_max := sum a[j] * u[j] + sum a[j] * l[j]
  76. * j in J+ j in J-
  77. * (6)
  78. * j_max := 0
  79. *
  80. * 2) if there is exactly one x[k] such that k in J+ and u[k] = +inf
  81. * or k in J- and l[k] = -inf, then
  82. *
  83. * f_max := sum a[j] * u[j] + sum a[j] * l[j]
  84. * j in J+\{k} j in J-\{k}
  85. * (7)
  86. * j_max := k
  87. *
  88. * 3) if there are two or more x[k] such that k in J+ and u[k] = +inf
  89. * or k in J- and l[k] = -inf, then
  90. *
  91. * f_max := +inf
  92. * (8)
  93. * j_max := 0 */
  94. struct f_info
  95. { int j_min, j_max;
  96. double f_min, f_max;
  97. };
  98. static void prepare_row_info(int n, const double a[], const double l[],
  99. const double u[], struct f_info *f)
  100. { int j, j_min, j_max;
  101. double f_min, f_max;
  102. xassert(n >= 0);
  103. /* determine f_min and j_min */
  104. f_min = 0.0, j_min = 0;
  105. for (j = 1; j <= n; j++)
  106. { if (a[j] > 0.0)
  107. { if (l[j] == -DBL_MAX)
  108. { if (j_min == 0)
  109. j_min = j;
  110. else
  111. { f_min = -DBL_MAX, j_min = 0;
  112. break;
  113. }
  114. }
  115. else
  116. f_min += a[j] * l[j];
  117. }
  118. else if (a[j] < 0.0)
  119. { if (u[j] == +DBL_MAX)
  120. { if (j_min == 0)
  121. j_min = j;
  122. else
  123. { f_min = -DBL_MAX, j_min = 0;
  124. break;
  125. }
  126. }
  127. else
  128. f_min += a[j] * u[j];
  129. }
  130. else
  131. xassert(a != a);
  132. }
  133. f->f_min = f_min, f->j_min = j_min;
  134. /* determine f_max and j_max */
  135. f_max = 0.0, j_max = 0;
  136. for (j = 1; j <= n; j++)
  137. { if (a[j] > 0.0)
  138. { if (u[j] == +DBL_MAX)
  139. { if (j_max == 0)
  140. j_max = j;
  141. else
  142. { f_max = +DBL_MAX, j_max = 0;
  143. break;
  144. }
  145. }
  146. else
  147. f_max += a[j] * u[j];
  148. }
  149. else if (a[j] < 0.0)
  150. { if (l[j] == -DBL_MAX)
  151. { if (j_max == 0)
  152. j_max = j;
  153. else
  154. { f_max = +DBL_MAX, j_max = 0;
  155. break;
  156. }
  157. }
  158. else
  159. f_max += a[j] * l[j];
  160. }
  161. else
  162. xassert(a != a);
  163. }
  164. f->f_max = f_max, f->j_max = j_max;
  165. return;
  166. }
  167. /***********************************************************************
  168. * row_implied_bounds - determine row implied bounds
  169. *
  170. * Given a row (linear form)
  171. *
  172. * n
  173. * sum a[j] * x[j]
  174. * j=1
  175. *
  176. * and bounds of columns (variables)
  177. *
  178. * l[j] <= x[j] <= u[j]
  179. *
  180. * this routine determines implied bounds of the row.
  181. *
  182. * ALGORITHM
  183. *
  184. * Let J+ = {j : a[j] > 0} and J- = {j : a[j] < 0}.
  185. *
  186. * The implied lower bound of the row is computed as follows:
  187. *
  188. * L' := sum a[j] * l[j] + sum a[j] * u[j] (9)
  189. * j in J+ j in J-
  190. *
  191. * and as it follows from (3), (4), and (5):
  192. *
  193. * L' := if j_min = 0 then f_min else -inf (10)
  194. *
  195. * The implied upper bound of the row is computed as follows:
  196. *
  197. * U' := sum a[j] * u[j] + sum a[j] * l[j] (11)
  198. * j in J+ j in J-
  199. *
  200. * and as it follows from (6), (7), and (8):
  201. *
  202. * U' := if j_max = 0 then f_max else +inf (12)
  203. *
  204. * The implied bounds are stored in locations LL and UU. */
  205. static void row_implied_bounds(const struct f_info *f, double *LL,
  206. double *UU)
  207. { *LL = (f->j_min == 0 ? f->f_min : -DBL_MAX);
  208. *UU = (f->j_max == 0 ? f->f_max : +DBL_MAX);
  209. return;
  210. }
  211. /***********************************************************************
  212. * col_implied_bounds - determine column implied bounds
  213. *
  214. * Given a row (constraint)
  215. *
  216. * n
  217. * L <= sum a[j] * x[j] <= U (13)
  218. * j=1
  219. *
  220. * and bounds of columns (variables)
  221. *
  222. * l[j] <= x[j] <= u[j]
  223. *
  224. * this routine determines implied bounds of variable x[k].
  225. *
  226. * It is assumed that if L != -inf, the lower bound of the row can be
  227. * active, and if U != +inf, the upper bound of the row can be active.
  228. *
  229. * ALGORITHM
  230. *
  231. * From (13) it follows that
  232. *
  233. * L <= sum a[j] * x[j] + a[k] * x[k] <= U
  234. * j!=k
  235. * or
  236. *
  237. * L - sum a[j] * x[j] <= a[k] * x[k] <= U - sum a[j] * x[j]
  238. * j!=k j!=k
  239. *
  240. * Thus, if the row lower bound L can be active, implied lower bound of
  241. * term a[k] * x[k] can be determined as follows:
  242. *
  243. * ilb(a[k] * x[k]) = min(L - sum a[j] * x[j]) =
  244. * j!=k
  245. * (14)
  246. * = L - max sum a[j] * x[j]
  247. * j!=k
  248. *
  249. * where, as it follows from (6), (7), and (8)
  250. *
  251. * / f_max - a[k] * u[k], j_max = 0, a[k] > 0
  252. * |
  253. * | f_max - a[k] * l[k], j_max = 0, a[k] < 0
  254. * max sum a[j] * x[j] = {
  255. * j!=k | f_max, j_max = k
  256. * |
  257. * \ +inf, j_max != 0
  258. *
  259. * and if the upper bound U can be active, implied upper bound of term
  260. * a[k] * x[k] can be determined as follows:
  261. *
  262. * iub(a[k] * x[k]) = max(U - sum a[j] * x[j]) =
  263. * j!=k
  264. * (15)
  265. * = U - min sum a[j] * x[j]
  266. * j!=k
  267. *
  268. * where, as it follows from (3), (4), and (5)
  269. *
  270. * / f_min - a[k] * l[k], j_min = 0, a[k] > 0
  271. * |
  272. * | f_min - a[k] * u[k], j_min = 0, a[k] < 0
  273. * min sum a[j] * x[j] = {
  274. * j!=k | f_min, j_min = k
  275. * |
  276. * \ -inf, j_min != 0
  277. *
  278. * Since
  279. *
  280. * ilb(a[k] * x[k]) <= a[k] * x[k] <= iub(a[k] * x[k])
  281. *
  282. * implied lower and upper bounds of x[k] are determined as follows:
  283. *
  284. * l'[k] := if a[k] > 0 then ilb / a[k] else ulb / a[k] (16)
  285. *
  286. * u'[k] := if a[k] > 0 then ulb / a[k] else ilb / a[k] (17)
  287. *
  288. * The implied bounds are stored in locations ll and uu. */
  289. static void col_implied_bounds(const struct f_info *f, int n,
  290. const double a[], double L, double U, const double l[],
  291. const double u[], int k, double *ll, double *uu)
  292. { double ilb, iub;
  293. xassert(n >= 0);
  294. xassert(1 <= k && k <= n);
  295. /* determine implied lower bound of term a[k] * x[k] (14) */
  296. if (L == -DBL_MAX || f->f_max == +DBL_MAX)
  297. ilb = -DBL_MAX;
  298. else if (f->j_max == 0)
  299. { if (a[k] > 0.0)
  300. { xassert(u[k] != +DBL_MAX);
  301. ilb = L - (f->f_max - a[k] * u[k]);
  302. }
  303. else if (a[k] < 0.0)
  304. { xassert(l[k] != -DBL_MAX);
  305. ilb = L - (f->f_max - a[k] * l[k]);
  306. }
  307. else
  308. xassert(a != a);
  309. }
  310. else if (f->j_max == k)
  311. ilb = L - f->f_max;
  312. else
  313. ilb = -DBL_MAX;
  314. /* determine implied upper bound of term a[k] * x[k] (15) */
  315. if (U == +DBL_MAX || f->f_min == -DBL_MAX)
  316. iub = +DBL_MAX;
  317. else if (f->j_min == 0)
  318. { if (a[k] > 0.0)
  319. { xassert(l[k] != -DBL_MAX);
  320. iub = U - (f->f_min - a[k] * l[k]);
  321. }
  322. else if (a[k] < 0.0)
  323. { xassert(u[k] != +DBL_MAX);
  324. iub = U - (f->f_min - a[k] * u[k]);
  325. }
  326. else
  327. xassert(a != a);
  328. }
  329. else if (f->j_min == k)
  330. iub = U - f->f_min;
  331. else
  332. iub = +DBL_MAX;
  333. /* determine implied bounds of x[k] (16) and (17) */
  334. #if 1
  335. /* do not use a[k] if it has small magnitude to prevent wrong
  336. implied bounds; for example, 1e-15 * x1 >= x2 + x3, where
  337. x1 >= -10, x2, x3 >= 0, would lead to wrong conclusion that
  338. x1 >= 0 */
  339. if (fabs(a[k]) < 1e-6)
  340. *ll = -DBL_MAX, *uu = +DBL_MAX; else
  341. #endif
  342. if (a[k] > 0.0)
  343. { *ll = (ilb == -DBL_MAX ? -DBL_MAX : ilb / a[k]);
  344. *uu = (iub == +DBL_MAX ? +DBL_MAX : iub / a[k]);
  345. }
  346. else if (a[k] < 0.0)
  347. { *ll = (iub == +DBL_MAX ? -DBL_MAX : iub / a[k]);
  348. *uu = (ilb == -DBL_MAX ? +DBL_MAX : ilb / a[k]);
  349. }
  350. else
  351. xassert(a != a);
  352. return;
  353. }
  354. /***********************************************************************
  355. * check_row_bounds - check and relax original row bounds
  356. *
  357. * Given a row (constraint)
  358. *
  359. * n
  360. * L <= sum a[j] * x[j] <= U
  361. * j=1
  362. *
  363. * and bounds of columns (variables)
  364. *
  365. * l[j] <= x[j] <= u[j]
  366. *
  367. * this routine checks the original row bounds L and U for feasibility
  368. * and redundancy. If the original lower bound L or/and upper bound U
  369. * cannot be active due to bounds of variables, the routine remove them
  370. * replacing by -inf or/and +inf, respectively.
  371. *
  372. * If no primal infeasibility is detected, the routine returns zero,
  373. * otherwise non-zero. */
  374. static int check_row_bounds(const struct f_info *f, double *L_,
  375. double *U_)
  376. { int ret = 0;
  377. double L = *L_, U = *U_, LL, UU;
  378. /* determine implied bounds of the row */
  379. row_implied_bounds(f, &LL, &UU);
  380. /* check if the original lower bound is infeasible */
  381. if (L != -DBL_MAX)
  382. { double eps = 1e-3 * (1.0 + fabs(L));
  383. if (UU < L - eps)
  384. { ret = 1;
  385. goto done;
  386. }
  387. }
  388. /* check if the original upper bound is infeasible */
  389. if (U != +DBL_MAX)
  390. { double eps = 1e-3 * (1.0 + fabs(U));
  391. if (LL > U + eps)
  392. { ret = 1;
  393. goto done;
  394. }
  395. }
  396. /* check if the original lower bound is redundant */
  397. if (L != -DBL_MAX)
  398. { double eps = 1e-12 * (1.0 + fabs(L));
  399. if (LL > L - eps)
  400. { /* it cannot be active, so remove it */
  401. *L_ = -DBL_MAX;
  402. }
  403. }
  404. /* check if the original upper bound is redundant */
  405. if (U != +DBL_MAX)
  406. { double eps = 1e-12 * (1.0 + fabs(U));
  407. if (UU < U + eps)
  408. { /* it cannot be active, so remove it */
  409. *U_ = +DBL_MAX;
  410. }
  411. }
  412. done: return ret;
  413. }
  414. /***********************************************************************
  415. * check_col_bounds - check and tighten original column bounds
  416. *
  417. * Given a row (constraint)
  418. *
  419. * n
  420. * L <= sum a[j] * x[j] <= U
  421. * j=1
  422. *
  423. * and bounds of columns (variables)
  424. *
  425. * l[j] <= x[j] <= u[j]
  426. *
  427. * for column (variable) x[j] this routine checks the original column
  428. * bounds l[j] and u[j] for feasibility and redundancy. If the original
  429. * lower bound l[j] or/and upper bound u[j] cannot be active due to
  430. * bounds of the constraint and other variables, the routine tighten
  431. * them replacing by corresponding implied bounds, if possible.
  432. *
  433. * NOTE: It is assumed that if L != -inf, the row lower bound can be
  434. * active, and if U != +inf, the row upper bound can be active.
  435. *
  436. * The flag means that variable x[j] is required to be integer.
  437. *
  438. * New actual bounds for x[j] are stored in locations lj and uj.
  439. *
  440. * If no primal infeasibility is detected, the routine returns zero,
  441. * otherwise non-zero. */
  442. static int check_col_bounds(const struct f_info *f, int n,
  443. const double a[], double L, double U, const double l[],
  444. const double u[], int flag, int j, double *_lj, double *_uj)
  445. { int ret = 0;
  446. double lj, uj, ll, uu;
  447. xassert(n >= 0);
  448. xassert(1 <= j && j <= n);
  449. lj = l[j], uj = u[j];
  450. /* determine implied bounds of the column */
  451. col_implied_bounds(f, n, a, L, U, l, u, j, &ll, &uu);
  452. /* if x[j] is integral, round its implied bounds */
  453. if (flag)
  454. { if (ll != -DBL_MAX)
  455. ll = (ll - floor(ll) < 1e-3 ? floor(ll) : ceil(ll));
  456. if (uu != +DBL_MAX)
  457. uu = (ceil(uu) - uu < 1e-3 ? ceil(uu) : floor(uu));
  458. }
  459. /* check if the original lower bound is infeasible */
  460. if (lj != -DBL_MAX)
  461. { double eps = 1e-3 * (1.0 + fabs(lj));
  462. if (uu < lj - eps)
  463. { ret = 1;
  464. goto done;
  465. }
  466. }
  467. /* check if the original upper bound is infeasible */
  468. if (uj != +DBL_MAX)
  469. { double eps = 1e-3 * (1.0 + fabs(uj));
  470. if (ll > uj + eps)
  471. { ret = 1;
  472. goto done;
  473. }
  474. }
  475. /* check if the original lower bound is redundant */
  476. if (ll != -DBL_MAX)
  477. { double eps = 1e-3 * (1.0 + fabs(ll));
  478. if (lj < ll - eps)
  479. { /* it cannot be active, so tighten it */
  480. lj = ll;
  481. }
  482. }
  483. /* check if the original upper bound is redundant */
  484. if (uu != +DBL_MAX)
  485. { double eps = 1e-3 * (1.0 + fabs(uu));
  486. if (uj > uu + eps)
  487. { /* it cannot be active, so tighten it */
  488. uj = uu;
  489. }
  490. }
  491. /* due to round-off errors it may happen that lj > uj (although
  492. lj < uj + eps, since no primal infeasibility is detected), so
  493. adjuct the new actual bounds to provide lj <= uj */
  494. if (!(lj == -DBL_MAX || uj == +DBL_MAX))
  495. { double t1 = fabs(lj), t2 = fabs(uj);
  496. double eps = 1e-10 * (1.0 + (t1 <= t2 ? t1 : t2));
  497. if (lj > uj - eps)
  498. { if (lj == l[j])
  499. uj = lj;
  500. else if (uj == u[j])
  501. lj = uj;
  502. else if (t1 <= t2)
  503. uj = lj;
  504. else
  505. lj = uj;
  506. }
  507. }
  508. *_lj = lj, *_uj = uj;
  509. done: return ret;
  510. }
  511. /***********************************************************************
  512. * check_efficiency - check if change in column bounds is efficient
  513. *
  514. * Given the original bounds of a column l and u and its new actual
  515. * bounds l' and u' (possibly tighten by the routine check_col_bounds)
  516. * this routine checks if the change in the column bounds is efficient
  517. * enough. If so, the routine returns non-zero, otherwise zero.
  518. *
  519. * The flag means that the variable is required to be integer. */
  520. static int check_efficiency(int flag, double l, double u, double ll,
  521. double uu)
  522. { int eff = 0;
  523. /* check efficiency for lower bound */
  524. if (l < ll)
  525. { if (flag || l == -DBL_MAX)
  526. eff++;
  527. else
  528. { double r;
  529. if (u == +DBL_MAX)
  530. r = 1.0 + fabs(l);
  531. else
  532. r = 1.0 + (u - l);
  533. if (ll - l >= 0.25 * r)
  534. eff++;
  535. }
  536. }
  537. /* check efficiency for upper bound */
  538. if (u > uu)
  539. { if (flag || u == +DBL_MAX)
  540. eff++;
  541. else
  542. { double r;
  543. if (l == -DBL_MAX)
  544. r = 1.0 + fabs(u);
  545. else
  546. r = 1.0 + (u - l);
  547. if (u - uu >= 0.25 * r)
  548. eff++;
  549. }
  550. }
  551. return eff;
  552. }
  553. /***********************************************************************
  554. * basic_preprocessing - perform basic preprocessing
  555. *
  556. * This routine performs basic preprocessing of the specified MIP that
  557. * includes relaxing some row bounds and tightening some column bounds.
  558. *
  559. * On entry the arrays L and U contains original row bounds, and the
  560. * arrays l and u contains original column bounds:
  561. *
  562. * L[0] is the lower bound of the objective row;
  563. * L[i], i = 1,...,m, is the lower bound of i-th row;
  564. * U[0] is the upper bound of the objective row;
  565. * U[i], i = 1,...,m, is the upper bound of i-th row;
  566. * l[0] is not used;
  567. * l[j], j = 1,...,n, is the lower bound of j-th column;
  568. * u[0] is not used;
  569. * u[j], j = 1,...,n, is the upper bound of j-th column.
  570. *
  571. * On exit the arrays L, U, l, and u contain new actual bounds of rows
  572. * and column in the same locations.
  573. *
  574. * The parameters nrs and num specify an initial list of rows to be
  575. * processed:
  576. *
  577. * nrs is the number of rows in the initial list, 0 <= nrs <= m+1;
  578. * num[0] is not used;
  579. * num[1,...,nrs] are row numbers (0 means the objective row).
  580. *
  581. * The parameter max_pass specifies the maximal number of times that
  582. * each row can be processed, max_pass > 0.
  583. *
  584. * If no primal infeasibility is detected, the routine returns zero,
  585. * otherwise non-zero. */
  586. static int basic_preprocessing(glp_prob *mip, double L[], double U[],
  587. double l[], double u[], int nrs, const int num[], int max_pass)
  588. { int m = mip->m;
  589. int n = mip->n;
  590. struct f_info f;
  591. int i, j, k, len, size, ret = 0;
  592. int *ind, *list, *mark, *pass;
  593. double *val, *lb, *ub;
  594. xassert(0 <= nrs && nrs <= m+1);
  595. xassert(max_pass > 0);
  596. /* allocate working arrays */
  597. ind = xcalloc(1+n, sizeof(int));
  598. list = xcalloc(1+m+1, sizeof(int));
  599. mark = xcalloc(1+m+1, sizeof(int));
  600. memset(&mark[0], 0, (m+1) * sizeof(int));
  601. pass = xcalloc(1+m+1, sizeof(int));
  602. memset(&pass[0], 0, (m+1) * sizeof(int));
  603. val = xcalloc(1+n, sizeof(double));
  604. lb = xcalloc(1+n, sizeof(double));
  605. ub = xcalloc(1+n, sizeof(double));
  606. /* initialize the list of rows to be processed */
  607. size = 0;
  608. for (k = 1; k <= nrs; k++)
  609. { i = num[k];
  610. xassert(0 <= i && i <= m);
  611. /* duplicate row numbers are not allowed */
  612. xassert(!mark[i]);
  613. list[++size] = i, mark[i] = 1;
  614. }
  615. xassert(size == nrs);
  616. /* process rows in the list until it becomes empty */
  617. while (size > 0)
  618. { /* get a next row from the list */
  619. i = list[size--], mark[i] = 0;
  620. /* increase the row processing count */
  621. pass[i]++;
  622. /* if the row is free, skip it */
  623. if (L[i] == -DBL_MAX && U[i] == +DBL_MAX) continue;
  624. /* obtain coefficients of the row */
  625. len = 0;
  626. if (i == 0)
  627. { for (j = 1; j <= n; j++)
  628. { GLPCOL *col = mip->col[j];
  629. if (col->coef != 0.0)
  630. len++, ind[len] = j, val[len] = col->coef;
  631. }
  632. }
  633. else
  634. { GLPROW *row = mip->row[i];
  635. GLPAIJ *aij;
  636. for (aij = row->ptr; aij != NULL; aij = aij->r_next)
  637. len++, ind[len] = aij->col->j, val[len] = aij->val;
  638. }
  639. /* determine lower and upper bounds of columns corresponding
  640. to non-zero row coefficients */
  641. for (k = 1; k <= len; k++)
  642. j = ind[k], lb[k] = l[j], ub[k] = u[j];
  643. /* prepare the row info to determine implied bounds */
  644. prepare_row_info(len, val, lb, ub, &f);
  645. /* check and relax bounds of the row */
  646. if (check_row_bounds(&f, &L[i], &U[i]))
  647. { /* the feasible region is empty */
  648. ret = 1;
  649. goto done;
  650. }
  651. /* if the row became free, drop it */
  652. if (L[i] == -DBL_MAX && U[i] == +DBL_MAX) continue;
  653. /* process columns having non-zero coefficients in the row */
  654. for (k = 1; k <= len; k++)
  655. { GLPCOL *col;
  656. int flag, eff;
  657. double ll, uu;
  658. /* take a next column in the row */
  659. j = ind[k], col = mip->col[j];
  660. flag = col->kind != GLP_CV;
  661. /* check and tighten bounds of the column */
  662. if (check_col_bounds(&f, len, val, L[i], U[i], lb, ub,
  663. flag, k, &ll, &uu))
  664. { /* the feasible region is empty */
  665. ret = 1;
  666. goto done;
  667. }
  668. /* check if change in the column bounds is efficient */
  669. eff = check_efficiency(flag, l[j], u[j], ll, uu);
  670. /* set new actual bounds of the column */
  671. l[j] = ll, u[j] = uu;
  672. /* if the change is efficient, add all rows affected by the
  673. corresponding column, to the list */
  674. if (eff > 0)
  675. { GLPAIJ *aij;
  676. for (aij = col->ptr; aij != NULL; aij = aij->c_next)
  677. { int ii = aij->row->i;
  678. /* if the row was processed maximal number of times,
  679. skip it */
  680. if (pass[ii] >= max_pass) continue;
  681. /* if the row is free, skip it */
  682. if (L[ii] == -DBL_MAX && U[ii] == +DBL_MAX) continue;
  683. /* put the row into the list */
  684. if (mark[ii] == 0)
  685. { xassert(size <= m);
  686. list[++size] = ii, mark[ii] = 1;
  687. }
  688. }
  689. }
  690. }
  691. }
  692. done: /* free working arrays */
  693. xfree(ind);
  694. xfree(list);
  695. xfree(mark);
  696. xfree(pass);
  697. xfree(val);
  698. xfree(lb);
  699. xfree(ub);
  700. return ret;
  701. }
  702. /***********************************************************************
  703. * NAME
  704. *
  705. * ios_preprocess_node - preprocess current subproblem
  706. *
  707. * SYNOPSIS
  708. *
  709. * #include "glpios.h"
  710. * int ios_preprocess_node(glp_tree *tree, int max_pass);
  711. *
  712. * DESCRIPTION
  713. *
  714. * The routine ios_preprocess_node performs basic preprocessing of the
  715. * current subproblem.
  716. *
  717. * RETURNS
  718. *
  719. * If no primal infeasibility is detected, the routine returns zero,
  720. * otherwise non-zero. */
  721. int ios_preprocess_node(glp_tree *tree, int max_pass)
  722. { glp_prob *mip = tree->mip;
  723. int m = mip->m;
  724. int n = mip->n;
  725. int i, j, nrs, *num, ret = 0;
  726. double *L, *U, *l, *u;
  727. /* the current subproblem must exist */
  728. xassert(tree->curr != NULL);
  729. /* determine original row bounds */
  730. L = xcalloc(1+m, sizeof(double));
  731. U = xcalloc(1+m, sizeof(double));
  732. switch (mip->mip_stat)
  733. { case GLP_UNDEF:
  734. L[0] = -DBL_MAX, U[0] = +DBL_MAX;
  735. break;
  736. case GLP_FEAS:
  737. switch (mip->dir)
  738. { case GLP_MIN:
  739. L[0] = -DBL_MAX, U[0] = mip->mip_obj - mip->c0;
  740. break;
  741. case GLP_MAX:
  742. L[0] = mip->mip_obj - mip->c0, U[0] = +DBL_MAX;
  743. break;
  744. default:
  745. xassert(mip != mip);
  746. }
  747. break;
  748. default:
  749. xassert(mip != mip);
  750. }
  751. for (i = 1; i <= m; i++)
  752. { L[i] = glp_get_row_lb(mip, i);
  753. U[i] = glp_get_row_ub(mip, i);
  754. }
  755. /* determine original column bounds */
  756. l = xcalloc(1+n, sizeof(double));
  757. u = xcalloc(1+n, sizeof(double));
  758. for (j = 1; j <= n; j++)
  759. { l[j] = glp_get_col_lb(mip, j);
  760. u[j] = glp_get_col_ub(mip, j);
  761. }
  762. /* build the initial list of rows to be analyzed */
  763. nrs = m + 1;
  764. num = xcalloc(1+nrs, sizeof(int));
  765. for (i = 1; i <= nrs; i++) num[i] = i - 1;
  766. /* perform basic preprocessing */
  767. if (basic_preprocessing(mip , L, U, l, u, nrs, num, max_pass))
  768. { ret = 1;
  769. goto done;
  770. }
  771. /* set new actual (relaxed) row bounds */
  772. for (i = 1; i <= m; i++)
  773. { /* consider only non-active rows to keep dual feasibility */
  774. if (glp_get_row_stat(mip, i) == GLP_BS)
  775. { if (L[i] == -DBL_MAX && U[i] == +DBL_MAX)
  776. glp_set_row_bnds(mip, i, GLP_FR, 0.0, 0.0);
  777. else if (U[i] == +DBL_MAX)
  778. glp_set_row_bnds(mip, i, GLP_LO, L[i], 0.0);
  779. else if (L[i] == -DBL_MAX)
  780. glp_set_row_bnds(mip, i, GLP_UP, 0.0, U[i]);
  781. }
  782. }
  783. /* set new actual (tightened) column bounds */
  784. for (j = 1; j <= n; j++)
  785. { int type;
  786. if (l[j] == -DBL_MAX && u[j] == +DBL_MAX)
  787. type = GLP_FR;
  788. else if (u[j] == +DBL_MAX)
  789. type = GLP_LO;
  790. else if (l[j] == -DBL_MAX)
  791. type = GLP_UP;
  792. else if (l[j] != u[j])
  793. type = GLP_DB;
  794. else
  795. type = GLP_FX;
  796. glp_set_col_bnds(mip, j, type, l[j], u[j]);
  797. }
  798. done: /* free working arrays and return */
  799. xfree(L);
  800. xfree(U);
  801. xfree(l);
  802. xfree(u);
  803. xfree(num);
  804. return ret;
  805. }
  806. /* eof */