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