-
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hi @azev77, I moved this over to the discussion forum since this is a usage question. Yes, you can readily incorporate a terminal value using point variables. For instance: using InfiniteOpt
model = InfiniteModel()
@infinite_parameter(model, t in [0, 1])
@variable(model, x, Infinite(t))
# Set objective where f(x(t)) = x(t)^2 and s(x(T)) = 2x(T)
@objective(model, Min, ∫(x^2, t) + 2 * x(1)) |
Beta Was this translation helpful? Give feedback.
-
I just tried it and it works! I think it would help users a lot if a generic form of the optimal control problem was written down somewhere in the Readme or Docs & corresponding code was provided to show how to implement. t0=0.0; tf=1.0;
u(s,c,t) = -s;
S(s,t) = 0.0; # s(s(T),T)
LOM1(s,c,t) = c; # ṡ=LOM(s,c)
g1(s,c,t) = c +1; # c +1>=0 or c>= -1
g2(s,c,t) = -c +1; # -c +1>=0
s_0=1.0;
#s_T
opt = Ipopt.Optimizer # desired solver
ns = 1_000; # number of points in the time grid
m = InfiniteModel(opt)
@infinite_parameter(m, t ∈ [t0, tf], num_supports = ns)
@variable(m, s, Infinite(t)) ## state variables
@variable(m, c, Infinite(t)) ## control variables
@objective(m, Max, integral(u(s,c,t), t) + S(s(tf),tf)) #, weight_func = discount
@constraint(m, LOM_1, deriv(s, t) == LOM1(s,c,t))
@constraint(m, CON_1, g1(s,c,t) >= 0.0) #@constraint(m, CON_1, 1.0 >= c >= -1.0)
@constraint(m, CON_2, g2(s,c,t) >= 0.0)
@constraint(m, s(0) == s_0) ## initial condition
optimize!(m)
termination_status(m)
c_opt = value(c)
s_opt = value(s)
ts = supports(t)
opt_obj = objective_value(m) # V(B0, 0)
# using Plots
ix = 2:(length(ts)-1) # index for plotting
plot()
plot!(ts[ix], s_opt[ix], c=1, lab = "s")
plot!(ts[ix], tt -> 1-tt, c=1, l=:dash, lw=3, lab = "s: closed form")
plot!(ts[ix], c_opt[ix], c=2, lab = "c")
plot!(ts[ix], tt -> -1, c=2, l=:dash, lw=3, lab = "c: closed form")
plot!([0.0], seriestype = :hline, lab="", color="grey") And make it very clear that this is for generic Optimal Control problems where the terminal time is fixed (not free)... |
Beta Was this translation helpful? Give feedback.
Hi @azev77, I moved this over to the discussion forum since this is a usage question.
Yes, you can readily incorporate a terminal value using point variables. For instance: