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
25 /**
26 * \file src/Flipper.cpp
27 * \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches
28 * \version 3.2
29 * \date 2007-2017
30 *
31 * Implementation of the Flipper class designed to manage working sets of
32 * constraints and bounds within a QProblem.
33 */
34
35
36 #include <qpOASES/Flipper.hpp>
37
38
39 BEGIN_NAMESPACE_QPOASES
40
41
42 /*****************************************************************************
43 * P U B L I C *
44 *****************************************************************************/
45
46
47 /*
48 * F l i p p e r
49 */
Flipper()50 Flipper::Flipper( )
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 */
Flipper(uint_t _nV,uint_t _nC)63 Flipper::Flipper( uint_t _nV,
64 uint_t _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 */
Flipper(const Flipper & rhs)78 Flipper::Flipper( const Flipper& rhs )
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 */
~Flipper()91 Flipper::~Flipper( )
92 {
93 clear( );
94 }
95
96
97 /*
98 * o p e r a t o r =
99 */
operator =(const Flipper & rhs)100 Flipper& Flipper::operator=( const Flipper& rhs )
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 */
init(uint_t _nV,uint_t _nC)116 returnValue Flipper::init( uint_t _nV,
117 uint_t _nC
118 )
119 {
120 clear( );
121
122 nV = _nV;
123 nC = _nC;
124
125 return SUCCESSFUL_RETURN;
126 }
127
128
129
130 /*
131 * g e t
132 */
get(Bounds * const _bounds,real_t * const _R,Constraints * const _constraints,real_t * const _Q,real_t * const _T) const133 returnValue Flipper::get( Bounds* const _bounds,
134 real_t* const _R,
135 Constraints* const _constraints,
136 real_t* const _Q,
137 real_t* const _T
138 ) const
139 {
140 if ( _bounds != 0 )
141 *_bounds = bounds;
142
143 if ( _constraints != 0 )
144 *_constraints = constraints;
145
146 if ( ( _R != 0 ) && ( R != 0 ) )
147 memcpy( _R,R, nV*nV*sizeof(real_t) );
148
149 if ( ( _Q != 0 ) && ( Q != 0 ) )
150 memcpy( _Q,Q, nV*nV*sizeof(real_t) );
151
152 if ( ( _T != 0 ) && ( T != 0 ) )
153 memcpy( _T,T, getDimT()*sizeof(real_t) );
154
155 return SUCCESSFUL_RETURN;
156 }
157
158
159 /*
160 * s e t
161 */
set(const Bounds * const _bounds,const real_t * const _R,const Constraints * const _constraints,const real_t * const _Q,const real_t * const _T)162 returnValue Flipper::set( const Bounds* const _bounds,
163 const real_t* const _R,
164 const Constraints* const _constraints,
165 const real_t* const _Q,
166 const real_t* const _T
167 )
168 {
169 if ( _bounds != 0 )
170 bounds = *_bounds;
171
172 if ( _constraints != 0 )
173 constraints = *_constraints;
174
175 if ( _R != 0 )
176 {
177 if ( R == 0 )
178 R = new real_t[nV*nV];
179
180 memcpy( R,_R, nV*nV*sizeof(real_t) );
181 }
182
183 if ( _Q != 0 )
184 {
185 if ( Q == 0 )
186 Q = new real_t[nV*nV];
187
188 memcpy( Q,_Q, nV*nV*sizeof(real_t) );
189 }
190
191 if ( _T != 0 )
192 {
193 if ( T == 0 )
194 T = new real_t[getDimT()];
195
196 memcpy( T,_T, getDimT()*sizeof(real_t) );
197 }
198
199 return SUCCESSFUL_RETURN;
200 }
201
202
203
204 /*****************************************************************************
205 * P R O T E C T E D *
206 *****************************************************************************/
207
208 /*
209 * c l e a r
210 */
clear()211 returnValue Flipper::clear( )
212 {
213 if ( R != 0 )
214 {
215 delete[] R;
216 R = 0;
217 }
218
219 if ( Q != 0 )
220 {
221 delete[] Q;
222 Q = 0;
223 }
224
225 if ( T != 0 )
226 {
227 delete[] T;
228 T = 0;
229 }
230
231 return SUCCESSFUL_RETURN;
232 }
233
234
235 /*
236 * c o p y
237 */
copy(const Flipper & rhs)238 returnValue Flipper::copy( const Flipper& rhs
239 )
240 {
241 return set( &(rhs.bounds),rhs.R, &(rhs.constraints),rhs.Q,rhs.T );
242 }
243
244
getDimT() const245 uint_t Flipper::getDimT( ) const
246 {
247 if ( nV > nC )
248 return nC*nC;
249 else
250 return nV*nV;
251 }
252
253
254 END_NAMESPACE_QPOASES
255
256
257 /*
258 * end of file
259 */
260