qpOASES
3.0.1
|
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 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 00113 returnValue init( SymmetricMatrix *_H, 00114 const real_t* const _g, 00115 const real_t* const _lb, 00117 const real_t* const _ub, 00119 int& nWSR, 00121 real_t* const cputime = 0 00123 ); 00124 00136 returnValue init( const real_t* const _H, 00138 const real_t* const _g, 00139 const real_t* const _lb, 00141 const real_t* const _ub, 00143 int& nWSR, 00145 real_t* const cputime = 0 00147 ); 00148 00160 returnValue init( const char* const H_file, 00162 const char* const g_file, 00163 const char* const lb_file, 00165 const char* const ub_file, 00167 int& nWSR, 00169 real_t* const cputime = 0 00171 ); 00172 00191 returnValue init( SymmetricMatrix *_H, 00192 const real_t* const _g, 00193 const real_t* const _lb, 00195 const real_t* const _ub, 00197 int& nWSR, 00199 real_t* const cputime, 00201 const real_t* const xOpt, 00203 const real_t* const yOpt, 00205 const Bounds* const guessedBounds 00207 ); 00208 00227 returnValue init( const real_t* const _H, 00229 const real_t* const _g, 00230 const real_t* const _lb, 00232 const real_t* const _ub, 00234 int& nWSR, 00236 real_t* const cputime, 00238 const real_t* const xOpt, 00240 const real_t* const yOpt, 00242 const Bounds* const guessedBounds 00244 ); 00245 00264 returnValue init( const char* const H_file, 00266 const char* const g_file, 00267 const char* const lb_file, 00269 const char* const ub_file, 00271 int& nWSR, 00273 real_t* const cputime, 00275 const real_t* const xOpt, 00277 const real_t* const yOpt, 00279 const Bounds* const guessedBounds 00281 ); 00282 00283 00297 returnValue hotstart( const real_t* const g_new, 00298 const real_t* const lb_new, 00300 const real_t* const ub_new, 00302 int& nWSR, 00304 real_t* const cputime = 0 00306 ); 00307 00324 returnValue hotstart( const char* const g_file, 00325 const char* const lb_file, 00327 const char* const ub_file, 00329 int& nWSR, 00331 real_t* const cputime = 0 00333 ); 00334 00349 returnValue hotstart( const real_t* const g_new, 00350 const real_t* const lb_new, 00352 const real_t* const ub_new, 00354 int& nWSR, 00356 real_t* const cputime, 00358 const Bounds* const guessedBounds 00360 ); 00361 00379 returnValue hotstart( const char* const g_file, 00380 const char* const lb_file, 00382 const char* const ub_file, 00384 int& nWSR, 00386 real_t* const cputime, 00388 const Bounds* const guessedBounds 00390 ); 00391 00392 00395 virtual returnValue getWorkingSet( real_t* workingSet 00396 ); 00397 00401 inline returnValue getBounds( Bounds& _bounds 00402 ) const; 00403 00404 00407 inline int getNV( ) const; 00408 00411 inline int getNFR( ) const; 00412 00415 inline int getNFX( ) const; 00416 00419 inline int getNFV( ) const; 00420 00423 virtual int getNZ( ) const; 00424 00425 00429 real_t getObjVal( ) const; 00430 00433 real_t getObjVal( const real_t* const _x 00434 ) const; 00435 00439 returnValue getPrimalSolution( real_t* const xOpt 00440 ) const; 00441 00445 virtual returnValue getDualSolution( real_t* const yOpt 00446 ) const; 00447 00448 00451 inline QProblemStatus getStatus( ) const; 00452 00453 00457 inline BooleanType isInitialised( ) const; 00458 00462 inline BooleanType isSolved( ) const; 00463 00467 inline BooleanType isInfeasible( ) const; 00468 00472 inline BooleanType isUnbounded( ) const; 00473 00474 00477 inline HessianType getHessianType( ) const; 00478 00481 inline returnValue setHessianType( HessianType _hessianType 00482 ); 00483 00487 inline BooleanType usingRegularisation( ) const; 00488 00491 inline Options getOptions( ) const; 00492 00495 inline returnValue setOptions( const Options& _options 00496 ); 00497 00500 inline PrintLevel getPrintLevel( ) const; 00501 00504 returnValue setPrintLevel( PrintLevel _printlevel 00505 ); 00506 00507 00510 virtual returnValue printProperties( ); 00511 00514 returnValue printOptions( ) const; 00515 00516 00517 /* 00518 * PROTECTED MEMBER FUNCTIONS 00519 */ 00520 protected: 00523 returnValue clear( ); 00524 00527 returnValue copy( const QProblemB& rhs 00528 ); 00529 00535 returnValue determineHessianType( ); 00536 00540 virtual returnValue setupSubjectToType( ); 00541 00545 virtual returnValue setupSubjectToType( const real_t* const lb_new, 00546 const real_t* const ub_new 00547 ); 00548 00557 returnValue computeCholesky( ); 00558 00559 00565 virtual returnValue setupInitialCholesky( ); 00566 00572 returnValue obtainAuxiliaryWorkingSet( const real_t* const xOpt, 00574 const real_t* const yOpt, 00576 const Bounds* const guessedBounds, 00577 Bounds* auxiliaryBounds 00579 ) const; 00580 00586 returnValue areBoundsConsistent(const real_t* const lb, 00587 const real_t* const ub 00588 ) const; 00589 00593 returnValue backsolveR( const real_t* const b, 00594 BooleanType transposed, 00595 real_t* const a 00596 ) const; 00597 00602 returnValue backsolveR( const real_t* const b, 00603 BooleanType transposed, 00604 BooleanType removingBound, 00605 real_t* const a 00606 ) const; 00607 00608 00611 returnValue determineDataShift( const real_t* const g_new, 00612 const real_t* const lb_new, 00613 const real_t* const ub_new, 00614 real_t* const delta_g, 00615 real_t* const delta_lb, 00616 real_t* const delta_ub, 00617 BooleanType& Delta_bB_isZero 00618 ); 00619 00620 00624 returnValue setupQPdata( SymmetricMatrix *_H, 00625 const real_t* const _g, 00626 const real_t* const _lb, 00628 const real_t* const _ub 00630 ); 00631 00638 returnValue setupQPdata( const real_t* const _H, 00640 const real_t* const _g, 00641 const real_t* const _lb, 00643 const real_t* const _ub 00645 ); 00646 00655 returnValue setupQPdataFromFile( const char* const H_file, 00657 const char* const g_file, 00658 const char* const lb_file, 00660 const char* const ub_file 00662 ); 00663 00669 returnValue loadQPvectorsFromFile( const char* const g_file, 00670 const char* const lb_file, 00672 const char* const ub_file, 00674 real_t* const g_new, 00675 real_t* const lb_new, 00676 real_t* const ub_new 00677 ) const; 00678 00679 00685 returnValue setInfeasibilityFlag( returnValue returnvalue, 00686 BooleanType doThrowError = BT_FALSE 00687 ); 00688 00689 00693 BooleanType isCPUtimeLimitExceeded( const real_t* const cputime, 00694 real_t starttime, 00695 int nWSR 00696 ) const; 00697 00698 00702 returnValue regulariseHessian( ); 00703 00704 00707 inline returnValue setH( SymmetricMatrix* H_new 00708 ); 00709 00715 inline returnValue setH( const real_t* const H_new 00716 ); 00717 00721 inline returnValue setG( const real_t* const g_new 00722 ); 00723 00727 inline returnValue setLB( const real_t* const lb_new 00728 ); 00729 00734 inline returnValue setLB( int number, 00735 real_t value 00736 ); 00737 00741 inline returnValue setUB( const real_t* const ub_new 00742 ); 00743 00748 inline returnValue setUB( int number, 00749 real_t value 00750 ); 00751 00752 00755 inline void computeGivens( real_t xold, 00756 real_t yold, 00757 real_t& xnew, 00758 real_t& ynew, 00759 real_t& c, 00760 real_t& s 00761 ) const; 00762 00765 inline void applyGivens( real_t c, 00766 real_t s, 00767 real_t nu, 00768 real_t xold, 00770 real_t yold, 00772 real_t& xnew, 00774 real_t& ynew 00776 ) const; 00777 00778 00779 00783 real_t getRelativeHomotopyLength( const real_t* const g_new, 00784 const real_t* const lb_new, 00785 const real_t* const ub_new 00786 ); 00787 00791 virtual returnValue performRamping( ); 00792 00793 00795 returnValue updateFarBounds( real_t curFarBound, 00796 int nRamp, 00797 const real_t* const lb_new, 00798 real_t* const lb_new_far, 00799 const real_t* const ub_new, 00800 real_t* const ub_new_far 00801 ) const; 00802 00803 00807 returnValue performRatioTest( int nIdx, 00808 const int* const idxList, 00809 const SubjectTo* const subjectTo, 00810 const real_t* const num, 00811 const real_t* const den, 00812 real_t epsNum, 00813 real_t epsDen, 00814 real_t& t, 00815 int& BC_idx 00816 ) const; 00817 00821 inline BooleanType isBlocking( real_t num, 00822 real_t den, 00823 real_t epsNum, 00824 real_t epsDen, 00825 real_t& t 00827 ) const; 00828 00829 00834 SymSparseMat* createDiagSparseMat( int n, 00835 real_t diagVal = 1.0 00836 ); 00837 00838 00839 /* 00840 * PRIVATE MEMBER FUNCTIONS 00841 */ 00842 private: 00854 returnValue solveInitialQP( const real_t* const xOpt, 00856 const real_t* const yOpt, 00858 const Bounds* const guessedBounds, 00860 int& nWSR, 00862 real_t* const cputime 00864 ); 00865 00878 returnValue solveQP( const real_t* const g_new, 00879 const real_t* const lb_new, 00881 const real_t* const ub_new, 00883 int& nWSR, 00885 real_t* const cputime, 00887 int nWSRperformed = 0 00891 ); 00892 00893 00906 returnValue solveRegularisedQP( const real_t* const g_new, 00907 const real_t* const lb_new, 00909 const real_t* const ub_new, 00911 int& nWSR, 00913 real_t* const cputime, 00915 int nWSRperformed = 0 00918 ); 00919 00920 00928 returnValue setupAuxiliaryWorkingSet( const Bounds* const auxiliaryBounds, 00929 BooleanType setupAfresh 00931 ); 00932 00935 returnValue setupAuxiliaryQPsolution( const real_t* const xOpt, 00937 const real_t* const yOpt 00939 ); 00940 00945 returnValue setupAuxiliaryQPgradient( ); 00946 00952 returnValue setupAuxiliaryQPbounds( BooleanType useRelaxation 00953 ); 00954 00955 00961 returnValue setupAuxiliaryQP( const Bounds* const guessedBounds 00962 ); 00963 00967 returnValue determineStepDirection( const real_t* const delta_g, 00968 const real_t* const delta_lb, 00969 const real_t* const delta_ub, 00970 BooleanType Delta_bB_isZero, 00971 real_t* const delta_xFX, 00972 real_t* const delta_xFR, 00973 real_t* const delta_yFX 00974 ); 00975 00981 returnValue performStep( const real_t* const delta_g, 00982 const real_t* const delta_lb, 00983 const real_t* const delta_ub, 00984 const real_t* const delta_xFX, 00985 const real_t* const delta_xFR, 00986 const real_t* const delta_yFX, 00987 int& BC_idx, 00988 SubjectToStatus& BC_status 00989 ); 00990 00995 returnValue changeActiveSet( int BC_idx, 00996 SubjectToStatus BC_status 00997 ); 00998 01001 virtual returnValue performDriftCorrection( ); 01002 01007 BooleanType shallRefactorise( const Bounds* const guessedBounds 01008 ) const; 01009 01010 01014 returnValue addBound( int number, 01015 SubjectToStatus B_status, 01016 BooleanType updateCholesky 01017 ); 01018 01023 returnValue removeBound( int number, 01024 BooleanType updateCholesky 01025 ); 01026 01027 01030 returnValue printIteration( int iter, 01031 int BC_idx, 01032 SubjectToStatus BC_status, 01033 real_t homotopyLength 01034 ); 01035 01036 01037 /* 01038 * PROTECTED MEMBER VARIABLES 01039 */ 01040 protected: 01041 BooleanType freeHessian; 01042 SymmetricMatrix* H; 01044 real_t* g; 01045 real_t* lb; 01046 real_t* ub; 01048 Bounds bounds; 01050 real_t* R; 01051 BooleanType haveCholesky; 01053 real_t* x; 01054 real_t* y; 01056 real_t tau; 01058 QProblemStatus status; 01060 BooleanType infeasible; 01061 BooleanType unbounded; 01063 HessianType hessianType; 01064 real_t regVal; 01066 int count; 01068 real_t *delta_xFR_TMP; 01070 real_t ramp0; 01071 real_t ramp1; 01072 int rampOffset; 01074 Options options; 01076 Flipper flipper; 01078 TabularOutput tabularOutput; 01079 }; 01080 01081 01082 END_NAMESPACE_QPOASES 01083 01084 #include <qpOASES/QProblemB.ipp> 01085 01086 #endif /* QPOASES_QPROBLEMB_HPP */ 01087 01088 01089 /* 01090 * end of file 01091 */