test_example2.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 
37 #include <qpOASES.hpp>
38 #include <qpOASES/UnitTesting.hpp>
39 
40 
42 int main( )
43 {
45 
46  /* Setup data of first QP. */
47  real_t H[2*2] = { 1.0, 0.0, 0.0, 0.5 };
48  real_t A[1*2] = { 1.0, 1.0 };
49  real_t g[2] = { 1.5, 1.0 };
50  real_t lb[2] = { 0.5, -2.0 };
51  real_t ub[2] = { 5.0, 2.0 };
52  real_t lbA[1] = { -1.0 };
53  real_t ubA[1] = { 2.0 };
54 
55  /* Setup data of second QP. */
56  real_t H_new[2*2] = { 1.0, 0.5, 0.5, 0.5 };
57  real_t A_new[1*2] = { 1.0, 5.0 };
58  real_t g_new[2] = { 1.0, 1.5 };
59  real_t lb_new[2] = { 0.0, -1.0 };
60  real_t ub_new[2] = { 5.0, -0.5 };
61  real_t lbA_new[1] = { -2.0 };
62  real_t ubA_new[1] = { 1.0 };
63 
64 
65  /* Setting up SQProblem object and solution analyser. */
66  SQProblem example( 2,1 );
68 
69  /* Solve first QP ... */
70  int_t nWSR = 10;
71  example.init( H,g,A,lb,ub,lbA,ubA, nWSR,0 );
72 
73  /* ... and analyse it. */
74  real_t maxKktViolation = analyser.getKktViolation( &example );
75  printf( "maxKktViolation: %e\n", maxKktViolation );
76 
77  QPOASES_TEST_FOR_TOL( maxKktViolation,1e-15 );
78 
79 
80  /* Solve second QP ... */
81  nWSR = 10;
82  example.hotstart( H_new,g_new,A_new,lb_new,ub_new,lbA_new,ubA_new, nWSR,0 );
83 
84  /* ... and analyse it. */
85  maxKktViolation = analyser.getKktViolation( &example );
86  printf( "maxKktViolation: %e\n", maxKktViolation );
87 
88  QPOASES_TEST_FOR_TOL( maxKktViolation,1e-15 );
89 
90 
91 // ------------ VARIANCE-COVARIANCE EVALUATION --------------------
92 
93  real_t *Var = new real_t[5*5];
94  real_t *Primal_Dual_Var = new real_t[5*5];
95 
96  int_t run1, run2;
97  for( run1 = 0; run1 < 5*5; run1++ )
98  Var[run1] = 0.0;
99 
100  Var[0] = 1.0;
101  Var[6] = 1.0;
102 
103 // ( 1 0 0 0 0 )
104 // ( 0 1 0 0 0 )
105 // Var = ( 0 0 0 0 0 )
106 // ( 0 0 0 0 0 )
107 // ( 0 0 0 0 0 )
108 
109 
110  analyser.getVarianceCovariance( &example, Var,Primal_Dual_Var );
111 
112  printf("\nPrimal_Dual_VAR = \n");
113  for( run1 = 0; run1 < 5; run1++ ){
114  for( run2 = 0; run2 < 5; run2++ ){
115  printf(" %10f", Primal_Dual_Var[run1*5+run2]);
116  }
117  printf("\n");
118  }
119 
120  delete[] Primal_Dual_Var;
121  delete[] Var;
122 
123  QPOASES_TEST_FOR_NEAR( Primal_Dual_Var[3*5+3], 26.0 );
124 
125  return TEST_PASSED;
126 }
127 
128 
129 /*
130  * end of file
131  */
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)
Implements the online active set strategy for QPs with varying matrices.
int main()
#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
returnValue getVarianceCovariance(QProblemB *qp, real_t *g_b_bA_VAR, real_t *Primal_Dual_VAR) const
#define QPOASES_TEST_FOR_NEAR(x, y)
Definition: UnitTesting.hpp:58
double real_t
Definition: AD_test.c:10
Primal_Dual_Var
Definition: example2.py:78
returnValue hotstart(const real_t *const H_new, const real_t *const g_new, const real_t *const A_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 &nWSR, real_t *const cputime)


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