-
Notifications
You must be signed in to change notification settings - Fork 0
/
SubjectTo.cpp
289 lines (230 loc) · 5 KB
/
SubjectTo.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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
/*
* 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/SubjectTo.cpp
* \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches
* \version 3.2
* \date 2007-2015
*
* Implementation of the SubjectTo class designed to manage working sets of
* constraints and bounds within a QProblem.
*/
#include "SubjectTo.hpp"
BEGIN_NAMESPACE_QPOASES
/*****************************************************************************
* P U B L I C *
*****************************************************************************/
/*
* S u b j e c t T o
*/
SubjectTo::SubjectTo( )
{
type = 0;
status = 0;
init( );
}
/*
* S u b j e c t T o
*/
SubjectTo::SubjectTo( int_t _n )
{
type = 0;
status = 0;
init( _n );
}
/*
* S u b j e c t T o
*/
SubjectTo::SubjectTo( const SubjectTo& rhs )
{
copy( rhs );
}
/*
* ~ S u b j e c t T o
*/
SubjectTo::~SubjectTo( )
{
clear( );
}
/*
* o p e r a t o r =
*/
SubjectTo& SubjectTo::operator=( const SubjectTo& rhs )
{
if ( this != &rhs )
{
clear( );
copy( rhs );
}
return *this;
}
/*
* i n i t
*/
returnValue SubjectTo::init( int_t _n
)
{
int_t i;
if ( _n < 0 )
return THROWERROR( RET_INVALID_ARGUMENTS );
clear( );
n = _n;
noLower = BT_TRUE;
noUpper = BT_TRUE;
if ( n > 0 )
{
type = new SubjectToType[n];
status = new SubjectToStatus[n];
for( i=0; i<n; ++i )
{
type[i] = ST_UNKNOWN;
status[i] = ST_UNDEFINED;
}
}
return SUCCESSFUL_RETURN;
}
/*****************************************************************************
* P R O T E C T E D *
*****************************************************************************/
/*
* c l e a r
*/
returnValue SubjectTo::clear( )
{
if ( type != 0 )
{
delete[] type;
type = 0;
}
if ( status != 0 )
{
delete[] status;
status = 0;
}
return SUCCESSFUL_RETURN;
}
/*
* c o p y
*/
returnValue SubjectTo::copy( const SubjectTo& rhs
)
{
int_t i;
n = rhs.n;
noLower = rhs.noLower;
noUpper = rhs.noUpper;
if ( rhs.n != 0 )
{
type = new SubjectToType[n];
status = new SubjectToStatus[n];
for( i=0; i<n; ++i )
{
type[i] = rhs.type[i];
status[i] = rhs.status[i];
}
}
else
{
type = 0;
status = 0;
}
return SUCCESSFUL_RETURN;
}
/*
* a d d I n d e x
*/
returnValue SubjectTo::addIndex( Indexlist* const indexlist,
int_t newnumber, SubjectToStatus newstatus
)
{
if ( status != 0 )
{
/* consistency check */
if ( status[newnumber] == newstatus )
return THROWERROR( RET_INDEX_ALREADY_OF_DESIRED_STATUS );
status[newnumber] = newstatus;
}
else
return THROWERROR( RET_ADDINDEX_FAILED );
if ( indexlist != 0 )
{
if ( indexlist->addNumber( newnumber ) == RET_INDEXLIST_EXCEEDS_MAX_LENGTH )
return THROWERROR( RET_ADDINDEX_FAILED );
}
else
return THROWERROR( RET_INVALID_ARGUMENTS );
return SUCCESSFUL_RETURN;
}
/*
* r e m o v e I n d e x
*/
returnValue SubjectTo::removeIndex( Indexlist* const indexlist,
int_t removenumber
)
{
if ( status != 0 )
status[removenumber] = ST_UNDEFINED;
else
return THROWERROR( RET_REMOVEINDEX_FAILED );
if ( indexlist != 0 )
{
if ( indexlist->removeNumber( removenumber ) != SUCCESSFUL_RETURN )
return THROWERROR( RET_REMOVEINDEX_FAILED );
}
else
return THROWERROR( RET_INVALID_ARGUMENTS );
return SUCCESSFUL_RETURN;
}
/*
* s w a p I n d e x
*/
returnValue SubjectTo::swapIndex( Indexlist* const indexlist,
int_t number1, int_t number2
)
{
/* consistency checks */
if ( status != 0 )
{
if ( status[number1] != status[number2] )
return THROWERROR( RET_SWAPINDEX_FAILED );
}
else
return THROWERROR( RET_SWAPINDEX_FAILED );
if ( number1 == number2 )
{
THROWWARNING( RET_NOTHING_TO_DO );
return SUCCESSFUL_RETURN;
}
if ( indexlist != 0 )
{
if ( indexlist->swapNumbers( number1,number2 ) != SUCCESSFUL_RETURN )
return THROWERROR( RET_SWAPINDEX_FAILED );
}
else
return THROWERROR( RET_INVALID_ARGUMENTS );
return SUCCESSFUL_RETURN;
}
END_NAMESPACE_QPOASES
/*
* end of file
*/