car_ws.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 
00047 // IMPLEMENTATION:
00048 // ---------------
00049 
00050 #include <acado_optimal_control.hpp>
00051 #include <acado_gnuplot.hpp>
00052 
00053 
00054 /* >>> start tutorial code >>> */
00055 int main( ){
00056 
00057     USING_NAMESPACE_ACADO
00058 
00059     // INTRODUCE THE VARIABLES:
00060     // -------------------------
00061     DifferentialState     x1,x2;
00062     Control               u    ;
00063     Parameter             t1   ;
00064     DifferentialEquation  f(0.0,t1);
00065 
00066 
00067     // DEFINE A DIFFERENTIAL EQUATION:
00068     // -------------------------------
00069     f << dot(x1) ==  x2;
00070     f << dot(x2) ==   u;
00071 
00072 
00073     // DEFINE AN OPTIMAL CONTROL PROBLEM:
00074     // ----------------------------------
00075     OCP ocp(0.0,t1,25);
00076     ocp.minimizeMayerTerm( 0, x2         );
00077     ocp.minimizeMayerTerm( 1, 2.0*t1/20.0);
00078 
00079     ocp.subjectTo( f );
00080 
00081     ocp.subjectTo( AT_START, x1 ==   0.0 );
00082     ocp.subjectTo( AT_START, x2 ==   0.0 );
00083     ocp.subjectTo( AT_END  , x1 == 200.0 );
00084 
00085     ocp.subjectTo( 0.0 <= x1 <= 200.0001 );
00086     ocp.subjectTo( 0.0 <= x2 <=  40.0    );
00087     ocp.subjectTo( 0.0 <= u  <=   5.0    );
00088     ocp.subjectTo( 0.1 <= t1 <=  50.0    );
00089 
00090 
00091     // DEFINE A MULTI-OBJECTIVE ALGORITHM AND SOLVE THE OCP:
00092     // -----------------------------------------------------
00093     MultiObjectiveAlgorithm algorithm(ocp);
00094 
00095     algorithm.set( PARETO_FRONT_GENERATION    , PFG_WEIGHTED_SUM );
00096     algorithm.set( PARETO_FRONT_DISCRETIZATION, 11               );
00097     algorithm.set( KKT_TOLERANCE, 1e-8 );
00098 
00099     // Generate Pareto set
00100     algorithm.solve();
00101 
00102     algorithm.getWeights("car_ws_weights.txt");
00103     algorithm.getAllDifferentialStates("car_ws_states.txt");
00104     algorithm.getAllControls("car_ws_controls.txt");
00105     algorithm.getAllParameters("car_ws_parameters.txt");
00106 
00107     // GET THE RESULT FOR THE PARETO FRONT AND PLOT IT:
00108     // ------------------------------------------------
00109     VariablesGrid paretoFront;
00110     algorithm.getParetoFront( paretoFront );
00111 
00112     GnuplotWindow window1;
00113     window1.addSubplot( paretoFront, "Pareto Front (time versus energy)", "ENERGY","TIME", PM_POINTS );
00114     window1.plot( );
00115 
00116 
00117     // PRINT INFORMATION ABOUT THE ALGORITHM:
00118     // --------------------------------------
00119     algorithm.printInfo();
00120 
00121 
00122     // SAVE INFORMATION:
00123     // -----------------
00124     paretoFront.print( "car_ws_pareto.txt" );
00125 
00126     return 0;
00127 }
00128 /* <<< end tutorial code <<< */
00129 


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Thu Aug 27 2015 11:57:54