test_exampleLP.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 #include <qpOASES/UnitTesting.hpp>
38 
39 
41 int main( )
42 {
44 
45  real_t tol = 1e-14;
46 
47  /* Setup data of first LP. */
48  real_t A[1*2] = { 1.0, 1.0 };
49  real_t g[2] = { 1.5, 1.0 };
50  real_t lb[2] = { 0.5, -2.0 };
51  real_t ub[2] = { 5.0, 2.0 };
52  real_t lbA[1] = { -1.0 };
53  real_t ubA[1] = { 2.0 };
54 
55  /* Setup data of second LP. */
56  real_t g_new[2] = { 1.0, 1.5 };
57  real_t lb_new[2] = { 0.0, -1.0 };
58  real_t ub_new[2] = { 5.0, -0.5 };
59  real_t lbA_new[1] = { -2.0 };
60  real_t ubA_new[1] = { 1.0 };
61 
62 
63  /* Setting up QProblem object with zero Hessian matrix. */
64  QProblem example( 2,1,HST_ZERO );
65 
67  /*options.setToMPC();*/
68  example.setOptions( options );
69 
70  /* Solve first LP. */
71  int_t nWSR = 10;
72  example.init( 0,g,A,lb,ub,lbA,ubA, nWSR,0 );
73 
74  real_t xOpt[2];
75  real_t yOpt[2+1];
76  example.getPrimalSolution( xOpt );
77  example.getDualSolution( yOpt );
78 
79  /* Compute KKT tolerances */
80  real_t stat, feas, cmpl;
81  SolutionAnalysis analyzer;
82  printf( "%d\n",example.getHessianType() );
83 
84  analyzer.getKktViolation( &example, &stat,&feas,&cmpl );
85  printf( "stat = %e\nfeas = %e\ncmpl = %e\n", stat,feas,cmpl );
86 
87  QPOASES_TEST_FOR_TOL( stat,tol );
88  QPOASES_TEST_FOR_TOL( feas,tol );
89  QPOASES_TEST_FOR_TOL( cmpl,tol );
90 
91 
92  /* Solve second LP. */
93  nWSR = 10;
94  example.hotstart( g_new,lb_new,ub_new,lbA_new,ubA_new, nWSR,0 );
95 
96 
97  /* Get and print solution of second LP. */
98  example.getPrimalSolution( xOpt );
99  example.getDualSolution( yOpt );
100  printf( "\nxOpt = [ %e, %e ]; objVal = %e\n\n", xOpt[0],xOpt[1],example.getObjVal() );
101 
102  analyzer.getKktViolation( &example, &stat,&feas,&cmpl );
103  printf( "stat = %e\nfeas = %e\ncmpl = %e\n", stat,feas,cmpl );
104 
105  QPOASES_TEST_FOR_TOL( stat,tol );
106  QPOASES_TEST_FOR_TOL( feas,tol );
107  QPOASES_TEST_FOR_TOL( cmpl,tol );
108 
109  return TEST_PASSED;
110 }
111 
112 
113 /*
114  * end of file
115  */
HessianType getHessianType() const
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)
returnValue hotstart(const real_t *const g_new, const real_t *const lb_new, const real_t *const ub_new, const real_t *const lbA_new, const real_t *const ubA_new, int &nWSR, real_t *const cputime)
returnValue setOptions(const Options &_options)
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 TEST_PASSED
Definition: UnitTesting.hpp:45
real_t getKktViolation(QProblemB *const qp, real_t *const maxStat=0, real_t *const maxFeas=0, real_t *const maxCmpl=0) const
#define HST_ZERO
double real_t
Definition: AD_test.c:10
Implements the online active set strategy for QPs with general constraints.
int main()


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