qpOASES
3.1.1
|
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 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 _nV, 00081 HessianType _hessianType = HST_UNKNOWN 00082 ); 00083 00085 QProblemB( const QProblemB& rhs 00086 ); 00087 00089 virtual ~QProblemB( ); 00090 00092 QProblemB& operator=( const QProblemB& rhs 00093 ); 00094 00095 00099 virtual returnValue reset( ); 00100 00101 00122 returnValue init( SymmetricMatrix *_H, 00123 const real_t* const _g, 00124 const real_t* const _lb, 00126 const real_t* const _ub, 00128 int& nWSR, 00130 real_t* const cputime = 0, 00132 const real_t* const xOpt = 0, 00134 const real_t* const yOpt = 0, 00136 const Bounds* const guessedBounds = 0, 00138 const real_t* const _R = 0 00142 ); 00143 00164 returnValue init( const real_t* const _H, 00166 const real_t* const _g, 00167 const real_t* const _lb, 00169 const real_t* const _ub, 00171 int& nWSR, 00173 real_t* const cputime = 0, 00175 const real_t* const xOpt = 0, 00177 const real_t* const yOpt = 0, 00179 const Bounds* const guessedBounds = 0, 00181 const real_t* const _R = 0 00185 ); 00186 00207 returnValue init( const char* const H_file, 00209 const char* const g_file, 00210 const char* const lb_file, 00212 const char* const ub_file, 00214 int& nWSR, 00216 real_t* const cputime = 0, 00218 const real_t* const xOpt = 0, 00220 const real_t* const yOpt = 0, 00222 const Bounds* const guessedBounds = 0, 00224 const char* const R_file = 0 00227 ); 00228 00229 00248 returnValue hotstart( const real_t* const g_new, 00249 const real_t* const lb_new, 00251 const real_t* const ub_new, 00253 int& nWSR, 00255 real_t* const cputime = 0, 00257 const Bounds* const guessedBounds = 0 00259 ); 00260 00282 returnValue hotstart( const char* const g_file, 00283 const char* const lb_file, 00285 const char* const ub_file, 00287 int& nWSR, 00289 real_t* const cputime = 0, 00291 const Bounds* const guessedBounds = 0 00293 ); 00294 00295 00299 virtual returnValue getWorkingSet( real_t* workingSet 00300 ); 00301 00305 virtual returnValue getWorkingSetBounds( real_t* workingSetB 00306 ); 00307 00311 virtual returnValue getWorkingSetConstraints( real_t* workingSetC 00312 ); 00313 00314 00318 inline returnValue getBounds( Bounds& _bounds 00319 ) const; 00320 00321 00324 inline int getNV( ) const; 00325 00328 inline int getNFR( ) const; 00329 00332 inline int getNFX( ) const; 00333 00336 inline int getNFV( ) const; 00337 00340 virtual int getNZ( ) const; 00341 00342 00346 real_t getObjVal( ) const; 00347 00350 real_t getObjVal( const real_t* const _x 00351 ) const; 00352 00356 returnValue getPrimalSolution( real_t* const xOpt 00357 ) const; 00358 00362 virtual returnValue getDualSolution( real_t* const yOpt 00363 ) const; 00364 00365 00368 inline QProblemStatus getStatus( ) const; 00369 00370 00374 inline BooleanType isInitialised( ) const; 00375 00379 inline BooleanType isSolved( ) const; 00380 00384 inline BooleanType isInfeasible( ) const; 00385 00389 inline BooleanType isUnbounded( ) const; 00390 00391 00394 inline HessianType getHessianType( ) const; 00395 00398 inline returnValue setHessianType( HessianType _hessianType 00399 ); 00400 00404 inline BooleanType usingRegularisation( ) const; 00405 00408 inline Options getOptions( ) const; 00409 00412 inline returnValue setOptions( const Options& _options 00413 ); 00414 00417 inline PrintLevel getPrintLevel( ) const; 00418 00421 returnValue setPrintLevel( PrintLevel _printlevel 00422 ); 00423 00424 00427 inline unsigned int getCount( ) const; 00428 00431 inline returnValue resetCounter( ); 00432 00433 00436 virtual returnValue printProperties( ); 00437 00440 returnValue printOptions( ) const; 00441 00442 00443 /* 00444 * PROTECTED MEMBER FUNCTIONS 00445 */ 00446 protected: 00449 returnValue clear( ); 00450 00453 returnValue copy( const QProblemB& rhs 00454 ); 00455 00461 returnValue determineHessianType( ); 00462 00466 virtual returnValue setupSubjectToType( ); 00467 00471 virtual returnValue setupSubjectToType( const real_t* const lb_new, 00472 const real_t* const ub_new 00473 ); 00474 00483 returnValue computeCholesky( ); 00484 00485 00491 virtual returnValue setupInitialCholesky( ); 00492 00498 returnValue obtainAuxiliaryWorkingSet( const real_t* const xOpt, 00500 const real_t* const yOpt, 00502 const Bounds* const guessedBounds, 00503 Bounds* auxiliaryBounds 00505 ) const; 00506 00512 returnValue areBoundsConsistent(const real_t* const lb, 00513 const real_t* const ub 00514 ) const; 00515 00519 returnValue backsolveR( const real_t* const b, 00520 BooleanType transposed, 00521 real_t* const a 00522 ) const; 00523 00528 returnValue backsolveR( const real_t* const b, 00529 BooleanType transposed, 00530 BooleanType removingBound, 00531 real_t* const a 00532 ) const; 00533 00534 00537 returnValue determineDataShift( const real_t* const g_new, 00538 const real_t* const lb_new, 00539 const real_t* const ub_new, 00540 real_t* const delta_g, 00541 real_t* const delta_lb, 00542 real_t* const delta_ub, 00543 BooleanType& Delta_bB_isZero 00544 ); 00545 00546 00550 returnValue setupQPdata( SymmetricMatrix *_H, 00551 const real_t* const _g, 00552 const real_t* const _lb, 00554 const real_t* const _ub 00556 ); 00557 00564 returnValue setupQPdata( const real_t* const _H, 00566 const real_t* const _g, 00567 const real_t* const _lb, 00569 const real_t* const _ub 00571 ); 00572 00581 returnValue setupQPdataFromFile( const char* const H_file, 00583 const char* const g_file, 00584 const char* const lb_file, 00586 const char* const ub_file 00588 ); 00589 00595 returnValue loadQPvectorsFromFile( const char* const g_file, 00596 const char* const lb_file, 00598 const char* const ub_file, 00600 real_t* const g_new, 00601 real_t* const lb_new, 00602 real_t* const ub_new 00603 ) const; 00604 00605 00611 returnValue setInfeasibilityFlag( returnValue returnvalue, 00612 BooleanType doThrowError = BT_FALSE 00613 ); 00614 00615 00619 BooleanType isCPUtimeLimitExceeded( const real_t* const cputime, 00620 real_t starttime, 00621 int nWSR 00622 ) const; 00623 00624 00628 returnValue regulariseHessian( ); 00629 00630 00633 inline returnValue setH( SymmetricMatrix* H_new 00634 ); 00635 00641 inline returnValue setH( const real_t* const H_new 00642 ); 00643 00647 inline returnValue setG( const real_t* const g_new 00648 ); 00649 00653 inline returnValue setLB( const real_t* const lb_new 00654 ); 00655 00660 inline returnValue setLB( int number, 00661 real_t value 00662 ); 00663 00667 inline returnValue setUB( const real_t* const ub_new 00668 ); 00669 00674 inline returnValue setUB( int number, 00675 real_t value 00676 ); 00677 00678 00681 inline void computeGivens( real_t xold, 00682 real_t yold, 00683 real_t& xnew, 00684 real_t& ynew, 00685 real_t& c, 00686 real_t& s 00687 ) const; 00688 00691 inline void applyGivens( real_t c, 00692 real_t s, 00693 real_t nu, 00694 real_t xold, 00696 real_t yold, 00698 real_t& xnew, 00700 real_t& ynew 00702 ) const; 00703 00704 00705 00709 real_t getRelativeHomotopyLength( const real_t* const g_new, 00710 const real_t* const lb_new, 00711 const real_t* const ub_new 00712 ); 00713 00717 virtual returnValue performRamping( ); 00718 00719 00721 returnValue updateFarBounds( real_t curFarBound, 00722 int nRamp, 00723 const real_t* const lb_new, 00724 real_t* const lb_new_far, 00725 const real_t* const ub_new, 00726 real_t* const ub_new_far 00727 ) const; 00728 00729 00733 returnValue performRatioTest( int nIdx, 00734 const int* const idxList, 00735 const SubjectTo* const subjectTo, 00736 const real_t* const num, 00737 const real_t* const den, 00738 real_t epsNum, 00739 real_t epsDen, 00740 real_t& t, 00741 int& BC_idx 00742 ) const; 00743 00747 inline BooleanType isBlocking( real_t num, 00748 real_t den, 00749 real_t epsNum, 00750 real_t epsDen, 00751 real_t& t 00753 ) const; 00754 00755 00760 SymSparseMat* createDiagSparseMat( int n, 00761 real_t diagVal = 1.0 00762 ); 00763 00764 00765 /* 00766 * PRIVATE MEMBER FUNCTIONS 00767 */ 00768 private: 00780 returnValue solveInitialQP( const real_t* const xOpt, 00781 const real_t* const yOpt, 00782 const Bounds* const guessedBounds, 00783 const real_t* const _R, 00784 int& nWSR, 00786 real_t* const cputime 00788 ); 00789 00802 returnValue solveQP( const real_t* const g_new, 00803 const real_t* const lb_new, 00805 const real_t* const ub_new, 00807 int& nWSR, 00809 real_t* const cputime, 00811 int nWSRperformed = 0, 00815 BooleanType isFirstCall = BT_TRUE 00816 ); 00817 00818 00831 returnValue solveRegularisedQP( const real_t* const g_new, 00832 const real_t* const lb_new, 00834 const real_t* const ub_new, 00836 int& nWSR, 00838 real_t* const cputime, 00840 int nWSRperformed = 0, 00843 BooleanType isFirstCall = BT_TRUE 00844 ); 00845 00846 00854 returnValue setupAuxiliaryWorkingSet( const Bounds* const auxiliaryBounds, 00855 BooleanType setupAfresh 00857 ); 00858 00861 returnValue setupAuxiliaryQPsolution( const real_t* const xOpt, 00863 const real_t* const yOpt 00865 ); 00866 00871 returnValue setupAuxiliaryQPgradient( ); 00872 00878 returnValue setupAuxiliaryQPbounds( BooleanType useRelaxation 00879 ); 00880 00881 00882 protected: 00888 virtual returnValue setupAuxiliaryQP( const Bounds* const guessedBounds 00889 ); 00890 00891 private: 00895 returnValue determineStepDirection( const real_t* const delta_g, 00896 const real_t* const delta_lb, 00897 const real_t* const delta_ub, 00898 BooleanType Delta_bB_isZero, 00899 real_t* const delta_xFX, 00900 real_t* const delta_xFR, 00901 real_t* const delta_yFX 00902 ); 00903 00909 returnValue performStep( const real_t* const delta_g, 00910 const real_t* const delta_lb, 00911 const real_t* const delta_ub, 00912 const real_t* const delta_xFX, 00913 const real_t* const delta_xFR, 00914 const real_t* const delta_yFX, 00915 int& BC_idx, 00916 SubjectToStatus& BC_status 00917 ); 00918 00923 returnValue changeActiveSet( int BC_idx, 00924 SubjectToStatus BC_status 00925 ); 00926 00929 virtual returnValue performDriftCorrection( ); 00930 00935 BooleanType shallRefactorise( const Bounds* const guessedBounds 00936 ) const; 00937 00938 00942 returnValue addBound( int number, 00943 SubjectToStatus B_status, 00944 BooleanType updateCholesky 00945 ); 00946 00951 returnValue removeBound( int number, 00952 BooleanType updateCholesky 00953 ); 00954 00955 00958 returnValue printIteration( int iter, 00959 int BC_idx, 00960 SubjectToStatus BC_status, 00961 real_t homotopyLength, 00962 BooleanType isFirstCall = BT_TRUE 00963 ); 00964 00965 00966 /* 00967 * PROTECTED MEMBER VARIABLES 00968 */ 00969 protected: 00970 BooleanType freeHessian; 00971 SymmetricMatrix* H; 00973 real_t* g; 00974 real_t* lb; 00975 real_t* ub; 00977 Bounds bounds; 00979 real_t* R; 00980 BooleanType haveCholesky; 00982 real_t* x; 00983 real_t* y; 00985 real_t tau; 00987 QProblemStatus status; 00989 BooleanType infeasible; 00990 BooleanType unbounded; 00992 HessianType hessianType; 00993 real_t regVal; 00995 unsigned int count; 00997 real_t *delta_xFR_TMP; 00999 real_t ramp0; 01000 real_t ramp1; 01001 int rampOffset; 01003 Options options; 01005 Flipper flipper; 01007 TabularOutput tabularOutput; 01008 }; 01009 01010 01011 END_NAMESPACE_QPOASES 01012 01013 #include <qpOASES/QProblemB.ipp> 01014 01015 #endif /* QPOASES_QPROBLEMB_HPP */ 01016 01017 01018 /* 01019 * end of file 01020 */