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