Private API

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


From CTModels

@ensure

CTModels.@ensureMacro
@ensure condition exception

Throws the provided exception if condition is false.

Usage

julia> @ensure x > 0 CTBase.IncorrectArgument("x must be positive")

Arguments

  • condition: A Boolean expression to test.
  • exception: An instance of an exception to throw if condition is false.

Throws

  • The provided exception if the condition is not satisfied.

__constraint_label

CTModels.__constraint_labelFunction
__constraint_label() -> Symbol

Used to set the default value of the label of a constraint. A unique value is given to each constraint using the gensym function and prefixing by :unnamed.

__constraints

__control_components

CTModels.__control_componentsFunction
__control_components(
    m::Int64,
    name::String
) -> Vector{String}

Used to set the default value of the names of the controls. The default value is ["u"] for a one dimensional control, and ["u₁", "u₂", ...] for a multi dimensional control.

__control_name

CTModels.__control_nameFunction
__control_name() -> String

Used to set the default value of the names of the control. The default value is "u".

__criterion_type

CTModels.__criterion_typeFunction
__criterion_type() -> Symbol

Used to set the default value of the type of criterion. Either :min or :max. The default value is :min. The other possible criterion type is :max.

__filename_export_import

CTModels.__filename_export_importFunction
__filename_export_import() -> String

Return the default filename (without extension) for exporting and importing solutions.

The default value is "solution".

__format

CTModels.__formatFunction
__format() -> Symbol

Used to set the default value of the format of the file to be used for export and import.

__matrix_dimension_storage

CTModels.__matrix_dimension_storageFunction
__matrix_dimension_storage() -> Int64

Used to set the default value of the storage of elements in a matrix. The default value is 1.

__state_components

CTModels.__state_componentsFunction
__state_components(n::Int64, name::String) -> Vector{String}

Used to set the default value of the names of the states. The default value is ["x"] for a one dimensional state, and ["x₁", "x₂", ...] for a multi dimensional state.

__state_name

CTModels.__state_nameFunction
__state_name() -> String

Used to set the default value of the name of the state. The default value is "x".

__time_name

CTModels.__time_nameFunction
__time_name() -> String

Used to set the default value of the name of the time. The default value is t.

__variable_components

CTModels.__variable_componentsFunction
__variable_components(
    q::Int64,
    name::String
) -> Vector{String}

Used to set the default value of the names of the variables. The default value is ["v"] for a one dimensional variable, and ["v₁", "v₂", ...] for a multi dimensional variable.

__variable_name

CTModels.__variable_nameFunction
__variable_name(q::Int64) -> String

Used to set the default value of the names of the variables. The default value is "v".

ctinterpolate

CTModels.ctinterpolateFunction
ctinterpolate(x, f) -> Any

Return a linear interpolation function for the data f defined at points x.

This function creates a one-dimensional linear interpolant using the Interpolations.jl package, with linear extrapolation beyond the bounds of x.

Arguments

  • x: A vector of points at which the values f are defined.
  • f: A vector of values to interpolate.

Returns

A callable interpolation object that can be evaluated at new points.

Example

julia> x = 0:0.5:2
julia> f = [0.0, 1.0, 0.0, -1.0, 0.0]
julia> interp = ctinterpolate(x, f)
julia> interp(1.2)

matrix2vec

CTModels.matrix2vecFunction
matrix2vec(A::Matrix{<:Real}) -> Vector{<:Vector{<:Real}}
matrix2vec(
    A::Matrix{<:Real},
    dim::Int64
) -> Vector{<:Vector{<:Real}}

Transform a matrix into a vector of vectors along the specified dimension.

Each row or column of the matrix A is extracted and stored as an individual vector, depending on dim.

Arguments

  • A: A matrix of elements of type <:ctNumber.
  • dim: The dimension along which to split the matrix (1 for rows, 2 for columns). Defaults to 1.

Returns

A Vector of Vectors extracted from the rows or columns of A.

Note

This is useful when data needs to be represented as a sequence of state or control vectors in optimal control problems.

Example

julia> A = [1 2 3; 4 5 6]
julia> matrix2vec(A, 1)  # splits into rows: [[1, 2, 3], [4, 5, 6]]
julia> matrix2vec(A, 2)  # splits into columns: [[1, 4], [2, 5], [3, 6]]

to_out_of_place

CTModels.to_out_of_placeFunction
to_out_of_place(
    f!,
    n;
    T
) -> Union{Nothing, CTModels.var"#f#8"{CTModels.var"#f#7#9"{Type{Float64}, _A, _B}} where {_A, _B}}

Convert an in-place function f! to an out-of-place function f.

The resulting function f returns a vector of type T and length n by first allocating memory and then calling f! to fill it.

Arguments

  • f!: An in-place function of the form f!(result, args...).
  • n: The length of the output vector.
  • T: The element type of the output vector (default is Float64).

Returns

An out-of-place function f(args...; kwargs...) that returns the result as a vector or scalar, depending on n.

Example

julia> f!(r, x) = (r[1] = sin(x); r[2] = cos(x))
julia> f = to_out_of_place(f!, 2)
julia> f(π/4)  # returns approximately [0.707, 0.707]