Model
Index
CTModels.append_box_constraints!
CTModels.boundary_constraints_nl
CTModels.build
CTModels.build
CTModels.constraints
CTModels.control
CTModels.control_components
CTModels.control_constraints_box
CTModels.control_dimension
CTModels.control_name
CTModels.criterion
CTModels.dim_boundary_constraints_nl
CTModels.dim_control_constraints_box
CTModels.dim_path_constraints_nl
CTModels.dim_state_constraints_box
CTModels.dim_variable_constraints_box
CTModels.dynamics
CTModels.final_time
CTModels.final_time
CTModels.final_time
CTModels.final_time
CTModels.final_time
CTModels.final_time_name
CTModels.get_build_examodel
CTModels.get_build_examodel
CTModels.has_fixed_final_time
CTModels.has_fixed_initial_time
CTModels.has_free_final_time
CTModels.has_free_initial_time
CTModels.has_lagrange_cost
CTModels.has_mayer_cost
CTModels.initial_time
CTModels.initial_time
CTModels.initial_time
CTModels.initial_time_name
CTModels.is_autonomous
CTModels.is_autonomous
CTModels.isempty_constraints
CTModels.lagrange
CTModels.lagrange
CTModels.mayer
CTModels.mayer
CTModels.objective
CTModels.path_constraints_nl
CTModels.state
CTModels.state_components
CTModels.state_constraints_box
CTModels.state_dimension
CTModels.state_name
CTModels.time_name
CTModels.times
CTModels.variable
CTModels.variable_components
CTModels.variable_constraints_box
CTModels.variable_dimension
CTModels.variable_name
In the examples in the documentation below, the methods are not prefixed by the module name even if they are private.
julia> using CTModels
julia> x = 1
julia> private_fun(x) # throw an error
must be replaced by
julia> using CTModels
julia> x = 1
julia> CTModels.private_fun(x)
However, if the method is reexported by another package, then, there is no need of prefixing.
julia> module OptimalControl
import CTModels: private_fun
export private_fun
end
julia> using OptimalControl
julia> x = 1
julia> private_fun(x)
Documentation
CTModels.append_box_constraints!
— Methodappend_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 rangerg
will be appended.lbs::Vector{<:Real}
: Vector of lower bounds to whichlb
will be appended.ubs::Vector{<:Real}
: Vector of upper bounds to whichub
will be appended.labels::Vector{String}
: Vector of labels to which thelabel
will 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
, andlabels
vectors in-place.
CTModels.boundary_constraints_nl
— Methodboundary_constraints_nl(
ocp::CTModels.Model{<:CTModels.TimeDependence, <:CTModels.TimesModel, <:CTModels.AbstractStateModel, <:CTModels.AbstractControlModel, <:CTModels.AbstractVariableModel, <:Function, <:CTModels.AbstractObjectiveModel, <:CTModels.ConstraintsModel{<:Tuple, TB<:Tuple}}
) -> Any
Return the nonlinear boundary constraints.
CTModels.build
— Methodbuild(
pre_ocp::CTModels.PreModel;
build_examodel
) -> CTModels.Model{TD, var"#s182", var"#s1821", var"#s1822", var"#s1823", var"#s1824", var"#s1825", 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"#s182"<:CTModels.AbstractTimesModel, var"#s1821"<:CTModels.AbstractStateModel, var"#s1822"<:CTModels.AbstractControlModel, var"#s1823"<:CTModels.AbstractVariableModel, var"#s1824"<:Function, var"#s1825"<: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)
CTModels.build
— Methodbuild(
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)
CTModels.constraints
— Methodconstraints(
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.
CTModels.control
— Methodcontrol(
ocp::CTModels.Model{<:CTModels.TimeDependence, <:CTModels.TimesModel, <:CTModels.AbstractStateModel, T<:CTModels.AbstractControlModel}
) -> CTModels.AbstractControlModel
Return the control struct.
CTModels.control_components
— Methodcontrol_components(ocp::CTModels.Model) -> Vector{String}
Return the names of the components of the control.
CTModels.control_constraints_box
— Methodcontrol_constraints_box(
ocp::CTModels.Model{<:CTModels.TimeDependence, <:CTModels.TimesModel, <:CTModels.AbstractStateModel, <:CTModels.AbstractControlModel, <:CTModels.AbstractVariableModel, <:Function, <:CTModels.AbstractObjectiveModel, <:CTModels.ConstraintsModel{<:Tuple, <:Tuple, <:Tuple, TC<:Tuple}}
) -> Any
Return the box constraints on control.
CTModels.control_dimension
— Methodcontrol_dimension(ocp::CTModels.Model) -> Int64
Return the control dimension.
CTModels.control_name
— Methodcontrol_name(ocp::CTModels.Model) -> String
Return the name of the control.
CTModels.criterion
— Methodcriterion(ocp::CTModels.Model) -> Symbol
Return the type of criterion (:min or :max).
CTModels.dim_boundary_constraints_nl
— Methoddim_boundary_constraints_nl(ocp::CTModels.Model) -> Int64
Return the dimension of the boundary constraints.
CTModels.dim_control_constraints_box
— Methoddim_control_constraints_box(ocp::CTModels.Model) -> Int64
Return the dimension of box constraints on control.
CTModels.dim_path_constraints_nl
— Methoddim_path_constraints_nl(ocp::CTModels.Model) -> Int64
Return the dimension of nonlinear path constraints.
CTModels.dim_state_constraints_box
— Methoddim_state_constraints_box(ocp::CTModels.Model) -> Int64
Return the dimension of box constraints on state.
CTModels.dim_variable_constraints_box
— Methoddim_variable_constraints_box(ocp::CTModels.Model) -> Int64
Return the dimension of box constraints on variable.
CTModels.dynamics
— Methoddynamics(
ocp::CTModels.Model{<:CTModels.TimeDependence, <:CTModels.AbstractTimesModel, <:CTModels.AbstractStateModel, <:CTModels.AbstractControlModel, <:CTModels.AbstractVariableModel, D<:Function}
) -> Function
Return the dynamics.
CTModels.final_time
— Methodfinal_time(
ocp::CTModels.AbstractModel,
variable::AbstractVector
) -> Any
CTModels.final_time
— Methodfinal_time(ocp::CTModels.AbstractModel) -> Real
CTModels.final_time
— Methodfinal_time(
ocp::CTModels.Model{<:CTModels.TimeDependence, <:CTModels.TimesModel{<:CTModels.AbstractTimeModel, CTModels.FixedTimeModel{T<:Real}}}
) -> Real
Return the final time, for a fixed final time.
CTModels.final_time
— Methodfinal_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.
CTModels.final_time
— Methodfinal_time(
ocp::CTModels.Model{<:CTModels.TimeDependence, <:CTModels.TimesModel{<:CTModels.AbstractTimeModel, CTModels.FreeTimeModel}},
variable::Real
) -> Real
Return the final time, for a free final time.
CTModels.final_time_name
— Methodfinal_time_name(ocp::CTModels.Model) -> String
Return the name of the final time.
CTModels.get_build_examodel
— Methodget_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.
CTModels.get_build_examodel
— Methodget_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.
CTModels.has_fixed_final_time
— Methodhas_fixed_final_time(ocp::CTModels.Model) -> Bool
Check if the final time is fixed.
CTModels.has_fixed_initial_time
— Methodhas_fixed_initial_time(ocp::CTModels.Model) -> Bool
Check if the initial time is fixed.
CTModels.has_free_final_time
— Methodhas_free_final_time(ocp::CTModels.Model) -> Bool
Check if the final time is free.
CTModels.has_free_initial_time
— Methodhas_free_initial_time(ocp::CTModels.Model) -> Bool
Check if the initial time is free.
CTModels.has_lagrange_cost
— Methodhas_lagrange_cost(ocp::CTModels.Model) -> Bool
Check if the model has a Lagrange cost.
CTModels.has_mayer_cost
— Methodhas_mayer_cost(ocp::CTModels.Model) -> Bool
Check if the model has a Mayer cost.
CTModels.initial_time
— Methodinitial_time(
ocp::CTModels.Model{<:CTModels.TimeDependence, <:CTModels.TimesModel{CTModels.FixedTimeModel{T<:Real}}}
) -> Real
Return the initial time, for a fixed initial time.
CTModels.initial_time
— Methodinitial_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.
CTModels.initial_time
— Methodinitial_time(
ocp::CTModels.Model{<:CTModels.TimeDependence, <:CTModels.TimesModel{CTModels.FreeTimeModel}},
variable::Real
) -> Real
Return the initial time, for a free initial time.
CTModels.initial_time_name
— Methodinitial_time_name(ocp::CTModels.Model) -> String
Return the name of the initial time.
CTModels.is_autonomous
— Methodis_autonomous(
_::CTModels.Model{CTModels.Autonomous, <:CTModels.TimesModel}
) -> Bool
Return true
.
CTModels.is_autonomous
— Methodis_autonomous(
_::CTModels.Model{CTModels.NonAutonomous, <:CTModels.TimesModel}
) -> Bool
Return true
.
CTModels.isempty_constraints
— Methodisempty_constraints(ocp::CTModels.Model) -> Bool
Return true if the model has constraints or false if not.
CTModels.lagrange
— Methodlagrange(
ocp::CTModels.Model{<:CTModels.TimeDependence, <:CTModels.AbstractTimesModel, <:CTModels.AbstractStateModel, <:CTModels.AbstractControlModel, <:CTModels.AbstractVariableModel, <:Function, <:CTModels.BolzaObjectiveModel{<:Function, L<:Function}}
) -> Any
Return the Lagrange cost.
CTModels.lagrange
— Methodlagrange(
ocp::CTModels.Model{<:CTModels.TimeDependence, <:CTModels.AbstractTimesModel, <:CTModels.AbstractStateModel, <:CTModels.AbstractControlModel, <:CTModels.AbstractVariableModel, <:Function, CTModels.LagrangeObjectiveModel{L<:Function}}
) -> Function
Return the Lagrange cost.
CTModels.mayer
— Methodmayer(
ocp::CTModels.Model{<:CTModels.TimeDependence, <:CTModels.AbstractTimesModel, <:CTModels.AbstractStateModel, <:CTModels.AbstractControlModel, <:CTModels.AbstractVariableModel, <:Function, <:CTModels.BolzaObjectiveModel{M<:Function}}
) -> Any
Return the Mayer cost.
CTModels.mayer
— Methodmayer(
ocp::CTModels.Model{<:CTModels.TimeDependence, <:CTModels.AbstractTimesModel, <:CTModels.AbstractStateModel, <:CTModels.AbstractControlModel, <:CTModels.AbstractVariableModel, <:Function, <:CTModels.MayerObjectiveModel{M<:Function}}
) -> Any
Return the Mayer cost.
CTModels.objective
— Methodobjective(
ocp::CTModels.Model{<:CTModels.TimeDependence, <:CTModels.AbstractTimesModel, <:CTModels.AbstractStateModel, <:CTModels.AbstractControlModel, <:CTModels.AbstractVariableModel, <:Function, O<:CTModels.AbstractObjectiveModel}
) -> CTModels.AbstractObjectiveModel
Return the objective struct.
CTModels.path_constraints_nl
— Methodpath_constraints_nl(
ocp::CTModels.Model{<:CTModels.TimeDependence, <:CTModels.TimesModel, <:CTModels.AbstractStateModel, <:CTModels.AbstractControlModel, <:CTModels.AbstractVariableModel, <:Function, <:CTModels.AbstractObjectiveModel, <:CTModels.ConstraintsModel{TP<:Tuple}}
) -> Any
Return the nonlinear path constraints.
CTModels.state
— Methodstate(
ocp::CTModels.Model{<:CTModels.TimeDependence, <:CTModels.TimesModel, T<:CTModels.AbstractStateModel}
) -> CTModels.AbstractStateModel
Return the state struct.
CTModels.state_components
— Methodstate_components(ocp::CTModels.Model) -> Vector{String}
Return the names of the components of the state.
CTModels.state_constraints_box
— Methodstate_constraints_box(
ocp::CTModels.Model{<:CTModels.TimeDependence, <:CTModels.TimesModel, <:CTModels.AbstractStateModel, <:CTModels.AbstractControlModel, <:CTModels.AbstractVariableModel, <:Function, <:CTModels.AbstractObjectiveModel, <:CTModels.ConstraintsModel{<:Tuple, <:Tuple, TS<:Tuple}}
) -> Any
Return the box constraints on state.
CTModels.state_dimension
— Methodstate_dimension(ocp::CTModels.Model) -> Int64
Return the state dimension.
CTModels.state_name
— Methodstate_name(ocp::CTModels.Model) -> String
Return the name of the state.
CTModels.time_name
— Methodtime_name(ocp::CTModels.Model) -> String
Return the name of the time.
CTModels.times
— Methodtimes(
ocp::CTModels.Model{<:CTModels.TimeDependence, T<:CTModels.TimesModel}
) -> CTModels.TimesModel
Return the times struct.
CTModels.variable
— Methodvariable(
ocp::CTModels.Model{<:CTModels.TimeDependence, <:CTModels.TimesModel, <:CTModels.AbstractStateModel, <:CTModels.AbstractControlModel, T<:CTModels.AbstractVariableModel}
) -> CTModels.AbstractVariableModel
Return the variable struct.
CTModels.variable_components
— Methodvariable_components(ocp::CTModels.Model) -> Vector{String}
Return the names of the components of the variable.
CTModels.variable_constraints_box
— Methodvariable_constraints_box(
ocp::CTModels.Model{<:CTModels.TimeDependence, <:CTModels.TimesModel, <:CTModels.AbstractStateModel, <:CTModels.AbstractControlModel, <:CTModels.AbstractVariableModel, <:Function, <:CTModels.AbstractObjectiveModel, <:CTModels.ConstraintsModel{<:Tuple, <:Tuple, <:Tuple, <:Tuple, TV<:Tuple}}
) -> Any
Return the box constraints on variable.
CTModels.variable_dimension
— Methodvariable_dimension(ocp::CTModels.Model) -> Int64
Return the variable dimension.
CTModels.variable_name
— Methodvariable_name(ocp::CTModels.Model) -> String
Return the name of the variable.