qpOASES-3.2.0/examples/qrecipe.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 <qpOASES.hpp>
37 
38 #include "qrecipe_data.hpp"
39 
40 
41 
42 int main( )
43 {
45 
46  long i;
47  int_t nWSR;
48  real_t err, tic, toc;
49  real_t *x1 = new real_t[180];
50  real_t *y1 = new real_t[271];
51  real_t *x2 = new real_t[180];
52  real_t *y2 = new real_t[271];
53 
54  /* create sparse matrices */
55  SymSparseMat *H = new SymSparseMat(180, 180, H_ir, H_jc, H_val);
56  SparseMatrix *A = new SparseMatrix(91, 180, A_ir, A_jc, A_val);
57 
58  H->createDiagInfo();
59 
60  real_t* H_full = H->full();
61  real_t* A_full = A->full();
62 
63  SymDenseMat *Hd = new SymDenseMat(180,180,180,H_full);
64  DenseMatrix *Ad = new DenseMatrix(91,180,180,A_full);
65 
66  /* solve with dense matrices */
67  nWSR = 1000;
68  QProblem qrecipeD(180, 91);
69  tic = getCPUtime();
70  qrecipeD.init(Hd, g, Ad, lb, ub, lbA, ubA, nWSR, 0);
71  toc = getCPUtime();
72  qrecipeD.getPrimalSolution(x1);
73  qrecipeD.getDualSolution(y1);
74 
75  fprintf(stdFile, "Solved dense problem in %d iterations, %.3f seconds.\n", (int)nWSR, toc-tic);
76 
77  /* solve with sparse matrices */
78  nWSR = 1000;
79  QProblem qrecipeS(180, 91);
80  tic = getCPUtime();
81  qrecipeS.init(H, g, A, lb, ub, lbA, ubA, nWSR, 0);
82  toc = getCPUtime();
83  qrecipeS.getPrimalSolution(x2);
84  qrecipeS.getDualSolution(y2);
85 
86  fprintf(stdFile, "Solved sparse problem in %d iterations, %.3f seconds.\n", (int)nWSR, toc-tic);
87 
88  /* check distance of solutions */
89  err = 0.0;
90  for (i = 0; i < 180; i++)
91  if (getAbs(x1[i] - x2[i]) > err)
92  err = getAbs(x1[i] - x2[i]);
93  fprintf(stdFile, "Primal error: %9.2e\n", err);
94  err = 0.0;
95  for (i = 0; i < 271; i++)
96  if (getAbs(y1[i] - y2[i]) > err)
97  err = getAbs(y1[i] - y2[i]);
98  fprintf(stdFile, "Dual error: %9.2e (might not be unique)\n", err);
99 
100  delete H;
101  delete A;
102  delete[] H_full;
103  delete[] A_full;
104  delete Hd;
105  delete Ad;
106 
107  delete[] y2;
108  delete[] x2;
109  delete[] y1;
110  delete[] x1;
111 
112  return 0;
113 }
114 
115 
116 /*
117  * end of file
118  */
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.
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