Private API
This page lists non-exported (internal) symbols of CTModels.OCP.
From CTModels.OCP
__build_dynamics_from_parts
CTModels.OCP.__build_dynamics_from_parts — Function
__build_dynamics_from_parts(
parts::Vector{<:Tuple{var"#s39", var"#s38"} where {var"#s39"<:(AbstractRange{<:Int64}), var"#s38"<:Function}}
) -> CTModels.OCP.var"#dyn!#__build_dynamics_from_parts##0"{Vector{var"#s3"}} where var"#s3"<:(Tuple{var"#s2", var"#s1"} where {var"#s2"<:(AbstractRange{<:Int64}), var"#s1"<:Function})
Build a combined dynamics function from multiple parts.
This function constructs an in-place dynamics function dyn! by composing several sub-functions, each responsible for updating a specific segment of the output vector.
Arguments
parts::Vector{<:Tuple{<:AbstractRange{<:Int}, <:Function}}: A vector of tuples, where each tuple contains:- A range specifying the indices in the output vector
valthat the corresponding function updates. - A function
fwith the signature(output_segment, t, x, u, v), which updates the slice ofvalindicated by the range.
- A range specifying the indices in the output vector
Returns
dyn!: A function with signature(val, t, x, u, v)that updates the full output vectorvalin-place by applying each part function to its assigned segment.
Details
- The returned
dyn!function calls each part function with a view ofvalrestricted to the assigned range. This avoids unnecessary copying and allows efficient updates of sub-vectors. - Each part function is expected to modify its output segment in-place.
Example
# Define two sub-dynamics functions
julia> f1(out, t, x, u, v) = out .= x[1:2] .+ u[1:2]
julia> f2(out, t, x, u, v) = out .= x[3] * v
# Combine them into one dynamics function affecting different parts of the output vector
julia> parts = [(1:2, f1), (3:3, f2)]
julia> dyn! = __build_dynamics_from_parts(parts)
val = zeros(3)
julia> dyn!(val, 0.0, [1.0, 2.0, 3.0], [0.5, 0.5], 2.0)
julia> println(val) # prints [1.5, 2.5, 6.0]__constraint!
CTModels.OCP.__constraint! — Function
__constraint!(
ocp_constraints::OrderedCollections.OrderedDict{Symbol, Tuple{Symbol, Union{Function, OrdinalRange{<:Int64}}, AbstractVector{<:Real}, AbstractVector{<:Real}}},
type::Symbol,
n::Int64,
m::Int64,
q::Int64;
rg,
f,
lb,
ub,
label,
codim_f
)
Add a constraint to a dictionary of constraints.
Arguments
ocp_constraints: The dictionary of constraints to which the constraint will be added.type: The type of the constraint. It can be:state,:control,:variable,:boundary, or:path.n: The dimension of the state.m: The dimension of the control.q: The dimension of the variable.rg: The range of the constraint. It can be an integer or a range of integers.f: The function that defines the constraint. It must return a vector of the same dimension as the constraint.lb: The lower bound of the constraint. It can be a number or a vector.ub: The upper bound of the constraint. It can be a number or a vector.label: The label of the constraint. It must be unique in the dictionary of constraints.
Requirements
- The constraint must not be set before.
- The lower bound
lband the upper boundubcannot be bothnothing. - The lower bound
lband the upper boundubmust have the same length, if both provided.
If rg and f are not provided then,
typemust be:state,:control, or:variable.lbandubmust be of dimensionn,m, orqrespectively, when provided.
If rg is provided, then:
fmust not be provided.typemust be:state,:control, or:variable.rgmust be a range of integers, and must be contained in1:n,1:m, or1:qrespectively.
If f is provided, then:
rgmust not be provided.typemust be:boundaryor:path.fmust be a function that returns a vector of the same dimension as the constraint.lbandubmust be of the same dimension as the output off, when provided.
Example
# Example of adding a state constraint
julia> ocp_constraints = Dict()
julia> __constraint!(ocp_constraints, :state, 3, 2, 1, lb=[0.0], ub=[1.0], label=:my_constraint)as_range
CTModels.OCP.as_range — Function
as_range(::Nothing) -> NothingReturn nothing unchanged.
as_range(r::Int) -> UnitRange{Int}Convert a scalar integer to a single-element range r:r.
as_range(r::OrdinalRange{Int}) -> OrdinalRange{Int}Return an ordinal range unchanged.
as_vector
CTModels.OCP.as_vector — Function
as_vector(::Nothing) -> NothingReturn nothing unchanged.
as_vector(x::T) -> Vector{T} where {T<:ctNumber}Wrap a scalar number into a single-element vector.
as_vector(x::AbstractVector{T}) -> AbstractVector{T} where {T<:ctNumber}Return a vector unchanged.
final
CTModels.OCP.final — Function
final(
model::CTModels.OCP.TimesModel{<:CTModels.OCP.AbstractTimeModel, TF<:CTModels.OCP.AbstractTimeModel}
) -> CTModels.OCP.AbstractTimeModel
Get the final time from the times model.
initial
CTModels.OCP.initial — Function
initial(
model::CTModels.OCP.TimesModel{TI<:CTModels.OCP.AbstractTimeModel}
) -> CTModels.OCP.AbstractTimeModel
Get the initial time from the times model.
value
CTModels.OCP.value — Function
value(
model::CTModels.OCP.StateModelSolution{TS<:Function}
) -> Function
Get the state function from the state model solution.
value(
model::CTModels.OCP.ControlModelSolution{TS<:Function}
) -> Function
Get the control function associated with the solution.
Arguments
model::ControlModelSolution{TS}: The control model solution.
Returns
TS: A function giving the control value at a given time or state.
value(
model::CTModels.OCP.VariableModelSolution{TS<:Union{Real, AbstractVector{<:Real}}}
) -> Union{Real, AbstractVector{<:Real}}
Return the value stored in the variable solution model.