example4.cpp
Go to the documentation of this file.
00001 /*
00002  *      This file is part of qpOASES.
00003  *
00004  *      qpOASES -- An Implementation of the Online Active Set Strategy.
00005  *      Copyright (C) 2007-2011 by Hans Joachim Ferreau, Andreas Potschka,
00006  *      Christian Kirches et al. All rights reserved.
00007  *
00008  *      qpOASES is free software; you can redistribute it and/or
00009  *      modify it under the terms of the GNU Lesser General Public
00010  *      License as published by the Free Software Foundation; either
00011  *      version 2.1 of the License, or (at your option) any later version.
00012  *
00013  *      qpOASES is distributed in the hope that it will be useful,
00014  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00016  *      See the GNU Lesser General Public License for more details.
00017  *
00018  *      You should have received a copy of the GNU Lesser General Public
00019  *      License along with qpOASES; if not, write to the Free Software
00020  *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00021  *
00022  */
00023 
00024 
00037 #include <stdlib.h>
00038 
00039 #include <qpOASES.hpp>
00040 #include "example4CP.cpp"
00041 
00042 
00045 int main( )
00046 {
00047         USING_NAMESPACE_QPOASES
00048 
00049         int i,j;
00050 
00051         /* Setup data of first QP... */
00052         real_t H[7*7];
00053         real_t A[50*7];
00054         real_t g[7];
00055         real_t lbA[50];
00056 
00057         /*          ( 1.0 0.5 |                    )
00058          *          ( 0.5 2.0 |                    )
00059          *          ( --------+------------------- )
00060          *      H = (         | 1e-6               )
00061          *          (         |      1e-6          )
00062          *          (         |           ...      )
00063          *          (         |               1e-6 ) */
00064         for( i=0; i<7*7; ++i )
00065                 H[i] = 0.0;
00066         for( i=2; i<7; ++i )
00067                 H[i*7+i] = 1.0e-6;
00068         H[0] = 1.0;
00069         H[1] = 0.5;
00070         H[7] = 0.5;
00071         H[8] = 2.0;
00072 
00073         /*          ( x.x x.x | 1.0             )
00074          *          ( x.x x.x | ...             )
00075          *          ( x.x x.x | 1.0             )
00076          *          ( x.x x.x |     1.0         )
00077          *      A = ( x.x x.x |     ...         )
00078          *          ( x.x x.x |     1.0         )
00079          *          ( x.x x.x |         ...     )
00080          *          ( x.x x.x |             1.0 )
00081          *          ( x.x x.x |             ... )
00082          *          ( x.x x.x |             1.0 ) */
00083         for( i=0; i<50*7; ++i )
00084                 A[i] = 0.0;
00085         for( i=0; i<50; ++i )
00086         {
00087                 for( j=0; j<2; ++j )
00088                         A[i*7+j] = (real_t)rand() / (real_t)RAND_MAX;
00089 
00090                 A[i*7 + (i/10)+2] = 1.0;
00091         }
00092 
00093         /*          ( -1.0 )
00094          *          ( -0.5 )
00095          *          ( ---- )
00096          *      g = (      )
00097          *          (      )
00098          *          (      )
00099          *          (      ) */
00100         for( i=0; i<7; ++i )
00101                 g[i] = 0.0;
00102         g[0] = -1.0;
00103         g[1] = -0.5;
00104 
00105         for( i=0; i<50; ++i )
00106                 lbA[i] = 1.0;
00107 
00108         /* ... and setting up user-defined constraint product function. */
00109         MyConstraintProduct myCP( 7,50,A );
00110 
00111 
00112         /* Setting up QProblem object and set construct product function. */
00113         QProblem example( 7,50 );
00114         example.setConstraintProduct( &myCP );
00115 
00116 
00117         /* Solve first QP. */
00118         real_t cputime = 1.0;
00119         int nWSR = 100;
00120         example.init( H,g,A,0,0,lbA,0, nWSR,&cputime );
00121 
00122 
00123         /* Solve second QP using a modified gradient. */
00124         g[0] = -2.0;
00125         g[1] =  0.5;
00126 
00127         cputime = 1.0;
00128         nWSR = 100;
00129         example.hotstart( g,0,0,lbA,0, nWSR,&cputime );
00130 
00131         /* Get and print solution of second QP. */
00132         real_t xOpt[7];
00133         example.getPrimalSolution( xOpt );
00134         printf( "\nxOpt = [ %e, %e, %e ... ];  objVal = %e\n\n", xOpt[0],xOpt[1],xOpt[2],example.getObjVal() );
00135 
00136         return 0;
00137 }
00138 
00139 
00140 /*
00141  *      end of file
00142  */


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Thu Aug 27 2015 11:58:09