src/glpspm.h
author Alpar Juttner <alpar@cs.elte.hu>
Mon, 06 Dec 2010 13:09:21 +0100
changeset 1 c445c931472f
permissions -rw-r--r--
Import glpk-4.45

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