Solve with JuMP
A JuMP problem is a JuMP.Model, already discretized: the scheme, the grid and the order of the variables are chosen when the problem is built. The model reproduces the NLP that OptimalControl builds for the same scheme; see JuMP schemes.
julia
using JuMP, Ipopt, OptimalControlProblemsBuild and solve
julia
nlp = beam(JuMPBackend(); grid_size=grid_size_data(:beam, JuMPBackend()), scheme=:trapeze)
set_optimizer(nlp, Ipopt.Optimizer)
set_silent(nlp)
optimize!(nlp)
termination_status(nlp), objective_value(nlp)The keywords
| Keyword | Values | Default |
|---|---|---|
grid_size | number of steps | the default grid of the problem |
scheme | :euler, :euler_implicit, :trapeze, :midpoint, as in OptimalControl.Collocation | :trapeze |
ordering | :interleaved (as CTDirect) or :blocks (grouped by kind) | :interleaved |
parameters | the parameters to change | the default parameters |
init | another initial guess (see Initial guess) | the shared one |
Other arguments are passed to JuMP.Model.
Read the solution
The JuMP models store the names of the components and the time grid, so the solution reads as an OptimalControl one:
julia
x = state(nlp) # a function of the time
u = control(nlp)
t = time_grid(nlp)
x(t[end]), u(t[1])([-7.130607050246146e-39, -1.0], -6.644794477620481)With OptimalControl loaded, solution builds a full OptimalControl solution from the solved model and the Problem of the same problem, to display or plot it:
julia
using OptimalControl
pb = beam(OptimalControlBackend())
sol = solution(nlp, pb)
objective(sol), iterations(sol)(8.889282231873594, 22)