qpOASES  3.2.1
An Implementation of the Online Active Set Strategy
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-2017 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 #include <qpOASES/Matrices.hpp>
00045 
00046 
00047 BEGIN_NAMESPACE_QPOASES
00048 
00049 
00061 class QProblem : public QProblemB
00062 {
00063     /* allow SolutionAnalysis class to access private members */
00064     friend class SolutionAnalysis;
00065 
00066     /*
00067      *  PUBLIC MEMBER FUNCTIONS
00068      */
00069     public:
00071         QProblem( );
00072 
00078         QProblem(   int_t _nV,                              
00079                     int_t _nC,                              
00080                     HessianType _hessianType = HST_UNKNOWN, 
00081                     BooleanType allocDenseMats = BT_TRUE    
00082                     );
00083 
00085         QProblem(   const QProblem& rhs     
00086                     );
00087 
00089         virtual ~QProblem( );
00090 
00092         virtual QProblem& operator=(    const QProblem& rhs 
00093                                 );
00094 
00095 
00099         virtual returnValue reset( );
00100 
00101 
00123         returnValue init(   SymmetricMatrix *_H,                            
00124                             const real_t* const _g,                         
00125                             Matrix *_A,                                     
00126                             const real_t* const _lb,                        
00128                             const real_t* const _ub,                        
00130                             const real_t* const _lbA,                       
00132                             const real_t* const _ubA,                       
00134                             int_t& nWSR,                                    
00136                             real_t* const cputime = 0,                      
00138                             const real_t* const xOpt = 0,                   
00140                             const real_t* const yOpt = 0,                   
00142                             const Bounds* const guessedBounds = 0,          
00144                             const Constraints* const guessedConstraints = 0,
00146                             const real_t* const _R = 0                      
00150                             );
00151 
00152 
00174         returnValue init(   const real_t* const _H,                         
00176                             const real_t* const _g,                         
00177                             const real_t* const _A,                         
00178                             const real_t* const _lb,                        
00180                             const real_t* const _ub,                        
00182                             const real_t* const _lbA,                       
00184                             const real_t* const _ubA,                       
00186                             int_t& nWSR,                                    
00188                             real_t* const cputime = 0,                      
00190                             const real_t* const xOpt = 0,                   
00192                             const real_t* const yOpt = 0,                   
00194                             const Bounds* const guessedBounds = 0,          
00196                             const Constraints* const guessedConstraints = 0,
00198                             const real_t* const _R = 0                      
00202                             );
00203 
00226         returnValue init(   const char* const H_file,                       
00228                             const char* const g_file,                       
00229                             const char* const A_file,                       
00230                             const char* const lb_file,                      
00232                             const char* const ub_file,                      
00234                             const char* const lbA_file,                     
00236                             const char* const ubA_file,                     
00238                             int_t& nWSR,                                    
00240                             real_t* const cputime = 0,                      
00242                             const real_t* const xOpt = 0,                   
00244                             const real_t* const yOpt = 0,                   
00246                             const Bounds* const guessedBounds = 0,          
00248                             const Constraints* const guessedConstraints = 0,
00250                             const char* const R_file = 0                    
00253                             );
00254 
00255 
00273         returnValue hotstart(   const real_t* const g_new,                      
00274                                 const real_t* const lb_new,                     
00276                                 const real_t* const ub_new,                     
00278                                 const real_t* const lbA_new,                    
00280                                 const real_t* const ubA_new,                    
00282                                 int_t& nWSR,                                    
00284                                 real_t* const cputime = 0,                      
00286                                 const Bounds* const guessedBounds = 0,          
00288                                 const Constraints* const guessedConstraints = 0 
00290                                 );
00291 
00312         returnValue hotstart(   const char* const g_file,                       
00313                                 const char* const lb_file,                      
00315                                 const char* const ub_file,                      
00317                                 const char* const lbA_file,                     
00319                                 const char* const ubA_file,                     
00321                                 int_t& nWSR,                                    
00323                                 real_t* const cputime = 0,                      
00325                                 const Bounds* const guessedBounds = 0,          
00327                                 const Constraints* const guessedConstraints = 0 
00329                                 );
00330 
00331 
00337         returnValue solveCurrentEQP (   const int_t n_rhs,          
00338                                         const real_t* g_in,         
00339                                         const real_t* lb_in,        
00341                                         const real_t* ub_in,        
00343                                         const real_t* lbA_in,       
00345                                         const real_t* ubA_in,       
00346                                         real_t* x_out,              
00347                                         real_t* y_out               
00348                                         );
00349 
00353         virtual returnValue getWorkingSet(  real_t* workingSet      
00354                                             );
00355 
00359         virtual returnValue getWorkingSetBounds(    real_t* workingSetB     
00360                                                     );
00361 
00365         virtual returnValue getWorkingSetConstraints(   real_t* workingSetC 
00366                                                         );
00367 
00368 
00372         inline returnValue getConstraints(  Constraints& _constraints   
00373                                             ) const;
00374 
00375 
00378         inline int_t getNC( ) const;
00379 
00382         inline int_t getNEC( ) const;
00383 
00386         inline int_t getNAC( ) const;
00387 
00390         inline int_t getNIAC( ) const;
00391 
00394         virtual int_t getNZ( ) const;
00395 
00396 
00400         virtual returnValue getDualSolution(    real_t* const yOpt  
00401                                                 ) const;
00402 
00403 
00406         returnValue setConstraintProduct(   ConstraintProduct* const _constraintProduct
00407                                             );
00408 
00409 
00412         virtual returnValue printProperties( );
00413 
00416         returnValue getFreeVariablesFlags( BooleanType* varIsFree );
00417 
00418 
00419     /*
00420      *  PROTECTED MEMBER FUNCTIONS
00421      */
00422     protected:
00425         returnValue clear( );
00426 
00429         returnValue copy(   const QProblem& rhs 
00430                             );
00431 
00444         returnValue solveInitialQP( const real_t* const xOpt,                       
00445                                     const real_t* const yOpt,                       
00446                                     const Bounds* const guessedBounds,              
00447                                     const Constraints* const guessedConstraints,    
00448                                     const real_t* const _R,                         
00449                                     int_t& nWSR,                                    
00451                                     real_t* const cputime                           
00453                                     );
00454 
00467         returnValue solveQP(    const real_t* const g_new,          
00468                                 const real_t* const lb_new,         
00470                                 const real_t* const ub_new,         
00472                                 const real_t* const lbA_new,        
00474                                 const real_t* const ubA_new,        
00476                                 int_t& nWSR,                        
00478                                 real_t* const cputime,              
00480                                 int_t nWSRperformed = 0,            
00484                                 BooleanType isFirstCall = BT_TRUE   
00485                                 );
00486 
00487 
00500         returnValue solveRegularisedQP( const real_t* const g_new,          
00501                                         const real_t* const lb_new,         
00503                                         const real_t* const ub_new,         
00505                                         const real_t* const lbA_new,        
00507                                         const real_t* const ubA_new,        
00509                                         int_t& nWSR,                        
00511                                         real_t* const cputime,              
00513                                         int_t nWSRperformed = 0,            
00516                                         BooleanType isFirstCall = BT_TRUE   
00517                                         );
00518 
00519 
00522         /*  \return SUCCESSFUL_RETURN \n
00523                     RET_HOTSTART_FAILED */
00524         virtual returnValue updateActivitiesForHotstart( const real_t* const lb_new,    
00525                                                          const real_t* const ub_new,    
00526                                                          const real_t* const lbA_new,   
00527                                                          const real_t* const ubA_new    
00528                                                          );
00529 
00530 
00534         virtual returnValue setupSubjectToType( );
00535 
00539         using QProblemB::setupSubjectToType;
00540         virtual returnValue setupSubjectToType( const real_t* const lb_new,     
00541                                                 const real_t* const ub_new,     
00542                                                 const real_t* const lbA_new,    
00543                                                 const real_t* const ubA_new     
00544                                                 );
00545 
00552         virtual returnValue computeProjectedCholesky( );
00553 
00559         virtual returnValue setupInitialCholesky( );
00560 
00564         virtual returnValue setupTQfactorisation( );
00565 
00566 
00573         returnValue obtainAuxiliaryWorkingSet(  const real_t* const xOpt,                       
00575                                                 const real_t* const yOpt,                       
00577                                                 const Bounds* const guessedBounds,              
00578                                                 const Constraints* const guessedConstraints,    
00579                                                 Bounds* auxiliaryBounds,                        
00581                                                 Constraints* auxiliaryConstraints               
00583                                                 ) const;
00584 
00593         virtual returnValue setupAuxiliaryWorkingSet(   const Bounds* const auxiliaryBounds,            
00594                                                 const Constraints* const auxiliaryConstraints,  
00595                                                 BooleanType setupAfresh                         
00597                                                 );
00598 
00601         returnValue setupAuxiliaryQPsolution(   const real_t* const xOpt,           
00603                                                 const real_t* const yOpt            
00605                                                 );
00606 
00611         returnValue setupAuxiliaryQPgradient( );
00612 
00618         returnValue setupAuxiliaryQPbounds( const Bounds* const auxiliaryBounds,            
00619                                             const Constraints* const auxiliaryConstraints,  
00620                                             BooleanType useRelaxation                       
00621                                             );
00622 
00623 
00629         virtual returnValue addConstraint(  int_t number,                   
00630                                             SubjectToStatus C_status,       
00631                                             BooleanType updateCholesky,     
00632                                             BooleanType ensureLI = BT_TRUE  
00633                                             );
00634 
00640         virtual returnValue addConstraint_checkLI(  int_t number    
00641                                                     );
00642 
00651         virtual returnValue addConstraint_ensureLI( int_t number,               
00652                                                     SubjectToStatus C_status    
00653                                                     );
00654 
00660         virtual returnValue addBound(   int_t number,                   
00661                                         SubjectToStatus B_status,       
00662                                         BooleanType updateCholesky,     
00663                                         BooleanType ensureLI = BT_TRUE  
00664                                         );
00665 
00670         virtual returnValue addBound_checkLI(   int_t number    
00671                                                 );
00672 
00681         virtual returnValue addBound_ensureLI(  int_t number,               
00682                                                 SubjectToStatus B_status    
00683                                                 );
00684 
00690         virtual returnValue removeConstraint(   int_t number,                           
00691                                                 BooleanType updateCholesky,             
00692                                                 BooleanType allowFlipping = BT_FALSE,   
00693                                                 BooleanType ensureNZC = BT_FALSE        
00694                                                 );
00695 
00701         virtual returnValue removeBound(    int_t number,                           
00702                                             BooleanType updateCholesky,             
00703                                             BooleanType allowFlipping = BT_FALSE,   
00704                                             BooleanType ensureNZC = BT_FALSE        
00705                                             );
00706 
00707 
00711         returnValue performPlainRatioTest(  int_t nIdx,                         
00712                                             const int_t* const idxList,         
00713                                             const real_t* const num,            
00714                                             const real_t* const den,            
00715                                             real_t epsNum,                      
00716                                             real_t epsDen,                      
00717                                             real_t& t,                          
00718                                             int_t& BC_idx                       
00719                                             ) const;
00720 
00721 
00725         returnValue ensureNonzeroCurvature(
00726                 BooleanType removeBoundNotConstraint,   
00727                 int_t remIdx,                           
00728                 BooleanType &exchangeHappened,          
00729                 BooleanType &addBoundNotConstraint,     
00730                 int_t &addIdx,                          
00731                 SubjectToStatus &addStatus              
00732                 );
00733 
00734 
00738         virtual returnValue backsolveT( const real_t* const b,  
00739                                 BooleanType transposed, 
00740                                 real_t* const a         
00741                                 ) const;
00742 
00743 
00746         returnValue determineDataShift( const real_t* const g_new,  
00747                                         const real_t* const lbA_new,
00748                                         const real_t* const ubA_new,
00749                                         const real_t* const lb_new, 
00750                                         const real_t* const ub_new, 
00751                                         real_t* const delta_g,      
00752                                         real_t* const delta_lbA,    
00753                                         real_t* const delta_ubA,    
00754                                         real_t* const delta_lb,     
00755                                         real_t* const delta_ub,     
00756                                         BooleanType& Delta_bC_isZero,
00757                                         BooleanType& Delta_bB_isZero
00758                                         );
00759 
00764         virtual returnValue determineStepDirection( const real_t* const delta_g,    
00765                                             const real_t* const delta_lbA,  
00766                                             const real_t* const delta_ubA,  
00767                                             const real_t* const delta_lb,   
00768                                             const real_t* const delta_ub,   
00769                                             BooleanType Delta_bC_isZero,    
00770                                             BooleanType Delta_bB_isZero,    
00771                                             real_t* const delta_xFX,        
00772                                             real_t* const delta_xFR,        
00773                                             real_t* const delta_yAC,        
00774                                             real_t* const delta_yFX         
00775                                             );
00776 
00782         returnValue performStep(    const real_t* const delta_g,        
00783                                     const real_t* const delta_lbA,      
00784                                     const real_t* const delta_ubA,      
00785                                     const real_t* const delta_lb,       
00786                                     const real_t* const delta_ub,       
00787                                     const real_t* const delta_xFX,      
00788                                     const real_t* const delta_xFR,      
00789                                     const real_t* const delta_yAC,      
00790                                     const real_t* const delta_yFX,      
00791                                     int_t& BC_idx,                      
00792                                     SubjectToStatus& BC_status,         
00793                                     BooleanType& BC_isBound             
00794                                     );
00795 
00800         returnValue changeActiveSet(    int_t BC_idx,                       
00801                                         SubjectToStatus BC_status,          
00802                                         BooleanType BC_isBound              
00803                                         );
00804 
00805 
00809         real_t getRelativeHomotopyLength(   const real_t* const g_new,      
00810                                             const real_t* const lb_new,     
00811                                             const real_t* const ub_new,     
00812                                             const real_t* const lbA_new,    
00813                                             const real_t* const ubA_new     
00814                                             );
00815 
00816 
00820         virtual returnValue performRamping( );
00821 
00822 
00824         returnValue updateFarBounds(    real_t curFarBound,                 
00825                                         int_t nRamp,                        
00826                                         const real_t* const lb_new,         
00827                                         real_t* const lb_new_far,           
00828                                         const real_t* const ub_new,         
00829                                         real_t* const ub_new_far,           
00830                                         const real_t* const lbA_new,        
00831                                         real_t* const lbA_new_far,          
00832                                         const real_t* const ubA_new,        
00833                                         real_t* const ubA_new_far           
00834                                         ) const;
00835 
00836 
00839         virtual returnValue performDriftCorrection( );
00840 
00841 
00848         using QProblemB::setupAuxiliaryQP;
00849         virtual returnValue setupAuxiliaryQP(   const Bounds* const guessedBounds,          
00850                                                 const Constraints* const guessedConstraints 
00851                                                 );
00852 
00857         BooleanType shallRefactorise(   const Bounds* const guessedBounds,          
00858                                         const Constraints* const guessedConstraints 
00859                                         ) const;
00860 
00865         returnValue setupQPdata(    SymmetricMatrix *_H,        
00867                                     const real_t* const _g,     
00868                                     Matrix *_A,                 
00869                                     const real_t* const _lb,    
00871                                     const real_t* const _ub,    
00873                                     const real_t* const _lbA,   
00875                                     const real_t* const _ubA    
00877                                     );
00878 
00879 
00886         returnValue setupQPdata(    const real_t* const _H,     
00888                                     const real_t* const _g,     
00889                                     const real_t* const _A,     
00890                                     const real_t* const _lb,    
00892                                     const real_t* const _ub,    
00894                                     const real_t* const _lbA,   
00896                                     const real_t* const _ubA    
00898                                     );
00899 
00908         returnValue setupQPdataFromFile(    const char* const H_file,   
00910                                             const char* const g_file,   
00911                                             const char* const A_file,   
00912                                             const char* const lb_file,  
00914                                             const char* const ub_file,  
00916                                             const char* const lbA_file, 
00918                                             const char* const ubA_file  
00920                                             );
00921 
00927         returnValue loadQPvectorsFromFile(  const char* const g_file,   
00928                                             const char* const lb_file,  
00930                                             const char* const ub_file,  
00932                                             const char* const lbA_file, 
00934                                             const char* const ubA_file, 
00936                                             real_t* const g_new,        
00937                                             real_t* const lb_new,       
00938                                             real_t* const ub_new,       
00939                                             real_t* const lbA_new,      
00940                                             real_t* const ubA_new       
00941                                             ) const;
00942 
00943 
00946         returnValue printIteration( int_t iter,                         
00947                                     int_t BC_idx,                       
00948                                     SubjectToStatus BC_status,          
00949                                     BooleanType BC_isBound,             
00950                                     real_t homotopyLength,              
00951                                     BooleanType isFirstCall = BT_TRUE   
00952                                     );
00953 
00954 
00959         inline returnValue setA(    Matrix *A_new   
00960                                     );
00961 
00966         inline returnValue setA(    const real_t* const A_new   
00967                                     );
00968 
00969 
00973         inline returnValue setLBA(  const real_t* const lbA_new 
00974                                     );
00975 
00980         inline returnValue setLBA(  int_t number,   
00981                                     real_t value    
00982                                     );
00983 
00987         inline returnValue setUBA(  const real_t* const ubA_new 
00988                                     );
00989 
00994         inline returnValue setUBA(  int_t number,   
00995                                     real_t value    
00996                                     );
00997 
00998 
01003         returnValue dropInfeasibles (   int_t BC_number,            
01004                                         SubjectToStatus BC_status,  
01005                                         BooleanType BC_isBound,     
01006                                         real_t *xiB,                
01007                                         real_t *xiC                 
01008                                         );
01009 
01015                 returnValue areBoundsConsistent(const real_t* const lb,  
01016                                                 const real_t* const ub,  
01017                                                 const real_t* const lbA, 
01018                                                 const real_t* const ubA  
01019                                                 ) const;
01020 
01021 
01022     public:
01026         returnValue writeQpDataIntoMatFile( const char* const filename  
01027                                             ) const;
01028 
01032         returnValue writeQpWorkspaceIntoMatFile(    const char* const filename  
01033                                                     );
01034 
01035 
01036 
01037     /*
01038      *  PROTECTED MEMBER VARIABLES
01039      */
01040     protected:
01041         BooleanType freeConstraintMatrix;       
01042         Matrix* A;                              
01044         real_t* lbA;                            
01045         real_t* ubA;                            
01047         Constraints constraints;                
01049         real_t* T;                              
01050         real_t* Q;                              
01051         int_t sizeT;                            
01053         real_t* Ax;                             
01055         real_t* Ax_l;                           
01057         real_t* Ax_u;                           
01060         ConstraintProduct* constraintProduct;   
01062         real_t* tempA;                          
01063         real_t* tempB;                          
01064         real_t* ZFR_delta_xFRz;                 
01065         real_t* delta_xFRy;                     
01066         real_t* delta_xFRz;                     
01067         real_t* delta_yAC_TMP;                  
01069         real_t* tempC;                          
01070 };
01071 
01072 
01073 END_NAMESPACE_QPOASES
01074 
01075 #include <qpOASES/QProblem.ipp>
01076 
01077 #endif  /* QPOASES_QPROBLEM_HPP */
01078 
01079 
01080 /*
01081  *  end of file
01082  */