qpOASES-3.0beta/src/Flipper.cpp
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-2011 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 
36 #include <qpOASES/Flipper.hpp>
37 
38 
40 
41 
42 /*****************************************************************************
43  * P U B L I C *
44  *****************************************************************************/
45 
46 
47 /*
48  * F l i p p e r
49  */
51 {
52  R = 0;
53  Q = 0;
54  T = 0;
55 
56  init( );
57 }
58 
59 
60 /*
61  * F l i p p e r
62  */
64  int _nC
65  )
66 {
67  R = 0;
68  Q = 0;
69  T = 0;
70 
71  init( _nV,_nC );
72 }
73 
74 
75 /*
76  * F l i p p e r
77  */
79 {
80  R = 0;
81  Q = 0;
82  T = 0;
83 
84  copy( rhs );
85 }
86 
87 
88 /*
89  * ~ F l i p p e r
90  */
92 {
93  clear( );
94 }
95 
96 
97 /*
98  * o p e r a t o r =
99  */
101 {
102  if ( this != &rhs )
103  {
104  clear( );
105  copy( rhs );
106  }
107 
108  return *this;
109 }
110 
111 
112 
113 /*
114  * i n i t
115  */
117  int _nC
118  )
119 {
120  if ( ( _nV < 0 ) || ( _nC < 0 ) )
122 
123  clear( );
124 
125  nV = _nV;
126  nC = _nC;
127 
128  /*if ( nV > 0 )
129  {
130  R = new real_t[nV*nV];
131 
132  if ( nC > 0 )
133  {
134  Q = new real_t[nV*nV];
135  T = new real_t[getDimT()];
136  }
137  }*/
138 
139  return SUCCESSFUL_RETURN;
140 }
141 
142 
143 
144 /*
145  * g e t
146  */
148  double* const _R,
149  Constraints* const _constraints,
150  double* const _Q,
151  double* const _T
152  ) const
153 {
154  if ( _bounds != 0 )
155  *_bounds = bounds;
156 
157  if ( _constraints != 0 )
158  *_constraints = constraints;
159 
160  if ( ( _R != 0 ) && ( R != 0 ) )
161  memcpy( _R,R, nV*nV*sizeof(real_t) );
162 
163  if ( ( _Q != 0 ) && ( Q != 0 ) )
164  memcpy( _Q,Q, nV*nV*sizeof(real_t) );
165 
166  if ( ( _T != 0 ) && ( T != 0 ) )
167  memcpy( _T,T, getDimT()*sizeof(real_t) );
168 
169  return SUCCESSFUL_RETURN;
170 }
171 
172 
173 /*
174  * s e t
175  */
176 returnValue Flipper::set( const Bounds* const _bounds,
177  const double* const _R,
178  const Constraints* const _constraints,
179  const double* const _Q,
180  const double* const _T
181  )
182 {
183  if ( _bounds != 0 )
184  bounds = *_bounds;
185 
186  if ( _constraints != 0 )
187  constraints = *_constraints;
188 
189  if ( _R != 0 )
190  {
191  if ( R == 0 )
192  R = new real_t[nV*nV];
193 
194  memcpy( R,_R, nV*nV*sizeof(real_t) );
195  }
196 
197  if ( _Q != 0 )
198  {
199  if ( Q == 0 )
200  Q = new real_t[nV*nV];
201 
202  memcpy( Q,_Q, nV*nV*sizeof(real_t) );
203  }
204 
205  if ( _T != 0 )
206  {
207  if ( T == 0 )
208  T = new real_t[getDimT()];
209 
210  memcpy( T,_T, getDimT()*sizeof(real_t) );
211  }
212 
213  return SUCCESSFUL_RETURN;
214 }
215 
216 
217 
218 /*****************************************************************************
219  * P R O T E C T E D *
220  *****************************************************************************/
221 
222 /*
223  * c l e a r
224  */
226 {
227  if ( R != 0 )
228  {
229  delete[] R;
230  R = 0;
231  }
232 
233  if ( Q != 0 )
234  {
235  delete[] Q;
236  Q = 0;
237  }
238 
239  if ( T != 0 )
240  {
241  delete[] T;
242  T = 0;
243  }
244 
245  return SUCCESSFUL_RETURN;
246 }
247 
248 
249 /*
250  * c o p y
251  */
253  )
254 {
255  return set( &(rhs.bounds),rhs.R, &(rhs.constraints),rhs.Q,rhs.T );
256 }
257 
258 
259 int Flipper::getDimT( ) const
260 {
261  if ( nV > nC )
262  return nC*nC;
263  else
264  return nV*nV;
265 }
266 
267 
269 
270 
271 /*
272  * end of file
273  */
Allows to pass back messages to the calling function.
returnValue copy(const Flipper &rhs)
Auxiliary class for storing a copy of the current matrix factorisations.
returnValue set(const Bounds *const _bounds, const double *const _R, const Constraints *const _constraints=0, const double *const _Q=0, const double *const _T=0)
void rhs(const real_t *x, real_t *f)
Flipper & operator=(const Flipper &rhs)
Manages working sets of bounds (= box constraints).
double real_t
Definition: AD_test.c:10
returnValue init(int _nV=0, int _nC=0)
returnValue get(Bounds *const _bounds, double *const R, Constraints *const _constraints=0, double *const _Q=0, double *const _T=0) const


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:34:34