test_example6.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of qpOASES.
3  *
4  * qpOASES -- An Implementation of the Online Active Set Strategy.
5  * Copyright (C) 2007-2015 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 
36 #include <qpOASES.hpp>
37 #include <qpOASES/UnitTesting.hpp>
38 
39 
41 int main( )
42 {
44 
45  /* Setup data of first QP. */
46  real_t H[5*5] = { 1.224642131370767e+01, 2.908638763113702e+00, 0.0, 0.0, 0.0,
47  2.908638763113702e+00, 2.497106275003180e+00, 0.0, 0.0, 0.0,
48  0.0, 0.0, 1.0, 0.0, 0.0,
49  0.0, 0.0, 0.0, 5.158460640334052e-02, 4.723556059962540e-02,
50  0.0, 0.0, 0.0, 4.723556059962540e-02, 4.325317843302175e-02 };
51  real_t A[2*5] = { -1.404358970692652e+00, -2.556613491156063e+00, 3.202524559238066e+00, -1.0, 0.0,
52  6.587910295430314e-01, -5.349454475937998e-01, 4.391976356955536e-01, 0.0, -1.0 };
53  real_t g[5] = { 2.474135331302147e+01,
54  5.857286430296258e+00,
55  2.359382646348721e-01,
56  1.721047069188781e-01,
57  1.575947337774199e-01 };
58  real_t lb[5] = { -10.0, -10.0, -10.0, -10.0, -10.0 };
59  real_t ub[5] = { 10.0, 10.0, 10.0, 10.0, 10.0 };
60  real_t lbA[2] = { 1.643135416077167e+00, 1.056813028189597e+00 };
61  real_t ubA[2] = { 1.643135416077167e+00, 1.056813028189597e+00 };
62 
63  /* Setting up QProblem object. */
64  QProblem example( 5,2 );
65 
67  //options.enableFlippingBounds = BT_FALSE;
68  //options.enableEqualities = BT_TRUE;
69  //options.initialStatusBounds = ST_INACTIVE;
70  example.setOptions( options );
71  example.setPrintLevel( PL_NONE );
72 
73  /* Solve first QP. */
74  returnValue retVal;
75  int_t simpleStatus = -1;
76 
77  int_t nWSR = 10;
78  retVal = example.init( H,g,A,lb,ub,lbA,ubA, nWSR,0 );
79  simpleStatus = getSimpleStatus( retVal,BT_TRUE );
80 
81  QPOASES_TEST_FOR_TRUE( simpleStatus == 0 );
82 
83 
84  /* Get and print solution of second QP. */
85  real_t xOpt[5];
86  real_t yOpt[5+2];
87 
88  example.getPrimalSolution( xOpt );
89  example.getDualSolution( yOpt );
90  printf( "\nxOpt = [ %e, %e, ... ]; objVal = %e\n\n", xOpt[0],xOpt[1],example.getObjVal() );
91 
92  /* Compute KKT tolerances */
93  real_t stat, feas, cmpl;
94  SolutionAnalysis analyzer;
95 
96  analyzer.getKktViolation( &example, &stat,&feas,&cmpl );
97  printf( "stat = %e\nfeas = %e\ncmpl = %e\n", stat,feas,cmpl );
98 
99  QPOASES_TEST_FOR_TOL( stat,1e-14 );
100  QPOASES_TEST_FOR_TOL( feas,1e-14 );
101  QPOASES_TEST_FOR_TOL( cmpl,1e-15 );
102 
103  return TEST_PASSED;
104 }
105 
106 
107 /*
108  * end of file
109  */
returnValue init(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 &nWSR, const real_t *const yOpt=0, real_t *const cputime=0)
int main()
Allows to pass back messages to the calling function.
#define PL_NONE
returnValue setOptions(const Options &_options)
Provides a generic way to set and pass user-specified options.
Definition: options.hpp:65
#define QPOASES_TEST_FOR_TOL(x, tol)
Definition: UnitTesting.hpp:61
#define TEST_PASSED
Definition: UnitTesting.hpp:45
real_t getKktViolation(QProblemB *const qp, real_t *const maxStat=0, real_t *const maxFeas=0, real_t *const maxCmpl=0) const
#define BT_TRUE
Definition: acado_types.hpp:47
double real_t
Definition: AD_test.c:10
int_t getSimpleStatus(returnValue returnvalue, BooleanType doPrintStatus=BT_FALSE)
Implements the online active set strategy for QPs with general constraints.
#define QPOASES_TEST_FOR_TRUE(x)
Definition: UnitTesting.hpp:64


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:35:12