bioreactor.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 
00033 #include <acado_optimal_control.hpp>
00034 #include <acado_gnuplot.hpp>
00035 
00036 
00037 /* >>> start tutorial code >>> */
00038 int main( ){
00039 
00040     USING_NAMESPACE_ACADO
00041 
00042     // INTRODUCE THE VARIABLES:
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     // const double Sfbar   = 32.9;
00058     const double Sfmin   = 28.7;
00059     const double Sfmax   = 40.0;
00060     // const double Xbarmax = 5.8 ;
00061 
00062     const double t_start =  0.0;
00063     const double t_end   = 48.0;
00064 
00065     // DEFINE A DIFFERENTIAL EQUATION:
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     // DEFINE AN OPTIMAL CONTROL PROBLEM:
00076     // ----------------------------------
00077     OCP ocp( t_start, t_end, 20 );
00078     ocp.minimizeLagrangeTerm( D*(Sf-P) );  // weight this with the physical cost!!!
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 //     ocp.subjectTo( 0.0, X , -X, 0.0 );
00086 //     ocp.subjectTo( 0.0, S , -S, 0.0 );
00087 //     ocp.subjectTo( 0.0, P , -P, 0.0 );
00088 
00089     ocp.subjectTo( Sfmin <= Sf <= Sfmax );
00090 
00091 
00092     // DEFINE A PLOT WINDOW:
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     // DEFINE AN OPTIMIZATION ALGORITHM AND SOLVE THE OCP:
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 //     s3.print(stream, " ", PS_PLAIN );
00123     stream1.close();
00124     
00125     return 0;
00126 }
00127 /* <<< end tutorial code <<< */
00128 


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