src/glpspm.h
author Alpar Juttner <alpar@cs.elte.hu>
Sun, 05 Dec 2010 17:35:23 +0100
changeset 2 4c8956a7bdf4
permissions -rw-r--r--
Set up CMAKE build environment
     1 /* glpspm.h (general sparse matrix) */
     2 
     3 /***********************************************************************
     4 *  This code is part of GLPK (GNU Linear Programming Kit).
     5 *
     6 *  Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
     7 *  2009, 2010 Andrew Makhorin, Department for Applied Informatics,
     8 *  Moscow Aviation Institute, Moscow, Russia. All rights reserved.
     9 *  E-mail: <mao@gnu.org>.
    10 *
    11 *  GLPK is free software: you can redistribute it and/or modify it
    12 *  under the terms of the GNU General Public License as published by
    13 *  the Free Software Foundation, either version 3 of the License, or
    14 *  (at your option) any later version.
    15 *
    16 *  GLPK is distributed in the hope that it will be useful, but WITHOUT
    17 *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
    18 *  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
    19 *  License for more details.
    20 *
    21 *  You should have received a copy of the GNU General Public License
    22 *  along with GLPK. If not, see <http://www.gnu.org/licenses/>.
    23 ***********************************************************************/
    24 
    25 #ifndef GLPSPM_H
    26 #define GLPSPM_H
    27 
    28 #include "glpdmp.h"
    29 
    30 typedef struct SPM SPM;
    31 typedef struct SPME SPME;
    32 
    33 struct SPM
    34 {     /* general sparse matrix */
    35       int m;
    36       /* number of rows, m >= 0 */
    37       int n;
    38       /* number of columns, n >= 0 */
    39       DMP *pool;
    40       /* memory pool to store matrix elements */
    41       SPME **row; /* SPME *row[1+m]; */
    42       /* row[i], 1 <= i <= m, is a pointer to i-th row list */
    43       SPME **col; /* SPME *col[1+n]; */
    44       /* col[j], 1 <= j <= n, is a pointer to j-th column list */
    45 };
    46 
    47 struct SPME
    48 {     /* sparse matrix element */
    49       int i;
    50       /* row number */
    51       int j;
    52       /* column number */
    53       double val;
    54       /* element value */
    55       SPME *r_prev;
    56       /* pointer to previous element in the same row */
    57       SPME *r_next;
    58       /* pointer to next element in the same row */
    59       SPME *c_prev;
    60       /* pointer to previous element in the same column */
    61       SPME *c_next;
    62       /* pointer to next element in the same column */
    63 };
    64 
    65 typedef struct PER PER;
    66 
    67 struct PER
    68 {     /* permutation matrix */
    69       int n;
    70       /* matrix order, n >= 0 */
    71       int *row; /* int row[1+n]; */
    72       /* row[i] = j means p[i,j] = 1 */
    73       int *col; /* int col[1+n]; */
    74       /* col[j] = i means p[i,j] = 1 */
    75 };
    76 
    77 #define spm_create_mat _glp_spm_create_mat
    78 SPM *spm_create_mat(int m, int n);
    79 /* create general sparse matrix */
    80 
    81 #define spm_new_elem _glp_spm_new_elem
    82 SPME *spm_new_elem(SPM *A, int i, int j, double val);
    83 /* add new element to sparse matrix */
    84 
    85 #define spm_delete_mat _glp_spm_delete_mat
    86 void spm_delete_mat(SPM *A);
    87 /* delete general sparse matrix */
    88 
    89 #define spm_test_mat_e _glp_spm_test_mat_e
    90 SPM *spm_test_mat_e(int n, int c);
    91 /* create test sparse matrix of E(n,c) class */
    92 
    93 #define spm_test_mat_d _glp_spm_test_mat_d
    94 SPM *spm_test_mat_d(int n, int c);
    95 /* create test sparse matrix of D(n,c) class */
    96 
    97 #define spm_show_mat _glp_spm_show_mat
    98 int spm_show_mat(const SPM *A, const char *fname);
    99 /* write sparse matrix pattern in BMP file format */
   100 
   101 #define spm_read_hbm _glp_spm_read_hbm
   102 SPM *spm_read_hbm(const char *fname);
   103 /* read sparse matrix in Harwell-Boeing format */
   104 
   105 #define spm_count_nnz _glp_spm_count_nnz
   106 int spm_count_nnz(const SPM *A);
   107 /* determine number of non-zeros in sparse matrix */
   108 
   109 #define spm_drop_zeros _glp_spm_drop_zeros
   110 int spm_drop_zeros(SPM *A, double eps);
   111 /* remove zero elements from sparse matrix */
   112 
   113 #define spm_read_mat _glp_spm_read_mat
   114 SPM *spm_read_mat(const char *fname);
   115 /* read sparse matrix from text file */
   116 
   117 #define spm_write_mat _glp_spm_write_mat
   118 int spm_write_mat(const SPM *A, const char *fname);
   119 /* write sparse matrix to text file */
   120 
   121 #define spm_transpose _glp_spm_transpose
   122 SPM *spm_transpose(const SPM *A);
   123 /* transpose sparse matrix */
   124 
   125 #define spm_add_sym _glp_spm_add_sym
   126 SPM *spm_add_sym(const SPM *A, const SPM *B);
   127 /* add two sparse matrices (symbolic phase) */
   128 
   129 #define spm_add_num _glp_spm_add_num
   130 void spm_add_num(SPM *C, double alfa, const SPM *A, double beta,
   131       const SPM *B);
   132 /* add two sparse matrices (numeric phase) */
   133 
   134 #define spm_add_mat _glp_spm_add_mat
   135 SPM *spm_add_mat(double alfa, const SPM *A, double beta,
   136       const SPM *B);
   137 /* add two sparse matrices (driver routine) */
   138 
   139 #define spm_mul_sym _glp_spm_mul_sym
   140 SPM *spm_mul_sym(const SPM *A, const SPM *B);
   141 /* multiply two sparse matrices (symbolic phase) */
   142 
   143 #define spm_mul_num _glp_spm_mul_num
   144 void spm_mul_num(SPM *C, const SPM *A, const SPM *B);
   145 /* multiply two sparse matrices (numeric phase) */
   146 
   147 #define spm_mul_mat _glp_spm_mul_mat
   148 SPM *spm_mul_mat(const SPM *A, const SPM *B);
   149 /* multiply two sparse matrices (driver routine) */
   150 
   151 #define spm_create_per _glp_spm_create_per
   152 PER *spm_create_per(int n);
   153 /* create permutation matrix */
   154 
   155 #define spm_check_per _glp_spm_check_per
   156 void spm_check_per(PER *P);
   157 /* check permutation matrix for correctness */
   158 
   159 #define spm_delete_per _glp_spm_delete_per
   160 void spm_delete_per(PER *P);
   161 /* delete permutation matrix */
   162 
   163 #endif
   164 
   165 /* eof */