Solve
Index
CTDirect.available_methodsCTDirect.build_nlp!CTDirect.direct_transcriptionCTDirect.display_methodCTDirect.parse_descriptionCTDirect.set_initial_guessCTDirect.solveCTDirect.solve_docp
Documentation
CTDirect.available_methods — Methodavailable_methods() -> NTuple{6, Tuple{Symbol, Symbol}}
Return a tuple of available NLP model and solver combinations for solving optimal control problems.
Returns
algorithms::Tuple: A tuple of symbol pairs representing the available methods.
Example
julia> available_methods()
((:adnlp, :ipopt), (:adnlp, :madnlp), (:adnlp, :knitro), (:exa, :ipopt), (:exa, :madnlp), (:exa, :knitro))CTDirect.build_nlp! — Methodbuild_nlp!(
docp::CTDirect.DOCP{<:CTDirect.Discretization, <:CTModels.Model, T<:CTDirect.AbstractNLPModelBackend},
x0;
kwargs...
)
Build the NLP model for a discretized optimal control problem using the specified NLP backend.
Arguments
docp::CTDirect.DOCP: The discretized optimal control problem.nlp_model_backend::T: The NLP model backend (subtype ofAbstractNLPModelBackend).x0: Initial guess for decision variables.
Returns
- Throws
CTBase.ExtensionErrorif the NLP model backend is unavailable.
Example
julia> build_nlp!(docp, ADNLPBackend(), x0)
ERROR: ExtensionError(...)CTDirect.direct_transcription — Methoddirect_transcription(
ocp::CTModels.Model,
description...;
grid_size,
disc_method,
time_grid,
init,
lagrange_to_mayer,
kwargs...
) -> CTDirect.DOCP
Convert a continuous-time optimal control problem into a discretized nonlinear programming problem.
Arguments
ocp::CTModels.Model: Continuous-time optimal control problem.description...: Symbols specifying the NLP model ([:adnlp] or:exa) and/or solver ([:ipopt], :madnlp or :knitro).
Keyword Arguments (optional)
grid_size::Int: Number of discretization steps ([250]).disc_method: Discretization scheme (:trapeze,:euler,:euler_implicit, [:midpoint],gauss_legendre_2,gauss_legendre_3).time_grid: Explicit time grid (can be non uniform).init: Initial guess values or existing solution.lagrange_to_mayer::Bool: Convert Lagrange cost to Mayer cost (trueorfalse).kwargs...: Additional arguments passed to the NLP modeler.
Returns
docp::CTDirect.DOCP: Discretized optimal control problem ready for NLP solving.
Example
julia> docp = direct_transcription(ocp, :adnlp, :ipopt; grid_size=100, disc_method=:trapeze)
CTDirect.DOCP(...)CTDirect.display_method — Methoddisplay_method(
ocp,
description::Symbol...;
grid_size,
disc_method,
time_grid,
kwargs...
)
Display information about the chosen NLP model, solver, discretization scheme, and number of steps.
Arguments
ocp: The continuous-time optimal control problem.description::Symbol...: Symbols specifying the solver and model.grid_size::Int: Number of time steps.disc_method: Discretization scheme.time_grid: Optional explicit time grid.kwargs...: Additional keyword arguments.
Returns
nothing
Example
julia> display_method(ocp, :adnlp, :ipopt; grid_size=100, disc_method=:trapeze)
▫ The optimal control problem is solved with CTDirect version vX.Y.Z.
...CTDirect.parse_description — Methodparse_description(
description,
info
) -> Union{CTDirect.ADNLPBackend, CTDirect.ExaBackend, CTDirect.IpoptBackend, CTDirect.KnitroBackend, CTDirect.MadNLPBackend}
Parse the method description to determine the NLP solver or model.
Arguments
description: A tuple of symbols representing the desired solver and/or model.- NLP solver:
ipopt,madnlporknitro - NLP model:
:adnlpor:exa
- NLP solver:
info::Symbol: Either:solverto return the solver backend or:modelto return the NLP model backend.
Returns
nlp_solver_backendornlp_model_backend: The corresponding backend instance.
Example
julia> parse_description((:adnlp, :ipopt), :solver)
CTDirect.IpoptBackend()
julia> parse_description((:exa, :madnlp), :model)
CTDirect.ExaBackend()CTDirect.set_initial_guess — Methodset_initial_guess(docp::CTDirect.DOCP, init) -> Any
Set the initial guess for the decision variables in a discretized optimal control problem.
Arguments
docp::DOCP: The discretized optimal control problem.init: Initial guess values as a named tuple or existing solution.
Returns
nothing
Example
julia> set_initial_guess(docp, init)CTDirect.solve — Methodsolve(
ocp::CTModels.Model,
description::Symbol...;
display,
grid_size,
disc_method,
time_grid,
init,
lagrange_to_mayer,
adnlp_backend,
exa_backend,
kwargs...
) -> CTModels.Solution{TimeGridModelType, TimesModelType, StateModelType, ControlModelType, VariableModelType, CostateModelType, Float64, DualModelType, CTModels.SolverInfos{Dict{Symbol, Any}}, ModelType} where {TimeGridModelType<:CTModels.TimeGridModel, TimesModelType<:CTModels.TimesModel, StateModelType<:Union{CTModels.StateModelSolution{TS} where TS<:CTModels.var"#84#85", CTModels.StateModelSolution{TS} where TS<:CTModels.var"#86#87"}, ControlModelType<:Union{CTModels.ControlModelSolution{TS} where TS<:CTModels.var"#88#89", CTModels.ControlModelSolution{TS} where TS<:CTModels.var"#90#91"}, VariableModelType<:Union{CTModels.VariableModelSolution{Vector{Float64}}, CTModels.VariableModelSolution{Float64}}, CostateModelType<:Union{CTModels.var"#92#93", CTModels.var"#94#95"}, DualModelType<:(CTModels.DualModel{PC_Dual, Vector{Float64}, SC_LB_Dual, SC_UB_Dual, CC_LB_Dual, CC_UB_Dual, Vector{Float64}, Vector{Float64}} where {PC_Dual<:Union{CTModels.var"#100#101"{CTModels.var"#96#97"}, CTModels.var"#98#99"{CTModels.var"#96#97"}}, SC_LB_Dual<:Union{CTModels.var"#104#105"{CTModels.var"#102#103"}, CTModels.var"#106#107"{CTModels.var"#102#103"}}, SC_UB_Dual<:Union{CTModels.var"#110#111"{CTModels.var"#108#109"}, CTModels.var"#112#113"{CTModels.var"#108#109"}}, CC_LB_Dual<:Union{CTModels.var"#116#117"{CTModels.var"#114#115"}, CTModels.var"#118#119"{CTModels.var"#114#115"}}, CC_UB_Dual<:Union{CTModels.var"#122#123"{CTModels.var"#120#121"}, CTModels.var"#124#125"{CTModels.var"#120#121"}}}), ModelType<:(CTModels.Model{<:CTModels.TimeDependence, T} where T<:CTModels.TimesModel)}
Solve an optimal control problem using a direct transcription method.
Arguments
ocp::CTModels.Model: The continuous-time optimal control problem.description::Symbol...: Symbols specifying the NLP model (:adnlpor:exa) and/or solver (:ipopt,:madnlp,:knitro).
Keyword Arguments (optional)
display::Bool: Display solver output ([true],false).grid_size::Int: Number of discretization steps ([250]).disc_method: Discretization scheme (:trapeze, [:midpoint],:gauss_legendre_2, etc.).time_grid: Explicit time grid, uniform or not.init: Initial guess for states, controls, or variables.adnlp_backend,exa_backend: Backend options for NLP modelers.lagrange_to_mayer: Convert Lagrange cost to Mayer costkwargs...: Additional parameters passed to NLP modelers and solvers.
Returns
solution::CTModels.Solution: The continuous-time solution with objective, state/control trajectories, solver status, and convergence information. Main features:objective(sol): value of the objectivestate(sol),control(sol): functions for state and control variables (trajectory)variable(sol): optimization variables if any (e.g. free final time)successful(sol): boolean indicating successful convergence of the NLP solverstatus(sol): symbol for the return code of the NLP solvermessage(sol): string with specific info from the NLP solver, if anyconstraints_violation(sol): primal feasibility at the solutioniterations(sol): number of iterations
Example
julia> sol = solve(ocp, :adnlp, :ipopt; grid_size=100)
CTModels.Solution(...)CTDirect.solve_docp — Methodsolve_docp(
solver_backend::CTDirect.AbstractNLPSolverBackend,
docp::CTDirect.DOCP;
kwargs...
) -> MadNLP.MadNLPExecutionStats
Solve a discretized optimal control problem using the specified solver backend.
Arguments
solver_backend::T: An NLP solver backend (subtype ofAbstractNLPSolverBackend).docp::CTDirect.DOCP: The discretized optimal control problem.
Returns
- Throws
CTBase.ExtensionErrorif the solver backend is unavailable.
Example
julia> solve_docp(IpoptBackend(), docp)
ERROR: ExtensionError(...)