test_guessedWS1.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  /* Setup data of first QP. */
46  real_t H[4*4] = { 1.0, 0.0, 0.0, 0.5,
47  0.0, 1.0, 0.0, 0.0,
48  0.0, 0.0, 1.0, 0.0,
49  0.5, 0.0, 0.0, 1.0 };
50  real_t A[3*4] = { 1.0, 1.0, 0.0, 0.0,
51  1.0, 1.0, 1.0, 0.0,
52  1.0, 1.0, 1.0, 1.0 };
53  real_t g[4] = { 1.5, 1.0, -1.0, -1.0 };
54  real_t lb[4] = { 0.5, -2.0, 0.0, 0.0 };
55  real_t ub[4] = { 1.0, 2.0, 1.0, 0.5 };
56  real_t lbA[3] = { -1.0, -1.0, -1.0 };
57  real_t ubA[3] = { 0.0, 0.25, 1.0 };
58 
59 
60 
61  /* Setting up QProblem object. */
62  QProblem example( 4,3 );
63 
65  example.setOptions( options );
66 
67  /* Solve first QP. */
68  int_t nWSR = 10;
69  example.init( H,g,A,lb,ub,lbA,ubA, nWSR );
70 
71  /* Get and print solution of second QP. */
72  real_t xOpt[4];
73  real_t yOpt[4+3];
74  example.getPrimalSolution( xOpt );
75  example.getDualSolution( yOpt );
76  print( xOpt,4,"xOpt" );
77  print( yOpt,4+3,"yOpt" );
78  printf( "objVal = %e\n\n", example.getObjVal() );
79 
80  /* Compute KKT tolerances */
81  real_t stat, feas, cmpl;
82  SolutionAnalysis analyzer;
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,1e-15 );
88  QPOASES_TEST_FOR_TOL( feas,1e-15 );
89  QPOASES_TEST_FOR_TOL( cmpl,1e-15 );
90 
91 
92  /* Solve first QP again (with optimal guess for working set). */
93  Bounds prevBounds;
94  Constraints prevConstraints;
95 
96  example.getBounds( prevBounds );
97  example.getConstraints( prevConstraints );
98 
99  nWSR = 10;
100  example.hotstart( g,lb,ub,lbA,ubA, nWSR,0,&prevBounds,&prevConstraints );
101 
102  /* Get and print solution of second QP. */
103  example.getPrimalSolution( xOpt );
104  example.getDualSolution( yOpt );
105  print( xOpt,4,"xOpt" );
106  print( yOpt,4+3,"yOpt" );
107  printf( "objVal = %e\n\n", example.getObjVal() );
108 
109  /* Compute KKT tolerances */
110  analyzer.getKktViolation( &example, &stat,&feas,&cmpl );
111  printf( "stat = %e\nfeas = %e\ncmpl = %e\n", stat,feas,cmpl );
112 
113  QPOASES_TEST_FOR_TOL( stat,1e-15 );
114  QPOASES_TEST_FOR_TOL( feas,1e-15 );
115  QPOASES_TEST_FOR_TOL( cmpl,1e-15 );
116 
117 
118  /* Solve first QP again (with inaccurate guess for working set). */
119  prevBounds.print();
120  prevBounds.rotate(1);
121  //prevBounds.moveFixedToFree(0);
122  prevBounds.print();
123 
124  prevConstraints.print();
125  //prevConstraints.moveInactiveToActive(0,ST_LOWER);
126  prevConstraints.moveActiveToInactive(1);
127  prevConstraints.print();
128 
129  nWSR = 10;
130  example.hotstart( g,lb,ub,lbA,ubA, nWSR,0,&prevBounds,&prevConstraints );
131 
132  /* Get and print solution of second QP. */
133  example.getPrimalSolution( xOpt );
134  example.getDualSolution( yOpt );
135  print( xOpt,4,"xOpt" );
136  print( yOpt,4+3,"yOpt" );
137  printf( "objVal = %e\n\n", example.getObjVal() );
138 
139  /* Compute KKT tolerances */
140  analyzer.getKktViolation( &example, &stat,&feas,&cmpl );
141  printf( "stat = %e\nfeas = %e\ncmpl = %e\n", stat,feas,cmpl );
142 
143  QPOASES_TEST_FOR_TOL( stat,1e-15 );
144  QPOASES_TEST_FOR_TOL( feas,1e-15 );
145  QPOASES_TEST_FOR_TOL( cmpl,1e-15 );
146 
147  return TEST_PASSED;
148 }
149 
150 
151 /*
152  * end of file
153  */
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)
virtual returnValue rotate(int offset)
int main()
returnValue getBounds(Bounds *const _bounds) const
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)
returnValue getConstraints(Constraints *const _constraints) const
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
BEGIN_NAMESPACE_QPOASES returnValue print(const real_t *const v, int n)
Manages working sets of bounds (= box constraints).
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