glplpf.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /* glplpf.h (LP basis factorization, Schur complement version) */
  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. #ifndef GLPLPF_H
  24. #define GLPLPF_H
  25. #include "glpscf.h"
  26. #include "glpluf.h"
  27. /***********************************************************************
  28. * The structure LPF defines the factorization of the basis mxm matrix
  29. * B, where m is the number of rows in corresponding problem instance.
  30. *
  31. * This factorization is the following septet:
  32. *
  33. * [B] = (L0, U0, R, S, C, P, Q), (1)
  34. *
  35. * and is based on the following main equality:
  36. *
  37. * ( B F^) ( B0 F ) ( L0 0 ) ( U0 R )
  38. * ( ) = P ( ) Q = P ( ) ( ) Q, (2)
  39. * ( G^ H^) ( G H ) ( S I ) ( 0 C )
  40. *
  41. * where:
  42. *
  43. * B is the current basis matrix (not stored);
  44. *
  45. * F^, G^, H^ are some additional matrices (not stored);
  46. *
  47. * B0 is some initial basis matrix (not stored);
  48. *
  49. * F, G, H are some additional matrices (not stored);
  50. *
  51. * P, Q are permutation matrices (stored in both row- and column-like
  52. * formats);
  53. *
  54. * L0, U0 are some matrices that defines a factorization of the initial
  55. * basis matrix B0 = L0 * U0 (stored in an invertable form);
  56. *
  57. * R is a matrix defined from L0 * R = F, so R = inv(L0) * F (stored in
  58. * a column-wise sparse format);
  59. *
  60. * S is a matrix defined from S * U0 = G, so S = G * inv(U0) (stored in
  61. * a row-wise sparse format);
  62. *
  63. * C is the Schur complement for matrix (B0 F G H). It is defined from
  64. * S * R + C = H, so C = H - S * R = H - G * inv(U0) * inv(L0) * F =
  65. * = H - G * inv(B0) * F. Matrix C is stored in an invertable form.
  66. *
  67. * REFERENCES
  68. *
  69. * 1. M.A.Saunders, "LUSOL: A basis package for constrained optimiza-
  70. * tion," SCCM, Stanford University, 2006.
  71. *
  72. * 2. M.A.Saunders, "Notes 5: Basis Updates," CME 318, Stanford Univer-
  73. * sity, Spring 2006.
  74. *
  75. * 3. M.A.Saunders, "Notes 6: LUSOL---a Basis Factorization Package,"
  76. * ibid. */
  77. typedef struct LPF LPF;
  78. struct LPF
  79. { /* LP basis factorization */
  80. int valid;
  81. /* the factorization is valid only if this flag is set */
  82. /*--------------------------------------------------------------*/
  83. /* initial basis matrix B0 */
  84. int m0_max;
  85. /* maximal value of m0 (increased automatically, if necessary) */
  86. int m0;
  87. /* the order of B0 */
  88. LUF *luf;
  89. /* LU-factorization of B0 */
  90. /*--------------------------------------------------------------*/
  91. /* current basis matrix B */
  92. int m;
  93. /* the order of B */
  94. double *B; /* double B[1+m*m]; */
  95. /* B in dense format stored by rows and used only for debugging;
  96. normally this array is not allocated */
  97. /*--------------------------------------------------------------*/
  98. /* augmented matrix (B0 F G H) of the order m0+n */
  99. int n_max;
  100. /* maximal number of additional rows and columns */
  101. int n;
  102. /* current number of additional rows and columns */
  103. /*--------------------------------------------------------------*/
  104. /* m0xn matrix R in column-wise format */
  105. int *R_ptr; /* int R_ptr[1+n_max]; */
  106. /* R_ptr[j], 1 <= j <= n, is a pointer to j-th column */
  107. int *R_len; /* int R_len[1+n_max]; */
  108. /* R_len[j], 1 <= j <= n, is the length of j-th column */
  109. /*--------------------------------------------------------------*/
  110. /* nxm0 matrix S in row-wise format */
  111. int *S_ptr; /* int S_ptr[1+n_max]; */
  112. /* S_ptr[i], 1 <= i <= n, is a pointer to i-th row */
  113. int *S_len; /* int S_len[1+n_max]; */
  114. /* S_len[i], 1 <= i <= n, is the length of i-th row */
  115. /*--------------------------------------------------------------*/
  116. /* Schur complement C of the order n */
  117. SCF *scf; /* SCF scf[1:n_max]; */
  118. /* factorization of the Schur complement */
  119. /*--------------------------------------------------------------*/
  120. /* matrix P of the order m0+n */
  121. int *P_row; /* int P_row[1+m0_max+n_max]; */
  122. /* P_row[i] = j means that P[i,j] = 1 */
  123. int *P_col; /* int P_col[1+m0_max+n_max]; */
  124. /* P_col[j] = i means that P[i,j] = 1 */
  125. /*--------------------------------------------------------------*/
  126. /* matrix Q of the order m0+n */
  127. int *Q_row; /* int Q_row[1+m0_max+n_max]; */
  128. /* Q_row[i] = j means that Q[i,j] = 1 */
  129. int *Q_col; /* int Q_col[1+m0_max+n_max]; */
  130. /* Q_col[j] = i means that Q[i,j] = 1 */
  131. /*--------------------------------------------------------------*/
  132. /* Sparse Vector Area (SVA) is a set of locations intended to
  133. store sparse vectors which represent columns of matrix R and
  134. rows of matrix S; each location is a doublet (ind, val), where
  135. ind is an index, val is a numerical value of a sparse vector
  136. element; in the whole each sparse vector is a set of adjacent
  137. locations defined by a pointer to its first element and its
  138. length, i.e. the number of its elements */
  139. int v_size;
  140. /* the SVA size, in locations; locations are numbered by integers
  141. 1, 2, ..., v_size, and location 0 is not used */
  142. int v_ptr;
  143. /* pointer to the first available location */
  144. int *v_ind; /* int v_ind[1+v_size]; */
  145. /* v_ind[k], 1 <= k <= v_size, is the index field of location k */
  146. double *v_val; /* double v_val[1+v_size]; */
  147. /* v_val[k], 1 <= k <= v_size, is the value field of location k */
  148. /*--------------------------------------------------------------*/
  149. double *work1; /* double work1[1+m0+n_max]; */
  150. /* working array */
  151. double *work2; /* double work2[1+m0+n_max]; */
  152. /* working array */
  153. };
  154. /* return codes: */
  155. #define LPF_ESING 1 /* singular matrix */
  156. #define LPF_ECOND 2 /* ill-conditioned matrix */
  157. #define LPF_ELIMIT 3 /* update limit reached */
  158. #define lpf_create_it _glp_lpf_create_it
  159. LPF *lpf_create_it(void);
  160. /* create LP basis factorization */
  161. #define lpf_factorize _glp_lpf_factorize
  162. int lpf_factorize(LPF *lpf, int m, const int bh[], int (*col)
  163. (void *info, int j, int ind[], double val[]), void *info);
  164. /* compute LP basis factorization */
  165. #define lpf_ftran _glp_lpf_ftran
  166. void lpf_ftran(LPF *lpf, double x[]);
  167. /* perform forward transformation (solve system B*x = b) */
  168. #define lpf_btran _glp_lpf_btran
  169. void lpf_btran(LPF *lpf, double x[]);
  170. /* perform backward transformation (solve system B'*x = b) */
  171. #define lpf_update_it _glp_lpf_update_it
  172. int lpf_update_it(LPF *lpf, int j, int bh, int len, const int ind[],
  173. const double val[]);
  174. /* update LP basis factorization */
  175. #define lpf_delete_it _glp_lpf_delete_it
  176. void lpf_delete_it(LPF *lpf);
  177. /* delete LP basis factorization */
  178. #endif
  179. /* eof */