test_janick1.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 #include <stdio.h>
40 
41 
42 //#define __MAKE_POS_DEF__
43 #undef __MAKE_POS_DEF__
44 
45 int main( )
46 {
48 
49  int_t nWSR = 100;
50  /* Setting up QProblem object. */
51  SQProblem example( 11,3 );
52 
54  options.setToFast();
55  //options.setToDefault();
56  //options.initialStatusBounds = qpOASES::ST_INACTIVE;
57  example.setOptions( options );
58 
59 
60  /* Setup data of first QP. */
61  real_t H[11*11] = {
62  6.20100988531485e+00, 0.00000000000000e+00, 0.00000000000000e+00, -3.84861756786704e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, -7.43268431723266e+00, 0.00000000000000e+00, 0.00000000000000e+00,
63  0.00000000000000e+00, 1.00000000000000e-01, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00,
64  0.00000000000000e+00, 0.00000000000000e+00, 2.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00,
65  -3.84861756786704e+00, 0.00000000000000e+00, 0.00000000000000e+00, 5.41188294952735e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 4.61304826562310e+00, 0.00000000000000e+00, 0.00000000000000e+00,
66  0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 2.10000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00,
67  0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 1.00000000000000e-01, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00,
68  0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 2.01000000000000e+01, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00,
69  0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 2.10000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00,
70  -7.43268431723266e+00, 0.00000000000000e+00, 0.00000000000000e+00, 4.61304826562310e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, -1.73544778892019e+01, 0.00000000000000e+00, 0.00000000000000e+00,
71  0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 2.00000000000000e+00, 0.00000000000000e+00,
72  0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 2.00000000000000e+01
73  };
74  real_t g[11] = {
75  -1.28196485091041e-07, 1.13322235104306e-08, 4.52417455660281e-06, 1.95881304363781e-07, 1.61991589634459e-06, 2.69786724710014e-09, 0.00000000000000e+00, 0.00000000000000e+00, -1.18185813270785e+02, 9.58903285459640e-06, 3.82276791847511e-06
76  };
77  real_t zLow[11] = {
78  -1.07876236159966e+01, -1.00000000002784e+12, -1.00000000000000e+12, 0.00000000000000e+00, -7.00000000000000e+00, -2.60479553037772e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, -4.50000000000000e+01, -1.00000000000000e+12
79  };
80  real_t zUpp[11] = {
81  9.99999999989212e+11, 9.99999999972157e+11, 1.00000000000000e+12, 4.68471854329546e+01, 7.00000000000000e+00, 9.99999999997395e+11, 1.00000000000000e+12, 1.00000000000000e+12, 0.00000000000000e+00, 4.50000000000000e+01, 1.00000000000000e+12
82  };
83  real_t D[11*3] = {
84  1.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, -1.00000000000000e-02, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00,
85  -1.00000000000000e+00, -0.00000000000000e+00, -0.00000000000000e+00, -0.00000000000000e+00, -0.00000000000000e+00, -0.00000000000000e+00, -1.00000000000000e-02, -0.00000000000000e+00, -0.00000000000000e+00, -0.00000000000000e+00, -0.00000000000000e+00,
86  0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 1.00000000000000e+00, 0.00000000000000e+00, -1.00000000000000e-02, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00
87  };
88  real_t dLow[3] = {
89  -1.00000000000000e+12, -1.00000000000000e+12, -1.00000000000000e+12
90  };
91  real_t dUpp[3] = {
92  2.12376384003361e-01, 4.78762361599664e+00, 8.95204469622285e-01
93  };
94 
95  #ifdef __MAKE_POS_DEF__
96  H[9*11+9] += 30;
97  #endif
98  returnValue status = example.init( H,g,D,zLow,zUpp,dLow,dUpp, nWSR );
99  printf("\nqpOASES_status = %d\n", (int)status );
100 
101  /* Get and print solution of first QP. */
102  real_t xOpt[11];
103  real_t yOpt[11+3];
104  example.getPrimalSolution( xOpt );
105  example.getDualSolution( yOpt );
106  printf("first QP:\n");
107  for (int_t ii =0; ii<11; ++ii ) {
108  printf("x[%d] = %.3e\n", (int)ii, xOpt[ii]);
109  }
110 
111  /* Compute KKT tolerances */
112  real_t stat, feas, cmpl;
113  SolutionAnalysis analyzer;
114 
115  analyzer.getKktViolation( &example, &stat,&feas,&cmpl );
116  printf( "\nstat = %e\nfeas = %e\ncmpl = %e\n", stat,feas,cmpl );
117 
118  QPOASES_TEST_FOR_TOL( stat,1e-9 );
119  QPOASES_TEST_FOR_TOL( feas,1e-7 );
120  QPOASES_TEST_FOR_TOL( cmpl,1e-15 );
121 
122 
123 
124  nWSR = 100;
125 
126  /* Setup data of second QP. */
127  real_t H2[11*11] = {
128  6.20100988531485e+00, 0.00000000000000e+00, 0.00000000000000e+00, -3.84861756786704e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, -7.43268433147671e+00, 0.00000000000000e+00, 0.00000000000000e+00,
129  0.00000000000000e+00, 1.00000000000000e-01, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00,
130  0.00000000000000e+00, 0.00000000000000e+00, 2.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00,
131  -3.84861756786704e+00, 0.00000000000000e+00, 0.00000000000000e+00, 5.41188294952735e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 4.61304827446359e+00, 0.00000000000000e+00, 0.00000000000000e+00,
132  0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 2.10000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00,
133  0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 1.00000000000000e-01, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00,
134  0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 2.01000000000000e+01, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00,
135  0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 2.10000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00,
136  -7.43268433147671e+00, 0.00000000000000e+00, 0.00000000000000e+00, 4.61304827446359e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, -1.73544778550554e+01, 0.00000000000000e+00, 0.00000000000000e+00,
137  0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 2.00000000000000e+00, 0.00000000000000e+00,
138  0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 2.00000000000000e+01
139  };
140  real_t g2[11] = {
141  -6.57752219998813e-04, 3.61759517784935e-04, -7.51224940044046e-05, 6.01232615232452e-04, 1.23562395380546e-04, 4.59040118744990e-05, 0.00000000000000e+00, 0.00000000000000e+00, -1.18185813270785e+02, 3.38813178901720e-21, 0.00000000000000e+00
142  };
143  real_t zLow2[11] = {
144  -2.41857058824735e-08, -2.77410094895458e-10, -9.90563843681406e-09, -3.85694249871449e-08, 4.50633213817586e-14, -2.22044604925031e-15, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, -4.49999952054836e+01, -1.00000000000000e+12
145  };
146  real_t zUpp2[11] = {
147  -2.41857058824735e-08, -2.77410094895458e-10, -9.90563843681406e-09, -3.85694249871449e-08, 4.50633213817586e-14, -2.22044604925031e-15, 1.00000000000000e+12, 1.00000000000000e+12, 0.00000000000000e+00, 4.50000047945164e+01, 1.00000000000000e+12,
148  };
149  real_t D2[11*3] = {
150  1.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, -1.00000000000000e-02, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00,
151  -1.00000000000000e+00, -0.00000000000000e+00, -0.00000000000000e+00, -0.00000000000000e+00, -0.00000000000000e+00, -0.00000000000000e+00, -1.00000000000000e-02, -0.00000000000000e+00, -0.00000000000000e+00, -0.00000000000000e+00, -0.00000000000000e+00,
152  0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 1.00000000000000e+00, 0.00000000000000e+00, -1.00000000000000e-02, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00
153  };
154  real_t dLow2[3] = {
155  -1.00000000000000e+12, -1.00000000000000e+12, -1.00000000000000e+12
156  };
157  real_t dUpp2[3] = {
158  2.12376363329877e-01, 4.78762363667012e+00, 8.95204496600957e-01
159  };
160  #ifdef __MAKE_POS_DEF__
161  H2[9*11+9] += 30;
162  #endif
163 
164 
165  status = example.hotstart( H2,g2,D2,zLow2,zUpp2,dLow2,dUpp2, nWSR );
166  printf("qpOASES_status = %d\n", (int)status );
167 
168  example.getPrimalSolution( xOpt );
169  example.getDualSolution( yOpt );
170  printf("second QP:\n");
171  for (int_t ii =0; ii<11; ++ii ) {
172  printf("x[%d] = %.3e\n", (int)ii, xOpt[ii]);
173  }
174 
175  /* Compute KKT tolerances */
176  analyzer.getKktViolation( &example, &stat,&feas,&cmpl );
177  printf( "stat = %e\nfeas = %e\ncmpl = %e\n", stat,feas,cmpl );
178 
179  QPOASES_TEST_FOR_TOL( stat,1e-9 );
180  QPOASES_TEST_FOR_TOL( feas,1e-7 );
181  QPOASES_TEST_FOR_TOL( cmpl,1e-12 );
182 
183 
184  return TEST_PASSED;
185 }
186 
187 
188 /*
189  * end of file
190  */
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.
Allows to pass back messages to the calling function.
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
double real_t
Definition: AD_test.c:10
int main()
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