Private API

This page lists non-exported (internal) symbols of CTModels.


From CTModels

_build_block_with_components

CTModels._build_block_with_componentsFunction
_build_block_with_components(
    ocp::CTModels.AbstractModel,
    role::Symbol,
    block_data,
    comp_data::Dict{Int64, Any}
) -> Any

Build an initialisation function combining block-level and component-level data.

Merges a base initialisation with per-component overrides.

_build_component_function

CTModels._build_component_functionFunction
_build_component_function(data) -> Function

Build a component-level initialisation function from data.

Handles both time-dependent (time, data) tuples and time-independent data.

_build_component_function_with_time

CTModels._build_component_function_with_timeFunction
_build_component_function_with_time(
    data,
    time::AbstractVector
) -> Function

Build a component function from data with an associated time grid.

Interpolates vector data over the time grid.

_build_component_function_without_time

_build_time_dependent_init

CTModels._build_time_dependent_initFunction
_build_time_dependent_init(
    ocp::CTModels.AbstractModel,
    role::Symbol,
    data,
    time::AbstractVector
) -> Function

Build a time-dependent initialisation function from data and a time grid.

Interpolates the provided data over the time grid to create a callable function.

_format_init_data_for_grid

_format_time_grid

_initial_guess_from_namedtuple

CTModels._initial_guess_from_namedtupleFunction
_initial_guess_from_namedtuple(
    ocp::CTModels.AbstractModel,
    init_data::NamedTuple
) -> CTModels.OptimalControlInitialGuess{<:Function, <:Function, V} where V<:Union{Real, Vector{<:Real}}

Build an initial guess from a NamedTuple.

Parses keys for state, control, variable (by name or component) and constructs the appropriate initialisation functions.

_initial_guess_from_preinit

CTModels._initial_guess_from_preinitFunction
_initial_guess_from_preinit(
    ocp::CTModels.AbstractModel,
    preinit::CTModels.OptimalControlPreInit
) -> CTModels.OptimalControlInitialGuess{<:Function, <:Function, V} where V<:Union{Real, Vector{<:Real}}

Convert a OptimalControlPreInit to an initial guess.

_initial_guess_from_solution

CTModels._initial_guess_from_solutionFunction
_initial_guess_from_solution(
    ocp::CTModels.AbstractModel,
    sol::CTModels.AbstractSolution
) -> Union{CTModels.OptimalControlInitialGuess{X, U, V} where {X<:Function, U<:Function, V<:Real}, CTModels.OptimalControlInitialGuess{X, U, V} where {V<:(Vector{<:Real}), X<:Function, U<:Function}}

Build an initial guess from a previous solution (warm start).

Extracts state, control, and variable trajectories from the solution and validates dimensions against the current problem.

_validate_initial_guess

CTModels._validate_initial_guessFunction
_validate_initial_guess(
    ocp::CTModels.AbstractModel,
    init::CTModels.OptimalControlInitialGuess
) -> CTModels.OptimalControlInitialGuess{<:Function, <:Function, V} where V<:Union{Real, Vector{<:Real}}

Internal validation of an OptimalControlInitialGuess.

Samples the state and control functions at a test time and verifies dimensions.

build_initial_guess

CTModels.build_initial_guessFunction
build_initial_guess(
    ocp::CTModels.AbstractModel,
    init_data
) -> CTModels.AbstractOptimalControlInitialGuess

Build an initial guess from various input formats.

Accepts multiple input types and converts them to an OptimalControlInitialGuess:

  • nothing or (): Returns default initial guess.
  • AbstractOptimalControlInitialGuess: Returns as-is.
  • AbstractOptimalControlPreInit: Converts from pre-initialisation.
  • AbstractSolution: Warm-starts from a previous solution.
  • NamedTuple: Parses named fields for state, control, and variable.

Arguments

  • ocp::AbstractOptimalControlProblem: The optimal control problem.
  • init_data: The initial guess data in one of the supported formats.

Returns

  • OptimalControlInitialGuess: A validated initial guess.

Example

julia> using CTModels

julia> init = CTModels.build_initial_guess(ocp, (state=t -> [0.0], control=t -> [1.0]))

initial_control

CTModels.initial_controlFunction
initial_control(
    _::CTModels.AbstractModel,
    control::Function
) -> Function

Return the control function directly when provided as a function.

initial_control(
    ocp::CTModels.AbstractModel,
    control::Real
) -> CTModels.var"#initial_control##0#initial_control##1"{<:Real}

Convert a scalar control value to a constant function for 1D control problems.

Throws CTBase.IncorrectArgument if the control dimension is not 1.

initial_control(
    ocp::CTModels.AbstractModel,
    control::Vector{<:Real}
) -> CTModels.var"#initial_control##2#initial_control##3"{Vector{var"#s204"}} where var"#s204"<:Real

Convert a control vector to a constant function.

Throws CTBase.IncorrectArgument if the vector length does not match the control dimension.

initial_control(
    ocp::CTModels.AbstractModel,
    _::Nothing
) -> Union{CTModels.var"#initial_control##4#initial_control##5", CTModels.var"#initial_control##6#initial_control##7"{Int64}}

Return a default control initialisation function when no control is provided.

Returns a constant function yielding 0.1 (scalar) or fill(0.1, dim) (vector).

initial_guess

