test_bench.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 <dirent.h>
37 #include <cstring>
38 #include <cstdlib>
39 #include <qpOASES.hpp>
40 #include <qpOASES/UnitTesting.hpp>
41 
42 
44 int main( int argc, char *argv[] )
45 {
47  #ifdef __USE_SINGLE_PRECISION__
48  const real_t TOL = 5e-2;
49  #else
50  const real_t TOL = 1e-5;
51  #endif
52 
53  /* 1) Define benchmark arguments. */
54  BooleanType isSparse = BT_FALSE;
55  //BooleanType isSparse = BT_TRUE;
57  options.setToDefault();
58  //options.setToMPC();
59  //options.setToReliable();
60  options.printLevel = PL_LOW;
61  //options.printLevel = PL_MEDIUM;
62  //options.printLevel = PL_TABULAR;
63  //options.enableFarBounds = BT_FALSE;
64 
65 // options.initialStatusBounds = ST_LOWER;
66  //options.numRegularisationSteps = 1;
67  //options.epsRegularisation = 1.0e3 * EPS;
68 
69  //options.enableFlippingBounds = BT_FALSE;
70  //options.enableFlippingBounds = BT_FALSE;
71  //options.enableRamping = BT_TRUE;
72  //options.enableFarBounds = BT_FALSE;
73  //options.enableNZCTests = BT_FALSE;
74  //options.epsNZCTests = 1.0e4 * EPS;
75  //options.epsFlipping = 1.0e5 * EPS;
76  //options.enableFullLITests = BT_TRUE;
77  //options.enableDriftCorrection = 1;
78  //options.enableEqualities = BT_TRUE;
79  //options.enableEqualities = BT_FALSE;
80  //options.epsNum = -1.0e3 * EPS;
81  //options.epsDen = 1.0e3 * EPS;
82 
83 
84  int_t nWSR;
85  real_t maxCPUtime; /* seconds */
86  real_t maxStationarity = 0.0, maxFeasibility = 0.0, maxComplementarity = 0.0;
87  real_t avgStationarity = 0.0, avgFeasibility = 0.0, avgComplementarity = 0.0;
88 
89  int_t scannedDir = 0;
90  int_t nfail = 0, npass = 0;
91  int_t nproblems, i;
92  struct dirent **namelist;
93  char resstr[MAX_STRING_LENGTH], oqpProblem[MAX_STRING_LENGTH];
94  char *problem;
95  returnValue returnvalue;
96 
97  int_t expectedNumSolvedProblems = 44;
98  real_t expectedAvgStationarity = TOL;
99  real_t expectedAvgFeasibility = TOL;
100  real_t expectedAvgComplementarity = TOL;
101 
102 
103  if ( argv[argc-1][0] == 'O' )
104  {
105  if ( strlen(argv[argc-1]) != 3 )
106  {
107  fprintf( stdout,"ERROR (testbench): Invalid options passed!\n" );
108  return TEST_DATA_NOT_FOUND;
109  }
110 
111  fprintf( stdout,"Analysing passed options: " );
112  switch ( argv[argc-1][1] )
113  {
114  case 'd':
115  fprintf( stdout,"default options, " );
116  options.setToDefault();
117  if ( argv[argc-1][2] == 's' )
118  {
119  expectedNumSolvedProblems = 44;
120  expectedAvgStationarity = 1e-9;
121  expectedAvgFeasibility = 1e-9;
122  expectedAvgComplementarity = 5e-7;
123  }
124  else
125  {
126  expectedNumSolvedProblems = 44;
127  expectedAvgStationarity = 5e-10;
128  expectedAvgFeasibility = 5e-10;
129  expectedAvgComplementarity = 5e-8;
130  }
131  break;
132 
133  case 'r':
134  fprintf( stdout,"reliable options, " );
135  options.setToReliable();
136  if ( argv[argc-1][2] == 's' )
137  {
138  expectedNumSolvedProblems = 44;
139  expectedAvgStationarity = 2e-9;
140  expectedAvgFeasibility = 2e-11;
141  expectedAvgComplementarity = 3e-9;
142  }
143  else
144  {
145  expectedNumSolvedProblems = 44;
146  expectedAvgStationarity = 2e-9;
147  expectedAvgFeasibility = 2e-9;
148  expectedAvgComplementarity = 3e-7;
149  }
150  break;
151 
152  case 'm':
153  fprintf( stdout,"MPC options, " );
154  options.setToMPC();
155  if ( argv[argc-1][2] == 's' )
156  {
157  expectedNumSolvedProblems = 42;
158  expectedAvgStationarity = 2e-8;
159  expectedAvgFeasibility = 1e-8;
160  expectedAvgComplementarity = 2e-7;
161  }
162  else
163  {
164  expectedNumSolvedProblems = 42;
165  expectedAvgStationarity = 3e-8;
166  expectedAvgFeasibility = 1e-8;
167  expectedAvgComplementarity = 5e-8;
168  }
169  break;
170 
171  default:
172  fprintf( stdout,"ERROR (testbench): Invalid options passed!\n" );
173  return TEST_DATA_NOT_FOUND;
174  }
175 
176  switch ( argv[argc-1][2] )
177  {
178  case 's':
179  fprintf( stdout,"sparse QP data\n" );
180  isSparse = BT_TRUE;
181  break;
182 
183  case 'd':
184  fprintf( stdout,"dense QP data\n" );
185  isSparse = BT_FALSE;
186  break;
187 
188  default:
189  fprintf( stdout,"ERROR (testbench): Invalid options passed!\n" );
190  return TEST_DATA_NOT_FOUND;
191  }
192  options.printLevel = PL_NONE;
193  //options.enableFlippingBounds = BT_FALSE;
194 
195  nproblems = argc-2;
196  }
197  else
198  {
199  nproblems = argc-1;
200  }
201 
202 
203  if (nproblems == 0)
204  {
205  /* 2a) Scan problem directory */
206  nproblems = scandir("../testing/cpp/data/problems", &namelist, NULL, alphasort);
207  if (nproblems <= 0)
208  {
209  myPrintf( "No test problems found!\n" );
210  return TEST_DATA_NOT_FOUND;
211  }
212  scannedDir = 1;
213  }
214  else
215  {
216  /* 2b) Use problem list given by arguments */
217  scannedDir = 0;
218  }
219 
220  /* 3) Run benchmark. */
221  printf("%10s %9s %9s %9s %6s %-12s\n", "problem", "stat",
222  "feas", "compl", "nWSR", "result");
223  for (i = 0; i < nproblems; i++)
224  {
225  if (scannedDir)
226  {
227  /* skip special directories and zip file cuter.*bz2 */
228  if (namelist[i]->d_name[0] == '.' || namelist[i]->d_name[0] == 'c')
229  {
230  free(namelist[i]);
231  continue;
232  }
233  problem = namelist[i]->d_name;
234  }
235  else
236  {
237  problem = argv[i+1];
238  }
239 
240  fprintf(stdFile, "%-10s ", problem);
241  fflush(stdFile);
242 
243  snprintf(oqpProblem, MAX_STRING_LENGTH, "../testing/cpp/data/problems/%s/", problem);
244  maxCPUtime = 300.0;
245  nWSR = 2500;
246 
247  returnvalue = runOqpBenchmark( oqpProblem, isSparse, options,
248  nWSR, maxCPUtime, maxStationarity, maxFeasibility, maxComplementarity
249  );
250  if (returnvalue == SUCCESSFUL_RETURN
251  && maxStationarity < TOL
252  && maxFeasibility < TOL
253  && maxComplementarity < TOL)
254  {
255  npass++;
256 
257  avgStationarity += maxStationarity;
258  avgFeasibility += maxFeasibility;
259  avgComplementarity += maxComplementarity;
260 
261  strncpy(resstr, "pass", MAX_STRING_LENGTH);
262  }
263  else
264  {
265  if ( returnvalue == RET_BENCHMARK_ABORTED )
266  return TEST_DATA_NOT_FOUND;
267 
268  nfail++;
269  snprintf (resstr, MAX_STRING_LENGTH, "fail (%d)",(int)returnvalue);
270  }
271  fprintf(stdFile, "%9.2e %9.2e %9.2e %6d %-12s\n", maxStationarity,
272  maxFeasibility, maxComplementarity, (int)nWSR, resstr);
273 
274  if (scannedDir) free(namelist[i]);
275  }
276  if (scannedDir) free(namelist);
277 
278  avgStationarity /= npass;
279  avgFeasibility /= npass;
280  avgComplementarity /= npass;
281 
282 
283  /* 4) Print results. */
284  printf( "\n\n" );
285  printf( "Testbench results:\n" );
286  printf( "======================\n\n" );
287  printf( "Pass: %3d\n",(int)npass );
288  printf( "Fail: %3d\n",(int)nfail );
289  printf( "Ratio: %5.1f%%\n", 100.0 * (real_t)npass / (real_t)(npass+nfail) );
290  printf( "\n" );
291 
292  QPOASES_TEST_FOR_TRUE( npass >= expectedNumSolvedProblems );
293 
294 
295  printf( "avg. stat: %e\n", avgStationarity );
296  printf( "avg. feas: %e\n", avgFeasibility );
297  printf( "avg. cmpl: %e\n", avgComplementarity );
298 
299  QPOASES_TEST_FOR_TOL( avgStationarity, expectedAvgStationarity );
300  QPOASES_TEST_FOR_TOL( avgFeasibility, expectedAvgFeasibility );
301  QPOASES_TEST_FOR_TOL( avgComplementarity, expectedAvgComplementarity );
302 
303 
304  return 0;
305 }
306 
307 
308 /*
309  * end of file
310  */
#define TEST_DATA_NOT_FOUND
Definition: UnitTesting.hpp:51
returnValue setToDefault()
Allows to pass back messages to the calling function.
#define stdFile
#define PL_NONE
returnValue myPrintf(const char *s)
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 PL_LOW
returnValue runOqpBenchmark(const char *path, BooleanType isSparse, const Options &options, int_t &nWSR, real_t &maxCPUtime, real_t &maxStationarity, real_t &maxFeasibility, real_t &maxComplementarity)
#define BT_TRUE
Definition: acado_types.hpp:47
returnValue setToMPC()
#define BT_FALSE
Definition: acado_types.hpp:49
double real_t
Definition: AD_test.c:10
returnValue setToReliable()
#define QPOASES_TEST_FOR_TRUE(x)
Definition: UnitTesting.hpp:64
int main(int argc, char *argv[])
Definition: test_bench.cpp:44


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