simple_dae_c.cpp
Go to the documentation of this file.
00001 /*
00002  *    This file is part of ACADO Toolkit.
00003  *
00004  *    ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization.
00005  *    Copyright (C) 2008-2014 by Boris Houska, Hans Joachim Ferreau,
00006  *    Milan Vukov, Rien Quirynen, KU Leuven.
00007  *    Developed within the Optimization in Engineering Center (OPTEC)
00008  *    under supervision of Moritz Diehl. All rights reserved.
00009  *
00010  *    ACADO Toolkit is free software; you can redistribute it and/or
00011  *    modify it under the terms of the GNU Lesser General Public
00012  *    License as published by the Free Software Foundation; either
00013  *    version 3 of the License, or (at your option) any later version.
00014  *
00015  *    ACADO Toolkit is distributed in the hope that it will be useful,
00016  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  *    Lesser General Public License for more details.
00019  *
00020  *    You should have received a copy of the GNU Lesser General Public
00021  *    License along with ACADO Toolkit; if not, write to the Free Software
00022  *    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00023  *
00024  */
00025 
00026 
00027 
00035 #include <acado_optimal_control.hpp>
00036 #include <acado_gnuplot.hpp>
00037 
00038 /* >>> start tutorial code >>> */
00039 
00040 
00041 void myAcadoDifferentialEquation1( double *xx, double *f, void *user_data ){
00042 
00043     //double t = xx[0];
00044     double x = xx[1];
00045     //double l = xx[2];
00046     double z = xx[3];
00047     double u = xx[4];
00048 
00049     f[0] = -x + 0.5*x*x + u + 0.5*z;
00050     f[1] =  x*x + 3.0*u*u          ;
00051     f[2] =  z + exp(z) - 1.0 + x;
00052 }
00053 
00054 
00055 
00056 
00057 int main( ){
00058 
00059     USING_NAMESPACE_ACADO
00060 
00061     TIME autotime;
00062     DifferentialState x("", 2, 1);
00063     AlgebraicState z;
00064     Control u;
00065     DifferentialEquation f1;
00066     IntermediateState setc_is_1(5);
00067     setc_is_1(0) = autotime;
00068     setc_is_1(1) = x(0);
00069     setc_is_1(2) = x(1);
00070     setc_is_1(3) = z;
00071     setc_is_1(4) = u;
00072 
00073 
00074     CFunction cLinkModel_1( 3, myAcadoDifferentialEquation1 );
00075     f1 << cLinkModel_1(setc_is_1);
00076 
00077 
00078     double dconstant1 = 0.0;
00079     double dconstant2 = 5.0;
00080     int dconstant3 = 10;
00081     OCP ocp1(dconstant1, dconstant2, dconstant3);
00082     ocp1.minimizeMayerTerm(x(1));
00083     ocp1.subjectTo(f1);
00084     ocp1.subjectTo(AT_START, x(0) == 1.0 );
00085     ocp1.subjectTo(AT_START, x(1) == 0.0 );
00086 
00087 
00088     GnuplotWindow window;
00089         window.addSubplot(x(0),"DIFFERENTIAL STATE  x");
00090         window.addSubplot(z,"ALGEBRAIC STATE  z"   );
00091         window.addSubplot(u,"CONTROL u"            );
00092 
00093 
00094     OptimizationAlgorithm algo1(ocp1);
00095     algo1.set( KKT_TOLERANCE, 1.000000E-05 );
00096     algo1.set( RELAXATION_PARAMETER, 1.500000E+00 );
00097 
00098  // algo1.set( HESSIAN_APPROXIMATION, EXACT_HESSIAN );
00099  // 
00100     algo1 << window;
00101 
00102     algo1.solve();
00103 
00104     return 0;
00105 }
00106 /* <<< end tutorial code <<< */
00107 
00108 


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Thu Aug 27 2015 12:00:00