qpOASES-3.0beta/examples/example4.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-2011 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 
37 #include <stdlib.h>
38 
39 #include <qpOASES.hpp>
40 #include "example4CP.cpp"
41 
42 
45 int main( )
46 {
48 
49  int i,j;
50 
51  /* Setup data of first QP... */
52  real_t H[7*7];
53  real_t A[50*7];
54  real_t g[7];
55  real_t lbA[50];
56 
57  /* ( 1.0 0.5 | )
58  * ( 0.5 2.0 | )
59  * ( --------+------------------- )
60  * H = ( | 1e-6 )
61  * ( | 1e-6 )
62  * ( | ... )
63  * ( | 1e-6 ) */
64  for( i=0; i<7*7; ++i )
65  H[i] = 0.0;
66  for( i=2; i<7; ++i )
67  H[i*7+i] = 1.0e-6;
68  H[0] = 1.0;
69  H[1] = 0.5;
70  H[7] = 0.5;
71  H[8] = 2.0;
72 
73  /* ( x.x x.x | 1.0 )
74  * ( x.x x.x | ... )
75  * ( x.x x.x | 1.0 )
76  * ( x.x x.x | 1.0 )
77  * A = ( x.x x.x | ... )
78  * ( x.x x.x | 1.0 )
79  * ( x.x x.x | ... )
80  * ( x.x x.x | 1.0 )
81  * ( x.x x.x | ... )
82  * ( x.x x.x | 1.0 ) */
83  for( i=0; i<50*7; ++i )
84  A[i] = 0.0;
85  for( i=0; i<50; ++i )
86  {
87  for( j=0; j<2; ++j )
88  A[i*7+j] = (real_t)rand() / (real_t)RAND_MAX;
89 
90  A[i*7 + (i/10)+2] = 1.0;
91  }
92 
93  /* ( -1.0 )
94  * ( -0.5 )
95  * ( ---- )
96  * g = ( )
97  * ( )
98  * ( )
99  * ( ) */
100  for( i=0; i<7; ++i )
101  g[i] = 0.0;
102  g[0] = -1.0;
103  g[1] = -0.5;
104 
105  for( i=0; i<50; ++i )
106  lbA[i] = 1.0;
107 
108  /* ... and setting up user-defined constraint product function. */
109  MyConstraintProduct myCP( 7,50,A );
110 
111 
112  /* Setting up QProblem object and set construct product function. */
113  QProblem example( 7,50 );
114  example.setConstraintProduct( &myCP );
115 
116 
117  /* Solve first QP. */
118  real_t cputime = 1.0;
119  int nWSR = 100;
120  example.init( H,g,A,0,0,lbA,0, nWSR,&cputime );
121 
122 
123  /* Solve second QP using a modified gradient. */
124  g[0] = -2.0;
125  g[1] = 0.5;
126 
127  cputime = 1.0;
128  nWSR = 100;
129  example.hotstart( g,0,0,lbA,0, nWSR,&cputime );
130 
131  /* Get and print solution of second QP. */
132  real_t xOpt[7];
133  example.getPrimalSolution( xOpt );
134  printf( "\nxOpt = [ %e, %e, %e ... ]; objVal = %e\n\n", xOpt[0],xOpt[1],xOpt[2],example.getObjVal() );
135 
136  return 0;
137 }
138 
139 
140 /*
141  * end of file
142  */
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)
Example illustrating the use of the ConstraintProduct class.
returnValue setConstraintProduct(ConstraintProduct *const _constraintProduct)
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:34:33