ocp/simple_dae_c.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ACADO Toolkit.
3  *
4  * ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization.
5  * Copyright (C) 2008-2014 by Boris Houska, Hans Joachim Ferreau,
6  * Milan Vukov, Rien Quirynen, KU Leuven.
7  * Developed within the Optimization in Engineering Center (OPTEC)
8  * under supervision of Moritz Diehl. All rights reserved.
9  *
10  * ACADO Toolkit is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 3 of the License, or (at your option) any later version.
14  *
15  * ACADO Toolkit is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with ACADO Toolkit; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23  *
24  */
25 
26 
27 
36 #include <acado_gnuplot.hpp>
37 
38 /* >>> start tutorial code >>> */
39 
40 
41 void myAcadoDifferentialEquation1( double *xx, double *f, void *user_data ){
42 
43  //double t = xx[0];
44  double x = xx[1];
45  //double l = xx[2];
46  double z = xx[3];
47  double u = xx[4];
48 
49  f[0] = -x + 0.5*x*x + u + 0.5*z;
50  f[1] = x*x + 3.0*u*u ;
51  f[2] = z + exp(z) - 1.0 + x;
52 }
53 
54 
55 
56 
57 int main( ){
58 
60 
61  TIME autotime;
62  DifferentialState x("", 2, 1);
64  Control u;
66  IntermediateState setc_is_1(5);
67  setc_is_1(0) = autotime;
68  setc_is_1(1) = x(0);
69  setc_is_1(2) = x(1);
70  setc_is_1(3) = z;
71  setc_is_1(4) = u;
72 
73 
74  CFunction cLinkModel_1( 3, myAcadoDifferentialEquation1 );
75  f1 << cLinkModel_1(setc_is_1);
76 
77 
78  double dconstant1 = 0.0;
79  double dconstant2 = 5.0;
80  int dconstant3 = 10;
81  OCP ocp1(dconstant1, dconstant2, dconstant3);
82  ocp1.minimizeMayerTerm(x(1));
83  ocp1.subjectTo(f1);
84  ocp1.subjectTo(AT_START, x(0) == 1.0 );
85  ocp1.subjectTo(AT_START, x(1) == 0.0 );
86 
87 
88  GnuplotWindow window;
89  window.addSubplot(x(0),"DIFFERENTIAL STATE x");
90  window.addSubplot(z,"ALGEBRAIC STATE z" );
91  window.addSubplot(u,"CONTROL u" );
92 
93 
94  OptimizationAlgorithm algo1(ocp1);
95  algo1.set( KKT_TOLERANCE, 1.000000E-05 );
96  algo1.set( RELAXATION_PARAMETER, 1.500000E+00 );
97 
98  // algo1.set( HESSIAN_APPROXIMATION, EXACT_HESSIAN );
99  //
100  algo1 << window;
101 
102  algo1.solve();
103 
104  return 0;
105 }
106 /* <<< end tutorial code <<< */
107 
108 
void myAcadoDifferentialEquation1(double *xx, double *f, void *user_data)
User-interface to formulate and solve optimal control problems and static NLPs.
#define USING_NAMESPACE_ACADO
returnValue subjectTo(const DifferentialEquation &differentialEquation_)
Definition: ocp.cpp:153
returnValue minimizeMayerTerm(const Expression &arg)
Definition: ocp.cpp:238
returnValue addSubplot(PlotWindowSubplot &_subplot)
returnValue set(OptionsName name, int value)
Definition: options.cpp:126
#define E
Data class for defining optimal control problems.
Definition: ocp.hpp:89
int main()
(no description yet)
Definition: c_function.hpp:54
IntermediateState exp(const Expression &arg)
Provides an interface to Gnuplot for plotting algorithmic outputs.
virtual returnValue solve()
Allows to setup and evaluate differential equations (ODEs and DAEs) based on SymbolicExpressions.


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:35:04