test_qrecipeSchur.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 
38 #include <qpOASES.hpp>
39 #include <qpOASES/UnitTesting.hpp>
40 
41 #include "test_qrecipe_data.hpp"
42 
43 
44 
45 int main( )
46 {
48 
49  long i;
50  int_t nWSR;
51  real_t errP1, errP2, errP3, errD1, errD2, errD3, tic, toc;
52  real_t *x1 = new real_t[180];
53  real_t *y1 = new real_t[271];
54  real_t *x2 = new real_t[180];
55  real_t *y2 = new real_t[271];
56  real_t *x3 = new real_t[180];
57  real_t *y3 = new real_t[271];
58 
59  /* create sparse matrices */
60  SymSparseMat *H = new SymSparseMat(180, 180, H_ir, H_jc, H_val);
61  SparseMatrix *A = new SparseMatrix(91, 180, A_ir, A_jc, A_val);
62 
63  H->createDiagInfo();
64 
65  real_t* H_full = H->full();
66  real_t* A_full = A->full();
67 
68  SymDenseMat *Hd = new SymDenseMat(180,180,180,H_full);
69  DenseMatrix *Ad = new DenseMatrix(91,180,180,A_full);
70 
71  /* solve with dense matrices */
72  nWSR = 1000;
73  QProblem qrecipeD(180, 91);
74  tic = getCPUtime();
75  qrecipeD.init(Hd, g, Ad, lb, ub, lbA, ubA, nWSR, 0);
76  toc = getCPUtime();
77  qrecipeD.getPrimalSolution(x1);
78  qrecipeD.getDualSolution(y1);
79 
80  fprintf(stdFile, "Solved dense problem in %d iterations, %.3f seconds.\n", (int)nWSR, toc-tic);
81 
82  /* solve with sparse matrices (nullspace factorization) */
83  nWSR = 1000;
84  QProblem qrecipeS(180, 91);
85  tic = getCPUtime();
86  qrecipeS.init(H, g, A, lb, ub, lbA, ubA, nWSR, 0);
87  toc = getCPUtime();
88  qrecipeS.getPrimalSolution(x2);
89  qrecipeS.getDualSolution(y2);
90 
91  fprintf(stdFile, "Solved sparse problem in %d iterations, %.3f seconds.\n", (int)nWSR, toc-tic);
92 
93  /* solve with sparse matrices (Schur complement) */
94  #ifndef SOLVER_NONE
95  nWSR = 1000;
96  SQProblemSchur qrecipeSchur(180, 91);
97  tic = getCPUtime();
98  qrecipeSchur.init(H, g, A, lb, ub, lbA, ubA, nWSR, 0);
99  toc = getCPUtime();
100  qrecipeSchur.getPrimalSolution(x3);
101  qrecipeSchur.getDualSolution(y3);
102 
103  fprintf(stdFile, "Solved sparse problem (Schur complement approach) in %d iterations, %.3f seconds.\n", (int)nWSR, toc-tic);
104  #endif /* SOLVER_NONE */
105 
106  /* check distance of solutions */
107  errP1 = 0.0;
108  errP2 = 0.0;
109  errP3 = 0.0;
110  #ifndef SOLVER_NONE
111  for (i = 0; i < 180; i++)
112  if (getAbs(x1[i] - x2[i]) > errP1)
113  errP1 = getAbs(x1[i] - x2[i]);
114  for (i = 0; i < 180; i++)
115  if (getAbs(x1[i] - x3[i]) > errP2)
116  errP2 = getAbs(x1[i] - x3[i]);
117  for (i = 0; i < 180; i++)
118  if (getAbs(x2[i] - x3[i]) > errP3)
119  errP3 = getAbs(x2[i] - x3[i]);
120  #endif /* SOLVER_NONE */
121  fprintf(stdFile, "Primal error (dense and sparse): %9.2e\n", errP1);
122  fprintf(stdFile, "Primal error (dense and Schur): %9.2e\n", errP2);
123  fprintf(stdFile, "Primal error (sparse and Schur): %9.2e\n", errP3);
124 
125  errD1 = 0.0;
126  errD2 = 0.0;
127  errD3 = 0.0;
128  for (i = 0; i < 271; i++)
129  if (getAbs(y1[i] - y2[i]) > errD1)
130  errD1 = getAbs(y1[i] - y2[i]);
131  #ifndef SOLVER_NONE
132  for (i = 0; i < 271; i++)
133  if (getAbs(y1[i] - y3[i]) > errD2)
134  errD2 = getAbs(y1[i] - y3[i]);
135  for (i = 0; i < 271; i++)
136  if (getAbs(y2[i] - y3[i]) > errD3)
137  errD3 = getAbs(y2[i] - y3[i]);
138  #endif /* SOLVER_NONE */
139  fprintf(stdFile, "Dual error (dense and sparse): %9.2e (might not be unique)\n", errD1);
140  fprintf(stdFile, "Dual error (dense and Schur): %9.2e (might not be unique)\n", errD2);
141  fprintf(stdFile, "Dual error (sparse and Schur): %9.2e (might not be unique)\n", errD3);
142 
143  delete H;
144  delete A;
145  delete[] H_full;
146  delete[] A_full;
147  delete Hd;
148  delete Ad;
149 
150  delete[] y3;
151  delete[] x3;
152  delete[] y2;
153  delete[] x2;
154  delete[] y1;
155  delete[] x1;
156 
157  QPOASES_TEST_FOR_TOL( errP1,1e-13 );
158  QPOASES_TEST_FOR_TOL( errP2,1e-13 );
159  QPOASES_TEST_FOR_TOL( errP3,1e-13 );
160 
161  return TEST_PASSED;
162 }
163 
164 
165 /*
166  * end of file
167  */
Interfaces matrix-vector operations tailored to symmetric sparse matrices.
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)
real_t getAbs(real_t x)
int main()
real_t toc(timer *t)
Definition: AD_test.c:25
Interfaces matrix-vector operations tailored to symmetric dense matrices.
#define stdFile
void tic(timer *t)
Definition: AD_test.c:19
Interfaces matrix-vector operations tailored to general dense matrices.
Interfaces matrix-vector operations tailored to general sparse matrices.
#define QPOASES_TEST_FOR_TOL(x, tol)
Definition: UnitTesting.hpp:61
#define TEST_PASSED
Definition: UnitTesting.hpp:45
Implements the online active set strategy for QPs with varying, sparse matrices.
double real_t
Definition: AD_test.c:10
Implements the online active set strategy for QPs with general constraints.


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