Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00033 #include <acado_optimal_control.hpp>
00034 #include <acado_gnuplot.hpp>
00035
00036
00037
00038 int main( ){
00039
00040 USING_NAMESPACE_ACADO
00041
00042
00043
00044 DifferentialState X,S,P;
00045 Control Sf ;
00046 IntermediateState mu ;
00047 DifferentialEquation f ;
00048
00049 const double D = 0.15;
00050 const double Ki = 22.0;
00051 const double Km = 1.2 ;
00052 const double Pm = 50.0;
00053 const double Yxs = 0.4 ;
00054 const double alpha = 2.2 ;
00055 const double beta = 0.2 ;
00056 const double mum = 0.48;
00057
00058 const double Sfmin = 28.7;
00059 const double Sfmax = 40.0;
00060
00061
00062 const double t_start = 0.0;
00063 const double t_end = 48.0;
00064
00065
00066
00067
00068 mu = mum*(1.-P/Pm)*S/(Km+S+pow(S,2)/Ki);
00069
00070 f << dot(X) == -D*X+mu*X;
00071 f << dot(S) == D*(Sf-S)-(mu/Yxs)*X;
00072 f << dot(P) == -D*P+(alpha*mu+beta)*X;
00073
00074
00075
00076
00077 OCP ocp( t_start, t_end, 20 );
00078 ocp.minimizeLagrangeTerm( D*(Sf-P) );
00079 ocp.subjectTo( f );
00080
00081 ocp.subjectTo( AT_START, X == 6.5 );
00082 ocp.subjectTo( AT_START, S == 12.0 );
00083 ocp.subjectTo( AT_START, P == 22.0 );
00084
00085
00086
00087
00088
00089 ocp.subjectTo( Sfmin <= Sf <= Sfmax );
00090
00091
00092
00093
00094 GnuplotWindow window;
00095 window.addSubplot( X ,"X" );
00096 window.addSubplot( S ,"S" );
00097 window.addSubplot( P ,"P" );
00098 window.addSubplot( Sf,"Sf" );
00099
00100
00101
00102
00103 OptimizationAlgorithm algorithm(ocp);
00104 algorithm.set( HESSIAN_APPROXIMATION, EXACT_HESSIAN );
00105
00106 algorithm.initializeDifferentialStates("s2.txt");
00107 algorithm.initializeControls ("c2.txt");
00108
00109 algorithm.set( MAX_NUM_ITERATIONS, 20 );
00110 algorithm.set( KKT_TOLERANCE, 1e-8 );
00111 algorithm << window;
00112
00113 algorithm.solve();
00114
00115 VariablesGrid s3,c3;
00116 algorithm.getDifferentialStates(s3);
00117 algorithm.getControls (c3);
00118
00119 std::ofstream stream1( "s3.txt" );
00120
00121 s3.print(stream1, 0," "," ", 16, 16, " ", "\n" );
00122
00123 stream1.close();
00124
00125 return 0;
00126 }
00127
00128