bioreactor.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 
34 #include <acado_gnuplot.hpp>
35 
36 
37 /* >>> start tutorial code >>> */
38 int main( ){
39 
41 
42  // INTRODUCE THE VARIABLES:
43  // -------------------------
44  DifferentialState X,S,P;
45  Control Sf ;
48 
49  const double D = 0.15;
50  const double Ki = 22.0;
51  const double Km = 1.2 ;
52  const double Pm = 50.0;
53  const double Yxs = 0.4 ;
54  const double alpha = 2.2 ;
55  const double beta = 0.2 ;
56  const double mum = 0.48;
57  // const double Sfbar = 32.9;
58  const double Sfmin = 28.7;
59  const double Sfmax = 40.0;
60  // const double Xbarmax = 5.8 ;
61 
62  const double t_start = 0.0;
63  const double t_end = 48.0;
64 
65  // DEFINE A DIFFERENTIAL EQUATION:
66  // -------------------------------
67 
68  mu = mum*(1.-P/Pm)*S/(Km+S+pow(S,2)/Ki);
69 
70  f << dot(X) == -D*X+mu*X;
71  f << dot(S) == D*(Sf-S)-(mu/Yxs)*X;
72  f << dot(P) == -D*P+(alpha*mu+beta)*X;
73 
74 
75  // DEFINE AN OPTIMAL CONTROL PROBLEM:
76  // ----------------------------------
77  OCP ocp( t_start, t_end, 20 );
78  ocp.minimizeLagrangeTerm( D*(Sf-P) ); // weight this with the physical cost!!!
79  ocp.subjectTo( f );
80 
81  ocp.subjectTo( AT_START, X == 6.5 );
82  ocp.subjectTo( AT_START, S == 12.0 );
83  ocp.subjectTo( AT_START, P == 22.0 );
84 
85 // ocp.subjectTo( 0.0, X , -X, 0.0 );
86 // ocp.subjectTo( 0.0, S , -S, 0.0 );
87 // ocp.subjectTo( 0.0, P , -P, 0.0 );
88 
89  ocp.subjectTo( Sfmin <= Sf <= Sfmax );
90 
91 
92  // DEFINE A PLOT WINDOW:
93  // ---------------------
94  GnuplotWindow window;
95  window.addSubplot( X ,"X" );
96  window.addSubplot( S ,"S" );
97  window.addSubplot( P ,"P" );
98  window.addSubplot( Sf,"Sf" );
99 
100 
101  // DEFINE AN OPTIMIZATION ALGORITHM AND SOLVE THE OCP:
102  // ---------------------------------------------------
103  OptimizationAlgorithm algorithm(ocp);
105 
106  algorithm.initializeDifferentialStates("s2.txt");
107  algorithm.initializeControls ("c2.txt");
108 
109  algorithm.set( MAX_NUM_ITERATIONS, 20 );
110  algorithm.set( KKT_TOLERANCE, 1e-8 );
111  algorithm << window;
112 
113  algorithm.solve();
114 
115  VariablesGrid s3,c3;
116  algorithm.getDifferentialStates(s3);
117  algorithm.getControls (c3);
118 
119  std::ofstream stream1( "s3.txt" );
120 
121  s3.print(stream1, 0," "," ", 16, 16, " ", "\n" );
122 // s3.print(stream, " ", PS_PLAIN );
123  stream1.close();
124 
125  return 0;
126 }
127 /* <<< end tutorial code <<< */
128 
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
returnValue initializeControls(const char *fileName)
User-interface to formulate and solve optimal control problems and static NLPs.
#define USING_NAMESPACE_ACADO
Provides a time grid consisting of vector-valued optimization variables at each grid point...
IntermediateState pow(const Expression &arg1, const Expression &arg2)
returnValue addSubplot(PlotWindowSubplot &_subplot)
returnValue set(OptionsName name, int value)
Definition: options.cpp:126
returnValue initializeDifferentialStates(const char *fileName, BooleanType autoinit=BT_FALSE)
Data class for defining optimal control problems.
Definition: ocp.hpp:89
Expression dot(const Expression &arg)
returnValue getControls(VariablesGrid &p_) const
const double t_end
const double t_start
Provides an interface to Gnuplot for plotting algorithmic outputs.
virtual returnValue solve()
int main()
Definition: bioreactor.cpp:38
returnValue getDifferentialStates(VariablesGrid &xd_) 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:28