1 /* 2 * This file is part of qpOASES. 3 * 4 * qpOASES -- An Implementation of the Online Active Set Strategy. 5 * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, 6 * Christian Kirches et al. All rights reserved. 7 * 8 * qpOASES is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU Lesser General Public 10 * License as published by the Free Software Foundation; either 11 * version 2.1 of the License, or (at your option) any later version. 12 * 13 * qpOASES is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 16 * See the GNU Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public 19 * License along with qpOASES; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 21 * 22 */ 23 24 25 /** 26 * \file include/qpOASES/SQProblem.hpp 27 * \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches 28 * \version 3.2 29 * \date 2007-2017 30 * 31 * Declaration of the SQProblem class which is able to use the newly 32 * developed online active set strategy for parametric quadratic programming 33 * with varying matrices. 34 */ 35 36 37 38 #ifndef QPOASES_SQPROBLEM_HPP 39 #define QPOASES_SQPROBLEM_HPP 40 41 42 #include <qpOASES/QProblem.hpp> 43 44 45 BEGIN_NAMESPACE_QPOASES 46 47 48 /** 49 * \brief Implements the online active set strategy for QPs with varying matrices. 50 * 51 * A class for setting up and solving quadratic programs with varying QP matrices. 52 * The main feature is the possibily to use the newly developed online active set strategy 53 * for parametric quadratic programming. 54 * 55 * \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches 56 * \version 3.2 57 * \date 2007-2017 58 */ 59 class SQProblem : public QProblem 60 { 61 /* allow SolutionAnalysis class to access private members */ 62 friend class SolutionAnalysis; 63 64 /* 65 * PUBLIC MEMBER FUNCTIONS 66 */ 67 public: 68 /** Default constructor. */ 69 SQProblem( ); 70 71 /** Constructor which takes the QP dimension and Hessian type 72 * information. If the Hessian is the zero (i.e. HST_ZERO) or the 73 * identity matrix (i.e. HST_IDENTITY), respectively, no memory 74 * is allocated for it and a NULL pointer can be passed for it 75 * to the init() functions. */ 76 SQProblem( int_t _nV, /**< Number of variables. */ 77 int_t _nC, /**< Number of constraints. */ 78 HessianType _hessianType = HST_UNKNOWN, /**< Type of Hessian matrix. */ 79 BooleanType allocDenseMats = BT_TRUE /**< Enable allocation of dense matrices. */ 80 ); 81 82 /** Copy constructor (deep copy). */ 83 SQProblem( const SQProblem& rhs /**< Rhs object. */ 84 ); 85 86 /** Destructor. */ 87 virtual ~SQProblem( ); 88 89 /** Assignment operator (deep copy). */ 90 virtual SQProblem& operator=( const SQProblem& rhs /**< Rhs object. */ 91 ); 92 93 94 /** Solves an initialised QP sequence with matrix shift using 95 * the online active set strategy. 96 * \return SUCCESSFUL_RETURN \n 97 RET_MAX_NWSR_REACHED \n 98 RET_HOTSTART_FAILED_AS_QP_NOT_INITIALISED \n 99 RET_HOTSTART_FAILED \n 100 RET_MATRIX_SHIFT_FAILED \n 101 RET_SHIFT_DETERMINATION_FAILED \n 102 RET_STEPDIRECTION_DETERMINATION_FAILED \n 103 RET_STEPLENGTH_DETERMINATION_FAILED \n 104 RET_HOMOTOPY_STEP_FAILED \n 105 RET_HOTSTART_STOPPED_INFEASIBILITY \n 106 RET_HOTSTART_STOPPED_UNBOUNDEDNESS \n 107 RET_SETUP_AUXILIARYQP_FAILED */ 108 returnValue hotstart( SymmetricMatrix *H_new, /**< Hessian matrix of neighbouring QP to be solved (a shallow copy is made). \n 109 If Hessian matrix is trivial, a NULL pointer can be passed. */ 110 const real_t* const g_new, /**< Gradient of neighbouring QP to be solved. */ 111 Matrix *A_new, /**< Constraint matrix of neighbouring QP to be solved (a shallow copy is made). \n 112 If QP sequence does not involve constraints, a NULL pointer can be passed. */ 113 const real_t* const lb_new, /**< Lower bounds of neighbouring QP to be solved. \n 114 If no lower bounds exist, a NULL pointer can be passed. */ 115 const real_t* const ub_new, /**< Upper bounds of neighbouring QP to be solved. \n 116 If no upper bounds exist, a NULL pointer can be passed. */ 117 const real_t* const lbA_new, /**< Lower constraints' bounds of neighbouring QP to be solved. \n 118 If no lower constraints' bounds exist, a NULL pointer can be passed. */ 119 const real_t* const ubA_new, /**< Upper constraints' bounds of neighbouring QP to be solved. \n 120 If no upper constraints' bounds exist, a NULL pointer can be passed. */ 121 int_t& nWSR, /**< Input: Maximum number of working set recalculations; \n 122 Output: Number of performed working set recalculations. */ 123 real_t* const cputime = 0, /**< Input: Maximum CPU time allowed for QP solution. \n 124 Output: CPU time spen for QP solution (or to perform nWSR iterations). */ 125 const Bounds* const guessedBounds = 0, /**< Optimal working set of bounds for solution (xOpt,yOpt). \n 126 (If a null pointer is passed, the previous working set of bounds is kept!) */ 127 const Constraints* const guessedConstraints = 0 /**< Optimal working set of constraints for solution (xOpt,yOpt). \n 128 (If a null pointer is passed, the previous working set of constraints is kept!) */ 129 ); 130 131 /** Solves an initialised QP sequence with matrix shift using 132 * the online active set strategy. 133 * \return SUCCESSFUL_RETURN \n 134 RET_MAX_NWSR_REACHED \n 135 RET_HOTSTART_FAILED_AS_QP_NOT_INITIALISED \n 136 RET_HOTSTART_FAILED \n 137 RET_MATRIX_SHIFT_FAILED \n 138 RET_SHIFT_DETERMINATION_FAILED \n 139 RET_STEPDIRECTION_DETERMINATION_FAILED \n 140 RET_STEPLENGTH_DETERMINATION_FAILED \n 141 RET_HOMOTOPY_STEP_FAILED \n 142 RET_HOTSTART_STOPPED_INFEASIBILITY \n 143 RET_HOTSTART_STOPPED_UNBOUNDEDNESS \n 144 RET_SETUP_AUXILIARYQP_FAILED */ 145 returnValue hotstart( const real_t* const H_new, /**< Hessian matrix of neighbouring QP to be solved (a shallow copy is made). \n 146 If Hessian matrix is trivial, a NULL pointer can be passed. */ 147 const real_t* const g_new, /**< Gradient of neighbouring QP to be solved. */ 148 const real_t* const A_new, /**< Constraint matrix of neighbouring QP to be solved (a shallow copy is made). \n 149 If QP sequence does not involve constraints, a NULL pointer can be passed. */ 150 const real_t* const lb_new, /**< Lower bounds of neighbouring QP to be solved. \n 151 If no lower bounds exist, a NULL pointer can be passed. */ 152 const real_t* const ub_new, /**< Upper bounds of neighbouring QP to be solved. \n 153 If no upper bounds exist, a NULL pointer can be passed. */ 154 const real_t* const lbA_new, /**< Lower constraints' bounds of neighbouring QP to be solved. \n 155 If no lower constraints' bounds exist, a NULL pointer can be passed. */ 156 const real_t* const ubA_new, /**< Upper constraints' bounds of neighbouring QP to be solved. \n 157 If no upper constraints' bounds exist, a NULL pointer can be passed. */ 158 int_t& nWSR, /**< Input: Maximum number of working set recalculations; \n 159 Output: Number of performed working set recalculations. */ 160 real_t* const cputime = 0, /**< Input: Maximum CPU time allowed for QP solution. \n 161 Output: CPU time spent for QP solution (or to perform nWSR iterations). */ 162 const Bounds* const guessedBounds = 0, /**< Optimal working set of bounds for solution (xOpt,yOpt). \n 163 (If a null pointer is passed, the previous working set of bounds is kept!) */ 164 const Constraints* const guessedConstraints = 0 /**< Optimal working set of constraints for solution (xOpt,yOpt). \n 165 (If a null pointer is passed, the previous working set of constraints is kept!) */ 166 ); 167 168 /** Solves an initialised QP sequence with matrix shift using 169 * the online active set strategy, where QP data is read from files. 170 * \return SUCCESSFUL_RETURN \n 171 RET_MAX_NWSR_REACHED \n 172 RET_HOTSTART_FAILED_AS_QP_NOT_INITIALISED \n 173 RET_HOTSTART_FAILED \n 174 RET_MATRIX_SHIFT_FAILED \n 175 RET_SHIFT_DETERMINATION_FAILED \n 176 RET_STEPDIRECTION_DETERMINATION_FAILED \n 177 RET_STEPLENGTH_DETERMINATION_FAILED \n 178 RET_HOMOTOPY_STEP_FAILED \n 179 RET_HOTSTART_STOPPED_INFEASIBILITY \n 180 RET_HOTSTART_STOPPED_UNBOUNDEDNESS \n 181 RET_SETUP_AUXILIARYQP_FAILED \n 182 RET_UNABLE_TO_READ_FILE \n 183 RET_INVALID_ARGUMENTS */ 184 returnValue hotstart( const char* const H_file, /**< Name of file where Hessian matrix is stored. \n 185 If Hessian matrix is trivial, a NULL pointer can be passed. */ 186 const char* const g_file, /**< Name of file where gradient, of neighbouring QP to be solved, is stored. */ 187 const char* const A_file, /**< Name of file where constraint matrix is stored. \n 188 If QP sequence does not involve constraints, a NULL pointer can be passed. */ 189 const char* const lb_file, /**< Name of file where lower bounds, of neighbouring QP to be solved, is stored. \n 190 If no lower bounds exist, a NULL pointer can be passed. */ 191 const char* const ub_file, /**< Name of file where upper bounds, of neighbouring QP to be solved, is stored. \n 192 If no upper bounds exist, a NULL pointer can be passed. */ 193 const char* const lbA_file, /**< Name of file where lower constraints' bounds, of neighbouring QP to be solved, is stored. \n 194 If no lower constraints' bounds exist, a NULL pointer can be passed. */ 195 const char* const ubA_file, /**< Name of file where upper constraints' bounds, of neighbouring QP to be solved, is stored. \n 196 If no upper constraints' bounds exist, a NULL pointer can be passed. */ 197 int_t& nWSR, /**< Input: Maximum number of working set recalculations; \n 198 Output: Number of performed working set recalculations. */ 199 real_t* const cputime = 0, /**< Input: Maximum CPU time allowed for QP solution. \n 200 Output: CPU time spent for QP solution (or to perform nWSR iterations). */ 201 const Bounds* const guessedBounds = 0, /**< Optimal working set of bounds for solution (xOpt,yOpt). \n 202 (If a null pointer is passed, the previous working set of bounds is kept!) */ 203 const Constraints* const guessedConstraints = 0 /**< Optimal working set of constraints for solution (xOpt,yOpt). \n 204 (If a null pointer is passed, the previous working set of constraints is kept!) */ 205 ); 206 207 /** Solves an initialised QP sequence (without matrix shift) using 208 * the online active set strategy. 209 * By default, QP solution is started from previous solution. If a guess 210 * for the working set is provided, an initialised homotopy is performed. 211 * 212 * Note: This functions just forwards to the corresponding 213 * QProblem::hotstart member function. 214 * 215 * \return SUCCESSFUL_RETURN \n 216 RET_MAX_NWSR_REACHED \n 217 RET_HOTSTART_FAILED_AS_QP_NOT_INITIALISED \n 218 RET_HOTSTART_FAILED \n 219 RET_SHIFT_DETERMINATION_FAILED \n 220 RET_STEPDIRECTION_DETERMINATION_FAILED \n 221 RET_STEPLENGTH_DETERMINATION_FAILED \n 222 RET_HOMOTOPY_STEP_FAILED \n 223 RET_HOTSTART_STOPPED_INFEASIBILITY \n 224 RET_HOTSTART_STOPPED_UNBOUNDEDNESS */ 225 returnValue hotstart( const real_t* const g_new, /**< Gradient of neighbouring QP to be solved. */ 226 const real_t* const lb_new, /**< Lower bounds of neighbouring QP to be solved. \n 227 If no lower bounds exist, a NULL pointer can be passed. */ 228 const real_t* const ub_new, /**< Upper bounds of neighbouring QP to be solved. \n 229 If no upper bounds exist, a NULL pointer can be passed. */ 230 const real_t* const lbA_new, /**< Lower constraints' bounds of neighbouring QP to be solved. \n 231 If no lower constraints' bounds exist, a NULL pointer can be passed. */ 232 const real_t* const ubA_new, /**< Upper constraints' bounds of neighbouring QP to be solved. \n 233 If no upper constraints' bounds exist, a NULL pointer can be passed. */ 234 int_t& nWSR, /**< Input: Maximum number of working set recalculations; \n 235 Output: Number of performed working set recalculations. */ 236 real_t* const cputime = 0, /**< Input: Maximum CPU time allowed for QP solution. \n 237 Output: CPU time spent for QP solution (or to perform nWSR iterations). */ 238 const Bounds* const guessedBounds = 0, /**< Optimal working set of bounds for solution (xOpt,yOpt). \n 239 (If a null pointer is passed, the previous working set of bounds is kept!) */ 240 const Constraints* const guessedConstraints = 0 /**< Optimal working set of constraints for solution (xOpt,yOpt). \n 241 (If a null pointer is passed, the previous working set of constraints is kept!) */ 242 ); 243 244 /** Solves an initialised QP sequence (without matrix shift) using 245 * the online active set strategy, where QP data is read from files. 246 * By default, QP solution is started from previous solution. If a guess 247 * for the working set is provided, an initialised homotopy is performed. 248 * 249 * Note: This functions just forwards to the corresponding 250 * QProblem::hotstart member function. 251 * 252 * \return SUCCESSFUL_RETURN \n 253 RET_MAX_NWSR_REACHED \n 254 RET_HOTSTART_FAILED_AS_QP_NOT_INITIALISED \n 255 RET_HOTSTART_FAILED \n 256 RET_SHIFT_DETERMINATION_FAILED \n 257 RET_STEPDIRECTION_DETERMINATION_FAILED \n 258 RET_STEPLENGTH_DETERMINATION_FAILED \n 259 RET_HOMOTOPY_STEP_FAILED \n 260 RET_HOTSTART_STOPPED_INFEASIBILITY \n 261 RET_HOTSTART_STOPPED_UNBOUNDEDNESS \n 262 RET_UNABLE_TO_READ_FILE \n 263 RET_INVALID_ARGUMENTS */ 264 returnValue hotstart( const char* const g_file, /**< Name of file where gradient, of neighbouring QP to be solved, is stored. */ 265 const char* const lb_file, /**< Name of file where lower bounds, of neighbouring QP to be solved, is stored. \n 266 If no lower bounds exist, a NULL pointer can be passed. */ 267 const char* const ub_file, /**< Name of file where upper bounds, of neighbouring QP to be solved, is stored. \n 268 If no upper bounds exist, a NULL pointer can be passed. */ 269 const char* const lbA_file, /**< Name of file where lower constraints' bounds, of neighbouring QP to be solved, is stored. \n 270 If no lower constraints' bounds exist, a NULL pointer can be passed. */ 271 const char* const ubA_file, /**< Name of file where upper constraints' bounds, of neighbouring QP to be solved, is stored. \n 272 If no upper constraints' bounds exist, a NULL pointer can be passed. */ 273 int_t& nWSR, /**< Input: Maximum number of working set recalculations; \n 274 Output: Number of performed working set recalculations. */ 275 real_t* const cputime = 0, /**< Input: Maximum CPU time allowed for QP solution. \n 276 Output: CPU time spent for QP solution (or to perform nWSR iterations). */ 277 const Bounds* const guessedBounds = 0, /**< Optimal working set of bounds for solution (xOpt,yOpt). \n 278 (If a null pointer is passed, the previous working set of bounds is kept!) */ 279 const Constraints* const guessedConstraints = 0 /**< Optimal working set of constraints for solution (xOpt,yOpt). \n 280 (If a null pointer is passed, the previous working set of constraints is kept!) */ 281 ); 282 283 284 #ifdef __MATLAB__ 285 /** Sets pointer of Hessian and constraint matrix to zero. 286 * QUICK HACK FOR MAKING THE MATLAB INTERFACE RUN! TO BE REMOVED! 287 * \return SUCCESSFUL_RETURN */ 288 returnValue resetMatrixPointers( ); 289 #endif 290 291 292 /* 293 * PROTECTED MEMBER FUNCTIONS 294 */ 295 protected: 296 297 /** Sets new matrices and calculates their factorisations. If the 298 * current Hessian is trivial (i.e. HST_ZERO or HST_IDENTITY) but a 299 * non-trivial one is given, memory for Hessian is allocated and 300 * it is set to the given one. Afterwards, all QP vectors are 301 * transformed in order to start from an optimal solution. 302 * \return SUCCESSFUL_RETURN \n 303 * RET_MATRIX_FACTORISATION_FAILED \n 304 * RET_NO_HESSIAN_SPECIFIED */ 305 virtual returnValue setupNewAuxiliaryQP( SymmetricMatrix *H_new, /**< New Hessian matrix. \n 306 If Hessian matrix is trivial, a NULL pointer can be passed. */ 307 Matrix *A_new, /**< New constraint matrix. \n 308 If QP sequence does not involve constraints, a NULL pointer can be passed. */ 309 const real_t *lb_new, /**< New lower bounds. \n 310 If no lower bounds exist, a NULL pointer can be passed. */ 311 const real_t *ub_new, /**< New upper bounds. \n 312 If no lower bounds exist, a NULL pointer can be passed. */ 313 const real_t *lbA_new, /**< New lower constraints' bounds. \n 314 If no lower constraints' bounds exist, a NULL pointer can be passed. */ 315 const real_t *ubA_new /**< New lower constraints' bounds. \n 316 If no lower constraints' bounds exist, a NULL pointer can be passed. */ 317 ); 318 319 /** Sets new matrices and calculates their factorisations. If the 320 * current Hessian is trivial (i.e. HST_ZERO or HST_IDENTITY) but a 321 * non-trivial one is given, memory for Hessian is allocated and 322 * it is set to the given one. Afterwards, all QP vectors are 323 * transformed in order to start from an optimal solution. 324 * \return SUCCESSFUL_RETURN \n 325 * RET_MATRIX_FACTORISATION_FAILED \n 326 * RET_NO_HESSIAN_SPECIFIED */ 327 virtual returnValue setupNewAuxiliaryQP( const real_t* const H_new, /**< New Hessian matrix. \n 328 If Hessian matrix is trivial, a NULL pointer can be passed. */ 329 const real_t* const A_new, /**< New constraint matrix. \n 330 If QP sequence does not involve constraints, a NULL pointer can be passed. */ 331 const real_t *lb_new, /**< New lower bounds. \n 332 If no lower bounds exist, a NULL pointer can be passed. */ 333 const real_t *ub_new, /**< New upper bounds. \n 334 If no lower bounds exist, a NULL pointer can be passed. */ 335 const real_t *lbA_new, /**< New lower constraints' bounds. \n 336 If no lower constraints' bounds exist, a NULL pointer can be passed. */ 337 const real_t *ubA_new /**< New lower constraints' bounds. \n 338 If no lower constraints' bounds exist, a NULL pointer can be passed. */ 339 ); 340 341 342 /* 343 * PROTECTED MEMBER VARIABLES 344 */ 345 protected: 346 347 }; 348 349 350 END_NAMESPACE_QPOASES 351 352 #include <qpOASES/SQProblem.ipp> 353 354 #endif /* QPOASES_SQPROBLEM_HPP */ 355 356 357 /* 358 * end of file 359 */ 360