1 /*
2 * This file is part of qpOASES.
3 *
4 * qpOASES -- An Implementation of the Online Active Set Strategy.
5 * Copyright (C) 2007-2017 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
25 /**
26 * \file examples/example2.cpp
27 * \author Hans Joachim Ferreau (thanks to Boris Houska)
28 * \version 3.2
29 * \date 2008-2017
30 *
31 * Very simple example for testing qpOASES in combination
32 * with the SolutionAnalysis class.
33 */
34
35
36
37 #include <qpOASES.hpp>
38
39
40 /** Example for qpOASES main function using the SolutionAnalysis class. */
main()41 int main( )
42 {
43 USING_NAMESPACE_QPOASES
44
45 /* Setup data of first QP. */
46 real_t H[2*2] = { 1.0, 0.0, 0.0, 0.5 };
47 real_t A[1*2] = { 1.0, 1.0 };
48 real_t g[2] = { 1.5, 1.0 };
49 real_t lb[2] = { 0.5, -2.0 };
50 real_t ub[2] = { 5.0, 2.0 };
51 real_t lbA[1] = { -1.0 };
52 real_t ubA[1] = { 2.0 };
53
54 /* Setup data of second QP. */
55 real_t H_new[2*2] = { 1.0, 0.5, 0.5, 0.5 };
56 real_t A_new[1*2] = { 1.0, 5.0 };
57 real_t g_new[2] = { 1.0, 1.5 };
58 real_t lb_new[2] = { 0.0, -1.0 };
59 real_t ub_new[2] = { 5.0, -0.5 };
60 real_t lbA_new[1] = { -2.0 };
61 real_t ubA_new[1] = { 1.0 };
62
63
64 /* Setting up SQProblem object and solution analyser. */
65 SQProblem example( 2,1 );
66 SolutionAnalysis analyser;
67
68 /* Solve first QP ... */
69 int_t nWSR = 10;
70 example.init( H,g,A,lb,ub,lbA,ubA, nWSR,0 );
71
72 /* ... and analyse it. */
73 real_t maxKktViolation = analyser.getKktViolation( &example );
74 printf( "maxKktViolation: %e\n", maxKktViolation );
75
76 /* Solve second QP ... */
77 nWSR = 10;
78 example.hotstart( H_new,g_new,A_new,lb_new,ub_new,lbA_new,ubA_new, nWSR,0 );
79
80 /* ... and analyse it. */
81 maxKktViolation = analyser.getKktViolation( &example );
82 printf( "maxKktViolation: %e\n", maxKktViolation );
83
84
85 // ------------ VARIANCE-COVARIANCE EVALUATION --------------------
86
87 real_t *Var = new real_t[5*5];
88 real_t *Primal_Dual_Var = new real_t[5*5];
89
90 int_t run1, run2;
91 for( run1 = 0; run1 < 5*5; run1++ )
92 Var[run1] = 0.0;
93
94 Var[0] = 1.0;
95 Var[6] = 1.0;
96
97 // ( 1 0 0 0 0 )
98 // ( 0 1 0 0 0 )
99 // Var = ( 0 0 0 0 0 )
100 // ( 0 0 0 0 0 )
101 // ( 0 0 0 0 0 )
102
103
104 analyser.getVarianceCovariance( &example, Var,Primal_Dual_Var );
105
106 printf("\nPrimal_Dual_VAR = \n");
107 for( run1 = 0; run1 < 5; run1++ ){
108 for( run2 = 0; run2 < 5; run2++ ){
109 printf(" %10f", Primal_Dual_Var[run1*5+run2]);
110 }
111 printf("\n");
112 }
113
114 delete[] Primal_Dual_Var;
115 delete[] Var;
116
117 return 0;
118 }
119
120
121 /*
122 * end of file
123 */
124