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 testing/cpp/test_example1b.cpp
27 * \author Hans Joachim Ferreau
28 * \version 3.2
29 * \date 2007-2017
30 *
31 * Very simple example for testing qpOASES using the QProblemB class.
32 */
33
34
35 #include <qpOASES.hpp>
36 #include <qpOASES/UnitTesting.hpp>
37
38
39 /** Example for qpOASES main function using the QProblemB class. */
40 int main( )
41 {
42 USING_NAMESPACE_QPOASES
43
44 /* Setup data of first QP. */
45 real_t H[2*2] = { 1.0, 0.0, 0.0, 0.5 };
46 real_t g[2] = { 1.5, 1.0 };
47 real_t lb[2] = { 0.5, -2.0 };
48 real_t ub[2] = { 5.0, 2.0 };
49
50 /* Setup data of second QP. */
51 real_t g_new[2] = { 1.0, 1.5 };
52 real_t lb_new[2] = { 0.0, -1.0 };
53 real_t ub_new[2] = { 5.0, -0.5 };
54
55
56 /* Setting up QProblemB object. */
57 QProblemB example( 2 );
58
59 Options options;
60 //options.enableFlippingBounds = BT_FALSE;
61 options.initialStatusBounds = ST_INACTIVE;
62 options.numRefinementSteps = 1;
63 options.enableCholeskyRefactorisation = 1;
64 example.setOptions( options );
65
66 /* Solve first QP. */
67 int_t nWSR = 10;
68 example.init( H,g,lb,ub, nWSR,0 );
69 // printf( "\nnWSR = %d\n\n", nWSR );
70
71 real_t xOpt[2];
72 real_t yOpt[2];
73 example.getPrimalSolution( xOpt );
74 example.getDualSolution( yOpt );
75
76 /* Compute KKT tolerances */
77 real_t stat, feas, cmpl;
78 SolutionAnalysis analyzer;
79
80 analyzer.getKktViolation( &example, &stat,&feas,&cmpl );
81 printf( "stat = %e\nfeas = %e\ncmpl = %e\n", stat,feas,cmpl );
82
83 QPOASES_TEST_FOR_TOL( stat,1e-15 );
84 QPOASES_TEST_FOR_TOL( feas,1e-15 );
85 QPOASES_TEST_FOR_TOL( cmpl,1e-15 );
86
87
88 /* Solve second QP. */
89 nWSR = 10;
90 example.hotstart( g_new,lb_new,ub_new, nWSR,0 );
dissect_pcli_common(tvbuff_t * tvb,packet_info * pinfo,proto_tree * tree,int * offset)91 // printf( "\nnWSR = %d\n\n", nWSR );
92
93 /* Get and print solution of second QP. */
94 example.getPrimalSolution( xOpt );
95 example.getDualSolution( yOpt );
96 printf( "\nxOpt = [ %e, %e ]; objVal = %e\n\n", xOpt[0],xOpt[1],example.getObjVal() );
97
98 /* Compute KKT tolerances */
99 analyzer.getKktViolation( &example, &stat,&feas,&cmpl );
100 printf( "stat = %e\nfeas = %e\ncmpl = %e\n", stat,feas,cmpl );
101
102 QPOASES_TEST_FOR_TOL( stat,1e-15 );
103 QPOASES_TEST_FOR_TOL( feas,1e-15 );
104 QPOASES_TEST_FOR_TOL( cmpl,1e-15 );
105
106 return TEST_PASSED;
107 }
108
109
110 /*
111 * end of file
112 */
113