alpar@1: /* glpspm.h (general sparse matrix) */ alpar@1: alpar@1: /*********************************************************************** alpar@1: * This code is part of GLPK (GNU Linear Programming Kit). alpar@1: * alpar@1: * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, alpar@1: * 2009, 2010 Andrew Makhorin, Department for Applied Informatics, alpar@1: * Moscow Aviation Institute, Moscow, Russia. All rights reserved. alpar@1: * E-mail: . alpar@1: * alpar@1: * GLPK is free software: you can redistribute it and/or modify it alpar@1: * under the terms of the GNU General Public License as published by alpar@1: * the Free Software Foundation, either version 3 of the License, or alpar@1: * (at your option) any later version. alpar@1: * alpar@1: * GLPK is distributed in the hope that it will be useful, but WITHOUT alpar@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY alpar@1: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public alpar@1: * License for more details. alpar@1: * alpar@1: * You should have received a copy of the GNU General Public License alpar@1: * along with GLPK. If not, see . alpar@1: ***********************************************************************/ alpar@1: alpar@1: #ifndef GLPSPM_H alpar@1: #define GLPSPM_H alpar@1: alpar@1: #include "glpdmp.h" alpar@1: alpar@1: typedef struct SPM SPM; alpar@1: typedef struct SPME SPME; alpar@1: alpar@1: struct SPM alpar@1: { /* general sparse matrix */ alpar@1: int m; alpar@1: /* number of rows, m >= 0 */ alpar@1: int n; alpar@1: /* number of columns, n >= 0 */ alpar@1: DMP *pool; alpar@1: /* memory pool to store matrix elements */ alpar@1: SPME **row; /* SPME *row[1+m]; */ alpar@1: /* row[i], 1 <= i <= m, is a pointer to i-th row list */ alpar@1: SPME **col; /* SPME *col[1+n]; */ alpar@1: /* col[j], 1 <= j <= n, is a pointer to j-th column list */ alpar@1: }; alpar@1: alpar@1: struct SPME alpar@1: { /* sparse matrix element */ alpar@1: int i; alpar@1: /* row number */ alpar@1: int j; alpar@1: /* column number */ alpar@1: double val; alpar@1: /* element value */ alpar@1: SPME *r_prev; alpar@1: /* pointer to previous element in the same row */ alpar@1: SPME *r_next; alpar@1: /* pointer to next element in the same row */ alpar@1: SPME *c_prev; alpar@1: /* pointer to previous element in the same column */ alpar@1: SPME *c_next; alpar@1: /* pointer to next element in the same column */ alpar@1: }; alpar@1: alpar@1: typedef struct PER PER; alpar@1: alpar@1: struct PER alpar@1: { /* permutation matrix */ alpar@1: int n; alpar@1: /* matrix order, n >= 0 */ alpar@1: int *row; /* int row[1+n]; */ alpar@1: /* row[i] = j means p[i,j] = 1 */ alpar@1: int *col; /* int col[1+n]; */ alpar@1: /* col[j] = i means p[i,j] = 1 */ alpar@1: }; alpar@1: alpar@1: #define spm_create_mat _glp_spm_create_mat alpar@1: SPM *spm_create_mat(int m, int n); alpar@1: /* create general sparse matrix */ alpar@1: alpar@1: #define spm_new_elem _glp_spm_new_elem alpar@1: SPME *spm_new_elem(SPM *A, int i, int j, double val); alpar@1: /* add new element to sparse matrix */ alpar@1: alpar@1: #define spm_delete_mat _glp_spm_delete_mat alpar@1: void spm_delete_mat(SPM *A); alpar@1: /* delete general sparse matrix */ alpar@1: alpar@1: #define spm_test_mat_e _glp_spm_test_mat_e alpar@1: SPM *spm_test_mat_e(int n, int c); alpar@1: /* create test sparse matrix of E(n,c) class */ alpar@1: alpar@1: #define spm_test_mat_d _glp_spm_test_mat_d alpar@1: SPM *spm_test_mat_d(int n, int c); alpar@1: /* create test sparse matrix of D(n,c) class */ alpar@1: alpar@1: #define spm_show_mat _glp_spm_show_mat alpar@1: int spm_show_mat(const SPM *A, const char *fname); alpar@1: /* write sparse matrix pattern in BMP file format */ alpar@1: alpar@1: #define spm_read_hbm _glp_spm_read_hbm alpar@1: SPM *spm_read_hbm(const char *fname); alpar@1: /* read sparse matrix in Harwell-Boeing format */ alpar@1: alpar@1: #define spm_count_nnz _glp_spm_count_nnz alpar@1: int spm_count_nnz(const SPM *A); alpar@1: /* determine number of non-zeros in sparse matrix */ alpar@1: alpar@1: #define spm_drop_zeros _glp_spm_drop_zeros alpar@1: int spm_drop_zeros(SPM *A, double eps); alpar@1: /* remove zero elements from sparse matrix */ alpar@1: alpar@1: #define spm_read_mat _glp_spm_read_mat alpar@1: SPM *spm_read_mat(const char *fname); alpar@1: /* read sparse matrix from text file */ alpar@1: alpar@1: #define spm_write_mat _glp_spm_write_mat alpar@1: int spm_write_mat(const SPM *A, const char *fname); alpar@1: /* write sparse matrix to text file */ alpar@1: alpar@1: #define spm_transpose _glp_spm_transpose alpar@1: SPM *spm_transpose(const SPM *A); alpar@1: /* transpose sparse matrix */ alpar@1: alpar@1: #define spm_add_sym _glp_spm_add_sym alpar@1: SPM *spm_add_sym(const SPM *A, const SPM *B); alpar@1: /* add two sparse matrices (symbolic phase) */ alpar@1: alpar@1: #define spm_add_num _glp_spm_add_num alpar@1: void spm_add_num(SPM *C, double alfa, const SPM *A, double beta, alpar@1: const SPM *B); alpar@1: /* add two sparse matrices (numeric phase) */ alpar@1: alpar@1: #define spm_add_mat _glp_spm_add_mat alpar@1: SPM *spm_add_mat(double alfa, const SPM *A, double beta, alpar@1: const SPM *B); alpar@1: /* add two sparse matrices (driver routine) */ alpar@1: alpar@1: #define spm_mul_sym _glp_spm_mul_sym alpar@1: SPM *spm_mul_sym(const SPM *A, const SPM *B); alpar@1: /* multiply two sparse matrices (symbolic phase) */ alpar@1: alpar@1: #define spm_mul_num _glp_spm_mul_num alpar@1: void spm_mul_num(SPM *C, const SPM *A, const SPM *B); alpar@1: /* multiply two sparse matrices (numeric phase) */ alpar@1: alpar@1: #define spm_mul_mat _glp_spm_mul_mat alpar@1: SPM *spm_mul_mat(const SPM *A, const SPM *B); alpar@1: /* multiply two sparse matrices (driver routine) */ alpar@1: alpar@1: #define spm_create_per _glp_spm_create_per alpar@1: PER *spm_create_per(int n); alpar@1: /* create permutation matrix */ alpar@1: alpar@1: #define spm_check_per _glp_spm_check_per alpar@1: void spm_check_per(PER *P); alpar@1: /* check permutation matrix for correctness */ alpar@1: alpar@1: #define spm_delete_per _glp_spm_delete_per alpar@1: void spm_delete_per(PER *P); alpar@1: /* delete permutation matrix */ alpar@1: alpar@1: #endif alpar@1: alpar@1: /* eof */