Consider an optimal control problem as follows:
min int(0,1) x(t).u(t)+u(t)**2
x.dt()= x(t)+u(t), x(0)=1
0 <= u(t) <= t**2+(1-t)**3 for 0<=t<=1
My first question is how to define the upper bound of control in Gekko. Also, suppose we want to compare this problem with the case the control is constant during the planning horizon, i.e., u(0)=...=u(t)=...=u(1)
. How can we define it?
In another case, how is it possible to have fixed but unknown control in different sub-intervals? For example, in [0,t1]
, control should be fixed, in [t1,t2]
control should be fixed but can be different from control in [0,t1]
(e.g. t1=0.5, t2=1, Tf=t2=1).
I would be thankful to know if it is possible to study a case where t1, t2, ... are also control and should be determined?
Here is code that gives a solution to the problem:
The solution isn't very interesting because the optimal objective is
u(t)=0
andx(t)=0
. If you add a final condition likex(1)=0.75
then the solution is more interesting.If you want all of the interval to be one value then I recommend that you use a
u=m.FV()
type. Theu=m.MV()
type is adjustable by the optimizer at every interval when you setu.STATUS=1
. You can also reduce degrees of freedom with them.options.MV_STEP_HOR=5
as a global option in Gekko for all MVs or elseu.MV_STEP_HOR=5
to adjust it just for that MV. There is more information on the different Gekko types.You can set the final time by using m.time = [0,...,1] and then scale it with time final
tf
. The derivatives in your problem need to be divided bytf
as well. Here is a related rocket launch problem or the Jennings optimal control problem that minimize the final time. You can also set up multiple time intervals and then connect them withm.Connection()
.