Solve

Index

Documentation

CTDirect.available_methodsMethod
available_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))
source
CTDirect.build_nlp!Method
build_nlp!(
    docp::CTDirect.DOCP,
    nlp_model::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::T: The NLP model backend (subtype of AbstractNLPModelBackend).
  • x0: Initial guess for decision variables.

Returns

  • Throws CTBase.ExtensionError if the NLP model backend is unavailable.

Example

julia> build_nlp!(docp, ADNLPBackend(), x0)
ERROR: ExtensionError(...)
source
CTDirect.direct_transcriptionMethod
direct_transcription(
    ocp::CTModels.Model,
    description...;
    grid_size,
    disc_method,
    time_grid,
    init,
    lagrange_to_mayer,
    kwargs...
) -> Union{CTDirect.DOCP{_A, CTModels.Model{TD, TimesModelType, StateModelType, ControlModelType, VariableModelType, DynamicsModelType, ObjectiveModelType, ConstraintsModelType, BuildExaModelType}, CTDirect.ADNLPBackend} where {_A<:CTDirect.Discretization, TD<:CTModels.TimeDependence, TimesModelType<:CTModels.AbstractTimesModel, StateModelType<:CTModels.AbstractStateModel, ControlModelType<:CTModels.AbstractControlModel, VariableModelType<:CTModels.AbstractVariableModel, DynamicsModelType<:Function, ObjectiveModelType<:CTModels.AbstractObjectiveModel, ConstraintsModelType<:CTModels.AbstractConstraintsModel, BuildExaModelType<:Union{Nothing, Function}}, CTDirect.DOCP{_A, CTModels.Model{TD, TimesModelType, StateModelType, ControlModelType, VariableModelType, DynamicsModelType, ObjectiveModelType, ConstraintsModelType, BuildExaModelType}, CTDirect.ExaBackend} where {_A<:CTDirect.Discretization, TD<:CTModels.TimeDependence, TimesModelType<:CTModels.AbstractTimesModel, StateModelType<:CTModels.AbstractStateModel, ControlModelType<:CTModels.AbstractControlModel, VariableModelType<:CTModels.AbstractVariableModel, DynamicsModelType<:Function, ObjectiveModelType<:CTModels.AbstractObjectiveModel, ConstraintsModelType<:CTModels.AbstractConstraintsModel, BuildExaModelType<:Union{Nothing, Function}}}

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 (true or false).
  • 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(...)
source
CTDirect.display_methodMethod
display_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.
...
source
CTDirect.parse_descriptionMethod
parse_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, madnlp or knitro
    • NLP model: :adnlp or :exa
  • info::Symbol: Either :solver to return the solver backend or :model to return the NLP model backend.

Returns

  • nlp_solver or nlp_model: The corresponding backend instance.

Example

julia> parse_description((:adnlp, :ipopt), :solver)
CTDirect.IpoptBackend()

julia> parse_description((:exa, :madnlp), :model)
CTDirect.ExaBackend()
source
CTDirect.set_initial_guessMethod
set_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)
source
CTDirect.solveMethod
solve(
    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"#98#120", CTModels.StateModelSolution{TS} where TS<:CTModels.var"#99#121"}, ControlModelType<:Union{CTModels.ControlModelSolution{TS} where TS<:CTModels.var"#100#122", CTModels.ControlModelSolution{TS} where TS<:CTModels.var"#101#123"}, VariableModelType<:Union{CTModels.VariableModelSolution{Vector{Float64}}, CTModels.VariableModelSolution{Float64}}, CostateModelType<:Union{CTModels.var"#102#124", CTModels.var"#103#125"}, 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"#105#127"{CTModels.var"#104#126"}, CTModels.var"#106#128"{CTModels.var"#104#126"}}, SC_LB_Dual<:Union{CTModels.var"#108#130"{CTModels.var"#107#129"}, CTModels.var"#109#131"{CTModels.var"#107#129"}}, SC_UB_Dual<:Union{CTModels.var"#111#133"{CTModels.var"#110#132"}, CTModels.var"#112#134"{CTModels.var"#110#132"}}, CC_LB_Dual<:Union{CTModels.var"#114#136"{CTModels.var"#113#135"}, CTModels.var"#115#137"{CTModels.var"#113#135"}}, CC_UB_Dual<:Union{CTModels.var"#117#139"{CTModels.var"#116#138"}, CTModels.var"#118#140"{CTModels.var"#116#138"}}}), ModelType<:CTModels.Model}

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 (:adnlp or :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 cost
  • kwargs...: 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 objective
    • state(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 solver
    • status(sol): symbol for the return code of the NLP solver
    • message(sol): string with specific info from the NLP solver, if any
    • constraints_violation(sol): primal feasibility at the solution
    • iterations(sol): number of iterations

Example

julia> sol = solve(ocp, :adnlp, :ipopt; grid_size=100)
CTModels.Solution(...)
source
CTDirect.solve_docpMethod
solve_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 of AbstractNLPSolverBackend).
  • docp::CTDirect.DOCP: The discretized optimal control problem.

Returns

  • Throws CTBase.ExtensionError if the solver backend is unavailable.

Example

julia> solve_docp(IpoptBackend(), docp)
ERROR: ExtensionError(...)
source