Internal functions
CTDirect.DOCP
— TypeStruct for discretized optimal control problem DOCP
Contains:
- a copy of the original OCP
- data required to link the OCP with the discretized DOCP
CTDirect.Gauss_Legendre_1
— TypeImplicit Midpoint discretization, formulated as a generic IRK (ie Gauss Legendre 1) For testing purpose only, use :midpoint instead (cf midpoint.jl) !
CTDirect.Gauss_Legendre_2
— TypeGauss Legendre 2 discretization, formulated as a generic IRK
CTDirect.Gauss_Legendre_3
— TypeGauss Legendre 3 discretization, formulated as a generic IRK
CTDirect.DOCP_Hessian_pattern
— MethodDOCP_Hessian_pattern(
docp::CTDirect.DOCP{<:CTDirect.GenericIRK}
) -> SparseArrays.SparseMatrixCSC{Bool, Int64}
Build sparsity pattern for Hessian of Lagrangian
CTDirect.DOCP_Hessian_pattern
— MethodDOCP_Hessian_pattern(
docp::CTDirect.DOCP{CTDirect.Midpoint}
) -> SparseArrays.SparseMatrixCSC{Bool, Int64}
Build sparsity pattern for Hessian of Lagrangian
CTDirect.DOCP_Hessian_pattern
— MethodDOCP_Hessian_pattern(
docp::CTDirect.DOCP{CTDirect.Trapeze}
) -> SparseArrays.SparseMatrixCSC{Bool, Int64}
Build sparsity pattern for Hessian of Lagrangian
CTDirect.DOCP_Hessian_pattern
— MethodDOCP_Hessian_pattern(
docp::CTDirect.DOCP{D<:CTDirect.Discretization}
) -> SparseArrays.SparseMatrixCSC{Bool, Int64}
Build sparsity pattern for Hessian of Lagrangian
CTDirect.DOCP_Jacobian_pattern
— MethodDOCP_Jacobian_pattern(
docp::CTDirect.DOCP{<:CTDirect.GenericIRK}
) -> SparseArrays.SparseMatrixCSC{Bool, Int64}
Build sparsity pattern for Jacobian of constraints
CTDirect.DOCP_Jacobian_pattern
— MethodDOCP_Jacobian_pattern(
docp::CTDirect.DOCP{CTDirect.Midpoint}
) -> SparseArrays.SparseMatrixCSC{Bool, Int64}
Build sparsity pattern for Jacobian of constraints
CTDirect.DOCP_Jacobian_pattern
— MethodDOCP_Jacobian_pattern(
docp::CTDirect.DOCP{CTDirect.Trapeze}
) -> SparseArrays.SparseMatrixCSC{Bool, Int64}
Build sparsity pattern for Jacobian of constraints
CTDirect.DOCP_Jacobian_pattern
— MethodDOCP_Jacobian_pattern(
docp::CTDirect.DOCP{D<:CTDirect.Discretization}
) -> SparseArrays.SparseMatrixCSC{Bool, Int64}
Build sparsity pattern for Jacobian of constraints
CTDirect.DOCP_constraints!
— MethodDOCP_constraints!(c, xu, docp::CTDirect.DOCP) -> Any
Compute the constraints C for the DOCP problem (modeled as LB <= C(X) <= UB).
CTDirect.DOCP_initial_guess
— FunctionDOCP_initial_guess(docp::CTDirect.DOCP) -> Vector{Float64}
DOCP_initial_guess(
docp::CTDirect.DOCP,
init::CTModels.Init
) -> Vector{Float64}
Build initial guess for discretized problem
CTDirect.DOCP_objective
— MethodDOCP_objective(xu, docp::CTDirect.DOCP) -> Any
Compute the objective for the DOCP problem.
CTDirect.IRK_dims
— MethodIRK_dims(
dim_NLP_steps,
dim_NLP_x,
dim_NLP_u,
dim_NLP_v,
dim_path_cons,
dim_boundary_cons,
stage
) -> NTuple{5, Any}
Return the dimension of the NLP variables and constraints for a generic IRK discretizion, with the control taken constant per step (ie not distinct controls at time stages)
CTDirect.SolverInfos
— MethodSolverInfos() -> Tuple{Int64, Float64, String, Symbol, Bool}
Retrieve convergence information (Ipopt version)
CTDirect.__adnlp_backend
— Method__adnlp_backend() -> Symbol
Used to set the default backend for AD in ADNLPModels. The default value is :optimized
.
CTDirect.__disc_method
— Method__disc_method() -> Symbol
Used to set the default discretization method. The default value is trapeze
.
CTDirect.__display
— Method__display() -> Bool
Used to set the default display toggle. The default value is true.
CTDirect.__grid_size
— Method__grid_size() -> Int64
Used to set the default grid size. The default value is 250
.
CTDirect.__ipopt_linear_solver
— Method__ipopt_linear_solver() -> String
Used to set the default value of the linear solver of Ipopt for the direct method. The default value is mumps
.
CTDirect.__ipopt_mu_strategy
— Method__ipopt_mu_strategy() -> String
Used to set the default value of the μ strategy of Ipopt for the direct method. The default value is adaptive
.
CTDirect.__ipopt_print_level
— Method__ipopt_print_level() -> Int64
Used to set the default value of the print level of Ipopt for the direct method. The default value is 5
.
CTDirect.__knitro_print_level
— Method__knitro_print_level() -> Int64
Used to set the default value of the print level of Knitro for the direct method. The default value is 3
.
CTDirect.__madnlp_linear_solver
— Method__madnlp_linear_solver() -> String
Used to set the default value of the linear solver of MadNLP for the direct method. The default value is umfpack
.
CTDirect.__max_iterations
— Method__max_iterations() -> Int64
Used to set the default maximum of iterations. The default value is 1000
.
CTDirect.__ocp_init
— Method__ocp_init()
Used to set the default initial guess. The default value is nothing
and will correspond to 0.1 for all variables.
CTDirect.__time_grid
— Method__time_grid()
Used to set the default time grid. The default value is nothing
.
CTDirect.__tolerance
— Method__tolerance() -> Float64
Used to set the default tolerance. The default value is 1e-6
.
CTDirect.add_nonzero_block!
— Methodadd_nonzero_block!(M, i_start, i_end, j_start, j_end; sym)
Add block of nonzeros elements to a sparsity pattern Format: boolean matrix (M) or index vectors (Is, Js) Includes a more compact method for single element case Option to add the symmetric block also (eg for Hessian) Note: independent from discretization scheme
CTDirect.available_methods
— Methodavailable_methods(
) -> Tuple{Tuple{Symbol, Symbol}, Tuple{Symbol, Symbol}, Tuple{Symbol, Symbol}}
Return the list of available methods to solve the optimal control problem.
CTDirect.build_OCP_solution
— Methodbuild_OCP_solution(
docp,
docp_solution
) -> CTModels.Solution{TimeGridModelType, TimesModelType, StateModelType, ControlModelType, VariableModelType, CostateModelType, Float64, CTModels.DualModel{CTModels.var"#69#81"{Matrix{Float64}}, CTModels.var"#70#82"{Matrix{Float64}}, Vector{Float64}, Vector{Float64}, CTModels.var"#71#83"{Matrix{Float64}, Int64}, CTModels.var"#72#84"{Matrix{Float64}, Int64}, CTModels.var"#73#85"{Matrix{Float64}, Int64}, CTModels.var"#74#86"{Matrix{Float64}, Int64}, Vector{Float64}, Vector{Float64}}, CTModels.SolverInfos{Dict{Symbol, Any}}} where {TimeGridModelType<:CTModels.TimeGridModel, TimesModelType<:CTModels.TimesModel, StateModelType<:Union{CTModels.StateModelSolution{TS} where TS<:CTModels.var"#63#75", CTModels.StateModelSolution{TS} where TS<:CTModels.var"#64#76"}, ControlModelType<:Union{CTModels.ControlModelSolution{TS} where TS<:CTModels.var"#65#77", CTModels.ControlModelSolution{TS} where TS<:CTModels.var"#66#78"}, VariableModelType<:Union{CTModels.VariableModelSolution{Vector{Float64}}, CTModels.VariableModelSolution{Float64}}, CostateModelType<:Union{CTModels.var"#67#79", CTModels.var"#68#80"}}
Build OCP functional solution from DOCP discrete solution (given as a SolverCore.GenericExecutionStats)
CTDirect.build_OCP_solution
— Methodbuild_OCP_solution(docp; primal, dual, mult_LB, mult_UB)
Build OCP functional solution from DOCP discrete solution (given as a SolverCore.GenericExecutionStats)
CTDirect.build_bounds
— Methodbuild_bounds(
dim_var,
dim_box,
box_triplet
) -> Tuple{Any, Any}
Build full, ordered sets of bounds for state, control or optimization variables
CTDirect.constraints_bounds!
— Methodconstraints_bounds!(
docp::CTDirect.DOCP
) -> Tuple{Vector{Float64}, Vector{Float64}}
Build upper and lower bounds vectors for the DOCP nonlinear constraints.
CTDirect.direct_transcription
— Methoddirect_transcription(
ocp::CTModels.Model,
description...;
grid_size,
disc_method,
time_grid,
init,
adnlp_backend,
solver_backend,
show_time,
matrix_free
) -> Tuple{CTDirect.DOCP{_A, CTModels.Model{TimesModelType, StateModelType, ControlModelType, VariableModelType, DynamicsModelType, ObjectiveModelType, ConstraintsModelType}} where {_A<:CTDirect.Discretization, TimesModelType<:CTModels.AbstractTimesModel, StateModelType<:CTModels.AbstractStateModel, ControlModelType<:CTModels.AbstractControlModel, VariableModelType<:CTModels.AbstractVariableModel, DynamicsModelType<:Function, ObjectiveModelType<:CTModels.AbstractObjectiveModel, ConstraintsModelType<:CTModels.AbstractConstraintsModel}, ADNLPModels.ADNLPModel{Float64, Vector{Float64}, Vector{Int64}}}
Discretize an optimal control problem into a nonlinear optimization problem (ie direct transcription)
Arguments
- ocp: optimal control problem as defined in
CTModels
- [description]: can specifiy for instance the NLP model and / or solver (:ipopt, :madnlp or :knitro)
Keyword arguments (optional)
grid_size
: number of time steps for the discretized problem ([250])disc_method
: discretization method ([:trapeze
],:euler
,:euler_implicit
,:midpoint
,gauss_legendre_2
,gauss_legendre_3
)time_grid
: explicit time grid (can be non uniform)init
: info for the starting guess (values as named tuple or existing solution)adnlp_backend
: backend for automatic differentiation in ADNLPModels ([:optimized
],:manual
,:default
)- show_time: (:true, [:false]) show timing details from ADNLPModels
CTDirect.get_OCP_control_at_time_step
— Methodget_OCP_control_at_time_step(
xu,
docp::CTDirect.DOCP,
i
) -> Any
Retrieve control variables at given time step from the NLP variables. Convention: 1 <= i <= dimNLPsteps(+1), with convention u(tf) = U_N Vector output
CTDirect.get_OCP_control_at_time_step
— Methodget_OCP_control_at_time_step(
xu,
docp::CTDirect.DOCP{CTDirect.Euler},
i
) -> Any
Retrieve control variables at given time step from the NLP variables. Convention: see above for acplicit / implicit versions Vector output
CTDirect.get_OCP_state_at_time_step
— Methodget_OCP_state_at_time_step(
xu,
docp::CTDirect.DOCP,
i
) -> Any
Retrieve state variables at given time step from the NLP variables. Convention: 1 <= i <= dimNLPsteps+1 Vector output
CTDirect.get_OCP_variable
— Methodget_OCP_variable(xu, docp::CTDirect.DOCP) -> Any
Retrieve optimization variables from the NLP variables. Convention: stored at the end, hence not dependent on the discretization method Vector output
CTDirect.get_lagrange_state_at_time_step
— Methodget_lagrange_state_at_time_step(
xu,
docp::CTDirect.DOCP,
i
) -> Any
Retrieve state variable for lagrange cost at given time step from the NLP variables. Convention: 1 <= i <= dimNLPsteps+1 (no check for actual lagrange cost presence !)
CTDirect.get_stagevars_at_time_step
— Methodget_stagevars_at_time_step(
xu,
docp::CTDirect.DOCP,
i,
j
) -> Any
Retrieve stage variables at given time step/stage from the NLP variables. Convention: 1 <= i <= dimNLPsteps(+1), 1 <= j <= s Vector output Note that passing correct indices is up to the caller, no checks are made here.
CTDirect.get_time_grid
— Methodget_time_grid(xu, docp::CTDirect.DOCP) -> Any
Return time grid for variable time problems (times are then dependent on NLP variables)
CTDirect.is_solvable
— Methodis_solvable(ocp) -> Bool
Check if an OCP is solvable by the method solve
.
CTDirect.parse_DOCP_solution_dual
— Methodparse_DOCP_solution_dual(
docp,
multipliers,
constraints
) -> NTuple{5, Any}
Recover OCP costate and constraints multipliers from DOCP multipliers
CTDirect.parse_DOCP_solution_primal
— Methodparse_DOCP_solution_primal(
docp,
solution;
mult_LB,
mult_UB
) -> Tuple{Any, Any, Any, NTuple{6, Any}}
Recover OCP primal variables from DOCP solution
CTDirect.setPointConstraints!
— MethodsetPointConstraints!(docp::CTDirect.DOCP, c, xu, v) -> Any
Set the boundary and variable constraints
CTDirect.setStepConstraints!
— MethodsetStepConstraints!(
docp::CTDirect.DOCP{<:CTDirect.GenericIRK},
c,
xu,
v,
time_grid,
i,
work
) -> Any
Set the constraints corresponding to the state equation Convention: 1 <= i <= dimNLPsteps (+1)
CTDirect.setStepConstraints!
— MethodsetStepConstraints!(
docp::CTDirect.DOCP{CTDirect.Euler},
c,
xu,
v,
time_grid,
i,
work
) -> Any
Set the constraints corresponding to the state equation Convention: 1 <= i <= dimNLPsteps+1
CTDirect.setStepConstraints!
— MethodsetStepConstraints!(
docp::CTDirect.DOCP{CTDirect.Midpoint},
c,
xu,
v,
time_grid,
i,
work
) -> Any
Set the constraints corresponding to the state equation Convention: 1 <= i <= dimNLPsteps+1
CTDirect.setStepConstraints!
— MethodsetStepConstraints!(
docp::CTDirect.DOCP{CTDirect.Trapeze},
c,
xu,
v,
time_grid,
i,
work
) -> Any
Set the constraints corresponding to the state equation Convention: 1 <= i <= dimNLPsteps+1
CTDirect.setWorkArray
— MethodsetWorkArray(docp::CTDirect.DOCP, xu, time_grid, v) -> Any
Set work array for all dynamics and lagrange cost evaluations
CTDirect.setWorkArray
— MethodsetWorkArray(
docp::CTDirect.DOCP{<:CTDirect.GenericIRK},
xu,
time_grid,
v
) -> Any
Set work array for all dynamics and lagrange cost evaluations
CTDirect.setWorkArray
— MethodsetWorkArray(
docp::CTDirect.DOCP{CTDirect.Euler},
xu,
time_grid,
v
) -> Any
Set work array for all dynamics and lagrange cost evaluations
CTDirect.setWorkArray
— MethodsetWorkArray(
docp::CTDirect.DOCP{CTDirect.Midpoint},
xu,
time_grid,
v
) -> Any
Set work array for all dynamics and lagrange cost evaluations
CTDirect.setWorkArray
— MethodsetWorkArray(
docp::CTDirect.DOCP{CTDirect.Trapeze},
xu,
time_grid,
v
) -> Any
Set work array for all dynamics and lagrange cost evaluations
CTDirect.set_control_at_time_step!
— Methodset_control_at_time_step!(
xu,
u_init,
docp::CTDirect.DOCP,
i
) -> Any
Set initial guess for control variables at given time step Convention: 1 <= i <= dimNLPsteps(+1)
CTDirect.set_initial_guess
— Methodset_initial_guess(docp::CTDirect.DOCP, nlp, init) -> Any
Set initial guess in the DOCP
CTDirect.set_optim_variable!
— Methodset_optim_variable!(xu, v_init, docp) -> Any
Set optimization variables in the NLP variables (for initial guess)
CTDirect.set_state_at_time_step!
— Methodset_state_at_time_step!(
xu,
x_init,
docp::CTDirect.DOCP,
i
) -> Any
Set initial guess for state variables at given time step Convention: 1 <= i <= dimNLPsteps+1
CTDirect.solve
— Methodsolve(
ocp::CTModels.Model,
description::Symbol...;
display,
grid_size,
disc_method,
time_grid,
init,
adnlp_backend,
kwargs...
) -> CTModels.Solution{TimeGridModelType, TimesModelType, StateModelType, ControlModelType, VariableModelType, CostateModelType, Float64, CTModels.DualModel{CTModels.var"#69#81"{Matrix{Float64}}, CTModels.var"#70#82"{Matrix{Float64}}, Vector{Float64}, Vector{Float64}, CTModels.var"#71#83"{Matrix{Float64}, Int64}, CTModels.var"#72#84"{Matrix{Float64}, Int64}, CTModels.var"#73#85"{Matrix{Float64}, Int64}, CTModels.var"#74#86"{Matrix{Float64}, Int64}, Vector{Float64}, Vector{Float64}}, CTModels.SolverInfos{Dict{Symbol, Any}}} where {TimeGridModelType<:CTModels.TimeGridModel, TimesModelType<:CTModels.TimesModel, StateModelType<:Union{CTModels.StateModelSolution{TS} where TS<:CTModels.var"#63#75", CTModels.StateModelSolution{TS} where TS<:CTModels.var"#64#76"}, ControlModelType<:Union{CTModels.ControlModelSolution{TS} where TS<:CTModels.var"#65#77", CTModels.ControlModelSolution{TS} where TS<:CTModels.var"#66#78"}, VariableModelType<:Union{CTModels.VariableModelSolution{Vector{Float64}}, CTModels.VariableModelSolution{Float64}}, CostateModelType<:Union{CTModels.var"#67#79", CTModels.var"#68#80"}}
Solve an OCP with a direct method
Arguments
- ocp: optimal control problem as defined in
CTBase
- [description]: can specifiy for instance the NLP model and / or solver (:ipopt, :madnlp or :knitro)
Keyword arguments (optional)
display
: ([true], false) will disable output if set to falsegrid_size
: number of time steps for the discretized problem ([250])disc_method
: discretization method ([:trapeze
],:midpoint
,gauss_legendre_2
)time_grid
: explicit time grid (can be non uniform)init
: info for the starting guess (values or existing solution)adnlp_backend
: backend for automatic differentiation in ADNLPModels ([:optimized
],:manual
,:default
)
All further keywords are passed to the inner call of solve_docp
CTDirect.variables_bounds!
— Methodvariables_bounds!(
docp::CTDirect.DOCP
) -> Tuple{Vector{Float64}, Vector{Float64}}
Build upper and lower bounds vectors for the DOCP variable box constraints.