test_bench.c
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 #define _SVID_SOURCE
25 
26 
27 #include <dirent.h>
28 #include <string.h>
29 #include <stdlib.h>
30 #include <qpOASES_e.h>
31 #include <qpOASES_e/UnitTesting.h>
32 
33 
35 int main(int argc, char *argv[])
36 {
37  const real_t TOL = 1e-5;
38 
39  /* 1) Define benchmark arguments. */
40  BooleanType isSparse = BT_FALSE;
41  BooleanType useHotstarts = BT_FALSE;
42  static Options options;
43 
44  int maxAllowedNWSR;
45  real_t maxNWSR, avgNWSR, maxCPUtime, avgCPUtime;
46  real_t maxStationarity, maxFeasibility, maxComplementarity;
47 
48  int scannedDir = 0;
49  int nfail = 0, npass = 0;
50  int nproblems, i;
51  struct dirent **namelist;
52  char resstr[200], OQPproblem[200];
53  char *problem;
54  returnValue returnvalue;
55 
56  Options_setToDefault( &options );
57  /*options.enableFlippingBounds = BT_FALSE;*/
58  /*Options_setToReliable( &options );*/
59  Options_setToMPC( &options );
60  /*options.printLevel = PL_DEBUG_ITER;*/
61  options.printLevel = PL_LOW;
62  /*options.enableRamping = BT_FALSE;*/
63  /*options.enableFarBounds = BT_FALSE;*/
64 
65  if (argc == 1)
66  {
67  /* 2a) Scan problem directory */
68  nproblems = scandir("../testing/c/data/problems", &namelist, NULL, alphasort);
69  if (nproblems <= 0)
70  {
71  qpOASES_myPrintf( "No test problems found!\n" );
72  return -1;
73  }
74  scannedDir = 1;
75  }
76  else
77  {
78  /* 2b) Use problem list given by arguments */
79  nproblems = argc - 1;
80  scannedDir = 0;
81  }
82 
83  /* 3) Run benchmark. */
84  printf("%10s %9s %9s %9s %6s %-12s\n", "problem", "stat",
85  "feas", "compl", "nWSR", "result");
86  for (i = 0; i < nproblems; i++)
87  {
88  if (scannedDir)
89  {
90  /* skip special directories and zip file cuter.*bz2 */
91  if (namelist[i]->d_name[0] == '.' || namelist[i]->d_name[0] == 'c')
92  {
93  free(namelist[i]);
94  continue;
95  }
96  problem = namelist[i]->d_name;
97  }
98  else
99  {
100  problem = argv[i+1];
101  }
102 
103  fprintf(stdout, "%-10s ", problem);
104  fflush(stdout);
105 
106  snprintf(OQPproblem, 199, "../testing/c/data/problems/%s/", problem);
107  maxCPUtime = 300.0;
108  maxAllowedNWSR = 3500;
109  returnvalue = runOQPbenchmark( OQPproblem,
110  isSparse,useHotstarts,
111  &options,maxAllowedNWSR,
112  &maxNWSR,&avgNWSR,&maxCPUtime,&avgCPUtime,
113  &maxStationarity,&maxFeasibility,&maxComplementarity
114  );
115  if (returnvalue == SUCCESSFUL_RETURN
116  && maxStationarity < TOL
117  && maxFeasibility < TOL
118  && maxComplementarity < TOL)
119  {
120  npass++;
121  strncpy(resstr, "pass", 199);
122  }
123  else
124  {
125  nfail++;
126  snprintf (resstr, 199, "fail (%d)", returnvalue);
127  }
128  fprintf(stdout, "%9.2e %9.2e %9.2e %6d %-12s\n", maxStationarity,
129  maxFeasibility, maxComplementarity, (int)maxNWSR, resstr);
130 
131  if (scannedDir) free(namelist[i]);
132  }
133  if (scannedDir) free(namelist);
134 
135  /* 4) Print results. */
136  printf("\n\n" );
137  printf("Testbench results:\n" );
138  printf("======================\n\n" );
139  printf("Pass: %3d\n", npass);
140  printf("Fail: %3d\n", nfail);
141  printf("Ratio: %5.1f%%\n", 100.0 * (real_t)npass / (real_t)(npass+nfail));
142  printf("\n" );
143 
144  return 0;
145 }
146 
147 
148 /*
149  * end of file
150  */
returnValue runOQPbenchmark(const char *path, BooleanType isSparse, const Options &options, int &nWSR, real_t &maxCPUtime, real_t &maxStationarity, real_t &maxFeasibility, real_t &maxComplementarity)
Allows to pass back messages to the calling function.
int main(int argc, char *argv[])
Definition: test_bench.c:35
Provides a generic way to set and pass user-specified options.
Definition: options.hpp:65
returnValue qpOASES_myPrintf(const char *s)
Definition: Utils.c:269
#define PL_LOW
returnValue Options_setToMPC(Options *_THIS)
Definition: Options.c:214
returnValue Options_setToDefault(Options *_THIS)
Definition: Options.c:112
#define BT_FALSE
Definition: acado_types.hpp:49
double real_t
Definition: AD_test.c:10


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