qpOASES
3.2.1
An Implementation of the Online Active Set Strategy
|
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 00038 #ifndef QPOASES_QPROBLEMB_HPP 00039 #define QPOASES_QPROBLEMB_HPP 00040 00041 00042 #include <qpOASES/Flipper.hpp> 00043 #include <qpOASES/Options.hpp> 00044 #include <qpOASES/Matrices.hpp> 00045 00046 00047 BEGIN_NAMESPACE_QPOASES 00048 00049 00050 class SolutionAnalysis; 00051 00063 class QProblemB 00064 { 00065 /* allow SolutionAnalysis class to access private members */ 00066 friend class SolutionAnalysis; 00067 00068 /* 00069 * PUBLIC MEMBER FUNCTIONS 00070 */ 00071 public: 00073 QProblemB( ); 00074 00080 QProblemB( int_t _nV, 00081 HessianType _hessianType = HST_UNKNOWN, 00082 BooleanType allocDenseMats = BT_TRUE 00083 ); 00084 00086 QProblemB( const QProblemB& rhs 00087 ); 00088 00090 virtual ~QProblemB( ); 00091 00093 virtual QProblemB& operator=( const QProblemB& rhs 00094 ); 00095 00096 00100 virtual returnValue reset( ); 00101 00102 00123 returnValue init( SymmetricMatrix *_H, 00124 const real_t* const _g, 00125 const real_t* const _lb, 00127 const real_t* const _ub, 00129 int_t& nWSR, 00131 real_t* const cputime = 0, 00133 const real_t* const xOpt = 0, 00135 const real_t* const yOpt = 0, 00137 const Bounds* const guessedBounds = 0, 00139 const real_t* const _R = 0 00143 ); 00144 00165 returnValue init( const real_t* const _H, 00167 const real_t* const _g, 00168 const real_t* const _lb, 00170 const real_t* const _ub, 00172 int_t& nWSR, 00174 real_t* const cputime = 0, 00176 const real_t* const xOpt = 0, 00178 const real_t* const yOpt = 0, 00180 const Bounds* const guessedBounds = 0, 00182 const real_t* const _R = 0 00186 ); 00187 00208 returnValue init( const char* const H_file, 00210 const char* const g_file, 00211 const char* const lb_file, 00213 const char* const ub_file, 00215 int_t& nWSR, 00217 real_t* const cputime = 0, 00219 const real_t* const xOpt = 0, 00221 const real_t* const yOpt = 0, 00223 const Bounds* const guessedBounds = 0, 00225 const char* const R_file = 0 00228 ); 00229 00230 00249 returnValue hotstart( const real_t* const g_new, 00250 const real_t* const lb_new, 00252 const real_t* const ub_new, 00254 int_t& nWSR, 00256 real_t* const cputime = 0, 00258 const Bounds* const guessedBounds = 0 00260 ); 00261 00283 returnValue hotstart( const char* const g_file, 00284 const char* const lb_file, 00286 const char* const ub_file, 00288 int_t& nWSR, 00290 real_t* const cputime = 0, 00292 const Bounds* const guessedBounds = 0 00294 ); 00295 00296 00300 virtual returnValue getWorkingSet( real_t* workingSet 00301 ); 00302 00306 virtual returnValue getWorkingSetBounds( real_t* workingSetB 00307 ); 00308 00312 virtual returnValue getWorkingSetConstraints( real_t* workingSetC 00313 ); 00314 00315 00319 inline returnValue getBounds( Bounds& _bounds 00320 ) const; 00321 00322 00325 inline int_t getNV( ) const; 00326 00329 inline int_t getNFR( ) const; 00330 00333 inline int_t getNFX( ) const; 00334 00337 inline int_t getNFV( ) const; 00338 00341 virtual int_t getNZ( ) const; 00342 00343 00347 real_t getObjVal( ) const; 00348 00351 real_t getObjVal( const real_t* const _x 00352 ) const; 00353 00357 returnValue getPrimalSolution( real_t* const xOpt 00358 ) const; 00359 00363 virtual returnValue getDualSolution( real_t* const yOpt 00364 ) const; 00365 00366 00369 inline QProblemStatus getStatus( ) const; 00370 00371 00375 inline BooleanType isInitialised( ) const; 00376 00380 inline BooleanType isSolved( ) const; 00381 00385 inline BooleanType isInfeasible( ) const; 00386 00390 inline BooleanType isUnbounded( ) const; 00391 00392 00395 inline HessianType getHessianType( ) const; 00396 00399 inline returnValue setHessianType( HessianType _hessianType 00400 ); 00401 00405 inline BooleanType usingRegularisation( ) const; 00406 00409 inline Options getOptions( ) const; 00410 00413 inline returnValue setOptions( const Options& _options 00414 ); 00415 00418 inline PrintLevel getPrintLevel( ) const; 00419 00422 returnValue setPrintLevel( PrintLevel _printlevel 00423 ); 00424 00425 00428 inline uint_t getCount( ) const; 00429 00432 inline returnValue resetCounter( ); 00433 00434 00437 virtual returnValue printProperties( ); 00438 00441 returnValue printOptions( ) const; 00442 00443 00444 /* 00445 * PROTECTED MEMBER FUNCTIONS 00446 */ 00447 protected: 00450 returnValue clear( ); 00451 00454 returnValue copy( const QProblemB& rhs 00455 ); 00456 00462 returnValue determineHessianType( ); 00463 00467 virtual returnValue setupSubjectToType( ); 00468 00472 virtual returnValue setupSubjectToType( const real_t* const lb_new, 00473 const real_t* const ub_new 00474 ); 00475 00484 virtual returnValue computeCholesky( ); 00485 00486 00492 virtual returnValue setupInitialCholesky( ); 00493 00499 returnValue obtainAuxiliaryWorkingSet( const real_t* const xOpt, 00501 const real_t* const yOpt, 00503 const Bounds* const guessedBounds, 00504 Bounds* auxiliaryBounds 00506 ) const; 00507 00513 returnValue areBoundsConsistent(const real_t* const lb, 00514 const real_t* const ub 00515 ) const; 00516 00520 virtual returnValue backsolveR( const real_t* const b, 00521 BooleanType transposed, 00522 real_t* const a 00523 ) const; 00524 00529 virtual returnValue backsolveR( const real_t* const b, 00530 BooleanType transposed, 00531 BooleanType removingBound, 00532 real_t* const a 00533 ) const; 00534 00535 00538 returnValue determineDataShift( const real_t* const g_new, 00539 const real_t* const lb_new, 00540 const real_t* const ub_new, 00541 real_t* const delta_g, 00542 real_t* const delta_lb, 00543 real_t* const delta_ub, 00544 BooleanType& Delta_bB_isZero 00545 ); 00546 00547 00551 returnValue setupQPdata( SymmetricMatrix *_H, 00552 const real_t* const _g, 00553 const real_t* const _lb, 00555 const real_t* const _ub 00557 ); 00558 00565 returnValue setupQPdata( const real_t* const _H, 00567 const real_t* const _g, 00568 const real_t* const _lb, 00570 const real_t* const _ub 00572 ); 00573 00582 returnValue setupQPdataFromFile( const char* const H_file, 00584 const char* const g_file, 00585 const char* const lb_file, 00587 const char* const ub_file 00589 ); 00590 00596 returnValue loadQPvectorsFromFile( const char* const g_file, 00597 const char* const lb_file, 00599 const char* const ub_file, 00601 real_t* const g_new, 00602 real_t* const lb_new, 00603 real_t* const ub_new 00604 ) const; 00605 00606 00612 returnValue setInfeasibilityFlag( returnValue returnvalue, 00613 BooleanType doThrowError = BT_FALSE 00614 ); 00615 00616 00620 BooleanType isCPUtimeLimitExceeded( const real_t* const cputime, 00621 real_t starttime, 00622 int_t nWSR 00623 ) const; 00624 00625 00629 returnValue regulariseHessian( ); 00630 00631 00634 inline returnValue setH( SymmetricMatrix* H_new 00635 ); 00636 00642 inline returnValue setH( const real_t* const H_new 00643 ); 00644 00648 inline returnValue setG( const real_t* const g_new 00649 ); 00650 00654 inline returnValue setLB( const real_t* const lb_new 00655 ); 00656 00661 inline returnValue setLB( int_t number, 00662 real_t value 00663 ); 00664 00668 inline returnValue setUB( const real_t* const ub_new 00669 ); 00670 00675 inline returnValue setUB( int_t number, 00676 real_t value 00677 ); 00678 00679 00682 inline void computeGivens( real_t xold, 00683 real_t yold, 00684 real_t& xnew, 00685 real_t& ynew, 00686 real_t& c, 00687 real_t& s 00688 ) const; 00689 00692 inline void applyGivens( real_t c, 00693 real_t s, 00694 real_t nu, 00695 real_t xold, 00697 real_t yold, 00699 real_t& xnew, 00701 real_t& ynew 00703 ) const; 00704 00705 00706 00710 real_t getRelativeHomotopyLength( const real_t* const g_new, 00711 const real_t* const lb_new, 00712 const real_t* const ub_new 00713 ); 00714 00718 virtual returnValue performRamping( ); 00719 00720 00722 returnValue updateFarBounds( real_t curFarBound, 00723 int_t nRamp, 00724 const real_t* const lb_new, 00725 real_t* const lb_new_far, 00726 const real_t* const ub_new, 00727 real_t* const ub_new_far 00728 ) const; 00729 00730 00734 returnValue performRatioTest( int_t nIdx, 00735 const int_t* const idxList, 00736 const SubjectTo* const subjectTo, 00737 const real_t* const num, 00738 const real_t* const den, 00739 real_t epsNum, 00740 real_t epsDen, 00741 real_t& t, 00742 int_t& BC_idx 00743 ) const; 00744 00748 inline BooleanType isBlocking( real_t num, 00749 real_t den, 00750 real_t epsNum, 00751 real_t epsDen, 00752 real_t& t 00754 ) const; 00755 00756 00761 SymSparseMat* createDiagSparseMat( int_t n, 00762 real_t diagVal = 1.0 00763 ); 00764 00765 00766 /* 00767 * PRIVATE MEMBER FUNCTIONS 00768 */ 00769 private: 00781 returnValue solveInitialQP( const real_t* const xOpt, 00782 const real_t* const yOpt, 00783 const Bounds* const guessedBounds, 00784 const real_t* const _R, 00785 int_t& nWSR, 00787 real_t* const cputime 00789 ); 00790 00803 returnValue solveQP( const real_t* const g_new, 00804 const real_t* const lb_new, 00806 const real_t* const ub_new, 00808 int_t& nWSR, 00810 real_t* const cputime, 00812 int_t nWSRperformed = 0, 00816 BooleanType isFirstCall = BT_TRUE 00817 ); 00818 00819 00832 returnValue solveRegularisedQP( const real_t* const g_new, 00833 const real_t* const lb_new, 00835 const real_t* const ub_new, 00837 int_t& nWSR, 00839 real_t* const cputime, 00841 int_t nWSRperformed = 0, 00844 BooleanType isFirstCall = BT_TRUE 00845 ); 00846 00847 00855 returnValue setupAuxiliaryWorkingSet( const Bounds* const auxiliaryBounds, 00856 BooleanType setupAfresh 00858 ); 00859 00862 returnValue setupAuxiliaryQPsolution( const real_t* const xOpt, 00864 const real_t* const yOpt 00866 ); 00867 00872 returnValue setupAuxiliaryQPgradient( ); 00873 00879 returnValue setupAuxiliaryQPbounds( BooleanType useRelaxation 00880 ); 00881 00882 00883 protected: 00889 virtual returnValue setupAuxiliaryQP( const Bounds* const guessedBounds 00890 ); 00891 00892 private: 00896 returnValue determineStepDirection( const real_t* const delta_g, 00897 const real_t* const delta_lb, 00898 const real_t* const delta_ub, 00899 BooleanType Delta_bB_isZero, 00900 real_t* const delta_xFX, 00901 real_t* const delta_xFR, 00902 real_t* const delta_yFX 00903 ); 00904 00910 returnValue performStep( const real_t* const delta_g, 00911 const real_t* const delta_lb, 00912 const real_t* const delta_ub, 00913 const real_t* const delta_xFX, 00914 const real_t* const delta_xFR, 00915 const real_t* const delta_yFX, 00916 int_t& BC_idx, 00917 SubjectToStatus& BC_status 00918 ); 00919 00924 returnValue changeActiveSet( int_t BC_idx, 00925 SubjectToStatus BC_status 00926 ); 00927 00930 virtual returnValue performDriftCorrection( ); 00931 00936 BooleanType shallRefactorise( const Bounds* const guessedBounds 00937 ) const; 00938 00939 00943 returnValue addBound( int_t number, 00944 SubjectToStatus B_status, 00945 BooleanType updateCholesky 00946 ); 00947 00952 returnValue removeBound( int_t number, 00953 BooleanType updateCholesky 00954 ); 00955 00956 00959 returnValue printIteration( int_t iter, 00960 int_t BC_idx, 00961 SubjectToStatus BC_status, 00962 real_t homotopyLength, 00963 BooleanType isFirstCall = BT_TRUE 00964 ); 00965 00966 00967 /* 00968 * PROTECTED MEMBER VARIABLES 00969 */ 00970 protected: 00971 BooleanType freeHessian; 00972 SymmetricMatrix* H; 00974 real_t* g; 00975 real_t* lb; 00976 real_t* ub; 00978 Bounds bounds; 00980 real_t* R; 00981 BooleanType haveCholesky; 00983 real_t* x; 00984 real_t* y; 00986 real_t tau; 00988 QProblemStatus status; 00990 BooleanType infeasible; 00991 BooleanType unbounded; 00993 HessianType hessianType; 00994 real_t regVal; 00996 uint_t count; 00998 real_t *delta_xFR_TMP; 01000 real_t ramp0; 01001 real_t ramp1; 01002 int_t rampOffset; 01004 Options options; 01006 Flipper flipper; 01008 TabularOutput tabularOutput; 01009 }; 01010 01011 01012 END_NAMESPACE_QPOASES 01013 01014 #include <qpOASES/QProblemB.ipp> 01015 01016 #endif /* QPOASES_QPROBLEMB_HPP */ 01017 01018 01019 /* 01020 * end of file 01021 */