qpOASES 3.2.2
An Implementation of the Online Active Set Strategy
SparseSolver.hpp
Go to the documentation of this file.
1/*
2 * This file is part of qpOASES.
3 *
4 * qpOASES -- An Implementation of the Online Active Set Strategy.
5 * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka,
6 * Christian Kirches et al. All rights reserved.
7 *
8 * qpOASES is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * qpOASES is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 * See the GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with qpOASES; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 *
22 */
23
24
35#ifndef QPOASES_SPARSESOLVER_HPP
36#define QPOASES_SPARSESOLVER_HPP
37#include <limits>
38#include <sstream>
39
40#include <qpOASES/Utils.hpp>
41
42
44
45
55{
56 /*
57 * PUBLIC MEMBER FUNCTIONS
58 */
59 public:
61 SparseSolver( );
62
64 SparseSolver( const SparseSolver& rhs
65 );
66
68 virtual ~SparseSolver( );
69
71 virtual SparseSolver& operator=( const SparseSolver& rhs
72 );
73
78 int_t numNonzeros,
79 const int_t* const airn,
80 const int_t* const acjn,
81 const real_t* const avals
82 ) = 0;
83
85 virtual returnValue factorize( ) = 0;
86
88 virtual returnValue solve( int_t dim,
89 const real_t* const rhs,
90 real_t* const sol
91 ) = 0;
92
94 virtual returnValue reset( );
95
98
100 virtual int_t getRank( );
101
103 virtual returnValue getZeroPivots( int_t *&zeroPivots );
104
105 /*
106 * PROTECTED MEMBER FUNCTIONS
107 */
108 protected:
112
115 returnValue copy( const SparseSolver& rhs
116 );
117
118 /*
119 * PROTECTED MEMBER VARIABLES
120 */
121 protected:
122};
123
124
125#ifdef SOLVER_MA27
126
134class Ma27SparseSolver: public SparseSolver
135{
136 /*
137 * PUBLIC MEMBER FUNCTIONS
138 */
139 public:
141 Ma27SparseSolver( );
142
144 Ma27SparseSolver( const Ma27SparseSolver& rhs
145 );
146
148 virtual ~Ma27SparseSolver( );
149
151 virtual Ma27SparseSolver& operator=( const SparseSolver& rhs
152 );
153
157 virtual returnValue setMatrixData( int_t dim,
158 int_t numNonzeros,
159 const int_t* const airn,
160 const int_t* const acjn,
161 const real_t* const avals
162 );
163
165 virtual returnValue factorize( );
166
168 virtual returnValue solve( int_t dim,
169 const real_t* const rhs,
170 real_t* const sol
171 );
172
174 virtual returnValue reset( );
175
177 virtual int_t getNegativeEigenvalues( );
178
180 virtual int getRank( );
181
182 /*
183 * PROTECTED MEMBER FUNCTIONS
184 */
185 protected:
188 returnValue clear( );
189
192 returnValue copy( const Ma27SparseSolver& rhs
193 );
194
195 /*
196 * PRIVATE MEMBER FUNCTIONS
197 */
198 private:
199 /*
200 * PRIVATE MEMBER VARIABLES
201 */
202 private:
203 fint_t dim;
205 fint_t numNonzeros;
207 fint_t la_ma27;
209 double* a_ma27;
211 fint_t* irn_ma27;
213 fint_t* jcn_ma27;
215 fint_t icntl_ma27[30];
217 double cntl_ma27[5];
219 fint_t liw_ma27;
221 fint_t* iw_ma27;
223 fint_t* ikeep_ma27;
225 fint_t nsteps_ma27;
227 fint_t maxfrt_ma27;
229 bool have_factorization;
231 fint_t neig;
233 fint_t rank;
234};
235
236#endif /* SOLVER_MA27 */
237
238
239#ifdef SOLVER_MA57
240
248class Ma57SparseSolver: public SparseSolver
249{
250 /*
251 * PUBLIC MEMBER FUNCTIONS
252 */
253 public:
255 Ma57SparseSolver( );
256
258 Ma57SparseSolver( const Ma57SparseSolver& rhs
259 );
260
262 virtual ~Ma57SparseSolver( );
263
265 virtual Ma57SparseSolver& operator=( const SparseSolver& rhs
266 );
267
271 virtual returnValue setMatrixData( int_t dim,
272 int_t numNonzeros,
273 const int_t* const airn,
274 const int_t* const acjn,
275 const real_t* const avals
276 );
277
279 virtual returnValue factorize( );
280
282 virtual returnValue solve( int_t dim,
283 const real_t* const rhs,
284 real_t* const sol
285 );
286
288 virtual returnValue reset( );
289
291 virtual int_t getNegativeEigenvalues( );
292
294 virtual int_t getRank( );
295
297 virtual returnValue getZeroPivots( int_t* &zeroPivots
298 );
299 /*
300 * PROTECTED MEMBER FUNCTIONS
301 */
302 protected:
305 returnValue clear( );
306
309 returnValue copy( const Ma57SparseSolver& rhs
310 );
311
312 /*
313 * PRIVATE MEMBER FUNCTIONS
314 */
315 private:
316 /*
317 * PRIVATE MEMBER VARIABLES
318 */
319 private:
320 fint_t dim;
322 fint_t numNonzeros;
324 double* a_ma57;
326 fint_t* irn_ma57;
328 fint_t* jcn_ma57;
330 fint_t icntl_ma57[30];
332 double cntl_ma57[5];
334 double* fact_ma57;
336 fint_t lfact_ma57;
338 fint_t* ifact_ma57;
340 fint_t lifact_ma57;
342 bool have_factorization;
344 fint_t neig;
346 fint_t rank;
348 fint_t* pivots;
349};
350
351#endif /* SOLVER_MA57 */
352
353
354#ifdef SOLVER_MUMPS
355
363class MumpsSparseSolver: public SparseSolver
364{
365 /*
366 * PUBLIC MEMBER FUNCTIONS
367 */
368 public:
370 MumpsSparseSolver( );
371
373 MumpsSparseSolver( const MumpsSparseSolver& rhs
374 );
375
377 virtual ~MumpsSparseSolver( );
378
380 virtual MumpsSparseSolver& operator=( const SparseSolver& rhs
381 );
382
386 virtual returnValue setMatrixData( int_t dim,
387 int_t numNonzeros,
388 const int_t* const airn,
389 const int_t* const acjn,
390 const real_t* const avals
391 );
392
394 virtual returnValue factorize( );
395
397 virtual returnValue solve( int_t dim,
398 const real_t* const rhs,
399 real_t* const sol
400 );
401
403 virtual returnValue reset( );
404
406 virtual int_t getNegativeEigenvalues( );
407
409 virtual int_t getRank( );
410
412 virtual returnValue getZeroPivots( int_t* &zeroPivots
413 );
414 /*
415 * PROTECTED MEMBER FUNCTIONS
416 */
417 protected:
420 returnValue clear( );
421
424 returnValue copy( const MumpsSparseSolver& rhs
425 );
426
427 /*
428 * PRIVATE MEMBER FUNCTIONS
429 */
430 private:
431 /*
432 * PRIVATE MEMBER VARIABLES
433 */
434 private:
435
436
437 void* mumps_ptr_;
439 int dim;
441 int numNonzeros;
443 double* a_mumps;
445 int* irn_mumps;
447 int* jcn_mumps;
449 bool have_factorization;
451 int negevals_;
453 int mumps_pivot_order_; /* pivot order*/
454
455 bool initialized_;
459 bool pivtol_changed_;
464 bool refactorize_;
466
469
470 double pivtol_;
471
473 double pivtolmax_;
474
476 int mem_percent_;
477
479 int mumps_permuting_scaling_;
480
482 int mumps_scaling_;
483
485 double mumps_dep_tol_;
486
490 bool warm_start_same_structure_;
492
494 bool have_symbolic_factorization_;
495};
496
497template<typename T>
498inline void ComputeMemIncrease(
499 T& len,
500 double recommended,
501 T min,
502 const char* context
503)
504{
505 if( recommended >= std::numeric_limits<T>::max() )
506 {
507 // increase len to the maximum possible, if that is still an increase
508 if( len < std::numeric_limits<T>::max() )
509 {
510 len = std::numeric_limits<T>::max();
511 }
512 else
513 {
514 std::stringstream what;
515 what << "Cannot allocate more than " << std::numeric_limits<T>::max()*sizeof(T) << " bytes for " << context << " due to limitation on integer type";
516 throw std::overflow_error(what.str());
517 }
518 }
519 else
520 {
521 len = std::max(min, (T) recommended);
522 }
523}
524
525#endif /* SOLVER_MUMPS */
526
527
528
529#ifdef SOLVER_NONE
530
538class DummySparseSolver: public SparseSolver
539{
540 /*
541 * PUBLIC MEMBER FUNCTIONS
542 */
543 public:
547 virtual returnValue setMatrixData( int_t dim,
548 int_t numNonzeros,
549 const int_t* const airn,
550 const int_t* const acjn,
551 const real_t* const avals
552 );
553
555 virtual returnValue factorize( );
556
558 virtual returnValue solve( int_t dim,
559 const real_t* const rhs,
560 real_t* const sol
561 );
562};
563
564#endif /* SOLVER_NONE */
565
566
568
569#endif /* QPOASES_SPARSESOLVER_HPP */
570
571/*
572 * end of file
573 */
returnValue
Defines all symbols for global return values.
Definition MessageHandling.hpp:65
int int_t
Definition Types.hpp:180
BEGIN_NAMESPACE_QPOASES typedef double real_t
Definition Types.hpp:171
#define END_NAMESPACE_QPOASES
Definition Types.hpp:110
int fint_t
Definition Types.hpp:189
#define BEGIN_NAMESPACE_QPOASES
Definition Types.hpp:107
Base class for linear solvers that are used in a Schur-complement implementation in qpOASES.
Definition SparseSolver.hpp:55
virtual returnValue getZeroPivots(int_t *&zeroPivots)
Definition SparseSolver.cpp:138
returnValue copy(const SparseSolver &rhs)
Definition SparseSolver.cpp:162
virtual SparseSolver & operator=(const SparseSolver &rhs)
Definition SparseSolver.cpp:100
SparseSolver()
Definition SparseSolver.cpp:74
returnValue clear()
Definition SparseSolver.cpp:153
virtual ~SparseSolver()
Definition SparseSolver.cpp:91
virtual returnValue setMatrixData(int_t dim, int_t numNonzeros, const int_t *const airn, const int_t *const acjn, const real_t *const avals)=0
virtual returnValue factorize()=0
virtual returnValue reset()
Definition SparseSolver.cpp:114
virtual int_t getRank()
Definition SparseSolver.cpp:130
virtual returnValue solve(int_t dim, const real_t *const rhs, real_t *const sol)=0
virtual int_t getNegativeEigenvalues()
Definition SparseSolver.cpp:122