Minimize Final Time (Jennings)
Main.MinimizeFinalTime History
Hide minor edits - Show changes to markup
- Sabu, A.J., Can GEKKO solve Minimax Optimal Control problems?, 2022, Stack Overflow.
plt.plot(tm,x1.value,'k-',LineWidth=2,label=r'$x_1$') plt.plot(tm,x2.value,'b-',LineWidth=2,label=r'$x_2$') plt.plot(tm,x3.value,'g--',LineWidth=2,label=r'$x_3$') plt.plot(tm,u.value,'r--',LineWidth=2,label=r'$u$')
plt.plot(tm,x1.value,'k-',lw=2,label=r'$x_1$') plt.plot(tm,x2.value,'b-',lw=2,label=r'$x_2$') plt.plot(tm,x3.value,'g--',lw=2,label=r'$x_3$') plt.plot(tm,u.value,'r--',lw=2,label=r'$u$')
A differential equation is time-scaled by adding a final time parameter `t_f` that scales a simulation from time 0 to 1 to a range of 0 to `t_f`. The differential equation simulation time is adjusted by dividing each derivative term by `t_f`. A general expression for a differential equation is `0=(\frac{dx}{dt},x,u)` for simulation time 0.0 to 1.0. The `dt` term is adjusted from the current time derivative to a modified time derivative by adding the final time `t_f` as `t_f \, dt`. The new time scaled differential equation is
$$0=\left(\frac{\frac{dx}{dt}}{t_f},x,u\right)$$
A differential equation is time-scaled by adding a final time parameter `t_f` that scales a simulation from time 0 to 1 to a range of 0 to `t_f`. The differential equation simulation time is adjusted by dividing each derivative term by `t_f`. A general expression for a differential equation is `0=f(\frac{dx}{dt},x,u)` for simulation time 0.0 to 1.0. The `dt` term is adjusted from the current time derivative to a modified time derivative by adding the final time `t_f` as `t_f dt`. The new time scaled differential equation is
$$0=f\left(\frac{\frac{dx}{dt}}{t_f},x,u\right)$$
A differential equation is time-scaled by adding a final time parameter `t_f` that scales a simulation from time 0 to 1 to a range of 0 to `t_f`. The differential equation simulation time is adjusted by dividing each derivative term by `t_f`. A general expression for a differential equation is `0=(\frac{dx}{dt},x,u)` for simulation time 0.0 to 1.0. The `dt` term is adjusted from the current time derivative to a modified time derivative by adding the final time `t_f` as `t_f \, dt`. The new time scaled differential equation is
$$0=\left(\frac{\frac{dx}{dt}}{t_f},x,u\right)$$
In semi-explicit form `\dot x=f(x,u)`, this equation is time scaled
$$\frac{\frac{dx}{dt}}{t_f}=f(x,u)$$
and rearranged to the final form as applied to the Jennings optimal control problem `\frac{dx}{dt}=t_f f(x,u)`.
The Jennings optimal control problem minimizes the final time subject to differential constraints. Minimizing final time is found in many areas such as manufacturing, transportation, and energy systems. In each case, it is the desired end-state that must be met while the optimizer seeks to arrive at those conditions in the shortest time.
$$\min_{u(t)} \; t_f$$ $$\mathrm{subject \; to}$$ $$\frac{dx_1}{dt}=u$$ $$\frac{dx_2}{dt}=\cos\left(x_1(t)\right)$$ $$\frac{dx_3}{dt}=\sin\left(x_1(t)\right)$$ $$x(0) = \left[\pi/2,4,0\right]$$ $$x_2\left(t_f\right)=0$$ $$x_3\left(t_f\right)=0$$ $$-2 \le u(t) \le 2$$
The Jennings problem is solved by specifying a time horizon from 0.0 to 1.0 with the additional `t_f` parameter that scales the final time. The conditions `x_2(t_f)=0` and `x_3(t_f)=0` are binding at the end and limit the system from having a lower final time.
$$\min_{u(t), t_f} \; t_f$$ $$\mathrm{subject \; to}$$ $$\frac{dx_1}{dt}=t_f \, u$$ $$\frac{dx_2}{dt}=t_f \, \cos\left(x_1(t)\right)$$ $$\frac{dx_3}{dt}=t_f \, \sin\left(x_1(t)\right)$$ $$x(0) = \left[\pi/2,4,0\right]$$ $$x_2\left(t_f\right)=0$$ $$x_3\left(t_f\right)=0$$ $$-2 \le u(t) \le 2$$
The parameter `t_f` is declared as a Feedforward Variable/Fixed Value so that it has only one value over the time horizon. The adjustable value `u` is declared as a Manipulated Variable that is adjustable at all time points in the time horizon.
Solutions
(:html:) <iframe width="560" height="315" src="https://www.youtube.com/embed/yuj217itTa8" frameborder="0" allowfullscreen></iframe> (:htmlend:)
A differential equation is time-scaled by adding a final time parameter `t_f` that scales a simulation from time 0 to 1 to a range of 0 to `t_f`. The differential equation simulation time is adjusted by dividing each derivative term by `t_f`. A general expression for a differential equation is `0=(\frac{dx}{dt},x,u)` for simulation time 0.0 to 1.0. The `dt` term is adjusted from the current time derivative to a modified time derivative by adding the final time `t_f` as `t_f \, dt`. The new time scaled differential equation is
$$0=\left(\frac{\frac{dx}{dt}}{t_f},x,u\right)$$
In semi-explicit form `\dot x=f(x,u)`, this equation is time scaled
$$\frac{\frac{dx}{dt}}{t_f}=f(x,u)$$
and rearranged to the final form as applied to the Jennings optimal control problem `\frac{dx}{dt}=t_f f(x,u)`.
The Jennings optimal control problem minimizes the final time subject to differential constraints. Minimizing final time is found in many areas such as manufacturing, transportation, and energy systems. In each case, it is the desired end-state that must be met while the optimizer seeks to arrive at those conditions in the shortest time.
$$\min_{u(t)} \; t_f$$ $$\mathrm{subject \; to}$$ $$\frac{dx_1}{dt}=u$$ $$\frac{dx_2}{dt}=\cos\left(x_1(t)\right)$$ $$\frac{dx_3}{dt}=\sin\left(x_1(t)\right)$$ $$x(0) = \left[\pi/2,4,0\right]$$ $$x_2\left(t_f\right)=0$$ $$x_3\left(t_f\right)=0$$ $$-2 \le u(t) \le 2$$
The Jennings problem is solved by specifying a time horizon from 0.0 to 1.0 with the additional `t_f` parameter that scales the final time. The conditions `x_2(t_f)=0` and `x_3(t_f)=0` are binding at the end and limit the system from having a lower final time.
$$\min_{u(t), t_f} \; t_f$$ $$\mathrm{subject \; to}$$ $$\frac{dx_1}{dt}=t_f \, u$$ $$\frac{dx_2}{dt}=t_f \, \cos\left(x_1(t)\right)$$ $$\frac{dx_3}{dt}=t_f \, \sin\left(x_1(t)\right)$$ $$x(0) = \left[\pi/2,4,0\right]$$ $$x_2\left(t_f\right)=0$$ $$x_3\left(t_f\right)=0$$ $$-2 \le u(t) \le 2$$
The parameter `t_f` is declared as a Feedforward Variable/Fixed Value so that it has only one value over the time horizon. The adjustable value `u` is declared as a Manipulated Variable that is adjustable at all time points in the time horizon.
Solutions
(:html:) <iframe width="560" height="315" src="https://www.youtube.com/embed/yuj217itTa8" frameborder="0" allowfullscreen></iframe> (:htmlend:)
(:html:) <iframe width="560" height="315" src="https://www.youtube.com/embed/cfDoe3mRWmQ" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe> (:htmlend:)
$$\frac{dx_3}{dt}=\sin\left(x_2(t)\right)$$
$$\frac{dx_3}{dt}=\sin\left(x_1(t)\right)$$
$$\frac{dx_3}{dt}=t_f \, \sin\left(x_2(t)\right)$$
$$\frac{dx_3}{dt}=t_f \, \sin\left(x_1(t)\right)$$
m.Equation(x3.dt()==m.sin(x2)*tf)
m.Equation(x3.dt()==m.sin(x1)*tf)
m.time = np.linspace(0,1,nt)
tm = np.linspace(0,1,nt) m.time = tm
m.Equation(x3.dt()==m.sin(x1)*tf)
m.Equation(x3.dt()==m.sin(x2)*tf)
tm = tm * tf.value[0]
plt.plot(m.time,x1.value,'k-',LineWidth=2,label=r'$x_1$') plt.plot(m.time,x2.value,'b-',LineWidth=2,label=r'$x_2$') plt.plot(m.time,x3.value,'g--',LineWidth=2,label=r'$x_3$') plt.plot(m.time,u.value,'r--',LineWidth=2,label=r'$u$')
plt.plot(tm,x1.value,'k-',LineWidth=2,label=r'$x_1$') plt.plot(tm,x2.value,'b-',LineWidth=2,label=r'$x_2$') plt.plot(tm,x3.value,'g--',LineWidth=2,label=r'$x_3$') plt.plot(tm,u.value,'r--',LineWidth=2,label=r'$u$')
A differential equation is time-scaled by adding a final time parameter `t_f` that scales a simulation from time 0 to 1 to a range of 0 to `t_f`. The differential equation simulation time is adjusted by dividing each derivative term by `t_f`. A general expression for a differential equation is `0=(\frac{dx}{dt},x,u)` for simulation time 0.0 to 1.0. The `dt` term is adjusted from the current time derivative to a modified time derivative by adding the final time `t_f` as `t_f \, dt`. The new time scaled differential equation is then `0=(\frac{\frac{dx}{dt}}{t_f},x,u)`. In semi-explicit form `\dot x=f(x,u)`, this equation is time scale `\frac{\frac{dx}{dt}}{t_f}=f(x,u)` and rearranged to the final form as applied to the Jennings optimal control problem `\frac{dx}{dt}=t_f f(x,u)`.
The Jennings optimal control problem is to minimize the final time subject to differential constraints. Minimizing final time is found in many areas such as manufacturing, transportation, and energy systems. In each case, it is the desired end-state that must be met while the optimizer seeks to arrive at those conditions in the shortest time.
A differential equation is time-scaled by adding a final time parameter `t_f` that scales a simulation from time 0 to 1 to a range of 0 to `t_f`. The differential equation simulation time is adjusted by dividing each derivative term by `t_f`. A general expression for a differential equation is `0=(\frac{dx}{dt},x,u)` for simulation time 0.0 to 1.0. The `dt` term is adjusted from the current time derivative to a modified time derivative by adding the final time `t_f` as `t_f \, dt`. The new time scaled differential equation is
$$0=\left(\frac{\frac{dx}{dt}}{t_f},x,u\right)$$
In semi-explicit form `\dot x=f(x,u)`, this equation is time scaled
$$\frac{\frac{dx}{dt}}{t_f}=f(x,u)$$
and rearranged to the final form as applied to the Jennings optimal control problem `\frac{dx}{dt}=t_f f(x,u)`.
The Jennings optimal control problem minimizes the final time subject to differential constraints. Minimizing final time is found in many areas such as manufacturing, transportation, and energy systems. In each case, it is the desired end-state that must be met while the optimizer seeks to arrive at those conditions in the shortest time.
A differential equation is time-scaled by adding a final time parameter `t_f` that scales a simulation from time 0 to 1 to a range of 0 to `t_f`. The differential equation simulation time is adjusted by dividing each derivative term by `t_f`. A general expression for a differential equation is `0=\left(\frac{dx}{dt},x,u\right)` for simulation time 0.0 to 1.0. The `dt` term is adjusted from the current time derivative to a modified time derivative by adding the final time `t_f` as `t_f \, dt`. The new time scaled differential equation is then `0=\left(\frac{\frac{dx}{dt}}{t_f},x,u\right)`. In semi-explicit form `\dot x=f(x,u)`, this equation is time scale `\frac{\frac{dx}{dt}}{t_f}=f(x,u)` and rearranged to the final form as applied to the Jennings optimal control problem `\frac{dx}{dt}=t_f f(x,u)`.
A differential equation is time-scaled by adding a final time parameter `t_f` that scales a simulation from time 0 to 1 to a range of 0 to `t_f`. The differential equation simulation time is adjusted by dividing each derivative term by `t_f`. A general expression for a differential equation is `0=(\frac{dx}{dt},x,u)` for simulation time 0.0 to 1.0. The `dt` term is adjusted from the current time derivative to a modified time derivative by adding the final time `t_f` as `t_f \, dt`. The new time scaled differential equation is then `0=(\frac{\frac{dx}{dt}}{t_f},x,u)`. In semi-explicit form `\dot x=f(x,u)`, this equation is time scale `\frac{\frac{dx}{dt}}{t_f}=f(x,u)` and rearranged to the final form as applied to the Jennings optimal control problem `\frac{dx}{dt}=t_f f(x,u)`.
The Jennings problem is solved by specifying a time horizon from 0.0 to 1.0 with the additional `t_f` parameter that scales the final time. The conditions `x_2\left(t_f\right)=0` and `x_3\left(t_f\right)=0` are binding at the end and limit the system from having a lower final time.
The Jennings problem is solved by specifying a time horizon from 0.0 to 1.0 with the additional `t_f` parameter that scales the final time. The conditions `x_2(t_f)=0` and `x_3(t_f)=0` are binding at the end and limit the system from having a lower final time.
A differential equation is time-scaled by adding a final time parameter `t_f` that scales a simulation from time 0 to 1 to a range of 0 to `t_f`. The differential equation simulation time is adjusted by dividing each derivative term by `t_f`. A general expression for a differential equation is $$0=\left(\frac{dx}{dt},x,u\right)$$ for simulation time 0.0 to 1.0. The `dt` term is adjusted from the current time derivative to a modified time derivative by adding the final time `t_f` as `t_f \, dt`. The new time scaled differential equation is then $$0=\left(\frac{\frac{dx}{dt}}{t_f},x,u\right)$$. In semi-explicit form `\dot x=f(x,u)`, this equation is time scale `\frac{\frac{dx}{dt}}{t_f}=f(x,u)` and rearranged to the final form as applied to the Jennings optimal control problem `\frac{dx}{dt}=t_f f(x,u)`.
A differential equation is time-scaled by adding a final time parameter `t_f` that scales a simulation from time 0 to 1 to a range of 0 to `t_f`. The differential equation simulation time is adjusted by dividing each derivative term by `t_f`. A general expression for a differential equation is `0=\left(\frac{dx}{dt},x,u\right)` for simulation time 0.0 to 1.0. The `dt` term is adjusted from the current time derivative to a modified time derivative by adding the final time `t_f` as `t_f \, dt`. The new time scaled differential equation is then `0=\left(\frac{\frac{dx}{dt}}{t_f},x,u\right)`. In semi-explicit form `\dot x=f(x,u)`, this equation is time scale `\frac{\frac{dx}{dt}}{t_f}=f(x,u)` and rearranged to the final form as applied to the Jennings optimal control problem `\frac{dx}{dt}=t_f f(x,u)`.
The Jennings problem is solved by specifying a time horizon from 0.0 to 1.0 with the additional `t_f` parameter as follows:
The Jennings problem is solved by specifying a time horizon from 0.0 to 1.0 with the additional `t_f` parameter that scales the final time. The conditions `x_2\left(t_f\right)=0` and `x_3\left(t_f\right)=0` are binding at the end and limit the system from having a lower final time.
The parameter `t_f` is declared as a Feedforward Variable or Fixed Value while the adjustable value `u` is declared as a Manipulated Variable.
The parameter `t_f` is declared as a Feedforward Variable/Fixed Value so that it has only one value over the time horizon. The adjustable value `u` is declared as a Manipulated Variable that is adjustable at all time points in the time horizon.
A differential equation is time-scaled by adding a final time parameter `t_f` that scales a simulation from time 0 to 1 to a range of 0 to `t_f`. The differential equation simulation time is adjusted by dividing each derivative term by `t_f`. A general expression for a differential equation is:
$$0=\left(\frac{dx}{dt},x,u\right)$$
for simulation time 0 to 1. The `dt` term is adjusted from the current time derivative to a modified time derivative by adding the final time `t_f` as `t_f \, dt`. The new time scaled differential equation is then:
$$0=\left(\frac{\frac{dx}{dt}}{t_f},x,u\right)$$
In semi-explicit form `\frac{\frac{dx}{dt}}{t_f}=f(x,u)`, this equation can be rearranged to `\frac{dx}{dt}=t_f f(x,u)`.
A differential equation is time-scaled by adding a final time parameter `t_f` that scales a simulation from time 0 to 1 to a range of 0 to `t_f`. The differential equation simulation time is adjusted by dividing each derivative term by `t_f`. A general expression for a differential equation is $$0=\left(\frac{dx}{dt},x,u\right)$$ for simulation time 0.0 to 1.0. The `dt` term is adjusted from the current time derivative to a modified time derivative by adding the final time `t_f` as `t_f \, dt`. The new time scaled differential equation is then $$0=\left(\frac{\frac{dx}{dt}}{t_f},x,u\right)$$. In semi-explicit form `\dot x=f(x,u)`, this equation is time scale `\frac{\frac{dx}{dt}}{t_f}=f(x,u)` and rearranged to the final form as applied to the Jennings optimal control problem `\frac{dx}{dt}=t_f f(x,u)`.
Objective: Set up and solve the Jennings optimal control benchmark problem. Create a program to optimize and display the results. Estimated Time: 30 minutes
Objective: Solve an optimal control problem with a minimal final time. Set up and solve the Jennings optimal control benchmark problem. Create a program to optimize and display the results. Estimated Time: 30 minutes
A differential equation is time-scaled by adding a final time parameter `t_f` that scales a simulation from time 0 to 1 to a range of 0 to `t_f`. The differential equation simulation time is adjusted by dividing each derivative term by `t_f`. A general expression for a differential equation is:
$$0=\left(\frac{dx}{dt},x,u\right)$$
for simulation time 0 to 1. The `dt` term is adjusted from the current time derivative to a modified time derivative by adding the final time `t_f` as `t_f \, dt`. The new time scaled differential equation is then:
$$0=\left(\frac{\frac{dx}{dt}}{t_f},x,u\right)$$
In semi-explicit form `\frac{\frac{dx}{dt}}{t_f}=f(x,u)`, this equation can be rearranged to `\frac{dx}{dt}=t_f f(x,u)`.
A differential equation is time-scaled by adding a final time parameter `t_f` that scales a simulation from time 0 to 1 to a range of 0 to `t_f`. The differential equation simulation time is adjusted by dividing each derivative term by `t_f`. A general expression for a differential equation is:
$$0=\right(\frac{dx}{dt},x,u\right)$$
for simulation time 0 to 1. The `dt` term is adjusted from the current time derivative to a modified time derivative by adding the final time `t_f` as `t_f \, dt`. The new time scaled differential equation is then:
$$0=\right(\frac{\frac{dx}{dt}}{t_f},x,u\right)$$
In semi-explicit form `\frac{\frac{dx}{dt}}{t_f}=f(x,u)`, this equation can be rearranged to `\frac{dx}{dt}=t_f \, f(x,u)`. The Jennings problem is solved by specifying a time horizon from 0.0 to 1.0 with the additional {`t_f} parameter as follows:
The Jennings problem is solved by specifying a time horizon from 0.0 to 1.0 with the additional `t_f` parameter as follows:
(:title Minimize Final Time (Jennings):) (:keywords nonlinear control, Jennings, optimal control, dynamic optimization, engineering optimization, MATLAB, Python, GEKKO, optimization suite:) (:description Jennings optimal control problem solved with MATLAB, Python, and GEKKO. The objective is to minimize the final time subject to differential constraints, initial conditions, and select final conditions.:)
Objective: Set up and solve the Jennings optimal control benchmark problem. Create a program to optimize and display the results. Estimated Time: 30 minutes
The Jennings optimal control problem is to minimize the final time subject to differential constraints. Minimizing final time is found in many areas such as manufacturing, transportation, and energy systems. In each case, it is the desired end-state that must be met while the optimizer seeks to arrive at those conditions in the shortest time.
$$\min_{u(t)} \; t_f$$ $$\mathrm{subject \; to}$$ $$\frac{dx_1}{dt}=u$$ $$\frac{dx_2}{dt}=\cos\left(x_1(t)\right)$$ $$\frac{dx_3}{dt}=\sin\left(x_2(t)\right)$$ $$x(0) = \left[\pi/2,4,0\right]$$ $$x_2\left(t_f\right)=0$$ $$x_3\left(t_f\right)=0$$ $$-2 \le u(t) \le 2$$
A differential equation is time-scaled by adding a final time parameter `t_f` that scales a simulation from time 0 to 1 to a range of 0 to `t_f`. The differential equation simulation time is adjusted by dividing each derivative term by `t_f`. A general expression for a differential equation is:
$$0=\right(\frac{dx}{dt},x,u\right)$$
for simulation time 0 to 1. The `dt` term is adjusted from the current time derivative to a modified time derivative by adding the final time `t_f` as `t_f \, dt`. The new time scaled differential equation is then:
$$0=\right(\frac{\frac{dx}{dt}}{t_f},x,u\right)$$
In semi-explicit form `\frac{\frac{dx}{dt}}{t_f}=f(x,u)`, this equation can be rearranged to `\frac{dx}{dt}=t_f \, f(x,u)`. The Jennings problem is solved by specifying a time horizon from 0.0 to 1.0 with the additional {`t_f} parameter as follows:
$$\min_{u(t), t_f} \; t_f$$ $$\mathrm{subject \; to}$$ $$\frac{dx_1}{dt}=t_f \, u$$ $$\frac{dx_2}{dt}=t_f \, \cos\left(x_1(t)\right)$$ $$\frac{dx_3}{dt}=t_f \, \sin\left(x_2(t)\right)$$ $$x(0) = \left[\pi/2,4,0\right]$$ $$x_2\left(t_f\right)=0$$ $$x_3\left(t_f\right)=0$$ $$-2 \le u(t) \le 2$$
The parameter `t_f` is declared as a Feedforward Variable or Fixed Value while the adjustable value `u` is declared as a Manipulated Variable.
Solutions
(:html:) <iframe width="560" height="315" src="https://www.youtube.com/embed/yuj217itTa8" frameborder="0" allowfullscreen></iframe> (:htmlend:)
(:toggle hide gekko button show="GEKKO (Python) Solution":) (:div id=gekko:) (:source lang=python:) import numpy as np from gekko import GEKKO import matplotlib.pyplot as plt
m = GEKKO()
nt = 501 m.time = np.linspace(0,1,nt)
- Variables
x1 = m.Var(value=np.pi/2.0) x2 = m.Var(value=4.0) x3 = m.Var(value=0.0)
p = np.zeros(nt) p[-1] = 1.0 final = m.Param(value=p)
- FV
tf = m.FV(value=1.0,lb=0.1,ub=100.0) tf.STATUS = 1
- MV
u = m.MV(value=0,lb=-2,ub=2) u.STATUS = 1
m.Equation(x1.dt()==u*tf) m.Equation(x2.dt()==m.cos(x1)*tf) m.Equation(x3.dt()==m.sin(x1)*tf)
m.Equation(x2*final<=0) m.Equation(x3*final<=0)
m.Obj(tf)
m.options.IMODE = 6
m.solve()
print('Final Time: ' + str(tf.value[0]))
plt.figure(1) plt.plot(m.time,x1.value,'k-',LineWidth=2,label=r'$x_1$') plt.plot(m.time,x2.value,'b-',LineWidth=2,label=r'$x_2$') plt.plot(m.time,x3.value,'g--',LineWidth=2,label=r'$x_3$') plt.plot(m.time,u.value,'r--',LineWidth=2,label=r'$u$') plt.legend(loc='best') plt.xlabel('Time') plt.ylabel('Value') plt.show() (:sourceend:) (:divend:)
References
- Beal, L., GEKKO for Dynamic Optimization, 2018, URL: https://gekko.readthedocs.io/en/latest/
- Hedengren, J. D. and Asgharzadeh Shishavan, R., Powell, K.M., and Edgar, T.F., Nonlinear Modeling, Estimation and Predictive Control in APMonitor, Computers and Chemical Engineering, Volume 70, pg. 133–148, 2014. Article