SubjectTo.cpp
Go to the documentation of this file.
00001 /*
00002  *      This file is part of qpOASES.
00003  *
00004  *      qpOASES -- An Implementation of the Online Active Set Strategy.
00005  *      Copyright (C) 2007-2011 by Hans Joachim Ferreau, Andreas Potschka,
00006  *      Christian Kirches et al. All rights reserved.
00007  *
00008  *      qpOASES is free software; you can redistribute it and/or
00009  *      modify it under the terms of the GNU Lesser General Public
00010  *      License as published by the Free Software Foundation; either
00011  *      version 2.1 of the License, or (at your option) any later version.
00012  *
00013  *      qpOASES is distributed in the hope that it will be useful,
00014  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00016  *      See the GNU Lesser General Public License for more details.
00017  *
00018  *      You should have received a copy of the GNU Lesser General Public
00019  *      License along with qpOASES; if not, write to the Free Software
00020  *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00021  *
00022  */
00023 
00024 
00036 #include <qpOASES/SubjectTo.hpp>
00037 
00038 
00039 BEGIN_NAMESPACE_QPOASES
00040 
00041 
00042 /*****************************************************************************
00043  *  P U B L I C                                                              *
00044  *****************************************************************************/
00045 
00046 
00047 /*
00048  *      S u b j e c t T o
00049  */
00050 SubjectTo::SubjectTo( )
00051 {
00052         type   = 0;
00053         status = 0;
00054 
00055         init( );
00056 }
00057 
00058 
00059 /*
00060  *      S u b j e c t T o
00061  */
00062 SubjectTo::SubjectTo( int _n )
00063 {
00064         type   = 0;
00065         status = 0;
00066 
00067         init( _n );
00068 }
00069 
00070 
00071 /*
00072  *      S u b j e c t T o
00073  */
00074 SubjectTo::SubjectTo( const SubjectTo& rhs )
00075 {
00076         copy( rhs );
00077 }
00078 
00079 
00080 /*
00081  *      ~ S u b j e c t T o
00082  */
00083 SubjectTo::~SubjectTo( )
00084 {
00085         clear( );
00086 }
00087 
00088 
00089 /*
00090  *      o p e r a t o r =
00091  */
00092 SubjectTo& SubjectTo::operator=( const SubjectTo& rhs )
00093 {
00094         if ( this != &rhs )
00095         {
00096                 clear( );
00097                 copy( rhs );
00098         }
00099 
00100         return *this;
00101 }
00102 
00103 
00104 /*
00105  *      i n i t
00106  */
00107 returnValue SubjectTo::init(    int _n
00108                                                                 )
00109 {
00110         int i;
00111 
00112         if ( _n < 0 )
00113                 return THROWERROR( RET_INVALID_ARGUMENTS );
00114 
00115         clear( );
00116 
00117         n = _n;
00118         noLower = BT_TRUE;
00119         noUpper = BT_TRUE;
00120 
00121         if ( n > 0 )
00122         {
00123                 type   = new SubjectToType[n];
00124                 status = new SubjectToStatus[n];
00125 
00126                 for( i=0; i<n; ++i )
00127                 {
00128                         type[i]   = ST_UNKNOWN;
00129                         status[i] = ST_UNDEFINED;
00130                 }
00131         }
00132 
00133         return SUCCESSFUL_RETURN;
00134 }
00135 
00136 
00137 
00138 /*****************************************************************************
00139  *  P R O T E C T E D                                                        *
00140  *****************************************************************************/
00141 
00142 /*
00143  *      c l e a r
00144  */
00145 returnValue SubjectTo::clear( )
00146 {
00147         if ( type != 0 )
00148         {
00149                 delete[] type;
00150                 type = 0;
00151         }
00152 
00153         if ( status != 0 )
00154         {
00155                 delete[] status;
00156                 status = 0;
00157         }
00158 
00159         return SUCCESSFUL_RETURN;
00160 }
00161 
00162 
00163 /*
00164  *      c o p y
00165  */
00166 returnValue SubjectTo::copy(    const SubjectTo& rhs
00167                                                                 )
00168 {
00169         int i;
00170 
00171         n = rhs.n;
00172         noLower = rhs.noLower;
00173         noUpper = rhs.noUpper;
00174 
00175         if ( rhs.n != 0 )
00176         {
00177                 type   = new SubjectToType[n];
00178                 status = new SubjectToStatus[n];
00179 
00180                 for( i=0; i<n; ++i )
00181                 {
00182                         type[i]   = rhs.type[i];
00183                         status[i] = rhs.status[i];
00184                 }
00185         }
00186         else
00187         {
00188                 type   = 0;
00189                 status = 0;
00190         }
00191 
00192         return SUCCESSFUL_RETURN;
00193 }
00194 
00195 
00196 /*
00197  *      a d d I n d e x
00198  */
00199 returnValue SubjectTo::addIndex(        Indexlist* const indexlist,
00200                                                                         int newnumber, SubjectToStatus newstatus
00201                                                                         )
00202 {
00203         if ( status != 0 )
00204         {
00205                 /* consistency check */
00206                 if ( status[newnumber] == newstatus )
00207                         return THROWERROR( RET_INDEX_ALREADY_OF_DESIRED_STATUS );
00208 
00209                 status[newnumber] = newstatus;
00210         }
00211         else
00212                 return THROWERROR( RET_ADDINDEX_FAILED );
00213 
00214         if ( indexlist != 0 )
00215         {
00216                 if ( indexlist->addNumber( newnumber ) == RET_INDEXLIST_EXCEEDS_MAX_LENGTH )
00217                         return THROWERROR( RET_ADDINDEX_FAILED );
00218         }
00219         else
00220                 return THROWERROR( RET_INVALID_ARGUMENTS );
00221 
00222         return SUCCESSFUL_RETURN;
00223 }
00224 
00225 
00226 /*
00227  *      r e m o v e I n d e x
00228  */
00229 returnValue SubjectTo::removeIndex(     Indexlist* const indexlist,
00230                                                                         int removenumber
00231                                                                         )
00232 {
00233         if ( status != 0 )
00234                 status[removenumber] = ST_UNDEFINED;
00235         else
00236                 return THROWERROR( RET_REMOVEINDEX_FAILED );
00237 
00238         if ( indexlist != 0 )
00239         {
00240                 if ( indexlist->removeNumber( removenumber ) != SUCCESSFUL_RETURN )
00241                         return THROWERROR( RET_REMOVEINDEX_FAILED );
00242         }
00243         else
00244                 return THROWERROR( RET_INVALID_ARGUMENTS );
00245 
00246         return SUCCESSFUL_RETURN;
00247 }
00248 
00249 
00250 /*
00251  *      s w a p I n d e x
00252  */
00253 returnValue SubjectTo::swapIndex(       Indexlist* const indexlist,
00254                                                                         int number1, int number2
00255                                                                         )
00256 {
00257         /* consistency checks */
00258         if ( status != 0 )
00259         {
00260                 if ( status[number1] != status[number2] )
00261                         return THROWERROR( RET_SWAPINDEX_FAILED );
00262         }
00263         else
00264                 return THROWERROR( RET_SWAPINDEX_FAILED );
00265 
00266         if ( number1 == number2 )
00267         {
00268                 THROWWARNING( RET_NOTHING_TO_DO );
00269                 return SUCCESSFUL_RETURN;
00270         }
00271 
00272         if ( indexlist != 0 )
00273         {
00274                 if ( indexlist->swapNumbers( number1,number2 ) != SUCCESSFUL_RETURN )
00275                         return THROWERROR( RET_SWAPINDEX_FAILED );
00276         }
00277         else
00278                 return THROWERROR( RET_INVALID_ARGUMENTS );
00279 
00280         return SUCCESSFUL_RETURN;
00281 }
00282 
00283 
00284 END_NAMESPACE_QPOASES
00285 
00286 
00287 /*
00288  *      end of file
00289  */


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Sat Jun 8 2019 19:39:43