car_nnc.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 
46 // IMPLEMENTATION:
47 // ---------------
48 
50 #include <acado_gnuplot.hpp>
51 
52 
53 /* >>> start tutorial code >>> */
54 int main( ){
55 
57 
58  // INTRODUCE THE VARIABLES:
59  // -------------------------
60  DifferentialState x1,x2;
61  Control u ;
62  Parameter t1 ;
63  DifferentialEquation f(0.0,t1);
64 
65 
66  // DEFINE A DIFFERENTIAL EQUATION:
67  // -------------------------------
68  f << dot(x1) == x2;
69  f << dot(x2) == u;
70 
71 
72  // DEFINE AN OPTIMAL CONTROL PROBLEM:
73  // ----------------------------------
74  OCP ocp(0.0,t1,25);
75  ocp.minimizeMayerTerm( 0, x2 );
76  ocp.minimizeMayerTerm( 1, 2.0*t1/20.0);
77 
78  ocp.subjectTo( f );
79 
80  ocp.subjectTo( AT_START, x1 == 0.0 );
81  ocp.subjectTo( AT_START, x2 == 0.0 );
82  ocp.subjectTo( AT_END , x1 == 200.0 );
83 
84  ocp.subjectTo( 0.0 <= x1 <= 200.0001 );
85  ocp.subjectTo( 0.0 <= x2 <= 40.0 );
86  ocp.subjectTo( 0.0 <= u <= 5.0 );
87  ocp.subjectTo( 0.1 <= t1 <= 50.0 );
88 
89 
90  // DEFINE A MULTI-OBJECTIVE ALGORITHM AND SOLVE THE OCP:
91  // -----------------------------------------------------
92  MultiObjectiveAlgorithm algorithm(ocp);
93 
95  algorithm.set( PARETO_FRONT_DISCRETIZATION, 11 );
96  algorithm.set( KKT_TOLERANCE, 1e-8 );
97 
98  // Minimize individual objective function
99  algorithm.solveSingleObjective(0);
100 
101  // Minimize individual objective function
102  algorithm.solveSingleObjective(1);
103 
104  // Generate Pareto set
105  algorithm.solve();
106 
107  algorithm.getWeights("car_nnc_weights.txt");
108  algorithm.getAllDifferentialStates("car_nnc_states.txt");
109  algorithm.getAllControls("car_nnc_controls.txt");
110  algorithm.getAllParameters("car_nnc_parameters.txt");
111 
112 
113  // OBTAIN RESULTS FOR PLOTTING:
114  // ----------------------------
115  VariablesGrid paretoFront;
116  algorithm.getParetoFront( paretoFront );
117 
118  GnuplotWindow window1;
119  window1.addSubplot( paretoFront, "Pareto Front (time versus energy)", "ENERGY","TIME", PM_POINTS );
120  window1.plot( );
121 
122  printf("\n\n");
123  printf("-------------------------------------------\n\n");
124  printf("Pay off matrix: \n");
125  (algorithm.getPayOffMatrix()).print();
126  printf("\n\n");
127  printf("Utopia vector: \n");
128  (algorithm.getUtopiaVector()).print();
129  printf("\n\n");
130  printf("-------------------------------------------\n\n");
131 
132 
133  // PRINT INFORMATION ABOUT THE ALGORITHM:
134  // --------------------------------------
135  algorithm.printInfo();
136 
137 
138  // SAVE INFORMATION:
139  // -----------------
140  paretoFront.print( "car_nnc_pareto.txt" );
141 
142  return 0;
143 }
144 /* <<< end tutorial code <<< */
145 
returnValue print(std::ostream &stream=std::cout, const char *const name=DEFAULT_LABEL, const char *const startString=DEFAULT_START_STRING, const char *const endString=DEFAULT_END_STRING, uint width=DEFAULT_WIDTH, uint precision=DEFAULT_PRECISION, const char *const colSeparator=DEFAULT_COL_SEPARATOR, const char *const rowSeparator=DEFAULT_ROW_SEPARATOR) const
DMatrix getWeights() const
virtual returnValue plot(PlotFrequency _frequency=PLOT_IN_ANY_CASE)
#define USING_NAMESPACE_ACADO
DMatrix getPayOffMatrix() const
Provides a time grid consisting of vector-valued optimization variables at each grid point...
returnValue printInfo()
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()
Definition: car_nnc.cpp:54
DVector getUtopiaVector() const
returnValue getAllControls(const char *fileName) const
returnValue getParetoFront(VariablesGrid &paretoFront) const
Data class for defining optimal control problems.
Definition: ocp.hpp:89
Expression dot(const Expression &arg)
virtual returnValue solveSingleObjective(const int &number)
BEGIN_NAMESPACE_QPOASES returnValue print(const real_t *const v, int n)
User-interface to formulate and solve optimal control problems with multiple objectives.
returnValue getAllDifferentialStates(const char *fileName) const
Provides an interface to Gnuplot for plotting algorithmic outputs.
returnValue getAllParameters(const char *fileName) const
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:29