examples/ocp/lsq_term.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 
39 int main( ){
40 
42 
43 
44  // INTRODUCE THE VARIABLES:
45  // -------------------------
46  const int N = 2;
47 
48  DifferentialState x, y("", N, 1);
49  Control u;
51 
52  const double t_start = 0.0;
53  const double t_end = 10.0;
54 
55 
56  // DEFINE A DIFFERENTIAL EQUATION:
57  // -------------------------------
58 
59  f << dot(x) == -x + 0.9*x*x + u;
60 
61  int i;
62  for( i = 0; i < N; i++ )
63  f << dot( y(i) ) == -y(i) + 0.5*y(i)*y(i) + u;
64 
65 
66  // DEFINE LEAST SQUARE FUNCTION:
67  // -----------------------------
68 
69  Function h,m;
70 
71  h << x;
72  h << 2.0*u;
73 
74  m << 10.0*x ;
75  m << 0.1*x*x;
76 
77  DMatrix S(2,2);
78  DVector r(2);
79 
80  S.setIdentity();
81  r.setAll( 0.1 );
82 
83 
84  // DEFINE AN OPTIMAL CONTROL PROBLEM:
85  // ----------------------------------
86  OCP ocp( t_start, t_end, 5 );
87 
88  ocp.minimizeLSQ ( S, h, r );
89  ocp.minimizeLSQEndTerm( S, m, r );
90 
91  ocp.subjectTo( f );
92  ocp.subjectTo( AT_START, x == 1.0 );
93 
94  for( i = 0; i < N; i++ )
95  ocp.subjectTo( AT_START, y(i) == 1.0 );
96 
97 
98  // Additionally, flush a plotting object
99  GnuplotWindow window;
100  window.addSubplot( x,"DifferentialState x" );
101  window.addSubplot( u,"Control u" );
102 
103 
104  // DEFINE AN OPTIMIZATION ALGORITHM AND SOLVE THE OCP:
105  // ---------------------------------------------------
106  OptimizationAlgorithm algorithm(ocp);
107  algorithm << window;
108 
109 // algorithm.set( PRINT_SCP_METHOD_PROFILE, YES );
110 // algorithm.set( DYNAMIC_SENSITIVITY, FORWARD_SENSITIVITY_LIFTED );
111 // algorithm.set( HESSIAN_APPROXIMATION, CONSTANT_HESSIAN );
112 // algorithm.set( HESSIAN_APPROXIMATION, FULL_BFGS_UPDATE );
113 // algorithm.set( HESSIAN_APPROXIMATION, BLOCK_BFGS_UPDATE );
114  algorithm.set( HESSIAN_APPROXIMATION, GAUSS_NEWTON );
115 // algorithm.set( HESSIAN_APPROXIMATION, GAUSS_NEWTON_WITH_BLOCK_BFGS );
116 // algorithm.set( HESSIAN_APPROXIMATION, EXACT_HESSIAN );
117 
118  // Necessary to use with GN Hessian approximation.
119  algorithm.set( LEVENBERG_MARQUARDT, 1e-10 );
120 
121  algorithm.solve();
122 
123  return 0;
124 }
125 
126 
127 
#define N
Allows to setup and evaluate a general function based on SymbolicExpressions.
Definition: function_.hpp:59
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 addSubplot(PlotWindowSubplot &_subplot)
returnValue set(OptionsName name, int value)
Definition: options.cpp:126
int main()
returnValue minimizeLSQ(const DMatrix &S, const Function &h, const DVector &r)
Definition: ocp.cpp:244
returnValue minimizeLSQEndTerm(const DMatrix &S, const Function &m, const DVector &r)
Definition: ocp.cpp:297
Data class for defining optimal control problems.
Definition: ocp.hpp:89
Expression dot(const Expression &arg)
const double t_end
const double t_start
void setAll(const T &_value)
Definition: vector.hpp:160
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:34:48