fed_batch_bioreactor2_nbi.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 
44 #include <acado_gnuplot.hpp>
45 
46 
47 int main( ){
48 
50 
51  // INTRODUCE FIXED PARAMETERS:
52  // ---------------------------
53  #define Csin 2.8
54 
55  // INTRODUCE THE VARIABLES:
56  // -------------------------
57  DifferentialState x1,x2,x3,x4,x5;
58  IntermediateState mu,sigma,pif;
59  Control u ;
60  Parameter tf ;
61  DifferentialEquation f(0.0,tf) ;
62 
63 
64  // DEFINE A DIFFERENTIAL EQUATION:
65  // -------------------------------
66  mu = 0.125*x2/x4;
67  sigma = mu/0.135;
68  pif = (-384.0*mu*mu + 134.0*mu);
69 
70  f << dot(x1) == mu*x1;
71  f << dot(x2) == -sigma*x1 + u*Csin;
72  f << dot(x3) == pif*x1;
73  f << dot(x4) == u;
74  f << dot(x5) == 0.001*(u*u + 0.01*tf*tf);
75 
76  // DEFINE AN OPTIMAL CONTROL PROBLEM:
77  // ----------------------------------
78  OCP ocp( 0.0, tf, 50 );
79  ocp.minimizeMayerTerm(0, 0.01*x5 -x3/tf ); // Solve productivity optimal problem (Note: - due to maximization, small regularisation term)
80  ocp.minimizeMayerTerm(1, 0.01*x5 -x3/(Csin*(x4-5.0))); // Solve yield optimal problem (Note: Csin = x2(t=0)/x4(t=0); - due to maximization, small regularisation term)
81 
82  ocp.subjectTo( f );
83 
84  ocp.subjectTo( AT_START, x1 == 0.1 );
85  ocp.subjectTo( AT_START, x2 == 14.0 );
86  ocp.subjectTo( AT_START, x3 == 0.0 );
87  ocp.subjectTo( AT_START, x4 == 5.0 );
88  ocp.subjectTo( AT_START, x5 == 0.0 );
89  ocp.subjectTo( AT_END, x4 >= 5.0+20.0/Csin );
90 
91  ocp.subjectTo( 0.0 <= x1 <= 15.0 );
92  ocp.subjectTo( 0.0 <= x2 <= 30.0 );
93  ocp.subjectTo( -0.1 <= x3 <= 1000.0 );
94  ocp.subjectTo( 5.0 <= x4 <= 20.0 );
95  ocp.subjectTo( 20.0 <= tf <= 40.0 );
96  ocp.subjectTo( 0.0 <= u <= 2.0 );
97 
98 
99  // DEFINE A MULTI-OBJECTIVE ALGORITHM AND SOLVE THE OCP:
100  // -----------------------------------------------------
101  MultiObjectiveAlgorithm algorithm(ocp);
102 
103  algorithm.set( PARETO_FRONT_DISCRETIZATION, 41 );
105  algorithm.set( HESSIAN_APPROXIMATION , EXACT_HESSIAN );
106  //algorithm.set( DISCRETIZATION_TYPE , SINGLE_SHOOTING );
107  //algorithm.set( PARETO_FRONT_HOTSTART , BT_FALSE );
108  algorithm.set( KKT_TOLERANCE, 1e-8 );
109 
110 
111 
112  // Minimize individual objective function
113  algorithm.solveSingleObjective(1);
114 
115 
116  algorithm.initializeDifferentialStates("states.txt");
117  algorithm.initializeControls("controls.txt");
118  algorithm.initializeParameters("parameters.txt");
119 
120 
121  // Minimize individual objective function
122  algorithm.solveSingleObjective(0);
123 
124 
125 
126 
127 
128 
129  // Generate Pareto set
130  algorithm.set( KKT_TOLERANCE, 5.0e-6 );
131  algorithm.solveSingleObjective(1); // better to initialize afterwards
132  algorithm.solve();
133 
134  algorithm.getWeights("fed_batch_bioreactor2_nbi_weights.txt");
135  algorithm.getAllDifferentialStates("fed_batch_bioreactor2_nbi_states.txt");
136  algorithm.getAllControls("fed_batch_bioreactor2_nbi_controls.txt");
137  algorithm.getAllParameters("fed_batch_bioreactor2_nbi_parameters.txt");
138 
139 
140  // VISUALIZE THE RESULTS IN A GNUPLOT WINDOW:
141  // ------------------------------------------
142  VariablesGrid paretoFront;
143  algorithm.getParetoFront( paretoFront );
144 
145  GnuplotWindow window1;
146  window1.addSubplot( paretoFront, "Pareto Front (yield versus productivity)", "-PRODUCTIVTY", "-YIELD", PM_POINTS );
147  window1.plot( );
148 
149 
150  // PRINT INFORMATION ABOUT THE ALGORITHM:
151  // --------------------------------------
152  algorithm.printInfo();
153 
154 
155  // SAVE INFORMATION:
156  // -----------------
157  paretoFront.print();
158 
159  return 0;
160 }
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
DMatrix getWeights() const
virtual returnValue plot(PlotFrequency _frequency=PLOT_IN_ANY_CASE)
returnValue initializeControls(const char *fileName)
#define USING_NAMESPACE_ACADO
Provides a time grid consisting of vector-valued optimization variables at each grid point...
returnValue printInfo()
returnValue initializeParameters(const char *fileName)
returnValue subjectTo(const DifferentialEquation &differentialEquation_)
Definition: ocp.cpp:153
returnValue minimizeMayerTerm(const Expression &arg)
Definition: ocp.cpp:238
returnValue addSubplot(PlotWindowSubplot &_subplot)
returnValue set(OptionsName name, int value)
Definition: options.cpp:126
returnValue getAllControls(const char *fileName) const
returnValue getParetoFront(VariablesGrid &paretoFront) const
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)
virtual returnValue solveSingleObjective(const int &number)
User-interface to formulate and solve optimal control problems with multiple objectives.
returnValue getAllDifferentialStates(const char *fileName) const
Provides an interface to Gnuplot for plotting algorithmic outputs.
returnValue getAllParameters(const char *fileName) const
Allows to setup and evaluate differential equations (ODEs and DAEs) based on SymbolicExpressions.
#define Csin


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:34:34