glpspm.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /* glpspm.h (general sparse matrix) */
  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 GLPSPM_H
  24. #define GLPSPM_H
  25. #include "glpdmp.h"
  26. typedef struct SPM SPM;
  27. typedef struct SPME SPME;
  28. struct SPM
  29. { /* general sparse matrix */
  30. int m;
  31. /* number of rows, m >= 0 */
  32. int n;
  33. /* number of columns, n >= 0 */
  34. DMP *pool;
  35. /* memory pool to store matrix elements */
  36. SPME **row; /* SPME *row[1+m]; */
  37. /* row[i], 1 <= i <= m, is a pointer to i-th row list */
  38. SPME **col; /* SPME *col[1+n]; */
  39. /* col[j], 1 <= j <= n, is a pointer to j-th column list */
  40. };
  41. struct SPME
  42. { /* sparse matrix element */
  43. int i;
  44. /* row number */
  45. int j;
  46. /* column number */
  47. double val;
  48. /* element value */
  49. SPME *r_prev;
  50. /* pointer to previous element in the same row */
  51. SPME *r_next;
  52. /* pointer to next element in the same row */
  53. SPME *c_prev;
  54. /* pointer to previous element in the same column */
  55. SPME *c_next;
  56. /* pointer to next element in the same column */
  57. };
  58. typedef struct PER PER;
  59. struct PER
  60. { /* permutation matrix */
  61. int n;
  62. /* matrix order, n >= 0 */
  63. int *row; /* int row[1+n]; */
  64. /* row[i] = j means p[i,j] = 1 */
  65. int *col; /* int col[1+n]; */
  66. /* col[j] = i means p[i,j] = 1 */
  67. };
  68. #define spm_create_mat _glp_spm_create_mat
  69. SPM *spm_create_mat(int m, int n);
  70. /* create general sparse matrix */
  71. #define spm_new_elem _glp_spm_new_elem
  72. SPME *spm_new_elem(SPM *A, int i, int j, double val);
  73. /* add new element to sparse matrix */
  74. #define spm_delete_mat _glp_spm_delete_mat
  75. void spm_delete_mat(SPM *A);
  76. /* delete general sparse matrix */
  77. #define spm_test_mat_e _glp_spm_test_mat_e
  78. SPM *spm_test_mat_e(int n, int c);
  79. /* create test sparse matrix of E(n,c) class */
  80. #define spm_test_mat_d _glp_spm_test_mat_d
  81. SPM *spm_test_mat_d(int n, int c);
  82. /* create test sparse matrix of D(n,c) class */
  83. #define spm_show_mat _glp_spm_show_mat
  84. int spm_show_mat(const SPM *A, const char *fname);
  85. /* write sparse matrix pattern in BMP file format */
  86. #define spm_read_hbm _glp_spm_read_hbm
  87. SPM *spm_read_hbm(const char *fname);
  88. /* read sparse matrix in Harwell-Boeing format */
  89. #define spm_count_nnz _glp_spm_count_nnz
  90. int spm_count_nnz(const SPM *A);
  91. /* determine number of non-zeros in sparse matrix */
  92. #define spm_drop_zeros _glp_spm_drop_zeros
  93. int spm_drop_zeros(SPM *A, double eps);
  94. /* remove zero elements from sparse matrix */
  95. #define spm_read_mat _glp_spm_read_mat
  96. SPM *spm_read_mat(const char *fname);
  97. /* read sparse matrix from text file */
  98. #define spm_write_mat _glp_spm_write_mat
  99. int spm_write_mat(const SPM *A, const char *fname);
  100. /* write sparse matrix to text file */
  101. #define spm_transpose _glp_spm_transpose
  102. SPM *spm_transpose(const SPM *A);
  103. /* transpose sparse matrix */
  104. #define spm_add_sym _glp_spm_add_sym
  105. SPM *spm_add_sym(const SPM *A, const SPM *B);
  106. /* add two sparse matrices (symbolic phase) */
  107. #define spm_add_num _glp_spm_add_num
  108. void spm_add_num(SPM *C, double alfa, const SPM *A, double beta,
  109. const SPM *B);
  110. /* add two sparse matrices (numeric phase) */
  111. #define spm_add_mat _glp_spm_add_mat
  112. SPM *spm_add_mat(double alfa, const SPM *A, double beta,
  113. const SPM *B);
  114. /* add two sparse matrices (driver routine) */
  115. #define spm_mul_sym _glp_spm_mul_sym
  116. SPM *spm_mul_sym(const SPM *A, const SPM *B);
  117. /* multiply two sparse matrices (symbolic phase) */
  118. #define spm_mul_num _glp_spm_mul_num
  119. void spm_mul_num(SPM *C, const SPM *A, const SPM *B);
  120. /* multiply two sparse matrices (numeric phase) */
  121. #define spm_mul_mat _glp_spm_mul_mat
  122. SPM *spm_mul_mat(const SPM *A, const SPM *B);
  123. /* multiply two sparse matrices (driver routine) */
  124. #define spm_create_per _glp_spm_create_per
  125. PER *spm_create_per(int n);
  126. /* create permutation matrix */
  127. #define spm_check_per _glp_spm_check_per
  128. void spm_check_per(PER *P);
  129. /* check permutation matrix for correctness */
  130. #define spm_delete_per _glp_spm_delete_per
  131. void spm_delete_per(PER *P);
  132. /* delete permutation matrix */
  133. #endif
  134. /* eof */