DOCP

Index

Documentation

CTDirect.DOCPType
mutable 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{...}(...)
source
CTDirect.DOCPFlagsType
struct DOCPFlags

Internal 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)
source
CTDirect.DOCPFlagsMethod
DOCPFlags(
    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)
source
CTDirect.DOCPboundsType
struct DOCPbounds

Internal 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])
source
CTDirect.DOCPdimsType
struct DOCPdims

Internal 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)
source
CTDirect.DOCPdimsMethod
DOCPdims(
    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)
source
CTDirect.DOCPtimeType
struct DOCPtime

Internal 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])
source
CTDirect.DOCPtimeMethod
DOCPtime(
    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 (or nothing to 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])
source
CTDirect.DiscretizationType
abstract type Discretization

Abstract 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
MyDiscretization
source
CTDirect.DOCP_constraints!Method
DOCP_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, …]
source
CTDirect.DOCP_initial_guessFunction
DOCP_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, …]
source
CTDirect.DOCP_objectiveMethod
DOCP_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.34
source
CTDirect.build_boundsMethod
build_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])
source
CTDirect.constraints_bounds!Method
constraints_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, …])
source
CTDirect.disc_modelMethod
disc_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 in docp.

Example

julia> disc_model(docp)
DiscretizationModel(...)
source
CTDirect.get_time_gridMethod
get_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]
source
CTDirect.get_time_grid_exaMethod
get_time_grid_exa()

Helper for invalid execution paths.

Always throws an error.

Example

julia> get_time_grid_exa()
ERROR: you should not be here
source
CTDirect.is_solvableMethod
is_solvable(ocp) -> Bool

Check if an OCP is solvable by solve.

Arguments

  • ocp: The OCP model.

Returns

  • solvable::Bool: Always returns true in the current implementation.

Example

julia> is_solvable(ocp)
true
source
CTDirect.nlp_modelMethod
nlp_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 in docp.

Example

julia> nlp_model(docp)
NLPModel(...)
source
CTDirect.ocp_modelMethod
ocp_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 in docp.

Example

julia> ocp_model(docp)
OCPModel(...)
source
CTDirect.setPointConstraints!Method
setPointConstraints!(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: Modifies c in place.

Example

julia> setPointConstraints!(docp, c, xu, v)
source
CTDirect.variables_bounds!Method
variables_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, …])
source