-
Notifications
You must be signed in to change notification settings - Fork 0
/
SparseSolver.hpp
395 lines (303 loc) · 11.6 KB
/
SparseSolver.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
/*
* This file is part of qpOASES.
*
* qpOASES -- An Implementation of the Online Active Set Strategy.
*
* Copyright (C) 2012 by Andreas Waechter. All rights reserved.
*
* qpOASES is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* qpOASES is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with qpOASES; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
/**
* \file include/qpOASES/SparseSolver.hpp
* \author Andreas Waechter, Dennis Janka
* \version 3.2
* \date 2012-2015
*
* Interfaces to sparse linear solvers that are used in a Schur-complement
* implementation in qpOASES.
*/
#ifndef QPOASES_SPARSESOLVER_HPP
#define QPOASES_SPARSESOLVER_HPP
#include "Utils.hpp"
BEGIN_NAMESPACE_QPOASES
/**
* \brief Base class for linear solvers that are used in a Schur-complement
* implementation in qpOASES.
*
* \author Andreas Waechter, Dennis Janka
* \version 3.2
* \date 2012-2015
*/
class SparseSolver
{
/*
* PUBLIC MEMBER FUNCTIONS
*/
public:
/** Default constructor. */
SparseSolver( );
/** Copy constructor (deep copy). */
SparseSolver( const SparseSolver& rhs /**< Rhs object. */
);
/** Destructor. */
virtual ~SparseSolver( );
/** Assignment operator (deep copy). */
virtual SparseSolver& operator=( const SparseSolver& rhs /**< Rhs object. */
);
/** Set new matrix data. The matrix is to be provided
in the Harwell-Boeing format. Only the lower
triangular part should be set. */
virtual returnValue setMatrixData( int_t dim, /**< Dimension of the linear system. */
int_t numNonzeros, /**< Number of nonzeros in the matrix. */
const int_t* const airn, /**< Row indices for each matrix entry. */
const int_t* const acjn, /**< Column indices for each matrix entry. */
const real_t* const avals /**< Values for each matrix entry. */
) = 0;
/** Compute factorization of current matrix. This method must be called before solve.*/
virtual returnValue factorize( ) = 0;
/** Solve linear system with most recently set matrix data. */
virtual returnValue solve( int_t dim, /**< Dimension of the linear system. */
const real_t* const rhs, /**< Values for the right hand side. */
real_t* const sol /**< Solution of the linear system. */
) = 0;
/** Clears all data structures. */
virtual returnValue reset( );
/** Return the number of negative eigenvalues. */
virtual int_t getNegativeEigenvalues( );
/** Return the rank after a factorization */
virtual int_t getRank( );
/** Returns the zero pivots in case the matrix is rank deficient */
virtual returnValue getZeroPivots( int_t *&zeroPivots );
/*
* PROTECTED MEMBER FUNCTIONS
*/
protected:
/** Frees all allocated memory.
* \return SUCCESSFUL_RETURN */
returnValue clear( );
/** Copies all members from given rhs object.
* \return SUCCESSFUL_RETURN */
returnValue copy( const SparseSolver& rhs /**< Rhs object. */
);
/*
* PROTECTED MEMBER VARIABLES
*/
protected:
};
#ifdef SOLVER_MA27
/**
* \brief Implementation of the linear solver interface using Harwell's MA27.
*
* \author Andreas Waechter, Dennis Janka
* \version 3.2
* \date 2012-2015
*/
class Ma27SparseSolver: public SparseSolver
{
/*
* PUBLIC MEMBER FUNCTIONS
*/
public:
/** Default constructor. */
Ma27SparseSolver( );
/** Copy constructor (deep copy). */
Ma27SparseSolver( const Ma27SparseSolver& rhs /**< Rhs object. */
);
/** Destructor. */
virtual ~Ma27SparseSolver( );
/** Assignment operator (deep copy). */
virtual Ma27SparseSolver& operator=( const SparseSolver& rhs /**< Rhs object. */
);
/** Set new matrix data. The matrix is to be provided
in the Harwell-Boeing format. Only the lower
triangular part should be set. */
virtual returnValue setMatrixData( int_t dim, /**< Dimension of the linear system. */
int_t numNonzeros, /**< Number of nonzeros in the matrix. */
const int_t* const airn, /**< Row indices for each matrix entry. */
const int_t* const acjn, /**< Column indices for each matrix entry. */
const real_t* const avals /**< Values for each matrix entry. */
);
/** Compute factorization of current matrix. This method must be called before solve.*/
virtual returnValue factorize( );
/** Solve linear system with most recently set matrix data. */
virtual returnValue solve( int_t dim, /**< Dimension of the linear system. */
const real_t* const rhs, /**< Values for the right hand side. */
real_t* const sol /**< Solution of the linear system. */
);
/** Clears all data structures. */
virtual returnValue reset( );
/** Return the number of negative eigenvalues. */
virtual int_t getNegativeEigenvalues( );
/** Return the rank after a factorization */
virtual int getRank( );
/*
* PROTECTED MEMBER FUNCTIONS
*/
protected:
/** Frees all allocated memory.
* \return SUCCESSFUL_RETURN */
returnValue clear( );
/** Copies all members from given rhs object.
* \return SUCCESSFUL_RETURN */
returnValue copy( const Ma27SparseSolver& rhs /**< Rhs object. */
);
/*
* PRIVATE MEMBER FUNCTIONS
*/
private:
/*
* PRIVATE MEMBER VARIABLES
*/
private:
fint dim; /**< Dimension of the current linear system. */
fint numNonzeros; /**< Number of nonzeros in the current linear system. */
fint la_ma27; /**< size of a_ma27 (LA in MA27) */
double* a_ma27; /**< matrix/factor for MA27 (A in MA27). If have_factorization is false, it contains the matrix entries (and has length numNonzeros), otherwise the factor (and has length la_ma27). */
fint* irn_ma27; /**< Row entries of matrix (IRN in MA27) */
fint* jcn_ma27; /**< Column entries of matrix (JCN in MA27) */
fint icntl_ma27[30]; /**< integer control values (ICNRL in MA27) */
double cntl_ma27[5]; /**< real control values (CNRL in MA27) */
fint liw_ma27; /**< length of integer work space (LIW in MA27) */
fint* iw_ma27; /**< integer work space (IW in MA27) */
fint* ikeep_ma27; /**< IKEEP in MA27 */
fint nsteps_ma27; /**< NSTEPS in MA27 */
fint maxfrt_ma27; /**< MAXFRT in MA27 */
bool have_factorization; /**< flag indicating whether factorization for current matrix has already been computed */
fint neig; /**< number of negative eigenvalues */
fint rank; /**< rank of matrix */
};
#endif // SOLVER_MA27
#ifdef SOLVER_MA57
/**
* \brief Implementation of the linear solver interface using Harwell's MA57.
*
* \author Andreas Waechter, Dennis Janka
* \version 3.2
* \date 2013-2015
*/
class Ma57SparseSolver: public SparseSolver
{
/*
* PUBLIC MEMBER FUNCTIONS
*/
public:
/** Default constructor. */
Ma57SparseSolver( );
/** Copy constructor (deep copy). */
Ma57SparseSolver( const Ma57SparseSolver& rhs /**< Rhs object. */
);
/** Destructor. */
virtual ~Ma57SparseSolver( );
/** Assignment operator (deep copy). */
virtual Ma57SparseSolver& operator=( const SparseSolver& rhs /**< Rhs object. */
);
/** Set new matrix data. The matrix is to be provided
in the Harwell-Boeing format. Only the lower
triangular part should be set. */
virtual returnValue setMatrixData( int_t dim, /**< Dimension of the linear system. */
int_t numNonzeros, /**< Number of nonzeros in the matrix. */
const int_t* const airn, /**< Row indices for each matrix entry. */
const int_t* const acjn, /**< Column indices for each matrix entry. */
const real_t* const avals /**< Values for each matrix entry. */
);
/** Compute factorization of current matrix. This method must be called before solve.*/
virtual returnValue factorize( );
/** Solve linear system with most recently set matrix data. */
virtual returnValue solve( int_t dim, /**< Dimension of the linear system. */
const real_t* const rhs, /**< Values for the right hand side. */
real_t* const sol /**< Solution of the linear system. */
);
/** Clears all data structures. */
virtual returnValue reset( );
/** Return the number of negative eigenvalues. */
virtual int_t getNegativeEigenvalues( );
/** Return the rank after a factorization */
virtual int_t getRank( );
/** Returns the zero pivots in case the matrix is rank deficient */
virtual returnValue getZeroPivots( int_t *&zeroPivots );
/*
* PROTECTED MEMBER FUNCTIONS
*/
protected:
/** Frees all allocated memory.
* \return SUCCESSFUL_RETURN */
returnValue clear( );
/** Copies all members from given rhs object.
* \return SUCCESSFUL_RETURN */
returnValue copy( const Ma57SparseSolver& rhs /**< Rhs object. */
);
/*
* PRIVATE MEMBER FUNCTIONS
*/
private:
/*
* PRIVATE MEMBER VARIABLES
*/
private:
fint dim; /**< Dimension of the current linear system. */
fint numNonzeros; /**< Number of nonzeros in the current linear system. */
double* a_ma57; /**< matrix for MA57 (A in MA57) */
fint* irn_ma57; /**< Row entries of matrix (IRN in MA57) */
fint* jcn_ma57; /**< Column entries of matrix (JCN in MA57) */
fint icntl_ma57[30]; /**< integer control values (ICNRL in MA57) */
double cntl_ma57[5]; /**< real control values (CNRL in MA57) */
double* fact_ma57; /**< array for storing the factors */
fint lfact_ma57; /**< length of fact_ma57 */
fint* ifact_ma57; /**< indexing information about the factors */
fint lifact_ma57; /**< length of ifact_ma57 */
bool have_factorization;/**< flag indicating whether factorization for current matrix has already been computed */
fint neig; /**< number of negative eigenvalues */
fint rank; /**< rank of matrix */
fint* pivots; /**< sequence of pivots used in factorization */
};
#endif // SOLVER_MA57
#ifdef SOLVER_NONE
/**
* \brief Implementation of a dummy sparse solver. An error is thrown if a factorization is attempted.
*
* \author Dennis Janka
* \version 3.2
* \date 2015
*/
class DummySparseSolver: public SparseSolver
{
/*
* PUBLIC MEMBER FUNCTIONS
*/
public:
/** Set new matrix data. The matrix is to be provided
in the Harwell-Boeing format. Only the lower
triangular part should be set. */
virtual returnValue setMatrixData( int_t dim, /**< Dimension of the linear system. */
int_t numNonzeros, /**< Number of nonzeros in the matrix. */
const int_t* const airn, /**< Row indices for each matrix entry. */
const int_t* const acjn, /**< Column indices for each matrix entry. */
const real_t* const avals /**< Values for each matrix entry. */
);
/** Compute factorization of current matrix. This method must be called before solve.*/
virtual returnValue factorize( );
/** Solve linear system with most recently set matrix data. */
virtual returnValue solve( int_t dim, /**< Dimension of the linear system. */
const real_t* const rhs, /**< Values for the right hand side. */
real_t* const sol /**< Solution of the linear system. */
);
};
#endif // SOLVER_NONE
END_NAMESPACE_QPOASES
#endif /* QPOASES_SPARSESOLVER_HPP */
/*
* end of file
*/