glpscf.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. /* glpscf.c (Schur complement factorization) */
  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 "glpenv.h"
  24. #include "glpscf.h"
  25. #define xfault xerror
  26. #define _GLPSCF_DEBUG 0
  27. #define eps 1e-10
  28. /***********************************************************************
  29. * NAME
  30. *
  31. * scf_create_it - create Schur complement factorization
  32. *
  33. * SYNOPSIS
  34. *
  35. * #include "glpscf.h"
  36. * SCF *scf_create_it(int n_max);
  37. *
  38. * DESCRIPTION
  39. *
  40. * The routine scf_create_it creates the factorization of matrix C,
  41. * which initially has no rows and columns.
  42. *
  43. * The parameter n_max specifies the maximal order of matrix C to be
  44. * factorized, 1 <= n_max <= 32767.
  45. *
  46. * RETURNS
  47. *
  48. * The routine scf_create_it returns a pointer to the structure SCF,
  49. * which defines the factorization. */
  50. SCF *scf_create_it(int n_max)
  51. { SCF *scf;
  52. #if _GLPSCF_DEBUG
  53. xprintf("scf_create_it: warning: debug mode enabled\n");
  54. #endif
  55. if (!(1 <= n_max && n_max <= 32767))
  56. xfault("scf_create_it: n_max = %d; invalid parameter\n",
  57. n_max);
  58. scf = xmalloc(sizeof(SCF));
  59. scf->n_max = n_max;
  60. scf->n = 0;
  61. scf->f = xcalloc(1 + n_max * n_max, sizeof(double));
  62. scf->u = xcalloc(1 + n_max * (n_max + 1) / 2, sizeof(double));
  63. scf->p = xcalloc(1 + n_max, sizeof(int));
  64. scf->t_opt = SCF_TBG;
  65. scf->rank = 0;
  66. #if _GLPSCF_DEBUG
  67. scf->c = xcalloc(1 + n_max * n_max, sizeof(double));
  68. #else
  69. scf->c = NULL;
  70. #endif
  71. scf->w = xcalloc(1 + n_max, sizeof(double));
  72. return scf;
  73. }
  74. /***********************************************************************
  75. * The routine f_loc determines location of matrix element F[i,j] in
  76. * the one-dimensional array f. */
  77. static int f_loc(SCF *scf, int i, int j)
  78. { int n_max = scf->n_max;
  79. int n = scf->n;
  80. xassert(1 <= i && i <= n);
  81. xassert(1 <= j && j <= n);
  82. return (i - 1) * n_max + j;
  83. }
  84. /***********************************************************************
  85. * The routine u_loc determines location of matrix element U[i,j] in
  86. * the one-dimensional array u. */
  87. static int u_loc(SCF *scf, int i, int j)
  88. { int n_max = scf->n_max;
  89. int n = scf->n;
  90. xassert(1 <= i && i <= n);
  91. xassert(i <= j && j <= n);
  92. return (i - 1) * n_max + j - i * (i - 1) / 2;
  93. }
  94. /***********************************************************************
  95. * The routine bg_transform applies Bartels-Golub version of gaussian
  96. * elimination to restore triangular structure of matrix U.
  97. *
  98. * On entry matrix U has the following structure:
  99. *
  100. * 1 k n
  101. * 1 * * * * * * * * * *
  102. * . * * * * * * * * *
  103. * . . * * * * * * * *
  104. * . . . * * * * * * *
  105. * k . . . . * * * * * *
  106. * . . . . . * * * * *
  107. * . . . . . . * * * *
  108. * . . . . . . . * * *
  109. * . . . . . . . . * *
  110. * n . . . . # # # # # #
  111. *
  112. * where '#' is a row spike to be eliminated.
  113. *
  114. * Elements of n-th row are passed separately in locations un[k], ...,
  115. * un[n]. On exit the content of the array un is destroyed.
  116. *
  117. * REFERENCES
  118. *
  119. * R.H.Bartels, G.H.Golub, "The Simplex Method of Linear Programming
  120. * Using LU-decomposition", Comm. ACM, 12, pp. 266-68, 1969. */
  121. static void bg_transform(SCF *scf, int k, double un[])
  122. { int n = scf->n;
  123. double *f = scf->f;
  124. double *u = scf->u;
  125. int j, k1, kj, kk, n1, nj;
  126. double t;
  127. xassert(1 <= k && k <= n);
  128. /* main elimination loop */
  129. for (k = k; k < n; k++)
  130. { /* determine location of U[k,k] */
  131. kk = u_loc(scf, k, k);
  132. /* determine location of F[k,1] */
  133. k1 = f_loc(scf, k, 1);
  134. /* determine location of F[n,1] */
  135. n1 = f_loc(scf, n, 1);
  136. /* if |U[k,k]| < |U[n,k]|, interchange k-th and n-th rows to
  137. provide |U[k,k]| >= |U[n,k]| */
  138. if (fabs(u[kk]) < fabs(un[k]))
  139. { /* interchange k-th and n-th rows of matrix U */
  140. for (j = k, kj = kk; j <= n; j++, kj++)
  141. t = u[kj], u[kj] = un[j], un[j] = t;
  142. /* interchange k-th and n-th rows of matrix F to keep the
  143. main equality F * C = U * P */
  144. for (j = 1, kj = k1, nj = n1; j <= n; j++, kj++, nj++)
  145. t = f[kj], f[kj] = f[nj], f[nj] = t;
  146. }
  147. /* now |U[k,k]| >= |U[n,k]| */
  148. /* if U[k,k] is too small in the magnitude, replace U[k,k] and
  149. U[n,k] by exact zero */
  150. if (fabs(u[kk]) < eps) u[kk] = un[k] = 0.0;
  151. /* if U[n,k] is already zero, elimination is not needed */
  152. if (un[k] == 0.0) continue;
  153. /* compute gaussian multiplier t = U[n,k] / U[k,k] */
  154. t = un[k] / u[kk];
  155. /* apply gaussian elimination to nullify U[n,k] */
  156. /* (n-th row of U) := (n-th row of U) - t * (k-th row of U) */
  157. for (j = k+1, kj = kk+1; j <= n; j++, kj++)
  158. un[j] -= t * u[kj];
  159. /* (n-th row of F) := (n-th row of F) - t * (k-th row of F)
  160. to keep the main equality F * C = U * P */
  161. for (j = 1, kj = k1, nj = n1; j <= n; j++, kj++, nj++)
  162. f[nj] -= t * f[kj];
  163. }
  164. /* if U[n,n] is too small in the magnitude, replace it by exact
  165. zero */
  166. if (fabs(un[n]) < eps) un[n] = 0.0;
  167. /* store U[n,n] in a proper location */
  168. u[u_loc(scf, n, n)] = un[n];
  169. return;
  170. }
  171. /***********************************************************************
  172. * The routine givens computes the parameters of Givens plane rotation
  173. * c = cos(teta) and s = sin(teta) such that:
  174. *
  175. * ( c -s ) ( a ) ( r )
  176. * ( ) ( ) = ( ) ,
  177. * ( s c ) ( b ) ( 0 )
  178. *
  179. * where a and b are given scalars.
  180. *
  181. * REFERENCES
  182. *
  183. * G.H.Golub, C.F.Van Loan, "Matrix Computations", 2nd ed. */
  184. static void givens(double a, double b, double *c, double *s)
  185. { double t;
  186. if (b == 0.0)
  187. (*c) = 1.0, (*s) = 0.0;
  188. else if (fabs(a) <= fabs(b))
  189. t = - a / b, (*s) = 1.0 / sqrt(1.0 + t * t), (*c) = (*s) * t;
  190. else
  191. t = - b / a, (*c) = 1.0 / sqrt(1.0 + t * t), (*s) = (*c) * t;
  192. return;
  193. }
  194. /*----------------------------------------------------------------------
  195. * The routine gr_transform applies Givens plane rotations to restore
  196. * triangular structure of matrix U.
  197. *
  198. * On entry matrix U has the following structure:
  199. *
  200. * 1 k n
  201. * 1 * * * * * * * * * *
  202. * . * * * * * * * * *
  203. * . . * * * * * * * *
  204. * . . . * * * * * * *
  205. * k . . . . * * * * * *
  206. * . . . . . * * * * *
  207. * . . . . . . * * * *
  208. * . . . . . . . * * *
  209. * . . . . . . . . * *
  210. * n . . . . # # # # # #
  211. *
  212. * where '#' is a row spike to be eliminated.
  213. *
  214. * Elements of n-th row are passed separately in locations un[k], ...,
  215. * un[n]. On exit the content of the array un is destroyed.
  216. *
  217. * REFERENCES
  218. *
  219. * R.H.Bartels, G.H.Golub, "The Simplex Method of Linear Programming
  220. * Using LU-decomposition", Comm. ACM, 12, pp. 266-68, 1969. */
  221. static void gr_transform(SCF *scf, int k, double un[])
  222. { int n = scf->n;
  223. double *f = scf->f;
  224. double *u = scf->u;
  225. int j, k1, kj, kk, n1, nj;
  226. double c, s;
  227. xassert(1 <= k && k <= n);
  228. /* main elimination loop */
  229. for (k = k; k < n; k++)
  230. { /* determine location of U[k,k] */
  231. kk = u_loc(scf, k, k);
  232. /* determine location of F[k,1] */
  233. k1 = f_loc(scf, k, 1);
  234. /* determine location of F[n,1] */
  235. n1 = f_loc(scf, n, 1);
  236. /* if both U[k,k] and U[n,k] are too small in the magnitude,
  237. replace them by exact zero */
  238. if (fabs(u[kk]) < eps && fabs(un[k]) < eps)
  239. u[kk] = un[k] = 0.0;
  240. /* if U[n,k] is already zero, elimination is not needed */
  241. if (un[k] == 0.0) continue;
  242. /* compute the parameters of Givens plane rotation */
  243. givens(u[kk], un[k], &c, &s);
  244. /* apply Givens rotation to k-th and n-th rows of matrix U */
  245. for (j = k, kj = kk; j <= n; j++, kj++)
  246. { double ukj = u[kj], unj = un[j];
  247. u[kj] = c * ukj - s * unj;
  248. un[j] = s * ukj + c * unj;
  249. }
  250. /* apply Givens rotation to k-th and n-th rows of matrix F
  251. to keep the main equality F * C = U * P */
  252. for (j = 1, kj = k1, nj = n1; j <= n; j++, kj++, nj++)
  253. { double fkj = f[kj], fnj = f[nj];
  254. f[kj] = c * fkj - s * fnj;
  255. f[nj] = s * fkj + c * fnj;
  256. }
  257. }
  258. /* if U[n,n] is too small in the magnitude, replace it by exact
  259. zero */
  260. if (fabs(un[n]) < eps) un[n] = 0.0;
  261. /* store U[n,n] in a proper location */
  262. u[u_loc(scf, n, n)] = un[n];
  263. return;
  264. }
  265. /***********************************************************************
  266. * The routine transform restores triangular structure of matrix U.
  267. * It is a driver to the routines bg_transform and gr_transform (see
  268. * comments to these routines above). */
  269. static void transform(SCF *scf, int k, double un[])
  270. { switch (scf->t_opt)
  271. { case SCF_TBG:
  272. bg_transform(scf, k, un);
  273. break;
  274. case SCF_TGR:
  275. gr_transform(scf, k, un);
  276. break;
  277. default:
  278. xassert(scf != scf);
  279. }
  280. return;
  281. }
  282. /***********************************************************************
  283. * The routine estimate_rank estimates the rank of matrix C.
  284. *
  285. * Since all transformations applied to matrix F are non-singular,
  286. * and F is assumed to be well conditioned, from the main equaility
  287. * F * C = U * P it follows that rank(C) = rank(U), where rank(U) is
  288. * estimated as the number of non-zero diagonal elements of U. */
  289. static int estimate_rank(SCF *scf)
  290. { int n_max = scf->n_max;
  291. int n = scf->n;
  292. double *u = scf->u;
  293. int i, ii, inc, rank = 0;
  294. for (i = 1, ii = u_loc(scf, i, i), inc = n_max; i <= n;
  295. i++, ii += inc, inc--)
  296. if (u[ii] != 0.0) rank++;
  297. return rank;
  298. }
  299. #if _GLPSCF_DEBUG
  300. /***********************************************************************
  301. * The routine check_error computes the maximal relative error between
  302. * left- and right-hand sides of the main equality F * C = U * P. (This
  303. * routine is intended only for debugging.) */
  304. static void check_error(SCF *scf, const char *func)
  305. { int n = scf->n;
  306. double *f = scf->f;
  307. double *u = scf->u;
  308. int *p = scf->p;
  309. double *c = scf->c;
  310. int i, j, k;
  311. double d, dmax = 0.0, s, t;
  312. xassert(c != NULL);
  313. for (i = 1; i <= n; i++)
  314. { for (j = 1; j <= n; j++)
  315. { /* compute element (i,j) of product F * C */
  316. s = 0.0;
  317. for (k = 1; k <= n; k++)
  318. s += f[f_loc(scf, i, k)] * c[f_loc(scf, k, j)];
  319. /* compute element (i,j) of product U * P */
  320. k = p[j];
  321. t = (i <= k ? u[u_loc(scf, i, k)] : 0.0);
  322. /* compute the maximal relative error */
  323. d = fabs(s - t) / (1.0 + fabs(t));
  324. if (dmax < d) dmax = d;
  325. }
  326. }
  327. if (dmax > 1e-8)
  328. xprintf("%s: dmax = %g; relative error too large\n", func,
  329. dmax);
  330. return;
  331. }
  332. #endif
  333. /***********************************************************************
  334. * NAME
  335. *
  336. * scf_update_exp - update factorization on expanding C
  337. *
  338. * SYNOPSIS
  339. *
  340. * #include "glpscf.h"
  341. * int scf_update_exp(SCF *scf, const double x[], const double y[],
  342. * double z);
  343. *
  344. * DESCRIPTION
  345. *
  346. * The routine scf_update_exp updates the factorization of matrix C on
  347. * expanding it by adding a new row and column as follows:
  348. *
  349. * ( C x )
  350. * new C = ( )
  351. * ( y' z )
  352. *
  353. * where x[1,...,n] is a new column, y[1,...,n] is a new row, and z is
  354. * a new diagonal element.
  355. *
  356. * If on entry the factorization is empty, the parameters x and y can
  357. * be specified as NULL.
  358. *
  359. * RETURNS
  360. *
  361. * 0 The factorization has been successfully updated.
  362. *
  363. * SCF_ESING
  364. * The factorization has been successfully updated, however, new
  365. * matrix C is singular within working precision. Note that the new
  366. * factorization remains valid.
  367. *
  368. * SCF_ELIMIT
  369. * There is not enough room to expand the factorization, because
  370. * n = n_max. The factorization remains unchanged.
  371. *
  372. * ALGORITHM
  373. *
  374. * We can see that:
  375. *
  376. * ( F 0 ) ( C x ) ( FC Fx ) ( UP Fx )
  377. * ( ) ( ) = ( ) = ( ) =
  378. * ( 0 1 ) ( y' z ) ( y' z ) ( y' z )
  379. *
  380. * ( U Fx ) ( P 0 )
  381. * = ( ) ( ),
  382. * ( y'P' z ) ( 0 1 )
  383. *
  384. * therefore to keep the main equality F * C = U * P we can take:
  385. *
  386. * ( F 0 ) ( U Fx ) ( P 0 )
  387. * new F = ( ), new U = ( ), new P = ( ),
  388. * ( 0 1 ) ( y'P' z ) ( 0 1 )
  389. *
  390. * and eliminate the row spike y'P' in the last row of new U to restore
  391. * its upper triangular structure. */
  392. int scf_update_exp(SCF *scf, const double x[], const double y[],
  393. double z)
  394. { int n_max = scf->n_max;
  395. int n = scf->n;
  396. double *f = scf->f;
  397. double *u = scf->u;
  398. int *p = scf->p;
  399. #if _GLPSCF_DEBUG
  400. double *c = scf->c;
  401. #endif
  402. double *un = scf->w;
  403. int i, ij, in, j, k, nj, ret = 0;
  404. double t;
  405. /* check if the factorization can be expanded */
  406. if (n == n_max)
  407. { /* there is not enough room */
  408. ret = SCF_ELIMIT;
  409. goto done;
  410. }
  411. /* increase the order of the factorization */
  412. scf->n = ++n;
  413. /* fill new zero column of matrix F */
  414. for (i = 1, in = f_loc(scf, i, n); i < n; i++, in += n_max)
  415. f[in] = 0.0;
  416. /* fill new zero row of matrix F */
  417. for (j = 1, nj = f_loc(scf, n, j); j < n; j++, nj++)
  418. f[nj] = 0.0;
  419. /* fill new unity diagonal element of matrix F */
  420. f[f_loc(scf, n, n)] = 1.0;
  421. /* compute new column of matrix U, which is (old F) * x */
  422. for (i = 1; i < n; i++)
  423. { /* u[i,n] := (i-th row of old F) * x */
  424. t = 0.0;
  425. for (j = 1, ij = f_loc(scf, i, 1); j < n; j++, ij++)
  426. t += f[ij] * x[j];
  427. u[u_loc(scf, i, n)] = t;
  428. }
  429. /* compute new (spiked) row of matrix U, which is (old P) * y */
  430. for (j = 1; j < n; j++) un[j] = y[p[j]];
  431. /* store new diagonal element of matrix U, which is z */
  432. un[n] = z;
  433. /* expand matrix P */
  434. p[n] = n;
  435. #if _GLPSCF_DEBUG
  436. /* expand matrix C */
  437. /* fill its new column, which is x */
  438. for (i = 1, in = f_loc(scf, i, n); i < n; i++, in += n_max)
  439. c[in] = x[i];
  440. /* fill its new row, which is y */
  441. for (j = 1, nj = f_loc(scf, n, j); j < n; j++, nj++)
  442. c[nj] = y[j];
  443. /* fill its new diagonal element, which is z */
  444. c[f_loc(scf, n, n)] = z;
  445. #endif
  446. /* restore upper triangular structure of matrix U */
  447. for (k = 1; k < n; k++)
  448. if (un[k] != 0.0) break;
  449. transform(scf, k, un);
  450. /* estimate the rank of matrices C and U */
  451. scf->rank = estimate_rank(scf);
  452. if (scf->rank != n) ret = SCF_ESING;
  453. #if _GLPSCF_DEBUG
  454. /* check that the factorization is accurate enough */
  455. check_error(scf, "scf_update_exp");
  456. #endif
  457. done: return ret;
  458. }
  459. /***********************************************************************
  460. * The routine solve solves the system C * x = b.
  461. *
  462. * From the main equation F * C = U * P it follows that:
  463. *
  464. * C * x = b => F * C * x = F * b => U * P * x = F * b =>
  465. *
  466. * P * x = inv(U) * F * b => x = P' * inv(U) * F * b.
  467. *
  468. * On entry the array x contains right-hand side vector b. On exit this
  469. * array contains solution vector x. */
  470. static void solve(SCF *scf, double x[])
  471. { int n = scf->n;
  472. double *f = scf->f;
  473. double *u = scf->u;
  474. int *p = scf->p;
  475. double *y = scf->w;
  476. int i, j, ij;
  477. double t;
  478. /* y := F * b */
  479. for (i = 1; i <= n; i++)
  480. { /* y[i] = (i-th row of F) * b */
  481. t = 0.0;
  482. for (j = 1, ij = f_loc(scf, i, 1); j <= n; j++, ij++)
  483. t += f[ij] * x[j];
  484. y[i] = t;
  485. }
  486. /* y := inv(U) * y */
  487. for (i = n; i >= 1; i--)
  488. { t = y[i];
  489. for (j = n, ij = u_loc(scf, i, n); j > i; j--, ij--)
  490. t -= u[ij] * y[j];
  491. y[i] = t / u[ij];
  492. }
  493. /* x := P' * y */
  494. for (i = 1; i <= n; i++) x[p[i]] = y[i];
  495. return;
  496. }
  497. /***********************************************************************
  498. * The routine tsolve solves the transposed system C' * x = b.
  499. *
  500. * From the main equation F * C = U * P it follows that:
  501. *
  502. * C' * F' = P' * U',
  503. *
  504. * therefore:
  505. *
  506. * C' * x = b => C' * F' * inv(F') * x = b =>
  507. *
  508. * P' * U' * inv(F') * x = b => U' * inv(F') * x = P * b =>
  509. *
  510. * inv(F') * x = inv(U') * P * b => x = F' * inv(U') * P * b.
  511. *
  512. * On entry the array x contains right-hand side vector b. On exit this
  513. * array contains solution vector x. */
  514. static void tsolve(SCF *scf, double x[])
  515. { int n = scf->n;
  516. double *f = scf->f;
  517. double *u = scf->u;
  518. int *p = scf->p;
  519. double *y = scf->w;
  520. int i, j, ij;
  521. double t;
  522. /* y := P * b */
  523. for (i = 1; i <= n; i++) y[i] = x[p[i]];
  524. /* y := inv(U') * y */
  525. for (i = 1; i <= n; i++)
  526. { /* compute y[i] */
  527. ij = u_loc(scf, i, i);
  528. t = (y[i] /= u[ij]);
  529. /* substitute y[i] in other equations */
  530. for (j = i+1, ij++; j <= n; j++, ij++)
  531. y[j] -= u[ij] * t;
  532. }
  533. /* x := F' * y (computed as linear combination of rows of F) */
  534. for (j = 1; j <= n; j++) x[j] = 0.0;
  535. for (i = 1; i <= n; i++)
  536. { t = y[i]; /* coefficient of linear combination */
  537. for (j = 1, ij = f_loc(scf, i, 1); j <= n; j++, ij++)
  538. x[j] += f[ij] * t;
  539. }
  540. return;
  541. }
  542. /***********************************************************************
  543. * NAME
  544. *
  545. * scf_solve_it - solve either system C * x = b or C' * x = b
  546. *
  547. * SYNOPSIS
  548. *
  549. * #include "glpscf.h"
  550. * void scf_solve_it(SCF *scf, int tr, double x[]);
  551. *
  552. * DESCRIPTION
  553. *
  554. * The routine scf_solve_it solves either the system C * x = b (if tr
  555. * is zero) or the system C' * x = b, where C' is a matrix transposed
  556. * to C (if tr is non-zero). C is assumed to be non-singular.
  557. *
  558. * On entry the array x should contain the right-hand side vector b in
  559. * locations x[1], ..., x[n], where n is the order of matrix C. On exit
  560. * the array x contains the solution vector x in the same locations. */
  561. void scf_solve_it(SCF *scf, int tr, double x[])
  562. { if (scf->rank < scf->n)
  563. xfault("scf_solve_it: singular matrix\n");
  564. if (!tr)
  565. solve(scf, x);
  566. else
  567. tsolve(scf, x);
  568. return;
  569. }
  570. void scf_reset_it(SCF *scf)
  571. { /* reset factorization for empty matrix C */
  572. scf->n = scf->rank = 0;
  573. return;
  574. }
  575. /***********************************************************************
  576. * NAME
  577. *
  578. * scf_delete_it - delete Schur complement factorization
  579. *
  580. * SYNOPSIS
  581. *
  582. * #include "glpscf.h"
  583. * void scf_delete_it(SCF *scf);
  584. *
  585. * DESCRIPTION
  586. *
  587. * The routine scf_delete_it deletes the specified factorization and
  588. * frees all the memory allocated to this object. */
  589. void scf_delete_it(SCF *scf)
  590. { xfree(scf->f);
  591. xfree(scf->u);
  592. xfree(scf->p);
  593. #if _GLPSCF_DEBUG
  594. xfree(scf->c);
  595. #endif
  596. xfree(scf->w);
  597. xfree(scf);
  598. return;
  599. }
  600. /* eof */