Private API
This page lists non-exported (internal) symbols of CTModels.
From CTModels
append_box_constraints!
CTModels.append_box_constraints! — Function
append_box_constraints!(
inds,
lbs,
ubs,
labels,
rg,
lb,
ub,
label
)
Appends box constraint data to the provided vectors.
Arguments
inds::Vector{Int}: Vector of indices to which the rangergwill be appended.lbs::Vector{<:Real}: Vector of lower bounds to whichlbwill be appended.ubs::Vector{<:Real}: Vector of upper bounds to whichubwill be appended.labels::Vector{String}: Vector of labels to which thelabelwill be repeated and appended.rg::AbstractVector{Int}: Index range corresponding to the constraint variables.lb::AbstractVector{<:Real}: Lower bounds associated withrg.ub::AbstractVector{<:Real}: Upper bounds associated withrg.label::String: Label describing the constraint block (e.g., "state", "control").
Notes
- All input vectors (
rg,lb,ub) must have the same length. - The function modifies the
inds,lbs,ubs, andlabelsvectors in-place.
build
CTModels.build — Function
build(
constraints::OrderedCollections.OrderedDict{Symbol, Tuple{Symbol, Union{Function, OrdinalRange{<:Int64}}, AbstractVector{<:Real}, AbstractVector{<:Real}}}
) -> CTModels.ConstraintsModel{TP, TB, Tuple{Vector{Float64}, Vector{Int64}, Vector{Float64}, Vector{Symbol}}, Tuple{Vector{Float64}, Vector{Int64}, Vector{Float64}, Vector{Symbol}}, Tuple{Vector{Float64}, Vector{Int64}, Vector{Float64}, Vector{Symbol}}} where {TP<:Tuple{Vector{Float64}, Any, Vector{Float64}, Vector{Symbol}}, TB<:Tuple{Vector{Float64}, Any, Vector{Float64}, Vector{Symbol}}}
Constructs a ConstraintsModel from a dictionary of constraints.
This function processes a dictionary where each entry defines a constraint with its type, function or index range, lower and upper bounds, and label. It categorizes constraints into path, boundary, state, control, and variable constraints, assembling them into a structured ConstraintsModel.
Arguments
constraints::ConstraintsDictType: A dictionary mapping constraint labels to tuples of the form(type, function_or_range, lower_bound, upper_bound).
Returns
ConstraintsModel: A structured model encapsulating all provided constraints.
Example
julia> constraints = OrderedDict(
:c1 => (:path, f1, [0.0], [1.0]),
:c2 => (:state, 1:2, [-1.0, -1.0], [1.0, 1.0])
)
julia> model = build(constraints)build(
pre_ocp::CTModels.PreModel;
build_examodel
) -> CTModels.Model{TD, var"#s179", var"#s1791", var"#s1792", var"#s1793", var"#s1794", var"#s1795", CTModels.ConstraintsModel{TP, TB, Tuple{Vector{Float64}, Vector{Int64}, Vector{Float64}, Vector{Symbol}}, Tuple{Vector{Float64}, Vector{Int64}, Vector{Float64}, Vector{Symbol}}, Tuple{Vector{Float64}, Vector{Int64}, Vector{Float64}, Vector{Symbol}}}, Nothing} where {TD<:CTModels.TimeDependence, var"#s179"<:CTModels.AbstractTimesModel, var"#s1791"<:CTModels.AbstractStateModel, var"#s1792"<:CTModels.AbstractControlModel, var"#s1793"<:CTModels.AbstractVariableModel, var"#s1794"<:Function, var"#s1795"<:CTModels.AbstractObjectiveModel, TP<:Tuple{Vector{Float64}, Any, Vector{Float64}, Vector{Symbol}}, TB<:Tuple{Vector{Float64}, Any, Vector{Float64}, Vector{Symbol}}}
Converts a mutable PreModel into an immutable Model.
This function finalizes a pre-defined optimal control problem (PreModel) by verifying that all necessary components (times, state, control, dynamics) are set. It then constructs a Model instance, incorporating optional components like objective and constraints if they are defined.
Arguments
pre_ocp::PreModel: The pre-defined optimal control problem to be finalized.
Returns
Model: A fully constructed model ready for solving.
Example
julia> pre_ocp = PreModel()
julia> times!(pre_ocp, 0.0, 1.0, 100)
julia> state!(pre_ocp, 2, "x", ["x1", "x2"])
julia> control!(pre_ocp, 1, "u", ["u1"])
julia> dynamics!(pre_ocp, (dx, t, x, u, v) -> dx .= x + u)
julia> model = build(pre_ocp)constraints
CTModels.constraints — Function
constraints(
ocp::CTModels.Model{<:CTModels.TimeDependence, <:CTModels.AbstractTimesModel, <:CTModels.AbstractStateModel, <:CTModels.AbstractControlModel, <:CTModels.AbstractVariableModel, <:Function, <:CTModels.AbstractObjectiveModel, C<:CTModels.AbstractConstraintsModel}
) -> CTModels.AbstractConstraintsModel
Return the constraints struct.
control
CTModels.control — Function
control(
ocp::CTModels.Model{<:CTModels.TimeDependence, <:CTModels.TimesModel, <:CTModels.AbstractStateModel, T<:CTModels.AbstractControlModel}
) -> CTModels.AbstractControlModel
Return the control struct.
control(
sol::CTModels.Solution{<:CTModels.AbstractTimeGridModel, <:CTModels.AbstractTimesModel, <:CTModels.AbstractStateModel, <:CTModels.ControlModelSolution{TS<:Function}}
) -> Function
Return the control as a function of time.
julia> u = control(sol)
julia> t0 = time_grid(sol)[1]
julia> u0 = u(t0) # control at the initial timecontrol(
init::CTModels.OptimalControlInitialGuess{<:Function, U<:Function}
) -> Function
Extract the control trajectory function from an initial guess.
definition
CTModels.definition — Function
definition(ocp::CTModels.Model) -> Expr
Return the model definition of the optimal control problem.
Arguments
ocp::Model: The built optimal control problem model.
Returns
Expr: The symbolic expression defining the problem.
definition(ocp::CTModels.PreModel) -> Union{Nothing, Expr}
Return the model definition of the optimal control problem or nothing.
Arguments
ocp::PreModel: The pre-model (may not have a definition set).
Returns
Union{Expr, Nothing}: The symbolic expression ornothingif not set.
definition!
CTModels.definition! — Function
definition!(ocp::CTModels.PreModel, definition::Expr)
Set the model definition of the optimal control problem.
Arguments
ocp::PreModel: The pre-model to modify.definition::Expr: The symbolic expression defining the problem.
Returns
Nothing
dynamics
CTModels.dynamics — Function
dynamics(
ocp::CTModels.Model{<:CTModels.TimeDependence, <:CTModels.AbstractTimesModel, <:CTModels.AbstractStateModel, <:CTModels.AbstractControlModel, <:CTModels.AbstractVariableModel, D<:Function}
) -> Function
Return the dynamics.
final_time
CTModels.final_time — Function
final_time(
model::CTModels.TimesModel{<:CTModels.AbstractTimeModel, <:CTModels.FixedTimeModel{T<:Real}}
) -> Real
Get the final time from the times model, from a fixed final time model.
final_time(
model::CTModels.TimesModel{<:CTModels.AbstractTimeModel, CTModels.FreeTimeModel},
variable::AbstractArray{T<:Real, 1}
) -> Any
Get the final time from the times model, from a free final time model.
final_time(ocp::CTModels.AbstractModel) -> Real
Throw an error for unsupported final time access.
final_time(
ocp::CTModels.AbstractModel,
variable::AbstractVector
) -> Any
Throw an error for unsupported final time access with variable.
final_time(
ocp::CTModels.Model{<:CTModels.TimeDependence, <:CTModels.TimesModel{<:CTModels.AbstractTimeModel, CTModels.FixedTimeModel{T<:Real}}}
) -> Real
Return the final time, for a fixed final time.
final_time(
ocp::CTModels.Model{<:CTModels.TimeDependence, <:CTModels.TimesModel{<:CTModels.AbstractTimeModel, CTModels.FreeTimeModel}},
variable::AbstractArray{T<:Real, 1}
) -> Any
Return the final time, for a free final time.
final_time(
ocp::CTModels.Model{<:CTModels.TimeDependence, <:CTModels.TimesModel{<:CTModels.AbstractTimeModel, CTModels.FreeTimeModel}},
variable::Real
) -> Real
Return the final time, for a free final time.
get_build_examodel
CTModels.get_build_examodel — Function
get_build_examodel(
ocp::CTModels.Model{<:CTModels.TimeDependence, <:CTModels.AbstractTimesModel, <:CTModels.AbstractStateModel, <:CTModels.AbstractControlModel, <:CTModels.AbstractVariableModel, <:Function, <:CTModels.AbstractObjectiveModel, <:CTModels.AbstractConstraintsModel, BE<:Function}
) -> Function
Return the build_examodel.
get_build_examodel(
_::CTModels.Model{<:CTModels.TimeDependence, <:CTModels.AbstractTimesModel, <:CTModels.AbstractStateModel, <:CTModels.AbstractControlModel, <:CTModels.AbstractVariableModel, <:Function, <:CTModels.AbstractObjectiveModel, <:CTModels.AbstractConstraintsModel, <:Nothing}
)
Return an error (UnauthorizedCall) since the model is not built with the :exa backend.
initial_time
CTModels.initial_time — Function
initial_time(
model::CTModels.TimesModel{<:CTModels.FixedTimeModel{T<:Real}}
) -> Real
Get the initial time from the times model, from a fixed initial time model.
initial_time(
model::CTModels.TimesModel{CTModels.FreeTimeModel},
variable::AbstractArray{T<:Real, 1}
) -> Any
Get the initial time from the times model, from a free initial time model.
initial_time(ocp::CTModels.AbstractModel) -> Real
Throw an error for unsupported initial time access.
initial_time(
ocp::CTModels.AbstractModel,
variable::AbstractVector
) -> Any
Throw an error for unsupported initial time access with variable.
initial_time(
ocp::CTModels.Model{<:CTModels.TimeDependence, <:CTModels.TimesModel{CTModels.FixedTimeModel{T<:Real}}}
) -> Real
Return the initial time, for a fixed initial time.
initial_time(
ocp::CTModels.Model{<:CTModels.TimeDependence, <:CTModels.TimesModel{CTModels.FreeTimeModel}},
variable::AbstractArray{T<:Real, 1}
) -> Any
Return the initial time, for a free initial time.
initial_time(
ocp::CTModels.Model{<:CTModels.TimeDependence, <:CTModels.TimesModel{CTModels.FreeTimeModel}},
variable::Real
) -> Real
Return the initial time, for a free initial time.
is_autonomous
CTModels.is_autonomous — Function
is_autonomous(
ocp::CTModels.PreModel
) -> Union{Nothing, Bool}
Check whether the system is autonomous.
Arguments
ocp::PreModel: The optimal control problem.
Returns
Bool:trueif the system is autonomous (i.e., does not explicitly depend on time),falseotherwise.
Example
julia> is_autonomous(ocp) # returns true or falseis_autonomous(
_::CTModels.Model{CTModels.Autonomous, <:CTModels.TimesModel}
) -> Bool
Return true for an autonomous model.
is_autonomous(
_::CTModels.Model{CTModels.NonAutonomous, <:CTModels.TimesModel}
) -> Bool
Return false for a non-autonomous model.
isempty_constraints
CTModels.isempty_constraints — Function
isempty_constraints(ocp::CTModels.Model) -> Bool
Return true if the model has constraints or false if not.
time_dependence!
CTModels.time_dependence! — Function
time_dependence!(ocp::CTModels.PreModel; autonomous)
Set the time dependence of the optimal control problem ocp.
Arguments
ocp::PreModel: The optimal control problem being defined.autonomous::Bool: Indicates whether the system is autonomous (true) or time-dependent (false).
Preconditions
- The time dependence must not have been set previously.
Behavior
This function sets the autonomous field of the model to indicate whether the system's dynamics explicitly depend on time. It can only be called once.
Errors
Throws CTBase.UnauthorizedCall if the time dependence has already been set.
Example
julia> ocp = PreModel(...)
julia> time_dependence!(ocp; autonomous=true)times
CTModels.times — Function
times(
ocp::CTModels.Model{<:CTModels.TimeDependence, T<:CTModels.TimesModel}
) -> CTModels.TimesModel
Return the times struct.
variable
CTModels.variable — Function
variable(
ocp::CTModels.Model{<:CTModels.TimeDependence, <:CTModels.TimesModel, <:CTModels.AbstractStateModel, <:CTModels.AbstractControlModel, T<:CTModels.AbstractVariableModel}
) -> CTModels.AbstractVariableModel
Return the variable struct.
variable(
sol::CTModels.Solution{<:CTModels.AbstractTimeGridModel, <:CTModels.AbstractTimesModel, <:CTModels.AbstractStateModel, <:CTModels.AbstractControlModel, <:CTModels.VariableModelSolution{TS<:Union{Real, AbstractVector{<:Real}}}}
) -> Union{Real, AbstractVector{<:Real}}
Return the variable or nothing.
julia> v = variable(sol)variable(
init::CTModels.OptimalControlInitialGuess{<:Function, <:Function, V<:Union{Real, Vector{<:Real}}}
) -> Union{Real, Vector{<:Real}}
Extract the variable value from an initial guess.