CTModels.initial_guessFunction
initial_guess(
    ocp::CTModels.AbstractModel;
    state,
    control,
    variable
) -> CTModels.OptimalControlInitialGuess{X, U, V} where {X<:Union{CTModels.var"#initial_state##4#initial_state##5", CTModels.var"#initial_state##6#initial_state##7"{Int64}}, U<:Union{CTModels.var"#initial_control##4#initial_control##5", CTModels.var"#initial_control##6#initial_control##7"{Int64}}, V<:Union{Float64, Vector{Float64}}}

Construct a validated initial guess for an optimal control problem.

Builds an OptimalControlInitialGuess from the provided state, control, and variable data, validating dimensions against the problem definition.

Arguments

  • ocp::AbstractOptimalControlProblem: The optimal control problem.
  • state: State initialisation (function t -> x(t), constant, vector, or nothing).
  • control: Control initialisation (function t -> u(t), constant, vector, or nothing).
  • variable: Variable initialisation (scalar, vector, or nothing).

Returns

  • OptimalControlInitialGuess: A validated initial guess.

Example

julia> using CTModels

julia> init = CTModels.initial_guess(ocp; state=t -> [0.0, 0.0], control=t -> [1.0])

initial_state

CTModels.initial_stateFunction
initial_state(
    _::CTModels.AbstractModel,
    state::Function
) -> Function

Return the state function directly when provided as a function.

initial_state(
    ocp::CTModels.AbstractModel,
    state::Real
) -> CTModels.var"#initial_state##0#initial_state##1"{<:Real}

Convert a scalar state value to a constant function for 1D state problems.

Throws CTBase.IncorrectArgument if the state dimension is not 1.

initial_state(
    ocp::CTModels.AbstractModel,
    state::Vector{<:Real}
) -> CTModels.var"#initial_state##2#initial_state##3"{Vector{var"#s204"}} where var"#s204"<:Real

Convert a state vector to a constant function.

Throws CTBase.IncorrectArgument if the vector length does not match the state dimension.

initial_state(
    ocp::CTModels.AbstractModel,
    _::Nothing
) -> Union{CTModels.var"#initial_state##4#initial_state##5", CTModels.var"#initial_state##6#initial_state##7"{Int64}}

Return a default state initialisation function when no state is provided.

Returns a constant function yielding 0.1 (scalar) or fill(0.1, dim) (vector).

initial_variable

CTModels.initial_variableFunction
initial_variable(
    ocp::CTModels.AbstractModel,
    variable::Real
) -> Real

Return a scalar variable value for 1D variable problems.

Throws CTBase.IncorrectArgument if the variable dimension is not 1.

initial_variable(
    ocp::CTModels.AbstractModel,
    variable::Vector{<:Real}
) -> Vector{<:Real}

Return a variable vector.

Throws CTBase.IncorrectArgument if the vector length does not match the variable dimension.

initial_variable(
    ocp::CTModels.AbstractModel,
    _::Nothing
) -> Union{Float64, Vector{Float64}}

Return a default variable initialisation when no variable is provided.

Returns an empty vector if dim == 0, 0.1 if dim == 1, or fill(0.1, dim) otherwise.

pre_initial_guess

CTModels.pre_initial_guessFunction
pre_initial_guess(
;
    state,
    control,
    variable
) -> CTModels.OptimalControlPreInit{Nothing, Nothing, Nothing}

Create a pre-initialisation object for an initial guess.

This function creates an OptimalControlPreInit that can later be processed into a full OptimalControlInitialGuess.

Arguments

  • state: Raw state initialisation data (function, vector, matrix, or nothing).
  • control: Raw control initialisation data (function, vector, matrix, or nothing).
  • variable: Raw variable initialisation data (scalar, vector, or nothing).

Returns

  • OptimalControlPreInit: A pre-initialisation container.

Example

julia> using CTModels

julia> pre = CTModels.pre_initial_guess(state=t -> [0.0, 0.0], control=t -> [1.0])

state

CTModels.stateFunction
state(
    ocp::CTModels.Model{<:CTModels.TimeDependence, <:CTModels.TimesModel, T<:CTModels.AbstractStateModel}
) -> CTModels.AbstractStateModel

Return the state struct.

state(
    sol::CTModels.Solution{<:CTModels.AbstractTimeGridModel, <:CTModels.AbstractTimesModel, <:CTModels.StateModelSolution{TS<:Function}}
) -> Function

Return the state as a function of time.

julia> x  = state(sol)
julia> t0 = time_grid(sol)[1]
julia> x0 = x(t0) # state at the initial time
state(
    init::CTModels.OptimalControlInitialGuess{X<:Function}
) -> Function

Extract the state trajectory function from an initial guess.

validate_initial_guess

CTModels.validate_initial_guessFunction
validate_initial_guess(
    ocp::CTModels.AbstractModel,
    init::CTModels.AbstractOptimalControlInitialGuess
) -> CTModels.AbstractOptimalControlInitialGuess

Validate an initial guess against an optimal control problem.

Checks that the dimensions of state, control, and variable match the problem definition. Returns the validated initial guess or throws an error.

Arguments

  • ocp::AbstractOptimalControlProblem: The optimal control problem.
  • init::AbstractOptimalControlInitialGuess: The initial guess to validate.

Returns

  • The validated initial guess.

Throws

  • CTBase.IncorrectArgument if dimensions do not match.