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.

89 lines
2.6 KiB

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