examples/code_generation/mpc_mhe/getting_started_export/qpoases/SRC/Constraints.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 <Constraints.hpp>
36 
37 
38 /*****************************************************************************
39  * P U B L I C *
40  *****************************************************************************/
41 
42 
43 /*
44  * C o n s t r a i n t s
45  */
47  nC( 0 ),
48  nEC( 0 ),
49  nIC( 0 ),
50  nUC( 0 )
51 {
52 }
53 
54 
55 /*
56  * C o n s t r a i n t s
57  */
59  nC( rhs.nC ),
60  nEC( rhs.nEC ),
61  nIC( rhs.nIC ),
62  nUC( rhs.nUC )
63 {
64  active = rhs.active;
65  inactive = rhs.inactive;
66 }
67 
68 
69 /*
70  * ~ C o n s t r a i n t s
71  */
73 {
74 }
75 
76 
77 /*
78  * o p e r a t o r =
79  */
81 {
82  if ( this != &rhs )
83  {
84  SubjectTo::operator=( rhs );
85 
86  nC = rhs.nC;
87  nEC = rhs.nEC;
88  nIC = rhs.nIC;
89  nUC = rhs.nUC;
90 
91  active = rhs.active;
92  inactive = rhs.inactive;
93  }
94 
95  return *this;
96 }
97 
98 
99 /*
100  * i n i t
101  */
103 {
104  nC = n;
105  nEC = 0;
106  nIC = 0;
107  nUC = 0;
108 
109  active.init( );
110  inactive.init( );
111 
112  return SubjectTo::init( n );
113 }
114 
115 
116 /*
117  * s e t u p C o n s t r a i n t
118  */
120  )
121 {
122  /* consistency check */
123  if ( ( _number < 0 ) || ( _number >= getNC( ) ) )
125 
126  /* Add constraint index to respective index list. */
127  switch ( _status )
128  {
129  case ST_INACTIVE:
130  if ( this->addIndex( this->getInactive( ),_number,_status ) != SUCCESSFUL_RETURN )
132  break;
133 
134  case ST_LOWER:
135  if ( this->addIndex( this->getActive( ),_number,_status ) != SUCCESSFUL_RETURN )
137  break;
138 
139  case ST_UPPER:
140  if ( this->addIndex( this->getActive( ),_number,_status ) != SUCCESSFUL_RETURN )
142  break;
143 
144  default:
146  }
147 
148  return SUCCESSFUL_RETURN;
149 }
150 
151 
152 /*
153  * s e t u p A l l I n a c t i v e
154  */
156 {
157  int i;
158 
159 
160  /* 1) Place unbounded constraints at the beginning of the index list of inactive constraints. */
161  for( i=0; i<nC; ++i )
162  {
163  if ( getType( i ) == ST_UNBOUNDED )
164  {
167  }
168  }
169 
170  /* 2) Add remaining (i.e. "real" inequality) constraints to the index list of inactive constraints. */
171  for( i=0; i<nC; ++i )
172  {
173  if ( getType( i ) == ST_BOUNDED )
174  {
177  }
178  }
179 
180  /* 3) Place implicit equality constraints at the end of the index list of inactive constraints. */
181  for( i=0; i<nC; ++i )
182  {
183  if ( getType( i ) == ST_EQUALITY )
184  {
187  }
188  }
189 
190  /* 4) Moreover, add all constraints of unknown type. */
191  for( i=0; i<nC; ++i )
192  {
193  if ( getType( i ) == ST_UNKNOWN )
194  {
197  }
198  }
199 
200  return SUCCESSFUL_RETURN;
201 }
202 
203 
204 /*
205  * m o v e A c t i v e T o I n a c t i v e
206  */
208 {
209  /* consistency check */
210  if ( ( _number < 0 ) || ( _number >= getNC( ) ) )
212 
213  /* Move index from indexlist of active constraints to that of inactive ones. */
214  if ( this->removeIndex( this->getActive( ),_number ) != SUCCESSFUL_RETURN )
216 
217  if ( this->addIndex( this->getInactive( ),_number,ST_INACTIVE ) != SUCCESSFUL_RETURN )
219 
220  return SUCCESSFUL_RETURN;
221 }
222 
223 
224 /*
225  * m o v e I n a c t i v e T o A c t i v e
226  */
228  )
229 {
230  /* consistency check */
231  if ( ( _number < 0 ) || ( _number >= getNC( ) ) )
233 
234  /* Move index from indexlist of inactive constraints to that of active ones. */
235  if ( this->removeIndex( this->getInactive( ),_number ) != SUCCESSFUL_RETURN )
237 
238  if ( this->addIndex( this->getActive( ),_number,_status ) != SUCCESSFUL_RETURN )
240 
241  return SUCCESSFUL_RETURN;
242 }
243 
244 
245 
246 /*
247  * end of file
248  */
#define ST_LOWER
int getNC() const
returnValue moveInactiveToActive(int _number, SubjectToStatus _status)
Allows to pass back messages to the calling function.
Base class for managing working sets of bounds and constraints.
Indexlist * getInactive()
#define ST_INACTIVE
returnValue addIndex(Indexlist *const indexlist, int newnumber, SubjectToStatus newstatus)
returnValue setupConstraint(int _number, SubjectToStatus _status)
returnValue removeIndex(Indexlist *const indexlist, int removenumber)
void rhs(const real_t *x, real_t *f)
SubjectToType getType(int i) const
Indexlist * getActive()
#define ST_UPPER


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