qpOASES  3.0.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-2014 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 
00112         returnValue init(   SymmetricMatrix *_H,        
00113                             const real_t* const _g,     
00114                             Matrix *_A,                 
00115                             const real_t* const _lb,    
00117                             const real_t* const _ub,    
00119                             const real_t* const _lbA,   
00121                             const real_t* const _ubA,   
00123                             int& nWSR,                  
00125                             real_t* const cputime = 0   
00127                             );
00128 
00129 
00142         returnValue init(   const real_t* const _H,     
00144                             const real_t* const _g,     
00145                             const real_t* const _A,     
00146                             const real_t* const _lb,    
00148                             const real_t* const _ub,    
00150                             const real_t* const _lbA,   
00152                             const real_t* const _ubA,   
00154                             int& nWSR,                  
00156                             real_t* const cputime = 0   
00158                             );
00159 
00172         returnValue init(   const char* const H_file,   
00174                             const char* const g_file,   
00175                             const char* const A_file,   
00176                             const char* const lb_file,  
00178                             const char* const ub_file,  
00180                             const char* const lbA_file, 
00182                             const char* const ubA_file, 
00184                             int& nWSR,                  
00186                             real_t* const cputime = 0   
00188                             );
00189 
00209         returnValue init(   SymmetricMatrix *_H,                        
00210                             const real_t* const _g,                     
00211                             Matrix *_A,                                 
00212                             const real_t* const _lb,                    
00214                             const real_t* const _ub,                    
00216                             const real_t* const _lbA,                   
00218                             const real_t* const _ubA,                   
00220                             int& nWSR,                                  
00222                             real_t* const cputime,                      
00224                             const real_t* const xOpt,                   
00226                             const real_t* const yOpt,                   
00228                             const Bounds* const guessedBounds,          
00229                             const Constraints* const guessedConstraints 
00230                             );
00231 
00251         returnValue init(   const real_t* const _H,                     
00253                             const real_t* const _g,                     
00254                             const real_t* const _A,                     
00255                             const real_t* const _lb,                    
00257                             const real_t* const _ub,                    
00259                             const real_t* const _lbA,                   
00261                             const real_t* const _ubA,                   
00263                             int& nWSR,                                  
00265                             real_t* const cputime,                      
00267                             const real_t* const xOpt,                   
00269                             const real_t* const yOpt,                   
00271                             const Bounds* const guessedBounds,          
00272                             const Constraints* const guessedConstraints 
00273                             );
00274 
00294         returnValue init(   const char* const H_file,                   
00296                             const char* const g_file,                   
00297                             const char* const A_file,                   
00298                             const char* const lb_file,                  
00300                             const char* const ub_file,                  
00302                             const char* const lbA_file,                 
00304                             const char* const ubA_file,                 
00306                             int& nWSR,                                  
00308                             real_t* const cputime,                      
00310                             const real_t* const xOpt,                   
00312                             const real_t* const yOpt,                   
00314                             const Bounds* const guessedBounds,          
00315                             const Constraints* const guessedConstraints 
00316                             );
00317 
00318 
00332         returnValue hotstart(   const real_t* const g_new,      
00333                                 const real_t* const lb_new,     
00335                                 const real_t* const ub_new,     
00337                                 const real_t* const lbA_new,    
00339                                 const real_t* const ubA_new,    
00341                                 int& nWSR,                      
00343                                 real_t* const cputime = 0       
00345                                 );
00346 
00363         returnValue hotstart(   const char* const g_file,   
00364                                 const char* const lb_file,  
00366                                 const char* const ub_file,  
00368                                 const char* const lbA_file, 
00370                                 const char* const ubA_file, 
00372                                 int& nWSR,                  
00374                                 real_t* const cputime = 0       
00376                                 );
00377 
00392         returnValue hotstart(   const real_t* const g_new,                  
00393                                 const real_t* const lb_new,                 
00395                                 const real_t* const ub_new,                 
00397                                 const real_t* const lbA_new,                
00399                                 const real_t* const ubA_new,                
00401                                 int& nWSR,                                  
00403                                 real_t* const cputime,                      
00405                                 const Bounds* const guessedBounds,          
00407                                 const Constraints* const guessedConstraints 
00409                                 );
00410 
00428         returnValue hotstart(   const char* const g_file,                   
00429                                 const char* const lb_file,                  
00431                                 const char* const ub_file,                  
00433                                 const char* const lbA_file,                 
00435                                 const char* const ubA_file,                 
00437                                 int& nWSR,                                  
00439                                 real_t* const cputime,                      
00441                                 const Bounds* const guessedBounds,          
00443                                 const Constraints* const guessedConstraints 
00445                                 );
00446 
00451         returnValue solveCurrentEQP (   const int n_rhs,            
00452                                         const real_t* g_in,         
00453                                         const real_t* lb_in,        
00455                                         const real_t* ub_in,        
00457                                         const real_t* lbA_in,       
00459                                         const real_t* ubA_in,       
00460                                         real_t* x_out,              
00461                                         real_t* y_out               
00462                                         );
00463 
00466         returnValue getWorkingSet(  real_t* workingSet              
00467                                     );
00468 
00472         inline returnValue getConstraints(  Constraints& _constraints   
00473                                             ) const;
00474 
00475 
00478         inline int getNC( ) const;
00479 
00482         inline int getNEC( ) const;
00483 
00486         inline int getNAC( ) const;
00487 
00490         inline int getNIAC( ) const;
00491 
00494         virtual int getNZ( ) const;
00495 
00496 
00500         virtual returnValue getDualSolution(    real_t* const yOpt  
00501                                                 ) const;
00502 
00503 
00506         returnValue setConstraintProduct(   ConstraintProduct* const _constraintProduct
00507                                             );
00508 
00509 
00512         virtual returnValue printProperties( );
00513 
00514 
00515     /*
00516      *  PROTECTED MEMBER FUNCTIONS
00517      */
00518     protected:
00521         returnValue clear( );
00522 
00525         returnValue copy(   const QProblem& rhs 
00526                             );
00527 
00540         returnValue solveInitialQP( const real_t* const xOpt,                       
00542                                     const real_t* const yOpt,                       
00544                                     const Bounds* const guessedBounds,              
00546                                     const Constraints* const guessedConstraints,    
00548                                     int& nWSR,                                      
00550                                     real_t* const cputime                           
00552                                     );
00553 
00566         returnValue solveQP(    const real_t* const g_new,      
00567                                 const real_t* const lb_new, 
00569                                 const real_t* const ub_new,     
00571                                 const real_t* const lbA_new,    
00573                                 const real_t* const ubA_new,    
00575                                 int& nWSR,                      
00577                                 real_t* const cputime,          
00579                                 int  nWSRperformed = 0          
00583                                 );
00584 
00585 
00598         returnValue solveRegularisedQP( const real_t* const g_new,      
00599                                         const real_t* const lb_new,     
00601                                         const real_t* const ub_new,     
00603                                         const real_t* const lbA_new,    
00605                                         const real_t* const ubA_new,    
00607                                         int& nWSR,                      
00609                                         real_t* const cputime,          
00611                                         int  nWSRperformed = 0          
00614                                         );
00615 
00616 
00620         virtual returnValue setupSubjectToType( );
00621 
00625         virtual returnValue setupSubjectToType( const real_t* const lb_new,     
00626                                                 const real_t* const ub_new,     
00627                                                 const real_t* const lbA_new,    
00628                                                 const real_t* const ubA_new     
00629                                                 );
00630 
00637         returnValue computeProjectedCholesky( );
00638 
00644         virtual returnValue setupInitialCholesky( );
00645 
00649         returnValue setupTQfactorisation( );
00650 
00651 
00658         returnValue obtainAuxiliaryWorkingSet(  const real_t* const xOpt,                       
00660                                                 const real_t* const yOpt,                       
00662                                                 const Bounds* const guessedBounds,              
00663                                                 const Constraints* const guessedConstraints,    
00664                                                 Bounds* auxiliaryBounds,                        
00666                                                 Constraints* auxiliaryConstraints               
00668                                                 ) const;
00669 
00678         returnValue setupAuxiliaryWorkingSet(   const Bounds* const auxiliaryBounds,            
00679                                                 const Constraints* const auxiliaryConstraints,  
00680                                                 BooleanType setupAfresh                         
00682                                                 );
00683 
00686         returnValue setupAuxiliaryQPsolution(   const real_t* const xOpt,           
00688                                                 const real_t* const yOpt            
00690                                                 );
00691 
00696         returnValue setupAuxiliaryQPgradient( );
00697 
00703         returnValue setupAuxiliaryQPbounds( const Bounds* const auxiliaryBounds,            
00704                                             const Constraints* const auxiliaryConstraints,  
00705                                             BooleanType useRelaxation                       
00706                                             );
00707 
00708 
00714         returnValue addConstraint(  int number,                 
00715                                     SubjectToStatus C_status,   
00716                                     BooleanType updateCholesky, 
00717                                     BooleanType ensureLI = BT_TRUE  
00718                                     );
00719 
00725         returnValue addConstraint_checkLI(  int number          
00726                                             );
00727 
00736         returnValue addConstraint_ensureLI( int number,                 
00737                                             SubjectToStatus C_status    
00738                                             );
00739 
00745         returnValue addBound(   int number,                 
00746                                 SubjectToStatus B_status,   
00747                                 BooleanType updateCholesky, 
00748                                 BooleanType ensureLI = BT_TRUE  
00749                                 );
00750 
00755         returnValue addBound_checkLI(   int number          
00756                                         );
00757 
00766         returnValue addBound_ensureLI(  int number,                 
00767                                         SubjectToStatus B_status    
00768                                         );
00769 
00775         returnValue removeConstraint(   int number,                             
00776                                         BooleanType updateCholesky,             
00777                                         BooleanType allowFlipping = BT_FALSE,   
00778                                         BooleanType ensureNZC = BT_FALSE        
00779                                         );
00780 
00786         returnValue removeBound(    int number,                             
00787                                     BooleanType updateCholesky,             
00788                                     BooleanType allowFlipping = BT_FALSE,   
00789                                     BooleanType ensureNZC = BT_FALSE        
00790                                     );
00791 
00792 
00796         returnValue performPlainRatioTest(  int nIdx,                           
00797                                             const int* const idxList,           
00798                                             const real_t* const num,            
00799                                             const real_t* const den,            
00800                                             real_t epsNum,                      
00801                                             real_t epsDen,                      
00802                                             real_t& t,                          
00803                                             int& BC_idx                         
00804                                             ) const;
00805 
00806 
00810         returnValue ensureNonzeroCurvature(
00811                 BooleanType removeBoundNotConstraint,   
00812                 int remIdx,                             
00813                 BooleanType &exchangeHappened,          
00814                 BooleanType &addBoundNotConstraint,     
00815                 int &addIdx,                            
00816                 SubjectToStatus &addStatus              
00817                 );
00818 
00819 
00823         returnValue backsolveT( const real_t* const b,  
00824                                 BooleanType transposed, 
00825                                 real_t* const a         
00826                                 ) const;
00827 
00828 
00831         returnValue determineDataShift( const real_t* const g_new,  
00832                                         const real_t* const lbA_new,
00833                                         const real_t* const ubA_new,
00834                                         const real_t* const lb_new, 
00835                                         const real_t* const ub_new, 
00836                                         real_t* const delta_g,      
00837                                         real_t* const delta_lbA,    
00838                                         real_t* const delta_ubA,    
00839                                         real_t* const delta_lb,     
00840                                         real_t* const delta_ub,     
00841                                         BooleanType& Delta_bC_isZero,
00842                                         BooleanType& Delta_bB_isZero
00843                                         );
00844 
00849         returnValue determineStepDirection( const real_t* const delta_g,    
00850                                             const real_t* const delta_lbA,  
00851                                             const real_t* const delta_ubA,  
00852                                             const real_t* const delta_lb,   
00853                                             const real_t* const delta_ub,   
00854                                             BooleanType Delta_bC_isZero,    
00855                                             BooleanType Delta_bB_isZero,    
00856                                             real_t* const delta_xFX,        
00857                                             real_t* const delta_xFR,        
00858                                             real_t* const delta_yAC,        
00859                                             real_t* const delta_yFX         
00860                                             );
00861 
00867         returnValue performStep(    const real_t* const delta_g,        
00868                                     const real_t* const delta_lbA,      
00869                                     const real_t* const delta_ubA,      
00870                                     const real_t* const delta_lb,       
00871                                     const real_t* const delta_ub,       
00872                                     const real_t* const delta_xFX,      
00873                                     const real_t* const delta_xFR,      
00874                                     const real_t* const delta_yAC,      
00875                                     const real_t* const delta_yFX,      
00876                                     int& BC_idx,                        
00877                                     SubjectToStatus& BC_status,         
00878                                     BooleanType& BC_isBound             
00879                                     );
00880 
00885         returnValue changeActiveSet(    int BC_idx,                         
00886                                         SubjectToStatus BC_status,          
00887                                         BooleanType BC_isBound              
00888                                         );
00889 
00890 
00894         real_t getRelativeHomotopyLength(   const real_t* const g_new,      
00895                                             const real_t* const lb_new,     
00896                                             const real_t* const ub_new,     
00897                                             const real_t* const lbA_new,    
00898                                             const real_t* const ubA_new     
00899                                             );
00900 
00901 
00905         virtual returnValue performRamping( );
00906 
00907 
00909         returnValue updateFarBounds(    real_t curFarBound,                 
00910                                         int nRamp,                          
00911                                         const real_t* const lb_new,         
00912                                         real_t* const lb_new_far,           
00913                                         const real_t* const ub_new,         
00914                                         real_t* const ub_new_far,           
00915                                         const real_t* const lbA_new,        
00916                                         real_t* const lbA_new_far,          
00917                                         const real_t* const ubA_new,        
00918                                         real_t* const ubA_new_far           
00919                                         ) const;
00920 
00921 
00924         virtual returnValue performDriftCorrection( );
00925 
00926 
00933         virtual returnValue setupAuxiliaryQP(   const Bounds* const guessedBounds,          
00934                                                 const Constraints* const guessedConstraints 
00935                                                 );
00936 
00941         BooleanType shallRefactorise(   const Bounds* const guessedBounds,          
00942                                         const Constraints* const guessedConstraints 
00943                                         ) const;
00944 
00949         returnValue setupQPdata(    SymmetricMatrix *_H,        
00951                                     const real_t* const _g,     
00952                                     Matrix *_A,                 
00953                                     const real_t* const _lb,    
00955                                     const real_t* const _ub,    
00957                                     const real_t* const _lbA,   
00959                                     const real_t* const _ubA    
00961                                     );
00962 
00963 
00970         returnValue setupQPdata(    const real_t* const _H,     
00972                                     const real_t* const _g,     
00973                                     const real_t* const _A,     
00974                                     const real_t* const _lb,    
00976                                     const real_t* const _ub,    
00978                                     const real_t* const _lbA,   
00980                                     const real_t* const _ubA    
00982                                     );
00983 
00992         returnValue setupQPdataFromFile(    const char* const H_file,   
00994                                             const char* const g_file,   
00995                                             const char* const A_file,   
00996                                             const char* const lb_file,  
00998                                             const char* const ub_file,  
01000                                             const char* const lbA_file, 
01002                                             const char* const ubA_file  
01004                                             );
01005 
01011         returnValue loadQPvectorsFromFile(  const char* const g_file,   
01012                                             const char* const lb_file,  
01014                                             const char* const ub_file,  
01016                                             const char* const lbA_file, 
01018                                             const char* const ubA_file, 
01020                                             real_t* const g_new,        
01021                                             real_t* const lb_new,       
01022                                             real_t* const ub_new,       
01023                                             real_t* const lbA_new,      
01024                                             real_t* const ubA_new       
01025                                             ) const;
01026 
01027 
01030         returnValue printIteration( int iter,                   
01031                                     int BC_idx,                 
01032                                     SubjectToStatus BC_status,  
01033                                     BooleanType BC_isBound,     
01034                                     real_t homotopyLength       
01035                                     );
01036 
01037 
01042         inline returnValue setA(    Matrix *A_new   
01043                                     );
01044 
01049         inline returnValue setA(    const real_t* const A_new   
01050                                     );
01051 
01052 
01056         inline returnValue setLBA(  const real_t* const lbA_new 
01057                                     );
01058 
01063         inline returnValue setLBA(  int number,     
01064                                     real_t value    
01065                                     );
01066 
01070         inline returnValue setUBA(  const real_t* const ubA_new 
01071                                     );
01072 
01077         inline returnValue setUBA(  int number,     
01078                                     real_t value    
01079                                     );
01080 
01081 
01086         returnValue dropInfeasibles (   int BC_number,              
01087                                         SubjectToStatus BC_status,  
01088                                         BooleanType BC_isBound,     
01089                                         real_t *xiB,                
01090                                         real_t *xiC                 
01091                                         );
01092 
01098                 returnValue areBoundsConsistent(const real_t* const lb,  
01099                                                 const real_t* const ub,  
01100                                                 const real_t* const lbA, 
01101                                                 const real_t* const ubA  
01102                                                 ) const;
01103 
01104 
01105     public:
01109         returnValue writeQpDataIntoMatFile( const char* const filename  
01110                                             ) const;
01111 
01115         returnValue writeQpWorkspaceIntoMatFile(    const char* const filename  
01116                                                     );
01117 
01118 
01119 
01120     /*
01121      *  PROTECTED MEMBER VARIABLES
01122      */
01123     protected:
01124         BooleanType freeConstraintMatrix;       
01125         Matrix* A;                              
01127         real_t* lbA;                            
01128         real_t* ubA;                            
01130         Constraints constraints;                
01132         real_t* T;                              
01133         real_t* Q;                              
01134         int sizeT;                              
01136         real_t* Ax;                             
01138         real_t* Ax_l;                           
01140         real_t* Ax_u;                           
01143         ConstraintProduct* constraintProduct;   
01145         real_t* tempA;                          
01146         real_t* tempB;                          
01147         real_t* ZFR_delta_xFRz;                 
01148         real_t* delta_xFRy;                     
01149         real_t* delta_xFRz;                     
01150         real_t* delta_yAC_TMP;                  
01151 };
01152 
01153 
01154 END_NAMESPACE_QPOASES
01155 
01156 #include <qpOASES/QProblem.ipp>
01157 
01158 #endif  /* QPOASES_QPROBLEM_HPP */
01159 
01160 
01161 /*
01162  *  end of file
01163  */