### Run a Simple Test Example Source: https://github.com/coin-or/qpoases/wiki/QpoasesInstallation Executes a pre-compiled test program 'example1' to verify the qpOASES installation. Navigate to the 'bin' directory first. ```bash cd /bin ./example1 ``` -------------------------------- ### Run Quick Example Test Source: https://github.com/coin-or/qpoases/blob/master/interfaces/python/README.rst Execute a quick example script to test the Python interface installation. Navigate to the interface directory and run example1.py. ```bash cd ./interfaces/python/ python example1.py ``` -------------------------------- ### Basic qpOASES Configuration Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/05-options.md Demonstrates the basic setup for a QProblem object and applying default options. This is the starting point for most qpOASES integrations. ```cpp #include using namespace qpOASES; // Create QProblem QProblem qp(nV, nC); // Use default options Options options; qp.setOptions(options); // Solve QP... qp.init(H, g, A, lb, ub, lbA, ubA, nWSR); ``` -------------------------------- ### Compile qpOASES Library and Examples Source: https://github.com/coin-or/qpoases/wiki/QpoasesInstallation Compiles the qpOASES library ('libqpOASES.a' or 'libqpOASES.so') and test examples. This command should be run from the installation directory. ```bash cd make ``` -------------------------------- ### QPsolver Initialization and Status Check Example Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/07-types-constants.md Demonstrates how to initialize the qpOASES solver with options, check the return value for success, and retrieve the solution if the problem is solved. Also shows how to check for infeasibility. ```cpp #include using namespace qpOASES; // Create options Options options; // Set print level options.printLevel = PL_MEDIUM; // Check Hessian type HessianType h_type = HST_POSDEF; // Use return value returnValue ret = qp.init(H, g, A, lb, ub, lbA, ubA, nWSR); if (ret != SUCCESSFUL_RETURN) { printf("Initialization failed\n"); return 1; } // Check solver status if (qp.getStatus() == QPS_SOLVED) { // Get solution real_t xOpt[nV]; qp.getPrimalSolution(xOpt); } // Check for infeasibility/unboundedness if (qp.isInfeasible() == BT_TRUE) { printf("Problem is infeasible\n"); } ``` -------------------------------- ### Install Cython and NumPy Source: https://github.com/coin-or/qpoases/blob/master/interfaces/python/README.rst Install the necessary Python packages, Cython and NumPy, using pip. ```bash sudo pip install cython sudo pip install numpy ``` -------------------------------- ### Global Python Interface Installation Source: https://github.com/coin-or/qpoases/blob/master/interfaces/python/README.rst Install the Python interface globally using sudo privileges. ```bash sudo make pythoninstall ``` -------------------------------- ### Install Nose for Unit Testing Source: https://github.com/coin-or/qpoases/blob/master/interfaces/python/README.rst Install the 'nose' testing framework using pip, which is required for running the comprehensive unit tests. ```bash sudo pip install nose ``` -------------------------------- ### QP Problem Initialization and Solution Example Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/02-qproblem.md Demonstrates how to initialize a QProblem object with QP data, solve it, retrieve the primal and dual solutions, and then perform a warm-start with updated bounds and objective coefficients. ```cpp #include using namespace qpOASES; // Define QP data: 2 variables, 1 constraint real_t H[2*2] = { 1.0, 0.0, 0.0, 0.5 }; real_t A[1*2] = { 1.0, 1.0 }; real_t g[2] = { 1.5, 1.0 }; real_t lb[2] = { 0.5, -2.0 }; real_t ub[2] = { 5.0, 2.0 }; real_t lbA[1] = { -1.0 }; real_t ubA[1] = { 2.0 }; // Create solver QProblem qp(2, 1); // Solve initial QP int_t nWSR = 10; qp.init(H, g, A, lb, ub, lbA, ubA, nWSR); // Get solution real_t xOpt[2]; real_t yOpt[3]; // 2 for bounds + 1 for constraint qp.getPrimalSolution(xOpt); qp.getDualSolution(yOpt); printf("x: [%e, %e]\n", xOpt[0], xOpt[1]); printf("y: [%e, %e, %e]\n", yOpt[0], yOpt[1], yOpt[2]); // Warm-start with new bounds real_t g_new[2] = { 1.0, 1.5 }; real_t lb_new[2] = { 0.0, -1.0 }; real_t ub_new[2] = { 5.0, -0.5 }; real_t lbA_new[1] = { -2.0 }; real_t ubA_new[1] = { 1.0 }; nWSR = 10; qp.hotstart(g_new, lb_new, ub_new, lbA_new, ubA_new, nWSR); // Get new solution qp.getPrimalSolution(xOpt); qp.getDualSolution(yOpt); ``` -------------------------------- ### Bounds and Constraints Usage Example Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/04-bounds-constraints.md Demonstrates how to create, set up, and query bounds and constraints for variables using the qpOASES library. Shows how to manage variable bounds and constraint statuses. ```cpp #include using namespace qpOASES; // Create bounds for 3 variables Bounds bounds(3); // Set up bounds: variable 0 at lower, variable 1 free, variable 2 at upper bounds.setupBound(0, ST_LOWER); bounds.setupBound(1, ST_INACTIVE); bounds.setupBound(2, ST_UPPER); // Check counts printf("Free variables: %d\n", bounds.getNFR()); printf("At lower bound: %d\n", bounds.getNLB()); printf("At upper bound: %d\n", bounds.getNUB()); // Move variable 0 from lower to inactive bounds.removeBound(0); // Create constraints for 2 constraints Constraints constraints(2); // Set up constraints constraints.setupConstraint(0, ST_LOWER); constraints.setupConstraint(1, ST_INACTIVE); // Check status printf("Constraint 0 status: %d\n", constraints.getStatus(0)); printf("Active constraints: %d\n", constraints.getNAC()); // Swap constraint 0 from lower to upper constraints.swapConstraint(0, BT_FALSE); ``` -------------------------------- ### Initialize QProblem with Dense Matrices Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/06-matrices.md Example of initializing a QProblem solver using dense matrices for the Hessian and constraints. ```cpp #include using namespace qpOASES; // Create dense Hessian (2x2 symmetric) real_t H_vals[2*2] = { 1.0, 0.0, 0.0, 0.5 }; DenseSymmetricMatrix H(2, 2, H_vals); // Create constraint matrix (1x2) real_t A_vals[1*2] = { 1.0, 1.0 }; DenseMatrix A(1, 2, 2, A_vals); // Use in QProblem QProblem qp(2, 1); int_t nWSR = 10; qp.init(&H, g, &A, lb, ub, lbA, ubA, nWSR); ``` -------------------------------- ### hotstart() with Arrays Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/01-qproblemb.md Solves a neighboring QP using the online active set strategy starting from the previous solution. This variant accepts new gradient, lower bounds, and upper bounds as arrays. ```APIDOC ## hotstart() with Arrays ### Description Solves a neighboring QP using the online active set strategy starting from the previous solution. ### Method Signature ```cpp returnValue hotstart(const real_t* const g_new, const real_t* const lb_new, const real_t* const ub_new, int_t& nWSR, real_t* const cputime = 0, const Bounds* const guessedBounds = 0) ``` ### Parameters #### Input Arrays - **g_new** (`const real_t*`) - Gradient of next QP. - **lb_new** (`const real_t*`) - New lower bounds; NULL if none. - **ub_new** (`const real_t*`) - New upper bounds; NULL if none. #### In/Out Parameters - **nWSR** (`int_t&`) - [in/out] max/performed iterations. - **cputime** (`real_t*`) - [in/out] CPU time (optional), defaults to 0. #### Optional Parameters - **guessedBounds** (`const Bounds*`) - Working set hint; NULL retains previous, defaults to 0. ### Return Value - `SUCCESSFUL_RETURN` - `RET_MAX_NWSR_REACHED` - `RET_HOTSTART_FAILED_AS_QP_NOT_INITIALISED` - `RET_HOTSTART_FAILED` - `RET_SHIFT_DETERMINATION_FAILED` - `RET_STEPDIRECTION_DETERMINATION_FAILED` - `RET_STEPLENGTH_DETERMINATION_FAILED` - `RET_HOMOTOPY_STEP_FAILED` - `RET_HOTSTART_STOPPED_INFEASIBILITY` - `RET_HOTSTART_STOPPED_UNBOUNDEDNESS` ``` -------------------------------- ### Indexlist Default Constructor Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/10-indexlist-flipper.md Creates an empty index list. No setup is required. ```cpp Indexlist() ``` -------------------------------- ### Initialize QProblem with Sparse Matrix Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/06-matrices.md Example of initializing a QProblem solver using a sparse matrix for constraints in Harwell-Boeing format. ```cpp // Sparse matrix in Harwell-Boeing format int_t ir[3] = { 0, 0, 1 }; // Row indices int_t jc[3] = { 0, 1, 1 }; // Column indices real_t val[3] = { 2.0, 1.0, 1.0 }; // Non-zero values SparseMatrix A(2, 2, ir, jc, val); // Use in QProblem qp.init(H, g, &A, lb, ub, lbA, ubA, nWSR); ``` -------------------------------- ### Hot-start QP with Files Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/01-qproblemb.md Solves a neighboring QP using the online active set strategy starting from the previous solution. Reads new gradient, lower bounds, and upper bounds from files. ```cpp returnValue hotstart(const char* const g_file, const char* const lb_file, const char* const ub_file, int_t& nWSR, real_t* const cputime = 0, const Bounds* const guessedBounds = 0) ``` -------------------------------- ### Local Python Interface Installation Source: https://github.com/coin-or/qpoases/blob/master/interfaces/python/README.rst Build the Python interface locally, creating a qpoases.so file. Update your PYTHONPATH environment variable to include the build directory. ```bash make python ``` ```bash export PYTHONPATH=$PYTHONPATH:/home/swalter/projects/qpOASES/interfaces/python ``` -------------------------------- ### Build Python Interface In-Place Source: https://github.com/coin-or/qpoases/blob/master/interfaces/python/README.rst Build the Python interface in the current directory using setup.py. This method is useful for development or when a local installation is preferred. ```bash cd ./interfaces/python/ python setup.py build_ext --inplace ``` ```bash python setup.py install ``` -------------------------------- ### Hot-start QP with Arrays Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/01-qproblemb.md Solves a neighboring QP using the online active set strategy starting from the previous solution. Accepts new gradient, lower bounds, and upper bounds as arrays. ```cpp returnValue hotstart(const real_t* const g_new, const real_t* const lb_new, const real_t* const ub_new, int_t& nWSR, real_t* const cputime = 0, const Bounds* const guessedBounds = 0) ``` -------------------------------- ### SparseSolver Usage Example Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/08-sparse-solver.md Demonstrates how to initialize and use the SparseSolver with a matrix in Harwell-Boeing format to solve a linear system Ax = rhs. ```cpp #include using namespace qpOASES; // Define sparse matrix in Harwell-Boeing format // Example: 3x3 matrix with 5 non-zeros int_t irn[5] = { 1, 1, 2, 3, 3 }; // Row indices (1-based) int_t jcn[5] = { 1, 2, 2, 2, 3 }; // Column indices (1-based) real_t avals[5] = { 4.0, 2.0, 3.0, 5.0, 1.0 }; // Create and initialize sparse solver SparseSolver solver; solver.init(3, 3, 5, irn, jcn, avals); // Define right-hand side real_t rhs[3] = { 1.0, 2.0, 3.0 }; // Solve Ax = rhs solver.solve(1, rhs); printf("Solution x: [%%e, %%e, %%e]\n", rhs[0], rhs[1], rhs[2]); ``` -------------------------------- ### Default Constructor for Options Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/05-options.md Creates an Options object with default solver settings. Use this when starting with standard configurations. ```cpp Options() ``` -------------------------------- ### Default Constructor for QProblem Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/02-qproblem.md Creates a QProblem object with default initialization. No specific setup is required before calling this constructor. ```cpp QProblem() ``` -------------------------------- ### hotstart() with Files Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/02-qproblem.md Provides a file-based variant for warm-starting a QP. This method accepts file paths for new gradient, bounds, and constraints, useful when data is stored externally. It also manages iteration counts and optional CPU time recording. ```cpp returnValue hotstart(const char* const g_file, const char* const lb_file, const char* const ub_file, const char* const lbA_file, const char* const ubA_file, int_t& nWSR, real_t* const cputime = 0, const Bounds* const guessedBounds = 0, const Constraints* const guessedConstraints = 0) ``` -------------------------------- ### Create SparseSolver Object Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/08-sparse-solver.md Initializes a SparseSolver object for solving sparse linear systems. No setup is required before calling this constructor. ```cpp SparseSolver() ``` -------------------------------- ### hotstart() with Files Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/02-qproblem.md Solves a neighboring QP by warm-starting from the previous solution using file paths for new gradient, bounds, and constraint information. ```APIDOC ## hotstart() with Files ### Description File-based warm-start variant. Solves a neighboring QP by warm-starting from the previous solution, accepting new gradient, variable bounds, and constraint bounds via file paths. ### Method `returnValue hotstart(const char* const g_file, const char* const lb_file, const char* const ub_file, const char* const lbA_file, const char* const ubA_file, int_t& nWSR, real_t* const cputime = 0, const Bounds* const guessedBounds = 0, const Constraints* const guessedConstraints = 0)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **g_file** (`const char*`) - Path to the file containing the new gradient vector - **lb_file** (`const char*`) - Path to the file containing the new lower bounds on variables - **ub_file** (`const char*`) - Path to the file containing the new upper bounds on variables - **lbA_file** (`const char*`) - Path to the file containing the new lower constraint bounds - **ubA_file** (`const char*`) - Path to the file containing the new upper constraint bounds - **nWSR** (`int_t&`) - [in/out] max/performed iterations - **cputime** (`real_t*`) - [in/out] CPU time (optional, defaults to 0) - **guessedBounds** (`const Bounds*`) - Working set hint for bounds (defaults to 0) - **guessedConstraints** (`const Constraints*`) - Working set hint for constraints (defaults to 0) ### Request Example ```cpp // Example usage (conceptual) returnValue result = qp_solver.hotstart("g_new.txt", "lb_new.txt", "ub_new.txt", "lbA_new.txt", "ubA_new.txt", nWSR_var, cputime_var); ``` ### Response #### Success Response (200) Returns a `returnValue` indicating success or the specific reason for failure. Possible return values include: - `SUCCESSFUL_RETURN` - `RET_MAX_NWSR_REACHED` - `RET_HOTSTART_FAILED_AS_QP_NOT_INITIALISED` - `RET_HOTSTART_FAILED` - `RET_SHIFT_DETERMINATION_FAILED` - `RET_STEPDIRECTION_DETERMINATION_FAILED` - `RET_STEPLENGTH_DETERMINATION_FAILED` - `RET_HOMOTOPY_STEP_FAILED` - `RET_HOTSTART_STOPPED_INFEASIBILITY` - `RET_HOTSTART_STOPPED_UNBOUNDEDNESS` - `RET_SETUP_AUXILIARYQP_FAILED` #### Response Example ```cpp // Conceptual example of checking return value if (result == SUCCESSFUL_RETURN) { // QP solved successfully } else { // Handle error based on the specific return value } ``` ``` -------------------------------- ### Setup Bound with Status Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/04-bounds-constraints.md Adds a new bound to the working set with a specified initial status. Ensure the bound number is within the valid range. ```cpp returnValue setupBound(int_t number, SubjectToStatus _status) ``` -------------------------------- ### hotstart() with Files Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/01-qproblemb.md Solves a neighboring QP using the online active set strategy, reading input data from files. ```APIDOC ## hotstart() with Files ### Description Solves a neighboring QP using the online active set strategy, reading gradient, lower bounds, and upper bounds from files. It has the same semantics as the array variant. ### Method Signature ```cpp returnValue hotstart(const char* const g_file, const char* const lb_file, const char* const ub_file, int_t& nWSR, real_t* const cputime = 0, const Bounds* const guessedBounds = 0) ``` ### Parameters #### Input Files - **g_file** (`const char*`) - Path to the file containing the gradient of the next QP. - **lb_file** (`const char*`) - Path to the file containing the new lower bounds; NULL if none. - **ub_file** (`const char*`) - Path to the file containing the new upper bounds; NULL if none. #### In/Out Parameters - **nWSR** (`int_t&`) - [in/out] max/performed iterations. - **cputime** (`real_t*`) - [in/out] CPU time (optional), defaults to 0. #### Optional Parameters - **guessedBounds** (`const Bounds*`) - Working set hint; NULL retains previous, defaults to 0. ### Return Value - `SUCCESSFUL_RETURN` - `RET_MAX_NWSR_REACHED` - `RET_HOTSTART_FAILED_AS_QP_NOT_INITIALISED` - `RET_HOTSTART_FAILED` - `RET_SHIFT_DETERMINATION_FAILED` - `RET_STEPDIRECTION_DETERMINATION_FAILED` - `RET_STEPLENGTH_DETERMINATION_FAILED` - `RET_HOMOTOPY_STEP_FAILED` - `RET_HOTSTART_STOPPED_INFEASIBILITY` - `RET_HOTSTART_STOPPED_UNBOUNDEDNESS` ``` -------------------------------- ### hotstart() Methods Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/11-sqproblem-schur.md Methods for solving neighboring QPs using Schur complement updates. These methods allow for efficient warm-starting when the Hessian, constraint matrix, or bounds change, with variants for different data input types (matrices, dense arrays, files). ```APIDOC ## hotstart() Methods ### With Hessian and Matrix Changes ```cpp returnValue hotstart(SymmetricMatrix *_H, const real_t* const _g, Matrix *_A, const real_t* const _lb, const real_t* const _ub, const real_t* const _lbA, const real_t* const _ubA, int_t& nWSR, real_t* const cputime = 0, const Bounds* const guessedBounds = 0, const Constraints* const guessedConstraints = 0) ``` Solves a neighboring QP with new Hessian, constraint matrix, and bounds using Schur complement updates. **Return:** `SUCCESSFUL_RETURN`, `RET_MAX_NWSR_REACHED`, `RET_HOTSTART_FAILED`, `RET_HOTSTART_FAILED_AS_QP_NOT_INITIALISED`, `RET_MATRIX_SHIFT_FAILED`, or other error codes ### With Dense Arrays ```cpp returnValue hotstart(const real_t* const _H, const real_t* const _g, const real_t* const _A, const real_t* const _lb, const real_t* const _ub, const real_t* const _lbA, const real_t* const _ubA, int_t& nWSR, real_t* const cputime = 0, const Bounds* const guessedBounds = 0, const Constraints* const guessedConstraints = 0) ``` Dense array variant with same semantics. ### With File I/O ```cpp returnValue hotstart(const char* const H_file, const char* const g_file, const char* const A_file, const char* const lb_file, const char* const ub_file, const char* const lbA_file, const char* const ubA_file, int_t& nWSR, real_t* const cputime = 0, const Bounds* const guessedBounds = 0, const Constraints* const guessedConstraints = 0) ``` File-based variant for reading QP data from disk. ``` -------------------------------- ### Get Number of Constraints Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/02-qproblem.md Returns the total number of constraints in the problem. ```cpp inline int_t getNC() const ``` -------------------------------- ### Get Print Level Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/01-qproblemb.md Retrieves the current print level setting for the solver. ```cpp inline PrintLevel getPrintLevel() const ``` -------------------------------- ### hotstart() with Arrays Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/02-qproblem.md Solves a neighboring QP by warm-starting from the previous solution using array inputs for new gradient, bounds, and constraint information. ```APIDOC ## hotstart() with Arrays ### Description Solves a neighboring QP by warm-starting from the previous solution. This variant accepts new gradient, variable bounds, and constraint bounds as arrays. ### Method `returnValue hotstart(const real_t* const g_new, const real_t* const lb_new, const real_t* const ub_new, const real_t* const lbA_new, const real_t* const ubA_new, int_t& nWSR, real_t* const cputime = 0, const Bounds* const guessedBounds = 0, const Constraints* const guessedConstraints = 0)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **g_new** (`const real_t*`) - New gradient vector - **lb_new** (`const real_t*`) - New lower bounds on variables; NULL if none - **ub_new** (`const real_t*`) - New upper bounds on variables; NULL if none - **lbA_new** (`const real_t*`) - New lower constraint bounds; NULL if none - **ubA_new** (`const real_t*`) - New upper constraint bounds; NULL if none - **nWSR** (`int_t&`) - [in/out] max/performed iterations - **cputime** (`real_t*`) - [in/out] CPU time (optional, defaults to 0) - **guessedBounds** (`const Bounds*`) - Working set hint for bounds (defaults to 0) - **guessedConstraints** (`const Constraints*`) - Working set hint for constraints (defaults to 0) ### Request Example ```cpp // Example usage (conceptual) returnValue result = qp_solver.hotstart(g_new_array, lb_new_array, ub_new_array, lbA_new_array, ubA_new_array, nWSR_var, cputime_var); ``` ### Response #### Success Response (200) Returns a `returnValue` indicating success or the specific reason for failure. Possible return values include: - `SUCCESSFUL_RETURN` - `RET_MAX_NWSR_REACHED` - `RET_HOTSTART_FAILED_AS_QP_NOT_INITIALISED` - `RET_HOTSTART_FAILED` - `RET_SHIFT_DETERMINATION_FAILED` - `RET_STEPDIRECTION_DETERMINATION_FAILED` - `RET_STEPLENGTH_DETERMINATION_FAILED` - `RET_HOMOTOPY_STEP_FAILED` - `RET_HOTSTART_STOPPED_INFEASIBILITY` - `RET_HOTSTART_STOPPED_UNBOUNDEDNESS` - `RET_SETUP_AUXILIARYQP_FAILED` #### Response Example ```cpp // Conceptual example of checking return value if (result == SUCCESSFUL_RETURN) { // QP solved successfully } else { // Handle error based on the specific return value } ``` ``` -------------------------------- ### Get Solver Options Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/01-qproblemb.md Retrieves a copy of the current solver options struct. ```cpp inline Options getOptions() const ``` -------------------------------- ### QP Warm-start with Matrix Updates Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/11-sqproblem-schur.md This snippet demonstrates how to perform a warm-start on an existing QP problem after updating its matrices and bounds. It shows the process of calling `hotstart` with new problem data and retrieving the updated solution. ```cpp // First warm-start: update matrices and bounds real_t H_new[3*3] = { 2.2, 0.0, 0.0, 0.0, 2.1, 0.0, 0.0, 0.0, 2.3 }; real_t A_new[2*3] = { 1.0, 0.9, 0.1, 0.1, 1.0, 0.9 }; real_t g_new[3] = { 1.1, 2.1, 1.1 }; real_t lb_new[3] = { 0.1, 0.0, 0.0 }; real_t ub_new[3] = { 9.9, 10.0, 10.0 }; nWSR = 100; qp.hotstart(H_new, g_new, A_new, lb_new, ub_new, lbA, ubA, nWSR); qp.getPrimalSolution(xOpt); printf("After update 1: x = [%e, %e, %e]\n", xOpt[0], xOpt[1], xOpt[2]); ``` -------------------------------- ### Get Problem Status Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/01-qproblemb.md Returns the current status of the Quadratic Programming problem. ```cpp inline QProblemStatus getStatus() const ``` -------------------------------- ### Get Number of Fixed Variables Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/01-qproblemb.md Returns the number of variables that are fixed at their bounds. ```cpp inline int_t getNFX() const ``` -------------------------------- ### Initialize and Solve QP Problem Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/03-sqproblem.md Demonstrates the initialization and solving of an initial Quadratic Programming problem using the `init()` method. It sets up the problem with specific matrices, bounds, and constraints, then retrieves the primal and dual solutions. ```cpp #include using namespace qpOASES; // Define initial QP data: 2 variables, 1 constraint real_t H[2*2] = { 1.0, 0.0, 0.0, 0.5 }; real_t A[1*2] = { 1.0, 1.0 }; real_t g[2] = { 1.5, 1.0 }; real_t lb[2] = { 0.5, -2.0 }; real_t ub[2] = { 5.0, 2.0 }; real_t lbA[1] = { -1.0 }; real_t ubA[1] = { 2.0 }; // Create solver SQProblem qp(2, 1); // Solve initial QP int_t nWSR = 10; qp.init(H, g, A, lb, ub, lbA, ubA, nWSR); // Get solution real_t xOpt[2]; real_t yOpt[3]; qp.getPrimalSolution(xOpt); qp.getDualSolution(yOpt); printf("Initial solution: x = [%e, %e]\n", xOpt[0], xOpt[1]); ``` -------------------------------- ### Get Bounds Object Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/01-qproblemb.md Returns a deep copy of the internal bounds object. ```cpp inline returnValue getBounds(Bounds& _bounds) const ``` -------------------------------- ### Get Working Set Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/01-qproblemb.md Returns the state of all bounds and constraints in the working set. ```cpp virtual returnValue getWorkingSet(real_t* workingSet) ``` -------------------------------- ### Get Indexlist Length Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/10-indexlist-flipper.md Returns the current number of indices stored in the list. ```cpp inline int_t getLength() const ``` -------------------------------- ### init() with File I/O Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/01-qproblemb.md Initializes and solves a QP problem by reading data from specified files. This method is convenient for large problems or when data is stored persistently. ```APIDOC ## init() with File I/O ### Description Initializes and solves a QP with data read from files. ### Method `returnValue init(const char* const H_file, const char* const g_file, const char* const lb_file, const char* const ub_file, int_t& nWSR, real_t* const cputime = 0, const real_t* const xOpt = 0, const real_t* const yOpt = 0, const Bounds* const guessedBounds = 0, const char* const R_file = 0)` ### Parameters #### Path Parameters * `H_file` (const char*) - Optional - File path to Hessian matrix; NULL if trivial * `g_file` (const char*) - Required - File path to gradient vector * `lb_file` (const char*) - Optional - File path to lower bounds; NULL if none * `ub_file` (const char*) - Optional - File path to upper bounds; NULL if none * `nWSR` (int_t&) - Required - [in/out] working set iterations * `cputime` (real_t*) - Optional - [in/out] CPU time (optional) * `xOpt` (const real_t*) - Optional - Primal solution hint * `yOpt` (const real_t*) - Optional - Dual solution hint * `guessedBounds` (const Bounds*) - Optional - Working set hint * `R_file` (const char*) - Optional - File path to Cholesky factor ### Return Same as other init() variants + `RET_UNABLE_TO_READ_FILE` ``` -------------------------------- ### Warm-Start QP Sequence with Parameter Changes Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/00-index.md Initialize a QProblem once and then use hotstart() for subsequent QPs with only parameter changes. This is efficient when matrices remain constant. ```cpp // Initialize first QP QProblem qp(nV, nC); int_t nWSR = 100; qp.init(H, g, A, lb, ub, lbA, ubA, nWSR); // Warm-start for similar QPs nWSR = 100; qp.hotstart(g_new, lb_new, ub_new, lbA_new, ubA_new, nWSR); // Repeat as needed nWSR = 100; qp.hotstart(g_new2, lb_new2, ub_new2, lbA_new2, ubA_new2, nWSR); ``` -------------------------------- ### Warm-start QP from Files Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/00-index.md Performs a warm-start for a QP problem using updated data from files, potentially saving computation time. ```cpp // Warm-start from files qp.hotstart("g.txt", "lb.txt", "ub.txt", "lbA.txt", "ubA.txt", nWSR); ``` -------------------------------- ### Get Number of Variables Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/01-qproblemb.md Returns the total number of variables in the Quadratic Programming problem. ```cpp inline int_t getNV() const ``` -------------------------------- ### Get Objective Value Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/01-qproblemb.md Returns the optimal value of the objective function for the solved QP. ```cpp real_t getObjVal() const ``` -------------------------------- ### hotstart() with File I/O Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/03-sqproblem.md A file-based variant for warm-starting with matrix shifts. It reads the Hessian, gradient, constraint matrix, and bounds from specified files. ```APIDOC ## hotstart() with File I/O ### Description File-based variant for warm-start with matrix shifts. ### Method `hotstart` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None #### Input Parameters - **H_file** (`const char*`) - Required - File path for the Hessian matrix - **g_file** (`const char*`) - Required - File path for the gradient vector - **A_file** (`const char*`) - Required - File path for the constraint matrix - **lb_file** (`const char*`) - Required - File path for the lower bounds on variables - **ub_file** (`const char*`) - Required - File path for the upper bounds on variables - **lbA_file** (`const char*`) - Required - File path for the lower constraint bounds - **ubA_file** (`const char*`) - Required - File path for the upper constraint bounds - **nWSR** (`int_t&`) - Required - [in] Max iterations; [out] iterations performed - **cputime** (`real_t*`) - Optional - [in] Max CPU time; [out] time spent - **guessedBounds** (`const Bounds*`) - Optional - Working set hint for bounds - **guessedConstraints** (`const Constraints*`) - Optional - Working set hint for constraints ### Return Value Same as other `hotstart()` variants + `RET_UNABLE_TO_READ_FILE` ``` -------------------------------- ### Get Absolute Value Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/09-utilities.md Returns the absolute value of a number. Use this for magnitude calculations. ```cpp template TMax getAbs(T a) ``` -------------------------------- ### hotstart() with File I/O Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/03-sqproblem.md Use this overload for warm-starting when your problem data (Hessian, gradient, constraints, bounds) is stored in separate files. It supports matrix shifts and parameter changes, with an additional return code for file reading errors. ```cpp returnValue hotstart(const char* const H_file, const char* const g_file, const char* const A_file, const char* const lb_file, const char* const ub_file, const char* const lbA_file, const char* const ubA_file, int_t& nWSR, real_t* const cputime = 0, const Bounds* const guessedBounds = 0, const Constraints* const guessedConstraints = 0) ``` -------------------------------- ### Default Constructor for Constraints Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/04-bounds-constraints.md Creates an empty Constraints object. No setup is required before use. ```cpp Constraints() ``` -------------------------------- ### hotstart() with Arrays Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/02-qproblem.md Solves a neighboring QP by warm-starting from the previous solution using array inputs for new gradient, bounds, and constraints. The `nWSR` parameter tracks iterations, and `cputime` can optionally record CPU time. ```cpp returnValue hotstart(const real_t* const g_new, const real_t* const lb_new, const real_t* const ub_new, const real_t* const lbA_new, const real_t* const ubA_new, int_t& nWSR, real_t* const cputime = 0, const Bounds* const guessedBounds = 0, const Constraints* const guessedConstraints = 0) ``` -------------------------------- ### Get Primal Solution Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/01-qproblemb.md Retrieves the optimal primal solution vector x* after the QP has been solved. ```cpp returnValue getPrimalSolution(real_t* const xOpt) const ``` -------------------------------- ### Get Minimum of Two Values Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/09-utilities.md Returns the minimum of two values. Use this for simple comparisons. ```cpp template TMin getMin(T a, T b) ``` -------------------------------- ### Initialize QProblem with Sparse Matrices Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/08-sparse-solver.md Demonstrates the creation and initialization of a QProblem object using sparse Hessian and constraint matrices. Ensure you have the necessary sparse matrix data (indices and values) prepared. ```cpp // Create sparse Hessian int_t H_irn[...], H_jcn[...]; real_t H_vals[...]; SymmetricSparseMatrix H(nV, H_irn, H_jcn, H_vals); // Create sparse constraint matrix int_t A_irn[...], A_jcn[...]; real_t A_vals[...]; SparseMatrix A(nC, nV, A_irn, A_jcn, A_vals); // Create QProblem with sparse matrices QProblem qp(nV, nC); int_t nWSR = 100; qp.init(&H, g, &A, lb, ub, lbA, ubA, nWSR); ``` -------------------------------- ### Initialize QP from Files Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/00-index.md Initializes a Quadratic Programming (QP) problem using data read from multiple files. ```cpp // Initialize from files qp.init("H.txt", "g.txt", "A.txt", "lb.txt", "ub.txt", "lbA.txt", "ubA.txt", nWSR); ``` -------------------------------- ### Get Maximum of Two Values Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/09-utilities.md Returns the maximum of two values. Use this for simple comparisons. ```cpp template TMax getMax(T a, T b) ``` -------------------------------- ### Get Number of Inactive Constraints Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/04-bounds-constraints.md Returns the count of constraints that are currently inactive in the working set. ```cpp inline int_t getNIAC() const ``` -------------------------------- ### Update QP Problem with New Matrices and Bounds Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/03-sqproblem.md Shows how to update an existing QP problem using the `hotstart()` method when both the matrices (H, A) and bounds (g, lb, ub, lbA, ubA) change. This is useful for solving a sequence of related QP problems efficiently. ```cpp // Second iteration: update both matrices and bounds real_t H_new[2*2] = { 1.2, 0.0, 0.0, 0.6 }; real_t A_new[1*2] = { 1.0, 0.8 }; real_t g_new[2] = { 1.0, 1.5 }; real_t lb_new[2] = { 0.0, -1.0 }; real_t ub_new[2] = { 5.0, -0.5 }; real_t lbA_new[1] = { -2.0 }; real_t ubA_new[1] = { 1.0 }; nWSR = 10; qp.hotstart(H_new, g_new, A_new, lb_new, ub_new, lbA_new, ubA_new, nWSR); qp.getPrimalSolution(xOpt); qp.getDualSolution(yOpt); printf("Solution after matrix shift: x = [%e, %e]\n", xOpt[0], xOpt[1]); ``` -------------------------------- ### Get Number of Active Constraints Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/04-bounds-constraints.md Returns the count of constraints that are currently active in the working set. ```cpp inline int_t getNAC() const ``` -------------------------------- ### hotstart() from QProblem (Parameter Changes Only) Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/03-sqproblem.md This overload, inherited from QProblem, is used when only the bounds and gradient need to be updated, while the Hessian and constraint matrices remain fixed. It's suitable for solving a neighboring QP with updated parameters but unchanged structure. ```cpp virtual returnValue hotstart(const real_t* const g_new, const real_t* const lb_new, const real_t* const ub_new, const real_t* const lbA_new, const real_t* const ubA_new, int_t& nWSR, real_t* const cputime = 0, const Bounds* const guessedBounds = 0, const Constraints* const guessedConstraints = 0) ``` -------------------------------- ### Get Number of Inequality Constraints Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/04-bounds-constraints.md Returns the count of constraints that are currently defined as inequality constraints. ```cpp inline int_t getNIC() const ``` -------------------------------- ### Get Number of Equality Constraints Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/04-bounds-constraints.md Returns the count of constraints that are currently defined as equality constraints. ```cpp inline int_t getNEC() const ``` -------------------------------- ### Initialize QP with File I/O Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/01-qproblemb.md Initialize and solve a QP problem by reading data from specified files. This method supports file paths for the Hessian, gradient, lower bounds, upper bounds, and optionally the Cholesky factor. ```cpp returnValue init(const char* const H_file, const char* const g_file, const char* const lb_file, const char* const ub_file, int_t& nWSR, real_t* const cputime = 0, const real_t* const xOpt = 0, const real_t* const yOpt = 0, const Bounds* const guessedBounds = 0, const char* const R_file = 0) ``` -------------------------------- ### Get Number of Fixed Bounds Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/04-bounds-constraints.md Returns the count of bounds that are implicitly fixed by equality constraints. ```cpp inline int_t getNBX() const ``` -------------------------------- ### Get Number of Free Bounds Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/04-bounds-constraints.md Returns the count of bounds that are currently free (inactive and not at any limit). ```cpp inline int_t getNFR() const ``` -------------------------------- ### Initialize and Solve General QP Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/00-index.md Use QProblem for quadratic programming problems with both variable bounds and linear constraints. This snippet demonstrates initialization and solving. ```cpp QProblem qp(nV, nC); qp.init(H, g, A, lb, ub, lbA, ubA, nWSR); qp.hotstart(g_new, lb_new, ub_new, lbA_new, ubA_new, nWSR); ``` -------------------------------- ### init() Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/08-sparse-solver.md Initializes the solver with sparse matrix data in Harwell-Boeing format. ```APIDOC ## init() ### Description Initializes the solver with sparse matrix data in Harwell-Boeing format. ### Parameters #### Path Parameters - **m** (int_t) - Required - Number of rows - **n** (int_t) - Required - Number of columns - **nNonzeros** (int_t) - Required - Number of non-zero entries - **irn** (int_t*) - Required - Row indices (Harwell-Boeing format) - **jcn** (int_t*) - Required - Column indices (Harwell-Boeing format) - **avals** (real_t*) - Required - Numerical values ### Return SUCCESSFUL_RETURN or error code ``` -------------------------------- ### Get Hessian Type Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/01-qproblemb.md Retrieves the current Hessian type. Note that this value is not determined by this specific call. ```cpp inline HessianType getHessianType() const ``` -------------------------------- ### Get Square Root Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/09-utilities.md Calculates the square root of a real number. Use for distance or magnitude calculations. ```cpp real_t getSqrt(real_t a) ``` -------------------------------- ### Get Total Number of Constraints Managed Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/04-bounds-constraints.md Returns the total number of constraints that the Constraints object is managing. ```cpp inline int_t getM() const ``` -------------------------------- ### Get Number of Bounds at Upper Limit Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/04-bounds-constraints.md Returns the count of bounds that are currently fixed at their upper limit. ```cpp inline int_t getNUB() const ``` -------------------------------- ### Solve and Warm-start Quadratic Programming Problem Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/01-qproblemb.md This C++ snippet shows how to initialize and solve a QP problem using QProblemB, then warm-start it with new bounds. Ensure you have the qpOASES library included. ```cpp #include using namespace qpOASES; // Define QP data real_t H[2*2] = { 1.0, 0.0, 0.0, 0.5 }; real_t g[2] = { 1.5, 1.0 }; real_t lb[2] = { 0.5, -2.0 }; real_t ub[2] = { 5.0, 2.0 }; // Create solver QProblemB qp(2); // Solve initial QP int_t nWSR = 10; qp.init(H, g, lb, ub, nWSR); // Get solution real_t xOpt[2]; qp.getPrimalSolution(xOpt); printf("Optimal x: [%e, %e]\n", xOpt[0], xOpt[1]); printf("Objective: %e\n", qp.getObjVal()); // Warm-start with new bounds real_t lb_new[2] = { 0.0, -1.0 }; real_t ub_new[2] = { 5.0, -0.5 }; nWSR = 10; qp.hotstart(g, lb_new, ub_new, nWSR); // Get new solution qp.getPrimalSolution(xOpt); printf("New optimal x: [%e, %e]\n", xOpt[0], xOpt[1]); ``` -------------------------------- ### hotstart() from QProblem (Parameter Changes Only) Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/03-sqproblem.md Solves a neighboring QP by keeping the matrices fixed and only updating the bounds and gradient. This method is inherited from `QProblem`. ```APIDOC ## hotstart() from QProblem (Parameter Changes Only) ### Description Solves a neighboring QP keeping matrices fixed, only updating bounds and gradient. ### Method `hotstart` (inherited from `QProblem`) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None #### Input Parameters - **g_new** (`const real_t*`) - Required - New gradient vector - **lb_new** (`const real_t*`) - Required - New lower bounds on variables - **ub_new** (`const real_t*`) - Required - New upper bounds on variables - **lbA_new** (`const real_t*`) - Required - New lower constraint bounds - **ubA_new** (`const real_t*`) - Required - New upper constraint bounds - **nWSR** (`int_t&`) - Required - [in] Max iterations; [out] iterations performed - **cputime** (`real_t*`) - Optional - [in] Max CPU time; [out] time spent - **guessedBounds** (`const Bounds*`) - Optional - Working set hint for bounds - **guessedConstraints** (`const Constraints*`) - Optional - Working set hint for constraints ### Return Value `SUCCESSFUL_RETURN`, `RET_MAX_NWSR_REACHED`, etc. (same as other `hotstart()` variants). ``` -------------------------------- ### Get Number of Bounds at Lower Limit Source: https://github.com/coin-or/qpoases/blob/master/_autodocs/04-bounds-constraints.md Returns the count of bounds that are currently fixed at their lower limit. ```cpp inline int_t getNLB() const ```