qpOASES 3.2.1
An Implementation of the Online Active Set Strategy
QProblemB.ipp
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
39
40
41/*****************************************************************************
42 * P U B L I C *
43 *****************************************************************************/
44
45/*
46 * g e t B o u n d s
47 */
48inline returnValue QProblemB::getBounds( Bounds& _bounds ) const
49{
50 int_t nV = getNV( );
51
52 if ( nV == 0 )
54
55 _bounds = bounds;
56
57 return SUCCESSFUL_RETURN;
58}
59
60
61/*
62 * g e t N V
63 */
64inline int_t QProblemB::getNV( ) const
65{
66 return bounds.getNV( );
67}
68
69
70/*
71 * g e t N F R
72 */
73inline int_t QProblemB::getNFR( ) const
74{
75 return bounds.getNFR( );
76}
77
78
79/*
80 * g e t N F X
81 */
82inline int_t QProblemB::getNFX( ) const
83{
84 return bounds.getNFX( );
85}
86
87
88/*
89 * g e t N F V
90 */
91inline int_t QProblemB::getNFV( ) const
92{
93 return bounds.getNFV( );
94}
95
96
97/*
98 * g e t S t a t u s
99 */
101{
102 return status;
103}
104
105
106/*
107 * i s I n i t i a l i s e d
108 */
110{
111 if ( status == QPS_NOTINITIALISED )
112 return BT_FALSE;
113 else
114 return BT_TRUE;
115}
116
117
118/*
119 * i s S o l v e d
120 */
122{
123 if ( status == QPS_SOLVED )
124 return BT_TRUE;
125 else
126 return BT_FALSE;
127}
128
129
130/*
131 * i s I n f e a s i b l e
132 */
134{
135 return infeasible;
136}
137
138
139/*
140 * i s U n b o u n d e d
141 */
143{
144 return unbounded;
145}
146
147
148/*
149 * g e t H e s s i a n T y p e
150 */
152{
153 return hessianType;
154}
155
156
157/*
158 * s e t H e s s i a n T y p e
159 */
161{
162 hessianType = _hessianType;
163 return SUCCESSFUL_RETURN;
164}
165
166
167/*
168 * u s i n g R e g u l a r i s a t i o n
169 */
171{
172 if ( regVal > ZERO )
173 return BT_TRUE;
174 else
175 return BT_FALSE;
176}
177
178
179/*
180 * g e t O p t i o n s
181 */
183{
184 return options;
185}
186
187
188/*
189 * s e t O p t i o n s
190 */
192 )
193{
194 options = _options;
196
198
199 return SUCCESSFUL_RETURN;
200}
201
202
203/*
204 * g e t P r i n t L e v e l
205 */
207{
208 return options.printLevel;
209}
210
211
212
213/*
214 * g e t C o u n t
215 */
216inline uint_t QProblemB::getCount( ) const
217{
218 return count;
219}
220
221
222/*
223 * r e s e t C o u n t e r
224 */
226{
227 count = 0;
228 return SUCCESSFUL_RETURN;
229}
230
231
232/*****************************************************************************
233 * P R O T E C T E D *
234 *****************************************************************************/
235
236/*
237 * s e t H
238 */
240{
241 if ( ( freeHessian == BT_TRUE ) && ( H != 0 ) )
242 {
243 delete H;
244 H = 0;
245 }
246
247 H = H_new;
249
250 return SUCCESSFUL_RETURN;
251}
252
253
254/*
255 * s e t H
256 */
257inline returnValue QProblemB::setH( const real_t* const H_new )
258{
259 int_t nV = getNV();
260 SymDenseMat* dH;
261
262 /* if null pointer is passed, Hessian is set to zero matrix
263 * (or stays identity matrix) */
264 if ( H_new == 0 )
265 {
266 if ( hessianType == HST_IDENTITY )
267 return SUCCESSFUL_RETURN;
268
270
271 if ( ( freeHessian == BT_TRUE ) && ( H != 0 ) )
272 delete H;
273
274 H = 0;
276 }
277 else
278 {
279 if ( ( freeHessian == BT_TRUE ) && ( H != 0 ) )
280 delete H;
281
282 H = dH = new SymDenseMat( nV, nV, nV, (real_t*) H_new );
284 }
285
286 return SUCCESSFUL_RETURN;
287}
288
289
290/*
291 * s e t G
292 */
293inline returnValue QProblemB::setG( const real_t* const g_new )
294{
295 uint_t nV = (uint_t)getNV( );
296
297 if ( nV == 0 )
299
300 if ( g_new == 0 )
302
303 memcpy( g,g_new,nV*sizeof(real_t) );
304
305 return SUCCESSFUL_RETURN;
306}
307
308
309/*
310 * s e t L B
311 */
312inline returnValue QProblemB::setLB( const real_t* const lb_new )
313{
314 uint_t i;
315 uint_t nV = (uint_t)getNV( );
316
317 if ( nV == 0 )
319
320 if ( lb_new != 0 )
321 {
322 memcpy( lb,lb_new,nV*sizeof(real_t) );
323 }
324 else
325 {
326 /* if no lower bounds are specified, set them to -infinity */
327 for( i=0; i<nV; ++i )
328 lb[i] = -INFTY;
329 }
330
331 return SUCCESSFUL_RETURN;
332}
333
334
335/*
336 * s e t L B
337 */
339{
340 int_t nV = getNV( );
341
342 if ( nV == 0 )
344
345 if ( ( number >= 0 ) && ( number < nV ) )
346 {
347 lb[number] = value;
348 return SUCCESSFUL_RETURN;
349 }
350 else
351 {
353 }
354}
355
356
357/*
358 * s e t U B
359 */
360inline returnValue QProblemB::setUB( const real_t* const ub_new )
361{
362 uint_t i;
363 uint_t nV = (uint_t)getNV( );
364
365 if ( nV == 0 )
367
368 if ( ub_new != 0 )
369 {
370 memcpy( ub,ub_new,nV*sizeof(real_t) );
371 }
372 else
373 {
374 /* if no upper bounds are specified, set them to infinity */
375 for( i=0; i<nV; ++i )
376 ub[i] = INFTY;
377 }
378
379 return SUCCESSFUL_RETURN;
380}
381
382
383/*
384 * s e t U B
385 */
387{
388 int_t nV = getNV( );
389
390 if ( nV == 0 )
392
393 if ( ( number >= 0 ) && ( number < nV ) )
394 {
395 ub[number] = value;
396
397 return SUCCESSFUL_RETURN;
398 }
399 else
400 {
402 }
403}
404
405
406/*
407 * c o m p u t e G i v e n s
408 */
409inline void QProblemB::computeGivens( real_t xold, real_t yold, real_t& xnew, real_t& ynew,
410 real_t& c, real_t& s
411 ) const
412{
413 real_t t, mu;
414
415 if ( isZero( yold ) == BT_TRUE )
416 {
417 c = 1.0;
418 s = 0.0;
419
420 xnew = xold;
421 ynew = yold;
422 }
423 else
424 {
425 mu = getAbs( xold );
426 if ( getAbs( yold ) > mu )
427 mu = getAbs( yold );
428
429 t = mu * getSqrt( (xold/mu)*(xold/mu) + (yold/mu)*(yold/mu) );
430
431 if ( xold < 0.0 )
432 t = -t;
433
434 c = xold/t;
435 s = yold/t;
436 xnew = t;
437 ynew = 0.0;
438 }
439
440 return;
441}
442
443
444/*
445 * a p p l y G i v e n s
446 */
447inline void QProblemB::applyGivens( real_t c, real_t s, real_t nu, real_t xold, real_t yold,
448 real_t& xnew, real_t& ynew
449 ) const
450{
451 #ifdef __USE_THREE_MULTS_GIVENS__
452
453 /* Givens plane rotation requiring only three multiplications,
454 * cf. Hammarling, S.: A note on modifications to the givens plane rotation.
455 * J. Inst. Maths Applics, 13:215-218, 1974. */
456 xnew = xold*c + yold*s;
457 ynew = (xnew+xold)*nu - yold;
458
459 #else
460
461 /* Usual Givens plane rotation requiring four multiplications. */
462 xnew = c*xold + s*yold;
463 ynew = -s*xold + c*yold;
464
465 #endif
466
467 return;
468}
469
470
471/*
472 * i s B l o c k i n g
473 */
475 real_t den,
476 real_t epsNum,
477 real_t epsDen,
478 real_t& t
479 ) const
480{
481 if ( ( den >= epsDen ) && ( num >= epsNum ) )
482 {
483 if ( num < t*den )
484 return BT_TRUE;
485 }
486
487 return BT_FALSE;
488}
489
490
492
493
494/*
495 * end of file
496 */
const real_t INFTY
Definition Constants.hpp:61
const real_t ZERO
Definition Constants.hpp:57
returnValue
Defines all symbols for global return values.
Definition MessageHandling.hpp:65
@ RET_QPOBJECT_NOT_SETUP
Definition MessageHandling.hpp:100
@ RET_INVALID_ARGUMENTS
Definition MessageHandling.hpp:71
@ RET_INDEX_OUT_OF_BOUNDS
Definition MessageHandling.hpp:70
@ SUCCESSFUL_RETURN
Definition MessageHandling.hpp:68
#define THROWERROR(retval)
Definition MessageHandling.hpp:456
BooleanType
Definition Types.hpp:204
@ BT_TRUE
Definition Types.hpp:206
@ BT_FALSE
Definition Types.hpp:205
HessianType
Definition Types.hpp:249
@ HST_IDENTITY
Definition Types.hpp:251
@ HST_ZERO
Definition Types.hpp:250
PrintLevel
Definition Types.hpp:213
QProblemStatus
Definition Types.hpp:234
@ QPS_NOTINITIALISED
Definition Types.hpp:235
@ QPS_SOLVED
Definition Types.hpp:243
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
#define BEGIN_NAMESPACE_QPOASES
Definition Types.hpp:107
real_t getSqrt(real_t x)
Definition Utils.ipp:157
real_t getAbs(real_t x)
Definition Utils.ipp:143
BooleanType isZero(real_t x, real_t TOL=ZERO)
Definition Utils.ipp:60
Manages working sets of bounds (i.e. box constraints).
Definition Bounds.hpp:57
int_t getNFV() const
Definition Bounds.ipp:55
int_t getNV() const
Definition Bounds.ipp:46
int_t getNFR() const
Definition Bounds.ipp:82
int_t getNFX() const
Definition Bounds.ipp:91
Manages all user-specified options for solving QPs.
Definition Options.hpp:57
PrintLevel printLevel
Definition Options.hpp:122
returnValue ensureConsistency()
Definition Options.cpp:234
SymmetricMatrix * H
Definition QProblemB.hpp:972
uint_t getCount() const
Definition QProblemB.ipp:216
BooleanType freeHessian
Definition QProblemB.hpp:971
returnValue resetCounter()
Definition QProblemB.ipp:225
BooleanType isInfeasible() const
Definition QProblemB.ipp:133
returnValue setPrintLevel(PrintLevel _printlevel)
Definition QProblemB.cpp:824
void applyGivens(real_t c, real_t s, real_t nu, real_t xold, real_t yold, real_t &xnew, real_t &ynew) const
Definition QProblemB.ipp:447
real_t * g
Definition QProblemB.hpp:974
real_t * lb
Definition QProblemB.hpp:975
BooleanType isBlocking(real_t num, real_t den, real_t epsNum, real_t epsDen, real_t &t) const
Definition QProblemB.ipp:474
HessianType getHessianType() const
Definition QProblemB.ipp:151
returnValue setG(const real_t *const g_new)
Definition QProblemB.ipp:293
uint_t count
Definition QProblemB.hpp:996
returnValue setUB(const real_t *const ub_new)
Definition QProblemB.ipp:360
returnValue setOptions(const Options &_options)
Definition QProblemB.ipp:191
Options options
Definition QProblemB.hpp:1004
BooleanType isSolved() const
Definition QProblemB.ipp:121
BooleanType unbounded
Definition QProblemB.hpp:991
int_t getNFV() const
Definition QProblemB.ipp:91
returnValue setLB(const real_t *const lb_new)
Definition QProblemB.ipp:312
QProblemStatus getStatus() const
Definition QProblemB.ipp:100
BooleanType isUnbounded() const
Definition QProblemB.ipp:142
void computeGivens(real_t xold, real_t yold, real_t &xnew, real_t &ynew, real_t &c, real_t &s) const
Definition QProblemB.ipp:409
returnValue setHessianType(HessianType _hessianType)
Definition QProblemB.ipp:160
int_t getNV() const
Definition QProblemB.ipp:64
int_t getNFR() const
Definition QProblemB.ipp:73
returnValue getBounds(Bounds &_bounds) const
Definition QProblemB.ipp:48
Options getOptions() const
Definition QProblemB.ipp:182
BooleanType usingRegularisation() const
Definition QProblemB.ipp:170
PrintLevel getPrintLevel() const
Definition QProblemB.ipp:206
returnValue setH(SymmetricMatrix *H_new)
Definition QProblemB.ipp:239
QProblemStatus status
Definition QProblemB.hpp:988
int_t getNFX() const
Definition QProblemB.ipp:82
BooleanType infeasible
Definition QProblemB.hpp:990
BooleanType isInitialised() const
Definition QProblemB.ipp:109
real_t * ub
Definition QProblemB.hpp:976
Bounds bounds
Definition QProblemB.hpp:978
HessianType hessianType
Definition QProblemB.hpp:993
real_t regVal
Definition QProblemB.hpp:994
Interfaces matrix-vector operations tailored to symmetric dense matrices.
Definition Matrices.hpp:512
Abstract base class for interfacing matrix-vector operations tailored to symmetric matrices.
Definition Matrices.hpp:293