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/c/test_c_example1.c
27  *	\author Hans Joachim Ferreau
28  *	\version 3.2
29  *	\date 2014-2017
30  *
31  *	Very simple example for testing qpOASES (using QProblem class through C interface).
32  */
33 
34 #include <stdio.h>
35 
36 #include <qpOASES_wrapper.h>
37 
38 
39 /** Example for qpOASES main function using the QProblem class. */
main()40 int main( )
41 {
42 	/* Setup data of first QP. */
43 	real_t H[2*2] = { 1.0, 0.0, 0.0, 0.5 };
44 	real_t A[1*2] = { 1.0, 1.0 };
45 	real_t g[2] = { 1.5, 1.0 };
46 	real_t lb[2] = { 0.5, -2.0 };
47 	real_t ub[2] = { 5.0, 2.0 };
48 	real_t lbA[1] = { -1.0 };
49 	real_t ubA[1] = { 2.0 };
50 
51 	/* Setup data of second QP. */
52 	real_t g_new[2] = { 1.0, 1.5 };
53 	real_t lb_new[2] = { 0.0, -1.0 };
54 	real_t ub_new[2] = { 5.0, -0.5 };
55 	real_t lbA_new[1] = { -2.0 };
56 	real_t ubA_new[1] = { 1.0 };
57 
58 	int_t nWSR;
59 	qpOASES_Options options;
60 
61 	real_t xOpt[2];
62 	real_t yOpt[2+1];
63 	real_t obj;
64 	int_t status;
65 
66 	qpOASES_Options_init( &options,0 );
67 	options.printLevel = PL_MEDIUM;
68 
69 
70 	QProblem_setup(	2,1,HST_UNKNOWN );
71 
72 	/* Solve first QP. */
73 	nWSR = 10;
74 	QProblem_init(	H,g,A,lb,ub,lbA,ubA,
75 					&nWSR,0,&options,
76 					xOpt,yOpt,&obj,&status
77 					);
78 
79 	/* Print solution of first QP. */
80 	printf( "\nxOpt = [ %e, %e ];  yOpt = [ %e, %e, %e ];  objVal = %e\n\n",
81 			xOpt[0],xOpt[1],yOpt[0],yOpt[1],yOpt[2], obj );
82 
83 
84 	/* Solve second QP. */
85 	nWSR = 10;
86 	QProblem_hotstart(	g_new,lb_new,ub_new,lbA_new,ubA_new,
87 						&nWSR,0,
88 						xOpt,yOpt,&obj,&status
89 						);
90 
91 	/* Print solution of first QP. */
92 	printf( "\nxOpt = [ %e, %e ];  yOpt = [ %e, %e, %e ];  objVal = %e\n\n",
93 			xOpt[0],xOpt[1],yOpt[0],yOpt[1],yOpt[2], obj );
94 
95 
96 	QProblem_cleanup();
97 
98 	return 0;
99 }
100 
101 
102 /*
103  *	end of file
104  */
105