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-2008 by Hans Joachim Ferreau et al. All rights reserved.
00006  *
00007  *      qpOASES is free software; you can redistribute it and/or
00008  *      modify it under the terms of the GNU Lesser General Public
00009  *      License as published by the Free Software Foundation; either
00010  *      version 2.1 of the License, or (at your option) any later version.
00011  *
00012  *      qpOASES is distributed in the hope that it will be useful,
00013  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  *      Lesser General Public License for more details.
00016  *
00017  *      You should have received a copy of the GNU Lesser General Public
00018  *      License along with qpOASES; if not, write to the Free Software
00019  *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00020  *
00021  */
00022 
00023 
00035 #include <SubjectTo.hpp>
00036 
00037 
00038 /*****************************************************************************
00039  *  P U B L I C                                                              *
00040  *****************************************************************************/
00041 
00042 
00043 /*
00044  *      S u b j e c t T o
00045  */
00046 SubjectTo::SubjectTo( ) :       noLower( BT_TRUE ),
00047                                                         noUpper( BT_TRUE ),
00048                                                         size( 0 )
00049 {
00050         int i;
00051 
00052         for( i=0; i<size; ++i )
00053         {
00054                 type[i] = ST_UNKNOWN;
00055                 status[i] = ST_UNDEFINED;
00056         }
00057 }
00058 
00059 
00060 /*
00061  *      S u b j e c t T o
00062  */
00063 SubjectTo::SubjectTo( const SubjectTo& rhs ) :  noLower( rhs.noLower ),
00064                                                                                                 noUpper( rhs.noUpper ),
00065                                                                                                 size( rhs.size )
00066 {
00067         int i;
00068 
00069         for( i=0; i<size; ++i )
00070         {
00071                 type[i] = rhs.type[i];
00072                 status[i] = rhs.status[i];
00073         }
00074 }
00075 
00076 
00077 /*
00078  *      ~ S u b j e c t T o
00079  */
00080 SubjectTo::~SubjectTo( )
00081 {
00082 }
00083 
00084 
00085 /*
00086  *      o p e r a t o r =
00087  */
00088 SubjectTo& SubjectTo::operator=( const SubjectTo& rhs )
00089 {
00090         int i;
00091 
00092         if ( this != &rhs )
00093         {
00094                 size = rhs.size;
00095 
00096                 for( i=0; i<size; ++i )
00097                 {
00098                         type[i] = rhs.type[i];
00099                         status[i] = rhs.status[i];
00100                 }
00101 
00102                 noLower = rhs.noLower;
00103                 noUpper = rhs.noUpper;
00104         }
00105 
00106         return *this;
00107 }
00108 
00109 
00110 
00111 /*
00112  *      i n i t
00113  */
00114 returnValue SubjectTo::init( int n )
00115 {
00116         int i;
00117 
00118         size = n;
00119 
00120         noLower = BT_TRUE;
00121         noUpper = BT_TRUE;
00122 
00123         for( i=0; i<size; ++i )
00124         {
00125                 type[i] = ST_UNKNOWN;
00126                 status[i] = ST_UNDEFINED;
00127         }
00128 
00129         return SUCCESSFUL_RETURN;
00130 }
00131 
00132 
00133 
00134 /*****************************************************************************
00135  *  P R O T E C T E D                                                        *
00136  *****************************************************************************/
00137 
00138 /*
00139  *      a d d I n d e x
00140  */
00141 returnValue SubjectTo::addIndex(        Indexlist* const indexlist,
00142                                                                         int newnumber, SubjectToStatus newstatus
00143                                                                         )
00144 {
00145         /* consistency check */
00146         if ( status[newnumber] == newstatus )
00147                 return THROWERROR( RET_INDEX_ALREADY_OF_DESIRED_STATUS );
00148 
00149         status[newnumber] = newstatus;
00150 
00151         if ( indexlist->addNumber( newnumber ) == RET_INDEXLIST_EXCEEDS_MAX_LENGTH )
00152                 return THROWERROR( RET_ADDINDEX_FAILED );
00153 
00154         return SUCCESSFUL_RETURN;
00155 }
00156 
00157 
00158 /*
00159  *      r e m o v e I n d e x
00160  */
00161 returnValue SubjectTo::removeIndex(     Indexlist* const indexlist, 
00162                                                                         int removenumber
00163                                                                         )
00164 {
00165         status[removenumber] = ST_UNDEFINED;
00166 
00167         if ( indexlist->removeNumber( removenumber ) != SUCCESSFUL_RETURN )
00168                 return THROWERROR( RET_UNKNOWN_BUG );
00169 
00170         return SUCCESSFUL_RETURN;
00171 }
00172 
00173 
00174 /*
00175  *      s w a p I n d e x
00176  */
00177 returnValue SubjectTo::swapIndex(       Indexlist* const indexlist,
00178                                                                         int number1, int number2
00179                                                                         )
00180 {
00181         /* consistency checks */
00182         if ( status[number1] != status[number2] )
00183                 return THROWERROR( RET_SWAPINDEX_FAILED );
00184 
00185         if ( number1 == number2 )
00186         {
00187                 THROWWARNING( RET_NOTHING_TO_DO );
00188                 return SUCCESSFUL_RETURN;
00189         }
00190 
00191         if ( indexlist->swapNumbers( number1,number2 ) != SUCCESSFUL_RETURN )
00192                 return THROWERROR( RET_SWAPINDEX_FAILED );
00193 
00194         return SUCCESSFUL_RETURN;
00195 }
00196 
00197 
00198 /*
00199  *      end of file
00200  */


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