glpmat.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /* glpmat.h (linear algebra routines) */
  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 GLPMAT_H
  24. #define GLPMAT_H
  25. /***********************************************************************
  26. * FULL-VECTOR STORAGE
  27. *
  28. * For a sparse vector x having n elements, ne of which are non-zero,
  29. * the full-vector storage format uses two arrays x_ind and x_vec, which
  30. * are set up as follows:
  31. *
  32. * x_ind is an integer array of length [1+ne]. Location x_ind[0] is
  33. * not used, and locations x_ind[1], ..., x_ind[ne] contain indices of
  34. * non-zero elements in vector x.
  35. *
  36. * x_vec is a floating-point array of length [1+n]. Location x_vec[0]
  37. * is not used, and locations x_vec[1], ..., x_vec[n] contain numeric
  38. * values of ALL elements in vector x, including its zero elements.
  39. *
  40. * Let, for example, the following sparse vector x be given:
  41. *
  42. * (0, 1, 0, 0, 2, 3, 0, 4)
  43. *
  44. * Then the arrays are:
  45. *
  46. * x_ind = { X; 2, 5, 6, 8 }
  47. *
  48. * x_vec = { X; 0, 1, 0, 0, 2, 3, 0, 4 }
  49. *
  50. * COMPRESSED-VECTOR STORAGE
  51. *
  52. * For a sparse vector x having n elements, ne of which are non-zero,
  53. * the compressed-vector storage format uses two arrays x_ind and x_vec,
  54. * which are set up as follows:
  55. *
  56. * x_ind is an integer array of length [1+ne]. Location x_ind[0] is
  57. * not used, and locations x_ind[1], ..., x_ind[ne] contain indices of
  58. * non-zero elements in vector x.
  59. *
  60. * x_vec is a floating-point array of length [1+ne]. Location x_vec[0]
  61. * is not used, and locations x_vec[1], ..., x_vec[ne] contain numeric
  62. * values of corresponding non-zero elements in vector x.
  63. *
  64. * Let, for example, the following sparse vector x be given:
  65. *
  66. * (0, 1, 0, 0, 2, 3, 0, 4)
  67. *
  68. * Then the arrays are:
  69. *
  70. * x_ind = { X; 2, 5, 6, 8 }
  71. *
  72. * x_vec = { X; 1, 2, 3, 4 }
  73. *
  74. * STORAGE-BY-ROWS
  75. *
  76. * For a sparse matrix A, which has m rows, n columns, and ne non-zero
  77. * elements the storage-by-rows format uses three arrays A_ptr, A_ind,
  78. * and A_val, which are set up as follows:
  79. *
  80. * A_ptr is an integer array of length [1+m+1] also called "row pointer
  81. * array". It contains the relative starting positions of each row of A
  82. * in the arrays A_ind and A_val, i.e. element A_ptr[i], 1 <= i <= m,
  83. * indicates where row i begins in the arrays A_ind and A_val. If all
  84. * elements in row i are zero, then A_ptr[i] = A_ptr[i+1]. Location
  85. * A_ptr[0] is not used, location A_ptr[1] must contain 1, and location
  86. * A_ptr[m+1] must contain ne+1 that indicates the position after the
  87. * last element in the arrays A_ind and A_val.
  88. *
  89. * A_ind is an integer array of length [1+ne]. Location A_ind[0] is not
  90. * used, and locations A_ind[1], ..., A_ind[ne] contain column indices
  91. * of (non-zero) elements in matrix A.
  92. *
  93. * A_val is a floating-point array of length [1+ne]. Location A_val[0]
  94. * is not used, and locations A_val[1], ..., A_val[ne] contain numeric
  95. * values of non-zero elements in matrix A.
  96. *
  97. * Non-zero elements of matrix A are stored contiguously, and the rows
  98. * of matrix A are stored consecutively from 1 to m in the arrays A_ind
  99. * and A_val. The elements in each row of A may be stored in any order
  100. * in A_ind and A_val. Note that elements with duplicate column indices
  101. * are not allowed.
  102. *
  103. * Let, for example, the following sparse matrix A be given:
  104. *
  105. * | 11 . 13 . . . |
  106. * | 21 22 . 24 . . |
  107. * | . 32 33 . . . |
  108. * | . . 43 44 . 46 |
  109. * | . . . . . . |
  110. * | 61 62 . . . 66 |
  111. *
  112. * Then the arrays are:
  113. *
  114. * A_ptr = { X; 1, 3, 6, 8, 11, 11; 14 }
  115. *
  116. * A_ind = { X; 1, 3; 4, 2, 1; 2, 3; 4, 3, 6; 1, 2, 6 }
  117. *
  118. * A_val = { X; 11, 13; 24, 22, 21; 32, 33; 44, 43, 46; 61, 62, 66 }
  119. *
  120. * PERMUTATION MATRICES
  121. *
  122. * Let P be a permutation matrix of the order n. It is represented as
  123. * an integer array P_per of length [1+n+n] as follows: if p[i,j] = 1,
  124. * then P_per[i] = j and P_per[n+j] = i. Location P_per[0] is not used.
  125. *
  126. * Let A' = P*A. If i-th row of A corresponds to i'-th row of A', then
  127. * P_per[i'] = i and P_per[n+i] = i'.
  128. *
  129. * References:
  130. *
  131. * 1. Gustavson F.G. Some basic techniques for solving sparse systems of
  132. * linear equations. In Rose and Willoughby (1972), pp. 41-52.
  133. *
  134. * 2. Basic Linear Algebra Subprograms Technical (BLAST) Forum Standard.
  135. * University of Tennessee (2001). */
  136. #define check_fvs _glp_mat_check_fvs
  137. int check_fvs(int n, int nnz, int ind[], double vec[]);
  138. /* check sparse vector in full-vector storage format */
  139. #define check_pattern _glp_mat_check_pattern
  140. int check_pattern(int m, int n, int A_ptr[], int A_ind[]);
  141. /* check pattern of sparse matrix */
  142. #define transpose _glp_mat_transpose
  143. void transpose(int m, int n, int A_ptr[], int A_ind[], double A_val[],
  144. int AT_ptr[], int AT_ind[], double AT_val[]);
  145. /* transpose sparse matrix */
  146. #define adat_symbolic _glp_mat_adat_symbolic
  147. int *adat_symbolic(int m, int n, int P_per[], int A_ptr[], int A_ind[],
  148. int S_ptr[]);
  149. /* compute S = P*A*D*A'*P' (symbolic phase) */
  150. #define adat_numeric _glp_mat_adat_numeric
  151. void adat_numeric(int m, int n, int P_per[],
  152. int A_ptr[], int A_ind[], double A_val[], double D_diag[],
  153. int S_ptr[], int S_ind[], double S_val[], double S_diag[]);
  154. /* compute S = P*A*D*A'*P' (numeric phase) */
  155. #define min_degree _glp_mat_min_degree
  156. void min_degree(int n, int A_ptr[], int A_ind[], int P_per[]);
  157. /* minimum degree ordering */
  158. #define amd_order1 _glp_mat_amd_order1
  159. void amd_order1(int n, int A_ptr[], int A_ind[], int P_per[]);
  160. /* approximate minimum degree ordering (AMD) */
  161. #define symamd_ord _glp_mat_symamd_ord
  162. void symamd_ord(int n, int A_ptr[], int A_ind[], int P_per[]);
  163. /* approximate minimum degree ordering (SYMAMD) */
  164. #define chol_symbolic _glp_mat_chol_symbolic
  165. int *chol_symbolic(int n, int A_ptr[], int A_ind[], int U_ptr[]);
  166. /* compute Cholesky factorization (symbolic phase) */
  167. #define chol_numeric _glp_mat_chol_numeric
  168. int chol_numeric(int n,
  169. int A_ptr[], int A_ind[], double A_val[], double A_diag[],
  170. int U_ptr[], int U_ind[], double U_val[], double U_diag[]);
  171. /* compute Cholesky factorization (numeric phase) */
  172. #define u_solve _glp_mat_u_solve
  173. void u_solve(int n, int U_ptr[], int U_ind[], double U_val[],
  174. double U_diag[], double x[]);
  175. /* solve upper triangular system U*x = b */
  176. #define ut_solve _glp_mat_ut_solve
  177. void ut_solve(int n, int U_ptr[], int U_ind[], double U_val[],
  178. double U_diag[], double x[]);
  179. /* solve lower triangular system U'*x = b */
  180. #endif
  181. /* eof */