external_packages/qpoases/SRC/Bounds.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-2008 by Hans Joachim Ferreau et al. All rights reserved.
6  *
7  * qpOASES is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * qpOASES is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with qpOASES; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  *
21  */
22 
23 
35 #include <Bounds.hpp>
36 
37 
38 
39 /*****************************************************************************
40  * P U B L I C *
41  *****************************************************************************/
42 
43 
44 /*
45  * B o u n d s
46  */
48  nV( 0 ),
49  nFV( 0 ),
50  nBV( 0 ),
51  nUV( 0 )
52 {
53 }
54 
55 
56 /*
57  * B o u n d s
58  */
59 Bounds::Bounds( const Bounds& rhs ) : SubjectTo( rhs ),
60  nV( rhs.nV ),
61  nFV( rhs.nFV ),
62  nBV( rhs.nBV ),
63  nUV( rhs.nUV )
64 {
65  free = rhs.free;
66  fixed = rhs.fixed;
67 }
68 
69 
70 /*
71  * ~ B o u n d s
72  */
74 {
75 }
76 
77 
78 /*
79  * o p e r a t o r =
80  */
82 {
83  if ( this != &rhs )
84  {
85  SubjectTo::operator=( rhs );
86 
87  nV = rhs.nV;
88  nFV = rhs.nFV;
89  nBV = rhs.nBV;
90  nUV = rhs.nUV;
91 
92  free = rhs.free;
93  fixed = rhs.fixed;
94  }
95 
96  return *this;
97 }
98 
99 
100 /*
101  * i n i t
102  */
104 {
105  nV = n;
106  nFV = 0;
107  nBV = 0;
108  nUV = 0;
109 
110  free.init( );
111  fixed.init( );
112 
113  return SubjectTo::init( n );
114 }
115 
116 
117 /*
118  * s e t u p B o u n d
119  */
120 returnValue Bounds::setupBound( int _number, SubjectToStatus _status
121  )
122 {
123  /* consistency check */
124  if ( ( _number < 0 ) || ( _number >= getNV( ) ) )
126 
127  /* Add bound index to respective index list. */
128  switch ( _status )
129  {
130  case ST_INACTIVE:
131  if ( this->addIndex( this->getFree( ),_number,_status ) != SUCCESSFUL_RETURN )
133  break;
134 
135  case ST_LOWER:
136  if ( this->addIndex( this->getFixed( ),_number,_status ) != SUCCESSFUL_RETURN )
138  break;
139 
140  case ST_UPPER:
141  if ( this->addIndex( this->getFixed( ),_number,_status ) != SUCCESSFUL_RETURN )
143  break;
144 
145  default:
147  }
148 
149  return SUCCESSFUL_RETURN;
150 }
151 
152 
153 /*
154  * s e t u p A l l F r e e
155  */
157 {
158  int i;
159 
160  /* 1) Place unbounded variables at the beginning of the index list of free variables. */
161  for( i=0; i<nV; ++i )
162  {
163  if ( getType( i ) == ST_UNBOUNDED )
164  {
167  }
168  }
169 
170  /* 2) Add remaining (i.e. bounded but possibly free) variables to the index list of free variables. */
171  for( i=0; i<nV; ++i )
172  {
173  if ( getType( i ) == ST_BOUNDED )
174  {
177  }
178  }
179 
180  /* 3) Place implicitly fixed variables at the end of the index list of free variables. */
181  for( i=0; i<nV; ++i )
182  {
183  if ( getType( i ) == ST_EQUALITY )
184  {
187  }
188  }
189 
190  return SUCCESSFUL_RETURN;
191 }
192 
193 
194 /*
195  * m o v e F i x e d T o F r e e
196  */
198 {
199  /* consistency check */
200  if ( ( _number < 0 ) || ( _number >= getNV( ) ) )
202 
203  /* Move index from indexlist of fixed variables to that of free ones. */
204  if ( this->removeIndex( this->getFixed( ),_number ) != SUCCESSFUL_RETURN )
206 
207  if ( this->addIndex( this->getFree( ),_number,ST_INACTIVE ) != SUCCESSFUL_RETURN )
209 
210  return SUCCESSFUL_RETURN;
211 }
212 
213 
214 /*
215  * m o v e F r e e T o F i x e d
216  */
218  )
219 {
220  /* consistency check */
221  if ( ( _number < 0 ) || ( _number >= getNV( ) ) )
223 
224  /* Move index from indexlist of free variables to that of fixed ones. */
225  if ( this->removeIndex( this->getFree( ),_number ) != SUCCESSFUL_RETURN )
227 
228  if ( this->addIndex( this->getFixed( ),_number,_status ) != SUCCESSFUL_RETURN )
230 
231  return SUCCESSFUL_RETURN;
232 }
233 
234 
235 /*
236  * s w a p F r e e
237  */
238 returnValue Bounds::swapFree( int number1, int number2
239  )
240 {
241  /* consistency check */
242  if ( ( number1 < 0 ) || ( number1 >= getNV( ) ) || ( number2 < 0 ) || ( number2 >= getNV( ) ) )
244 
245  /* Swap index within indexlist of free variables. */
246  return this->swapIndex( this->getFree( ),number1,number2 );
247 }
248 
249 
250 /*
251  * end of file
252  */
#define ST_LOWER
int n
Definition: Bounds.h:58
Indexlist * getFree()
Allows to pass back messages to the calling function.
Base class for managing working sets of bounds and constraints.
int getNV() const
#define ST_INACTIVE
returnValue setupBound(int _number, SubjectToStatus _status)
returnValue swapIndex(Indexlist *const indexlist, int number1, int number2)
returnValue addIndex(Indexlist *const indexlist, int newnumber, SubjectToStatus newstatus)
returnValue removeIndex(Indexlist *const indexlist, int removenumber)
void rhs(const real_t *x, real_t *f)
SubjectToType getType(int i) const
Manages working sets of bounds (= box constraints).
#define ST_UPPER
Indexlist * getFixed()
returnValue moveFreeToFixed(int _number, SubjectToStatus _status)


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