matrix_vector_ocp.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 
36 #include <acado_gnuplot.hpp>
37 
38 
39 /* >>> start tutorial code >>> */
40 int main( ){
41 
43 
44  // INTRODUCE THE VARIABLES:
45  // ----------------------------
46  DifferentialState x("", 10, 1); // a differential state vector with dimension 10. (vector)
47  DifferentialState y ; // another differential state y (scalar)
48  Control u("", 2, 1); // a control input with dimension 2. (vector)
49  Parameter p ; // a parameter (here a scalar). (scalar)
50 
51  DifferentialEquation f ; // the differential equation
52 
53  const double t_start = 0.0;
54  const double t_end = 1.0;
55 
56 
57  // READ A MATRIX "A" FROM A FILE:
58  // ------------------------------
59  DMatrix A; A.read( "matrix_vector_ocp_A.txt" );
60  DMatrix B; B.read( "matrix_vector_ocp_B.txt" );
61 
62 
63  // READ A VECTOR "x0" FROM A FILE:
64  // -------------------------------
65  DVector x0; x0.read( "matrix_vector_ocp_x0.txt" );
66 
67 
68  // DEFINE A DIFFERENTIAL EQUATION:
69  // -------------------------------
70  f << dot(x) == -(A*x) + B*u; // matrix vector notation for a linear equation
71  f << dot(y) == x.transpose()*x + 2.0*u.transpose()*u; // matrix vector notation: x^x = scalar product = ||x||_2^2
72  // u^u = scalar product = ||u||_2^2
73 
74 
75  // DEFINE AN OPTIMAL CONTROL PROBLEM:
76  // ----------------------------------
77  OCP ocp( t_start, t_end, 20 );
78  ocp.minimizeMayerTerm( y );
79  ocp.subjectTo( f );
80 
81  ocp.subjectTo( AT_START, x == x0 );
82  ocp.subjectTo( AT_START, y == 0.0 );
83 
84 
85  GnuplotWindow window;
86  window.addSubplot( x(0),"x0" );
87  window.addSubplot( x(6),"x6" );
88  window.addSubplot( u(0),"u0" );
89  window.addSubplot( u(1),"u1" );
90 
91 
92  // DEFINE AN OPTIMIZATION ALGORITHM AND SOLVE THE OCP:
93  // ---------------------------------------------------
94  OptimizationAlgorithm algorithm(ocp);
95 
96  algorithm.set( MAX_NUM_ITERATIONS, 20 );
97  algorithm.set( KKT_TOLERANCE, 1e-10 );
98 
99  algorithm << window;
100  algorithm.solve();
101 
102  return 0;
103 }
104 /* <<< end tutorial code <<< */
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
int main()
Data class for defining optimal control problems.
Definition: ocp.hpp:89
Expression dot(const Expression &arg)
virtual returnValue read(std::istream &_stream)
Definition: matrix.cpp:419
Expression transpose() const
Definition: expression.cpp:811
const double t_end
const double t_start
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.
virtual returnValue read(std::istream &stream)
Definition: vector.cpp:251


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