test_janick2.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 
35 #include <qpOASES.hpp>
36 #include <qpOASES/UnitTesting.hpp>
37 #include <stdio.h>
38 
39 #define __MAKE_POS_DEF__
40 // #undef __MAKE_POS_DEF__
41 
42 int main( )
43 {
45 
46  int_t nWSR = 100;
47  /* Setting up QProblem object. */
48  SQProblem example( 11,3 );
49 
51  options.setToFast();
52 // options.setToDefault();
54 
55  //options.terminationTolerance = 1.e-12;
57  //options.enableFarBounds = REFER_NAMESPACE_QPOASES BT_FALSE;
58  //options.enableRegularisation = REFER_NAMESPACE_QPOASES BT_FALSE;
59 
60  example.setOptions( options );
61 
62 
63  /* Setup data of first QP. */
64  real_t H[11*11] = {
65  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,
66  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,
67  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,
68  -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,
69  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,
70  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,
71  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,
72  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,
73  -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,
74  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,
75  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,
76  };
77  real_t g[11] = {
78 // 9.13378607947379e-07,
79 // 0.00000000000000e+00,
80 // 0.00000000000000e+00,
81 // -1.12448469735682e-06,
82 // 0.00000000000000e+00,
83 // 0.00000000000000e+00,
84 // 0.00000000000000e+00,
85 // 0.00000000000000e+00,
86 // -1.18185650936822e+02,
87 // 0.00000000000000e+00,
88 // 0.00000000000000e+00,
89  -6.93766478421491e-04,
90  3.84943289898669e-04,
91  -3.63779116055460e-05,
92  6.38114176725135e-04,
93  1.85797765355698e-04,
94  6.21922122437904e-05,
95  0.00000000000000e+00,
96  0.00000000000000e+00,
97  -1.18185758699839e+02,
98  1.54357580390960e-05,
99  5.39852809009711e-06,
100  };
101  real_t zLow[11] = {
102  0.00000000000000e+00,
103  0.00000000000000e+00,
104  0.00000000000000e+00,
105  0.00000000000000e+00,
106  0.00000000000000e+00,
107  0.00000000000000e+00,
108  0.00000000000000e+00,
109  0.00000000000000e+00,
110  0.00000000000000e+00,
111  -4.50000000000000e+01,
112  -1.00000000000000e+12,
113  };
114  real_t zUpp[11] = {
115  0.00000000000000e+00,
116  0.00000000000000e+00,
117  0.00000000000000e+00,
118  0.00000000000000e+00,
119  0.00000000000000e+00,
120  0.00000000000000e+00,
121  1.00000000000000e+12,
122  1.00000000000000e+12,
123  0.00000000000000e+00,
124  4.50000000000000e+01,
125  1.00000000000000e+12,
126  };
127  real_t D[11*3] = {
128  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,
129  -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,
130  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,
131  };
132  real_t dLow[3] = {
133  -1.00000000000000e+12,
134  -1.00000000000000e+12,
135  -1.00000000000000e+12,
136  };
137  real_t dUpp[3] = {
138  2.12376384003361e-01,
139  4.78762361599664e+00,
140  8.95204469622285e-01,
141  };
142 
143 
144  #ifdef __MAKE_POS_DEF__
145 // H[9*11+9] += 30;
146  H[8*11+8] += 30;
147  #endif
148  returnValue status = example.init( H,g,D,zLow,zUpp,dLow,dUpp, nWSR );
149  printf("qpOASES_status = %d\n", (int)status );
150 
151  /* Get and print solution of second QP. */
152  real_t xOpt[11];
153  real_t yOpt[11+3];
154  example.getPrimalSolution( xOpt );
155  example.getDualSolution( yOpt );
156  printf("first QP:\n");
157  for (int_t ii =0; ii<11; ++ii ) {
158  printf("x[%d] = %.3e\n", (int)ii, xOpt[ii]);
159  }
160 
161  /* Compute KKT tolerances */
162  real_t stat, feas, cmpl;
163  SolutionAnalysis analyzer;
164 
165  analyzer.getKktViolation( &example, &stat,&feas,&cmpl );
166  printf( "\nstat = %e\nfeas = %e\ncmpl = %e\n", stat,feas,cmpl );
167 
168  QPOASES_TEST_FOR_TOL( stat,1e-9 );
169  QPOASES_TEST_FOR_TOL( feas,1e-7 );
170  QPOASES_TEST_FOR_TOL( cmpl,1e-15 );
171 
172  nWSR = 100;
173 
174  /* Setup data of second QP. */
175  real_t H2[11*11] = {
176  6.20101055067033e+00, 0.00000000000000e+00, 0.00000000000000e+00, -3.84861780549400e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, -7.43268533746787e+00, 0.00000000000000e+00, 0.00000000000000e+00,
177  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,
178  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,
179  -3.84861780549400e+00, 0.00000000000000e+00, 0.00000000000000e+00, 5.41188396792859e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 4.61304896387257e+00, 0.00000000000000e+00, 0.00000000000000e+00,
180  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,
181  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,
182  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,
183  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,
184  -7.43268533746787e+00, 0.00000000000000e+00, 0.00000000000000e+00, 4.61304896387257e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, 0.00000000000000e+00, -1.73544780086860e+01, 0.00000000000000e+00, 0.00000000000000e+00,
185  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,
186  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,
187  };
188  real_t g2[11] = {
189  -8.92227256391600e-08,
190  6.89531726031141e-08,
191  -1.91970120006650e-07,
192  1.77206607789402e-07,
193  -3.83145267945144e-09,
194  -1.88284265021358e-08,
195  0.00000000000000e+00,
196  0.00000000000000e+00,
197  -1.18185657392775e+02,
198  1.45337027424899e-17,
199  -6.04156175796480e-20,
200  };
201  real_t zLow2[11] = {
202  -1.07876236566374e+01,
203  -1.00000000002784e+12,
204  -1.00000000000000e+12,
205  -8.30554585107279e-08,
206  -7.00000003695781e+00,
207  -2.60479531522807e+00,
208  0.00000000000000e+00,
209  0.00000000000000e+00,
210  0.00000000000000e+00,
211  -4.50000000018062e+01,
212  -1.00000000000000e+12,
213  };
214  real_t zUpp2[11] = {
215  9.99999999989212e+11,
216  9.99999999972157e+11,
217  1.00000000000000e+12,
218  4.68471853498991e+01,
219  6.99999996304219e+00,
220  9.99999999997395e+11,
221  1.00000000000000e+12,
222  1.00000000000000e+12,
223  0.00000000000000e+00,
224  4.49999999981938e+01,
225  1.00000000000000e+12,
226  };
227  real_t D2[11*3] = {
228  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,
229  -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,
230  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,
231  };
232  real_t dLow2[3] = {
233  -1.00000000000000e+12,
234  -1.00000000000000e+12,
235  -1.00000000000000e+12,
236  };
237  real_t dUpp2[3] = {
238  2.12376343362616e-01,
239  4.78762365663739e+00,
240  8.95204684771929e-01,
241  };
242  #ifdef __MAKE_POS_DEF__
243  H2[8*11+8] += 30;
244 // H2[9*11+9] += 30;
245  #endif
246 
247 
248  status = example.hotstart( H2,g2,D2,zLow2,zUpp2,dLow2,dUpp2, nWSR );
249  printf("qpOASES_status = %d\n", (int)status );
250 
251  example.getPrimalSolution( xOpt );
252  example.getDualSolution( yOpt );
253  printf("second QP:\n");
254  for (int_t ii =0; ii<11; ++ii ) {
255  printf("x[%d] = %.3e\n", (int)ii, xOpt[ii]);
256  }
257 
258  printf( "\nQP objective value: %.3e\n", example.getObjVal() );
259 
260  /* Compute KKT tolerances */
261  analyzer.getKktViolation( &example, &stat,&feas,&cmpl );
262  printf( "\nstat = %e\nfeas = %e\ncmpl = %e\n", stat,feas,cmpl );
263 
264  QPOASES_TEST_FOR_TOL( stat,1e-9 );
265  QPOASES_TEST_FOR_TOL( feas,1e-7 );
266  QPOASES_TEST_FOR_TOL( cmpl,1e-15 );
267 
268 
269  return TEST_PASSED;
270 }
271 
272 
273 /*
274  * end of file
275  */
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.
#define ST_INACTIVE
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