glpbfx.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* glpbfx.c */
  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. typedef struct BFX BFX;
  24. #define GLPBFX_DEFINED
  25. #include "glpbfx.h"
  26. #include "glpenv.h"
  27. #include "glplux.h"
  28. struct BFX
  29. { int valid;
  30. LUX *lux;
  31. };
  32. BFX *bfx_create_binv(void)
  33. { /* create factorization of the basis matrix */
  34. BFX *bfx;
  35. bfx = xmalloc(sizeof(BFX));
  36. bfx->valid = 0;
  37. bfx->lux = NULL;
  38. return bfx;
  39. }
  40. int bfx_factorize(BFX *binv, int m, int (*col)(void *info, int j,
  41. int ind[], mpq_t val[]), void *info)
  42. { /* compute factorization of the basis matrix */
  43. int ret;
  44. xassert(m > 0);
  45. if (binv->lux != NULL && binv->lux->n != m)
  46. { lux_delete(binv->lux);
  47. binv->lux = NULL;
  48. }
  49. if (binv->lux == NULL)
  50. binv->lux = lux_create(m);
  51. ret = lux_decomp(binv->lux, col, info);
  52. binv->valid = (ret == 0);
  53. return ret;
  54. }
  55. void bfx_ftran(BFX *binv, mpq_t x[], int save)
  56. { /* perform forward transformation (FTRAN) */
  57. xassert(binv->valid);
  58. lux_solve(binv->lux, 0, x);
  59. xassert(save == save);
  60. return;
  61. }
  62. void bfx_btran(BFX *binv, mpq_t x[])
  63. { /* perform backward transformation (BTRAN) */
  64. xassert(binv->valid);
  65. lux_solve(binv->lux, 1, x);
  66. return;
  67. }
  68. int bfx_update(BFX *binv, int j)
  69. { /* update factorization of the basis matrix */
  70. xassert(binv->valid);
  71. xassert(1 <= j && j <= binv->lux->n);
  72. return 1;
  73. }
  74. void bfx_delete_binv(BFX *binv)
  75. { /* delete factorization of the basis matrix */
  76. if (binv->lux != NULL)
  77. lux_delete(binv->lux);
  78. xfree(binv);
  79. return;
  80. }
  81. /* eof */