-
Notifications
You must be signed in to change notification settings - Fork 0
/
Flipper.cpp
259 lines (199 loc) · 4.09 KB
/
Flipper.cpp
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
/*
* This file is part of qpOASES.
*
* qpOASES -- An Implementation of the Online Active Set Strategy.
* Copyright (C) 2007-2015 by Hans Joachim Ferreau, Andreas Potschka,
* Christian Kirches et al. 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 src/Flipper.cpp
* \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches
* \version 3.2
* \date 2007-2015
*
* Implementation of the Flipper class designed to manage working sets of
* constraints and bounds within a QProblem.
*/
#include "Flipper.hpp"
BEGIN_NAMESPACE_QPOASES
/*****************************************************************************
* P U B L I C *
*****************************************************************************/
/*
* F l i p p e r
*/
Flipper::Flipper( )
{
R = 0;
Q = 0;
T = 0;
init( );
}
/*
* F l i p p e r
*/
Flipper::Flipper( uint_t _nV,
uint_t _nC
)
{
R = 0;
Q = 0;
T = 0;
init( _nV,_nC );
}
/*
* F l i p p e r
*/
Flipper::Flipper( const Flipper& rhs )
{
R = 0;
Q = 0;
T = 0;
copy( rhs );
}
/*
* ~ F l i p p e r
*/
Flipper::~Flipper( )
{
clear( );
}
/*
* o p e r a t o r =
*/
Flipper& Flipper::operator=( const Flipper& rhs )
{
if ( this != &rhs )
{
clear( );
copy( rhs );
}
return *this;
}
/*
* i n i t
*/
returnValue Flipper::init( uint_t _nV,
uint_t _nC
)
{
clear( );
nV = _nV;
nC = _nC;
return SUCCESSFUL_RETURN;
}
/*
* g e t
*/
returnValue Flipper::get( Bounds* const _bounds,
real_t* const _R,
Constraints* const _constraints,
real_t* const _Q,
real_t* const _T
) const
{
if ( _bounds != 0 )
*_bounds = bounds;
if ( _constraints != 0 )
*_constraints = constraints;
if ( ( _R != 0 ) && ( R != 0 ) )
memcpy( _R,R, nV*nV*sizeof(real_t) );
if ( ( _Q != 0 ) && ( Q != 0 ) )
memcpy( _Q,Q, nV*nV*sizeof(real_t) );
if ( ( _T != 0 ) && ( T != 0 ) )
memcpy( _T,T, getDimT()*sizeof(real_t) );
return SUCCESSFUL_RETURN;
}
/*
* s e t
*/
returnValue Flipper::set( const Bounds* const _bounds,
const real_t* const _R,
const Constraints* const _constraints,
const real_t* const _Q,
const real_t* const _T
)
{
if ( _bounds != 0 )
bounds = *_bounds;
if ( _constraints != 0 )
constraints = *_constraints;
if ( _R != 0 )
{
if ( R == 0 )
R = new real_t[nV*nV];
memcpy( R,_R, nV*nV*sizeof(real_t) );
}
if ( _Q != 0 )
{
if ( Q == 0 )
Q = new real_t[nV*nV];
memcpy( Q,_Q, nV*nV*sizeof(real_t) );
}
if ( _T != 0 )
{
if ( T == 0 )
T = new real_t[getDimT()];
memcpy( T,_T, getDimT()*sizeof(real_t) );
}
return SUCCESSFUL_RETURN;
}
/*****************************************************************************
* P R O T E C T E D *
*****************************************************************************/
/*
* c l e a r
*/
returnValue Flipper::clear( )
{
if ( R != 0 )
{
delete[] R;
R = 0;
}
if ( Q != 0 )
{
delete[] Q;
Q = 0;
}
if ( T != 0 )
{
delete[] T;
T = 0;
}
return SUCCESSFUL_RETURN;
}
/*
* c o p y
*/
returnValue Flipper::copy( const Flipper& rhs
)
{
return set( &(rhs.bounds),rhs.R, &(rhs.constraints),rhs.Q,rhs.T );
}
uint_t Flipper::getDimT( ) const
{
if ( nV > nC )
return nC*nC;
else
return nV*nV;
}
END_NAMESPACE_QPOASES
/*
* end of file
*/