qpOASES  3.1.1
include/qpOASES/QProblem.hpp
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-2015 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 
00037 #ifndef QPOASES_QPROBLEM_HPP
00038 #define QPOASES_QPROBLEM_HPP
00039 
00040 
00041 #include <qpOASES/QProblemB.hpp>
00042 #include <qpOASES/Constraints.hpp>
00043 #include <qpOASES/ConstraintProduct.hpp>
00044 
00045 
00046 BEGIN_NAMESPACE_QPOASES
00047 
00048 
00060 class QProblem : public QProblemB
00061 {
00062     /* allow SolutionAnalysis class to access private members */
00063     friend class SolutionAnalysis;
00064 
00065     /*
00066      *  PUBLIC MEMBER FUNCTIONS
00067      */
00068     public:
00070         QProblem( );
00071 
00077         QProblem(   int _nV,                                
00078                     int _nC,                                
00079                     HessianType _hessianType = HST_UNKNOWN  
00080                     );
00081 
00083         QProblem(   const QProblem& rhs     
00084                     );
00085 
00087         virtual ~QProblem( );
00088 
00090         QProblem& operator=(    const QProblem& rhs 
00091                                 );
00092 
00093 
00097         virtual returnValue reset( );
00098 
00099 
00121         returnValue init(   SymmetricMatrix *_H,                            
00122                             const real_t* const _g,                         
00123                             Matrix *_A,                                     
00124                             const real_t* const _lb,                        
00126                             const real_t* const _ub,                        
00128                             const real_t* const _lbA,                       
00130                             const real_t* const _ubA,                       
00132                             int& nWSR,                                      
00134                             real_t* const cputime = 0,                      
00136                             const real_t* const xOpt = 0,                   
00138                             const real_t* const yOpt = 0,                   
00140                             const Bounds* const guessedBounds = 0,          
00142                             const Constraints* const guessedConstraints = 0,
00144                             const real_t* const _R = 0                      
00148                             );
00149 
00150 
00172         returnValue init(   const real_t* const _H,                         
00174                             const real_t* const _g,                         
00175                             const real_t* const _A,                         
00176                             const real_t* const _lb,                        
00178                             const real_t* const _ub,                        
00180                             const real_t* const _lbA,                       
00182                             const real_t* const _ubA,                       
00184                             int& nWSR,                                      
00186                             real_t* const cputime = 0,                      
00188                             const real_t* const xOpt = 0,                   
00190                             const real_t* const yOpt = 0,                   
00192                             const Bounds* const guessedBounds = 0,          
00194                             const Constraints* const guessedConstraints = 0,
00196                             const real_t* const _R = 0                      
00200                             );
00201 
00224         returnValue init(   const char* const H_file,                       
00226                             const char* const g_file,                       
00227                             const char* const A_file,                       
00228                             const char* const lb_file,                      
00230                             const char* const ub_file,                      
00232                             const char* const lbA_file,                     
00234                             const char* const ubA_file,                     
00236                             int& nWSR,                                      
00238                             real_t* const cputime = 0,                      
00240                             const real_t* const xOpt = 0,                   
00242                             const real_t* const yOpt = 0,                   
00244                             const Bounds* const guessedBounds = 0,          
00246                             const Constraints* const guessedConstraints = 0,
00248                             const char* const R_file = 0                    
00251                             );
00252 
00253 
00271         returnValue hotstart(   const real_t* const g_new,                      
00272                                 const real_t* const lb_new,                     
00274                                 const real_t* const ub_new,                     
00276                                 const real_t* const lbA_new,                    
00278                                 const real_t* const ubA_new,                    
00280                                 int& nWSR,                                      
00282                                 real_t* const cputime = 0,                      
00284                                 const Bounds* const guessedBounds = 0,          
00286                                 const Constraints* const guessedConstraints = 0 
00288                                 );
00289 
00310         returnValue hotstart(   const char* const g_file,                       
00311                                 const char* const lb_file,                      
00313                                 const char* const ub_file,                      
00315                                 const char* const lbA_file,                      
00317                                 const char* const ubA_file,                      
00319                                 int& nWSR,                                      
00321                                 real_t* const cputime = 0,                      
00323                                 const Bounds* const guessedBounds = 0,          
00325                                 const Constraints* const guessedConstraints = 0 
00327                                 );
00328 
00329 
00335         returnValue solveCurrentEQP (   const int n_rhs,            
00336                                         const real_t* g_in,         
00337                                         const real_t* lb_in,        
00339                                         const real_t* ub_in,        
00341                                         const real_t* lbA_in,       
00343                                         const real_t* ubA_in,       
00344                                         real_t* x_out,              
00345                                         real_t* y_out               
00346                                         );
00347 
00351         virtual returnValue getWorkingSet(  real_t* workingSet      
00352                                             );
00353 
00357         virtual returnValue getWorkingSetBounds(    real_t* workingSetB     
00358                                                     );
00359 
00363         virtual returnValue getWorkingSetConstraints(   real_t* workingSetC 
00364                                                         );
00365 
00366 
00370         inline returnValue getConstraints(  Constraints& _constraints   
00371                                             ) const;
00372 
00373 
00376         inline int getNC( ) const;
00377 
00380         inline int getNEC( ) const;
00381 
00384         inline int getNAC( ) const;
00385 
00388         inline int getNIAC( ) const;
00389 
00392         virtual int getNZ( ) const;
00393 
00394 
00398         virtual returnValue getDualSolution(    real_t* const yOpt  
00399                                                 ) const;
00400 
00401 
00404         returnValue setConstraintProduct(   ConstraintProduct* const _constraintProduct
00405                                             );
00406 
00407 
00410         virtual returnValue printProperties( );
00411 
00412 
00413     /*
00414      *  PROTECTED MEMBER FUNCTIONS
00415      */
00416     protected:
00419         returnValue clear( );
00420 
00423         returnValue copy(   const QProblem& rhs 
00424                             );
00425 
00438         returnValue solveInitialQP( const real_t* const xOpt,                       
00439                                     const real_t* const yOpt,                       
00440                                     const Bounds* const guessedBounds,              
00441                                     const Constraints* const guessedConstraints,    
00442                                     const real_t* const _R,                         
00443                                     int& nWSR,                                      
00445                                     real_t* const cputime                           
00447                                     );
00448 
00461         returnValue solveQP(    const real_t* const g_new,          
00462                                 const real_t* const lb_new,         
00464                                 const real_t* const ub_new,         
00466                                 const real_t* const lbA_new,        
00468                                 const real_t* const ubA_new,        
00470                                 int& nWSR,                          
00472                                 real_t* const cputime,              
00474                                 int  nWSRperformed = 0,             
00478                                 BooleanType isFirstCall = BT_TRUE   
00479                                 );
00480 
00481 
00494         returnValue solveRegularisedQP( const real_t* const g_new,          
00495                                         const real_t* const lb_new,         
00497                                         const real_t* const ub_new,         
00499                                         const real_t* const lbA_new,        
00501                                         const real_t* const ubA_new,        
00503                                         int& nWSR,                          
00505                                         real_t* const cputime,              
00507                                         int  nWSRperformed = 0,             
00510                                         BooleanType isFirstCall = BT_TRUE   
00511                                         );
00512 
00513 
00517         virtual returnValue setupSubjectToType( );
00518 
00522         using QProblemB::setupSubjectToType;
00523         virtual returnValue setupSubjectToType( const real_t* const lb_new,     
00524                                                 const real_t* const ub_new,     
00525                                                 const real_t* const lbA_new,    
00526                                                 const real_t* const ubA_new     
00527                                                 );
00528 
00535         returnValue computeProjectedCholesky( );
00536 
00542         virtual returnValue setupInitialCholesky( );
00543 
00547         returnValue setupTQfactorisation( );
00548 
00549 
00556         returnValue obtainAuxiliaryWorkingSet(  const real_t* const xOpt,                       
00558                                                 const real_t* const yOpt,                       
00560                                                 const Bounds* const guessedBounds,              
00561                                                 const Constraints* const guessedConstraints,    
00562                                                 Bounds* auxiliaryBounds,                        
00564                                                 Constraints* auxiliaryConstraints               
00566                                                 ) const;
00567 
00576         returnValue setupAuxiliaryWorkingSet(   const Bounds* const auxiliaryBounds,            
00577                                                 const Constraints* const auxiliaryConstraints,  
00578                                                 BooleanType setupAfresh                         
00580                                                 );
00581 
00584         returnValue setupAuxiliaryQPsolution(   const real_t* const xOpt,           
00586                                                 const real_t* const yOpt            
00588                                                 );
00589 
00594         returnValue setupAuxiliaryQPgradient( );
00595 
00601         returnValue setupAuxiliaryQPbounds( const Bounds* const auxiliaryBounds,            
00602                                             const Constraints* const auxiliaryConstraints,  
00603                                             BooleanType useRelaxation                       
00604                                             );
00605 
00606 
00612         returnValue addConstraint(  int number,                 
00613                                     SubjectToStatus C_status,   
00614                                     BooleanType updateCholesky, 
00615                                     BooleanType ensureLI = BT_TRUE  
00616                                     );
00617 
00623         returnValue addConstraint_checkLI(  int number          
00624                                             );
00625 
00634         returnValue addConstraint_ensureLI( int number,                 
00635                                             SubjectToStatus C_status    
00636                                             );
00637 
00643         returnValue addBound(   int number,                 
00644                                 SubjectToStatus B_status,   
00645                                 BooleanType updateCholesky, 
00646                                 BooleanType ensureLI = BT_TRUE  
00647                                 );
00648 
00653         returnValue addBound_checkLI(   int number          
00654                                         );
00655 
00664         returnValue addBound_ensureLI(  int number,                 
00665                                         SubjectToStatus B_status    
00666                                         );
00667 
00673         returnValue removeConstraint(   int number,                             
00674                                         BooleanType updateCholesky,             
00675                                         BooleanType allowFlipping = BT_FALSE,   
00676                                         BooleanType ensureNZC = BT_FALSE        
00677                                         );
00678 
00684         returnValue removeBound(    int number,                             
00685                                     BooleanType updateCholesky,             
00686                                     BooleanType allowFlipping = BT_FALSE,   
00687                                     BooleanType ensureNZC = BT_FALSE        
00688                                     );
00689 
00690 
00694         returnValue performPlainRatioTest(  int nIdx,                           
00695                                             const int* const idxList,           
00696                                             const real_t* const num,            
00697                                             const real_t* const den,            
00698                                             real_t epsNum,                      
00699                                             real_t epsDen,                      
00700                                             real_t& t,                          
00701                                             int& BC_idx                         
00702                                             ) const;
00703 
00704 
00708         returnValue ensureNonzeroCurvature(
00709                 BooleanType removeBoundNotConstraint,   
00710                 int remIdx,                             
00711                 BooleanType &exchangeHappened,          
00712                 BooleanType &addBoundNotConstraint,     
00713                 int &addIdx,                            
00714                 SubjectToStatus &addStatus              
00715                 );
00716 
00717 
00721         returnValue backsolveT( const real_t* const b,  
00722                                 BooleanType transposed, 
00723                                 real_t* const a         
00724                                 ) const;
00725 
00726 
00729         returnValue determineDataShift( const real_t* const g_new,  
00730                                         const real_t* const lbA_new,
00731                                         const real_t* const ubA_new,
00732                                         const real_t* const lb_new, 
00733                                         const real_t* const ub_new, 
00734                                         real_t* const delta_g,      
00735                                         real_t* const delta_lbA,    
00736                                         real_t* const delta_ubA,    
00737                                         real_t* const delta_lb,     
00738                                         real_t* const delta_ub,     
00739                                         BooleanType& Delta_bC_isZero,
00740                                         BooleanType& Delta_bB_isZero
00741                                         );
00742 
00747         returnValue determineStepDirection( const real_t* const delta_g,    
00748                                             const real_t* const delta_lbA,  
00749                                             const real_t* const delta_ubA,  
00750                                             const real_t* const delta_lb,   
00751                                             const real_t* const delta_ub,   
00752                                             BooleanType Delta_bC_isZero,    
00753                                             BooleanType Delta_bB_isZero,    
00754                                             real_t* const delta_xFX,        
00755                                             real_t* const delta_xFR,        
00756                                             real_t* const delta_yAC,        
00757                                             real_t* const delta_yFX         
00758                                             );
00759 
00765         returnValue performStep(    const real_t* const delta_g,        
00766                                     const real_t* const delta_lbA,      
00767                                     const real_t* const delta_ubA,      
00768                                     const real_t* const delta_lb,       
00769                                     const real_t* const delta_ub,       
00770                                     const real_t* const delta_xFX,      
00771                                     const real_t* const delta_xFR,      
00772                                     const real_t* const delta_yAC,      
00773                                     const real_t* const delta_yFX,      
00774                                     int& BC_idx,                        
00775                                     SubjectToStatus& BC_status,         
00776                                     BooleanType& BC_isBound             
00777                                     );
00778 
00783         returnValue changeActiveSet(    int BC_idx,                         
00784                                         SubjectToStatus BC_status,          
00785                                         BooleanType BC_isBound              
00786                                         );
00787 
00788 
00792         real_t getRelativeHomotopyLength(   const real_t* const g_new,      
00793                                             const real_t* const lb_new,     
00794                                             const real_t* const ub_new,     
00795                                             const real_t* const lbA_new,    
00796                                             const real_t* const ubA_new     
00797                                             );
00798 
00799 
00803         virtual returnValue performRamping( );
00804 
00805 
00807         returnValue updateFarBounds(    real_t curFarBound,                 
00808                                         int nRamp,                          
00809                                         const real_t* const lb_new,         
00810                                         real_t* const lb_new_far,           
00811                                         const real_t* const ub_new,         
00812                                         real_t* const ub_new_far,           
00813                                         const real_t* const lbA_new,        
00814                                         real_t* const lbA_new_far,          
00815                                         const real_t* const ubA_new,        
00816                                         real_t* const ubA_new_far           
00817                                         ) const;
00818 
00819 
00822         virtual returnValue performDriftCorrection( );
00823 
00824 
00831         using QProblemB::setupAuxiliaryQP;
00832         virtual returnValue setupAuxiliaryQP(   const Bounds* const guessedBounds,          
00833                                                 const Constraints* const guessedConstraints 
00834                                                 );
00835 
00840         BooleanType shallRefactorise(   const Bounds* const guessedBounds,          
00841                                         const Constraints* const guessedConstraints 
00842                                         ) const;
00843 
00848         returnValue setupQPdata(    SymmetricMatrix *_H,        
00850                                     const real_t* const _g,     
00851                                     Matrix *_A,                 
00852                                     const real_t* const _lb,    
00854                                     const real_t* const _ub,    
00856                                     const real_t* const _lbA,   
00858                                     const real_t* const _ubA    
00860                                     );
00861 
00862 
00869         returnValue setupQPdata(    const real_t* const _H,     
00871                                     const real_t* const _g,     
00872                                     const real_t* const _A,     
00873                                     const real_t* const _lb,    
00875                                     const real_t* const _ub,    
00877                                     const real_t* const _lbA,   
00879                                     const real_t* const _ubA    
00881                                     );
00882 
00891         returnValue setupQPdataFromFile(    const char* const H_file,   
00893                                             const char* const g_file,   
00894                                             const char* const A_file,   
00895                                             const char* const lb_file,  
00897                                             const char* const ub_file,  
00899                                             const char* const lbA_file, 
00901                                             const char* const ubA_file  
00903                                             );
00904 
00910         returnValue loadQPvectorsFromFile(  const char* const g_file,   
00911                                             const char* const lb_file,  
00913                                             const char* const ub_file,  
00915                                             const char* const lbA_file, 
00917                                             const char* const ubA_file, 
00919                                             real_t* const g_new,        
00920                                             real_t* const lb_new,       
00921                                             real_t* const ub_new,       
00922                                             real_t* const lbA_new,      
00923                                             real_t* const ubA_new       
00924                                             ) const;
00925 
00926 
00929         returnValue printIteration( int iter,                           
00930                                     int BC_idx,                         
00931                                     SubjectToStatus BC_status,          
00932                                     BooleanType BC_isBound,             
00933                                     real_t homotopyLength,              
00934                                     BooleanType isFirstCall = BT_TRUE   
00935                                     );
00936 
00937 
00942         inline returnValue setA(    Matrix *A_new   
00943                                     );
00944 
00949         inline returnValue setA(    const real_t* const A_new   
00950                                     );
00951 
00952 
00956         inline returnValue setLBA(  const real_t* const lbA_new 
00957                                     );
00958 
00963         inline returnValue setLBA(  int number,     
00964                                     real_t value    
00965                                     );
00966 
00970         inline returnValue setUBA(  const real_t* const ubA_new 
00971                                     );
00972 
00977         inline returnValue setUBA(  int number,     
00978                                     real_t value    
00979                                     );
00980 
00981 
00986         returnValue dropInfeasibles (   int BC_number,              
00987                                         SubjectToStatus BC_status,  
00988                                         BooleanType BC_isBound,     
00989                                         real_t *xiB,                
00990                                         real_t *xiC                 
00991                                         );
00992 
00998                 returnValue areBoundsConsistent(const real_t* const lb,  
00999                                                 const real_t* const ub,  
01000                                                 const real_t* const lbA, 
01001                                                 const real_t* const ubA  
01002                                                 ) const;
01003 
01004 
01005     public:
01009         returnValue writeQpDataIntoMatFile( const char* const filename  
01010                                             ) const;
01011 
01015         returnValue writeQpWorkspaceIntoMatFile(    const char* const filename  
01016                                                     );
01017 
01018 
01019 
01020     /*
01021      *  PROTECTED MEMBER VARIABLES
01022      */
01023     protected:
01024         BooleanType freeConstraintMatrix;       
01025         Matrix* A;                              
01027         real_t* lbA;                            
01028         real_t* ubA;                            
01030         Constraints constraints;                
01032         real_t* T;                              
01033         real_t* Q;                              
01034         int sizeT;                              
01036         real_t* Ax;                             
01038         real_t* Ax_l;                           
01040         real_t* Ax_u;                           
01043         ConstraintProduct* constraintProduct;   
01045         real_t* tempA;                          
01046         real_t* tempB;                          
01047         real_t* ZFR_delta_xFRz;                 
01048         real_t* delta_xFRy;                     
01049         real_t* delta_xFRz;                     
01050         real_t* delta_yAC_TMP;                  
01051 };
01052 
01053 
01054 END_NAMESPACE_QPOASES
01055 
01056 #include <qpOASES/QProblem.ipp>
01057 
01058 #endif  /* QPOASES_QPROBLEM_HPP */
01059 
01060 
01061 /*
01062  *  end of file
01063  */