fed_batch_bioreactor_nnc.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 #include "acado_optimal_control.hpp"
00048 #include <acado_gnuplot.hpp>
00049 
00050 
00051 int main( ){
00052 
00053     USING_NAMESPACE_ACADO
00054 
00055     // INTRODUCE FIXED PARAMETERS:
00056     // ---------------------------
00057     #define  Csin       2.8
00058 
00059 
00060     // INTRODUCE THE VARIABLES:
00061     // -------------------------
00062     DifferentialState     x1,x2,x3,x4,x5;
00063     IntermediateState     mu,sigma,pif;
00064     Control               u           ;
00065     Parameter             tf          ;
00066     DifferentialEquation  f(0.0,tf)   ;
00067 
00068 
00069     // DEFINE A DIFFERENTIAL EQUATION:
00070     // -------------------------------
00071     mu    = 0.125*x2/x4;
00072     sigma = mu/0.135;
00073     pif   = (-384.0*mu*mu + 134.0*mu);
00074 
00075     f << dot(x1) ==  mu*x1;
00076     f << dot(x2) == -sigma*x1 + u*Csin;
00077     f << dot(x3) ==  pif*x1;
00078     f << dot(x4) ==  u;
00079     f << dot(x5) ==  0.001*(u*u + 0.01*tf*tf);
00080 
00081 
00082     // DEFINE AN OPTIMAL CONTROL PROBLEM:
00083     // ----------------------------------
00084     OCP ocp( 0.0, tf, 50 );
00085     ocp.minimizeMayerTerm(0, 0.01*x5 -x3/tf          ); // Solve productivity optimal problem (Note: - due to maximization, small regularisation term)
00086     ocp.minimizeMayerTerm(1, 0.01*x5 -x3/(Csin*x4-x2)); // Solve yield optimal problem (Note: Csin = x2(t=0)/x4(t=0); - due to maximization, small regularisation term)
00087 
00088     ocp.subjectTo( f );
00089 
00090     ocp.subjectTo( AT_START, x1 ==   0.1           );
00091     ocp.subjectTo( AT_START, x2 ==  14.0           );
00092     ocp.subjectTo( AT_START, x3 ==   0.0           );
00093     ocp.subjectTo( AT_START, x4 ==   5.0           );
00094     ocp.subjectTo( AT_START, x5 ==   0.0           );
00095 
00096     ocp.subjectTo(  0.0 <= x1 <=   15.0  );
00097     ocp.subjectTo(  0.0 <= x2 <=   30.0  );
00098     ocp.subjectTo( -0.1 <= x3 <= 1000.0  );
00099     ocp.subjectTo(  5.0 <= x4 <=   20.0  );
00100     ocp.subjectTo( 20.0 <= tf <=   40.0  );
00101     ocp.subjectTo(  0.0 <= u  <=    2.0  );
00102 
00103 
00104     // DEFINE A MULTI-OBJECTIVE ALGORITHM AND SOLVE THE OCP:
00105     // -----------------------------------------------------
00106     MultiObjectiveAlgorithm algorithm(ocp);
00107 
00108     algorithm.set( PARETO_FRONT_DISCRETIZATION, 21                               );
00109     algorithm.set( PARETO_FRONT_GENERATION    , PFG_NORMALIZED_NORMAL_CONSTRAINT );
00110     algorithm.set( HESSIAN_APPROXIMATION, EXACT_HESSIAN );
00111     algorithm.set( KKT_TOLERANCE, 1e-7 );
00112 
00113     // Minimize individual objective function
00114     algorithm.solveSingleObjective(0);
00115 
00116     // Minimize individual objective function
00117     algorithm.solveSingleObjective(1);
00118 
00119     // Generate Pareto set
00120     algorithm.set( KKT_TOLERANCE, 1e-6 );
00121     algorithm.solve();
00122 
00123     algorithm.getWeights("fed_batch_bioreactor_nnc_weights.txt");
00124     algorithm.getAllDifferentialStates("fed_batch_bioreactor_nnc_states.txt");
00125     algorithm.getAllControls("fed_batch_bioreactor_nnc_controls.txt");
00126     algorithm.getAllParameters("fed_batch_bioreactor_nnc_parameters.txt");
00127 
00128 
00129     // VISUALIZE THE RESULTS IN A GNUPLOT WINDOW:
00130     // ------------------------------------------
00131     VariablesGrid paretoFront;
00132     algorithm.getParetoFront( paretoFront );
00133 
00134     GnuplotWindow window1;
00135     window1.addSubplot( paretoFront, "Pareto Front (yield versus productivity)", "-PRODUCTIVTY", "-YIELD", PM_POINTS );
00136     window1.plot( );
00137 
00138 
00139     // PRINT INFORMATION ABOUT THE ALGORITHM:
00140     // --------------------------------------
00141     algorithm.printInfo();
00142 
00143 
00144     // SAVE INFORMATION:
00145     // -----------------
00146     paretoFront.print();
00147 
00148     return 0;
00149 }


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