DOCP
Index
CTDirect.DOCPCTDirect.DOCPFlagsCTDirect.DOCPFlagsCTDirect.DOCPboundsCTDirect.DOCPdimsCTDirect.DOCPdimsCTDirect.DOCPtimeCTDirect.DOCPtimeCTDirect.DiscretizationCTDirect.DOCP_constraints!CTDirect.DOCP_initial_guessCTDirect.DOCP_objectiveCTDirect.build_boundsCTDirect.constraints_bounds!CTDirect.disc_modelCTDirect.get_time_gridCTDirect.get_time_grid_exaCTDirect.is_solvableCTDirect.nlp_modelCTDirect.ocp_modelCTDirect.setPointConstraints!CTDirect.variables_bounds!
Documentation
CTDirect.DOCP — Typemutable struct DOCP{D<:CTDirect.Discretization, O<:CTModels.Model, N<:CTDirect.AbstractNLPModelBackend}Struct representing a discretized optimal control problem (DOCP).
Fields
discretization::D: The discretization scheme.ocp::O: The original OCP model.nlp_model::N: The NLP model backend.nlp: The constructed NLP instance.exa_getter::Union{Nothing,Function}: Getter for ExaModels if used.flags::DOCPFlags: Boolean flags describing problem structure.dims::DOCPdims: Problem dimensions.time::DOCPtime: Time discretization.bounds::DOCPbounds: Variable and constraint bounds.dim_NLP_variables::Int: Number of NLP variables.dim_NLP_constraints::Int: Number of NLP constraints.
Example
julia> DOCP(ocp, nlp_model)
DOCP{...}(...)CTDirect.DOCPFlags — Typestruct DOCPFlagsInternal struct holding boolean flags that characterize properties of the discretized optimal control problem (DOCP).
Fields
freet0::Bool: Whether the OCP has a free initial time.freetf::Bool: Whether the OCP has a free final time.lagrange::Bool: Whether the OCP includes a Lagrange cost.mayer::Bool: Whether the OCP includes a Mayer cost.lagrange_to_mayer::Bool: Whether the Lagrange cost is reformulated as a Mayer term.max::Bool: Whether the OCP is a maximization problem.
Example
julia> DOCPFlags(true, false, true, true, false, false)
DOCPFlags(true, false, true, true, false, false)CTDirect.DOCPFlags — MethodDOCPFlags(
ocp::CTModels.Model,
lagrange_to_mayer::Bool
) -> CTDirect.DOCPFlags
Construct a DOCPFlags struct from an OCP model.
Arguments
ocp::CTModels.Model: The optimal control problem model.lagrange_to_mayer::Bool: Whether to reformulate the Lagrange cost as a Mayer term.
Returns
DOCPFlags: A struct encoding the problem’s boolean properties.
Example
julia> DOCPFlags(ocp, true)
DOCPFlags(false, true, true, false, true, false)CTDirect.DOCPbounds — Typestruct DOCPboundsInternal struct holding variable and constraint bounds for a DOCP.
Fields
var_l::Vector{Float64}: Lower bounds for NLP variables.var_u::Vector{Float64}: Upper bounds for NLP variables.con_l::Vector{Float64}: Lower bounds for NLP constraints.con_u::Vector{Float64}: Upper bounds for NLP constraints.
Example
julia> DOCPbounds([-1.0, -2.0], [1.0, 2.0], [0.0], [0.0])
DOCPbounds([-1.0, -2.0], [1.0, 2.0], [0.0], [0.0])CTDirect.DOCPdims — Typestruct DOCPdimsInternal struct holding problem dimensions for a DOCP.
Fields
NLP_x::Int: State dimension, possibly including an extra variable for Lagrange cost.NLP_u::Int: Control dimension.NLP_v::Int: Variable dimension.OCP_x::Int: State dimension of the original OCP.path_cons::Int: Path constraints dimension.boundary_cons::Int: Boundary constraints dimension.
Example
julia> DOCPdims(4, 2, 1, 3, 2, 1)
DOCPdims(4, 2, 1, 3, 2, 1)CTDirect.DOCPdims — MethodDOCPdims(
ocp::CTModels.Model,
lagrange_to_mayer::Bool
) -> CTDirect.DOCPdims
Construct a DOCPdims struct from an OCP model.
Arguments
ocp::CTModels.Model: The optimal control problem model.lagrange_to_mayer::Bool: Whether the Lagrange cost is reformulated as Mayer.
Returns
DOCPdims: A struct containing the problem dimensions.
Example
julia> DOCPdims(ocp, true)
DOCPdims(5, 2, 1, 4, 2, 1)CTDirect.DOCPtime — Typestruct DOCPtimeInternal struct holding time grid information for a DOCP.
Fields
steps::Int: Number of time steps.normalized_grid::Vector{Float64}: Normalized time grid in[0,1].fixed_grid::Vector{Float64}: Fixed time grid in[t0, tf].
Example
julia> DOCPtime(10, collect(0:0.1:1), collect(0.0:0.1:1.0))
DOCPtime(10, [0.0, 0.1, …, 1.0], [0.0, 0.1, …, 1.0])CTDirect.DOCPtime — MethodDOCPtime(
ocp::CTModels.Model,
grid_size::Int64,
time_grid
) -> CTDirect.DOCPtime
Construct a DOCPtime struct from an OCP model.
Arguments
ocp::CTModels.Model: The optimal control problem model.grid_size::Int: Number of grid steps if no grid is provided.time_grid: Custom time grid (ornothingto auto-generate).
Returns
DOCPtime: A struct encoding the time discretization.
Example
julia> DOCPtime(ocp, 10, nothing)
DOCPtime(10, [0.0, 0.1, …, 1.0], [0.0, 0.1, …, 1.0])CTDirect.Discretization — Typeabstract type DiscretizationAbstract type representing a discretization strategy for an optimal control problem.
Concrete subtypes of Discretization define specific schemes for transforming a continuous-time problem into a discrete-time representation suitable for numerical solution.
Example
julia> struct MyDiscretization <: Discretization end
MyDiscretizationCTDirect.DOCP_constraints! — MethodDOCP_constraints!(c, xu, docp::CTDirect.DOCP) -> Any
Compute the nonlinear constraints of a DOCP.
The constraints are modeled as lb <= C(x) <= ub.
Arguments
c: Preallocated constraint vector.xu: Vector of NLP decision variables.docp::DOCP: The discretized OCP.
Returns
c: The filled constraint vector.
Example
julia> DOCP_constraints!(zeros(docp.dim_NLP_constraints), xu, docp)
[0.0, 0.1, …]CTDirect.DOCP_initial_guess — FunctionDOCP_initial_guess(docp::CTDirect.DOCP) -> Vector{Float64}
DOCP_initial_guess(
docp::CTDirect.DOCP,
init::CTModels.Init
) -> Vector{Float64}
Build an initial guess vector for the discretized OCP.
Arguments
docp::DOCP: The discretized OCP.init::CTModels.Init: Initialization settings (default:CTModels.Init()).
Returns
NLP_X::Vector{Float64}: Initial guess vector.
Example
julia> DOCP_initial_guess(docp)
[0.1, 0.1, …]CTDirect.DOCP_objective — MethodDOCP_objective(xu, docp::CTDirect.DOCP) -> Any
Compute the objective value of a discretized OCP.
Arguments
xu: Vector of NLP decision variables.docp::DOCP: The discretized OCP.
Returns
obj::Float64: Objective function value.
Example
julia> DOCP_objective(xu, docp)
12.34CTDirect.build_bounds — Methodbuild_bounds(
dim_var,
dim_box,
box_triplet
) -> Tuple{Any, Any}
Build lower and upper bound vectors for state, control, or optimization variables.
Arguments
dim_var::Int: Variable dimension.dim_box::Int: Number of box constraints.box_triplet: Triplet defining box constraints.
Returns
(x_lb, x_ub)::Tuple{Vector{Float64},Vector{Float64}}: Lower and upper bounds.
Example
julia> build_bounds(3, 1, ([0.0], [2], [1.0]))
([-Inf, 0.0, -Inf], [Inf, 1.0, Inf])CTDirect.constraints_bounds! — Methodconstraints_bounds!(
docp::CTDirect.DOCP
) -> Tuple{Vector{Float64}, Vector{Float64}}
Build lower and upper bounds vectors for the nonlinear constraints of a DOCP.
Arguments
docp::DOCP: The discretized OCP.
Returns
(lb, ub)::Tuple{Vector{Float64},Vector{Float64}}: Lower and upper bounds.
Example
julia> constraints_bounds!(docp)
([-1.0, …], [1.0, …])CTDirect.disc_model — Methoddisc_model(docp::CTDirect.DOCP) -> CTDirect.Discretization
Return the discretization model associated with a given discretized optimal control problem (DOCP).
Arguments
docp::DOCP: The discretized optimal control problem.
Returns
discretization::Any: The discretization model stored indocp.
Example
julia> disc_model(docp)
DiscretizationModel(...)CTDirect.get_time_grid — Methodget_time_grid(xu, docp::CTDirect.DOCP) -> Any
Return the time grid for problems with free initial or final times.
Arguments
xu: Vector of NLP decision variables.docp::DOCP: The discretized OCP.
Returns
grid::Vector{Float64}: Time grid corresponding to current NLP variables.
Example
julia> get_time_grid(xu, docp)
[0.0, 0.1, …, 1.0]CTDirect.get_time_grid_exa — Methodget_time_grid_exa()
Helper for invalid execution paths.
Always throws an error.
Example
julia> get_time_grid_exa()
ERROR: you should not be hereCTDirect.is_solvable — Methodis_solvable(ocp) -> Bool
Check if an OCP is solvable by solve.
Arguments
ocp: The OCP model.
Returns
solvable::Bool: Always returnstruein the current implementation.
Example
julia> is_solvable(ocp)
trueCTDirect.nlp_model — Methodnlp_model(docp::CTDirect.DOCP) -> Any
Return the nonlinear programming (NLP) model associated with a given discretized optimal control problem (DOCP).
Arguments
docp::DOCP: The discretized optimal control problem.
Returns
nlp::Any: The underlying NLP model stored indocp.
Example
julia> nlp_model(docp)
NLPModel(...)CTDirect.ocp_model — Methodocp_model(docp::CTDirect.DOCP) -> CTModels.Model
Return the continuous-time optimal control problem (OCP) model associated with a given discretized optimal control problem (DOCP).
Arguments
docp::DOCP: The discretized optimal control problem.
Returns
ocp::Any: The underlying OCP model stored indocp.
Example
julia> ocp_model(docp)
OCPModel(...)CTDirect.setPointConstraints! — MethodsetPointConstraints!(docp::CTDirect.DOCP, c, xu, v) -> Any
Set boundary and variable point constraints for a DOCP.
Arguments
docp::DOCP: The discretized OCP.c: Constraint vector to modify.xu: Vector of NLP decision variables.v: Additional OCP variables.
Returns
nothing: Modifiescin place.
Example
julia> setPointConstraints!(docp, c, xu, v)CTDirect.variables_bounds! — Methodvariables_bounds!(
docp::CTDirect.DOCP
) -> Tuple{Vector{Float64}, Vector{Float64}}
Build lower and upper bounds vectors for the variable box constraints of a DOCP.
Arguments
docp::DOCP: The discretized OCP.
Returns
(var_l, var_u)::Tuple{Vector{Float64},Vector{Float64}}: Lower and upper bounds for variables.
Example
julia> variables_bounds!(docp)
([-Inf, …], [Inf, …])