The problem was originally presented by .
Consider the fed-batch reactor illustrated below
containing biomass (x), substrate (s) and product (p) at certain concentrations, and is of volume (v). The objective is find the optimal control profile for the substrate feed rate (u) such that the production is maximized:
The system dynamics can be expressed as
Additionally, we need simple bounds on variables
and boundary conditions
We require the numerical solution to fulfill the following accuracy criteria
We can specify the system dynamics in function BatchFermentor_Dynamics_Internal with
For this example problem, we do not have any path constraints, so function BatchFermentor_Dynamics_Internal only need to return the value of variable dx .
Similarly, the (optional) simulation dynamics can be specifed in function BatchFermentor_Dynamics_Sim .
First we provide the function handles for system dynamics with,
the optional files providing analytic derivatives,
and the function handle for the settings file.
Next we define the time variables with
For state variables, we need to provide the initial conditions
bounds on intial conditions
bbounds on the absolute local and global (integrated) discretization error of state variables
tolerance for state variable box constraint violation
terminal state bounds
and an initial guess of the state trajectory (optional but recommended)
Lastly for control variables, we need to define simple bounds
bounds on the first control action
tolerance for control variable box constraint violation
as well as an initial guess of the input trajectory (optional but recommended)
This problem has both Lagrange (stage) cost and Mayer (boundary) cost , thus we specify
for sub-function L_unscaled and E_unscaled respectively.
For this example problem, we do not have path constraints, variable rate constraints and additional boundary constraints (in addition to varialbe simple bounds). Thus we can leave sub-routines g_unscaled , avrc_unscaled and b_unscaled as they are.
The analytical derivatives for the problem can be supplied with the following additional files: gradCost_BatchFermentor.m for cost gradient, jacConst_BatchFermentor.m for constraint Jacobian, and hessianLagrangian_BatchFermentor.m for the Lagrangian Hessian. Instructions on how to formulate these files are included in the function descriptions.
Now we can fetch the problem and options, solve the resultant NLP, and generate some plots for the solution.
Note the last line of code will generate an open-loop simulation, applying the obtained input trajectory to the dynamics defined in BatchFermentor_Dynamics_Sim.m , using the Matlab builtin ode113 ODE solver with a step size of 0.01.
With the existance of singular control in this problem, it is recommended to solve the problem using a realtively dense mesh instead of mesh refinement schemes. This is becasue the fluctuations and ringing phenomena on the singular arc are known to make mesh refinement process diverge. In this case, one often have to make large compromises between solution speed and result accuracy. Here, we focus on the accuracy of the solution.
Using the Hermite-Simpson discretization scheme of ICLOCS2, the following state and input trajectories are obtained using an uniform mesh with 299 intervals. The computation time with IPOPT (NLP convergence tol set to 1e-09) is about 20 seconds , using finite difference derivative calculations on an Intel i7-6700 desktop computer.
If analytical derivative infomations are supplied in ICLOCS2, the total computation time can be reduced to 3 seconds (reduction of 85%).
 J.E. Cuthrell and L. T. Biegler, Simultaneous optimization and solution methods for batch reactor control profiles, Computers and Chemical Engineering, 13:49-62, 1989.