test_gradientShift.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-2009 by Hans Joachim Ferreau et al. All rights reserved.
6  *
7  * qpOASES is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * qpOASES is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15  * See the GNU Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with qpOASES; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  *
21  */
22 
23 
35 #include <math.h>
36 #include <iostream>
37 #include <qpOASES.hpp>
38 #include <qpOASES/UnitTesting.hpp>
39 
40 
42 int main( )
43 {
45 
46 
47  real_t H[2*2] = { 0.055944055944055944,0, 0, 0 };
48  real_t A[1*2] = { 0.70514808036997589, -1 };
49  //real_t g[2] = { -15.830543073928741, 0};
50  real_t g[2] = { 0, 0 };
51  real_t lb[2] = { 137.00242299940646, 154.0 };
52  real_t ub[2] = { 282.19008595111382, 198.98579740786641};
53  real_t lbA[1] = {0.0};
54  real_t ubA[1] = {0.0};
55 
56  real_t gStart=-16.4;
57 
58  /* Setting up QProblem object. */
59  QProblem example( 2,1 );
61  options.setToMPC();
63  example.setOptions( options );
64 
65  returnValue ret;
66  int_t nWSR = 10;
67  real_t Xopt[2]={0.0,0.0};
68  //fprintf(stdFile, "g[0]\t,\tReturn code\n");
69  int_t errorCount=0;
70  int_t i=0;
71  real_t granularity=0.00001;
72  g[0]=gStart;
73  for( i=0; i< 70000; i++)
74  {
75 
76  g[0] += granularity;
77  /* Solve first QP. */
78  nWSR = 10;
79  ret= example.init( H,g,A,lb,ub,lbA,ubA, nWSR,0 );
80  if (ret != SUCCESSFUL_RETURN)
81  {
82  //fprintf(stdFile, "%f\t,\t%d\n",g[0],ret);
83  errorCount++;
84  }
85  //fprintf(stdFile, "%f\t,\t%d\n",g[0],ret);
86  }
87  example.printProperties();
88  fprintf( stdFile, "#Number of optimizer runs: %d\n",(int)i );
89  fprintf( stdFile, "#g[0] test interval: %f < g[0] < %f\n",gStart,g[0] );
90  fprintf( stdFile, "#Granularity: %f\n",granularity);
91  real_t errorPercent = real_t(errorCount)/real_t(i)*100.0;
92  fprintf( stdFile, "#Number of errors (error): %d (%f)\n",(int)errorCount,errorPercent );
93 
94  example.getPrimalSolution(Xopt);
95  fprintf( stdFile,"#Optimization primary result : LD=%f BD=%f\n",Xopt[0], Xopt[1]);
96 
97  real_t Yopt[3]={0.0,0.0,0.0};
98  example.getDualSolution(Yopt);
99  fprintf( stdFile,"#Optimization dual result : %f %f %f8\n",Yopt[0], Yopt[1], Yopt[2]);
100 
101  int_t Nc=0;
102  Nc=example.getNC();
103  fprintf( stdFile,"#Number of constraints : %d\n",(int)Nc );
104 
105  int_t Nec=0;
106  Nec=example.getNEC();
107  fprintf( stdFile,"#Number of equality constraints : %d\n",(int)Nec );
108 
109  int_t Nac=0;
110  Nac=example.getNAC();
111  fprintf( stdFile,"#Number of active constraints : %d\n",(int)Nac );
112 
113  int_t Niac=0;
114  Niac=example.getNIAC();
115  fprintf( stdFile,"#Number of inactive constraints : %d\n",(int)Niac );
116 
117  QPOASES_TEST_FOR_TRUE( errorCount == 0 )
118 
119  return TEST_PASSED;
120 }
121 
122 
123 /*
124  * end of file
125  */
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)
Allows to pass back messages to the calling function.
int main()
#define stdFile
#define PL_NONE
int getNAC()
returnValue setOptions(const Options &_options)
Provides a generic way to set and pass user-specified options.
Definition: options.hpp:65
int getNEC() const
#define TEST_PASSED
Definition: UnitTesting.hpp:45
int getNC() const
returnValue setToMPC()
double real_t
Definition: AD_test.c:10
Implements the online active set strategy for QPs with general constraints.
#define QPOASES_TEST_FOR_TRUE(x)
Definition: UnitTesting.hpp:64
int getNIAC()


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