Model

Index

Warning

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!Method
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 range rg will be appended.
  • lbs::Vector{<:Real}: Vector of lower bounds to which lb will be appended.
  • ubs::Vector{<:Real}: Vector of upper bounds to which ub will be appended.
  • labels::Vector{String}: Vector of labels to which the label will be repeated and appended.
  • rg::AbstractVector{Int}: Index range corresponding to the constraint variables.
  • lb::AbstractVector{<:Real}: Lower bounds associated with rg.
  • ub::AbstractVector{<:Real}: Upper bounds associated with rg.
  • 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, and labels vectors in-place.
CTModels.boundary_constraints_nlMethod
boundary_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.buildMethod
build(
    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.buildMethod
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)
CTModels.constraintsMethod
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.

CTModels.controlMethod
control(
    ocp::CTModels.Model{<:CTModels.TimeDependence, <:CTModels.TimesModel, <:CTModels.AbstractStateModel, T<:CTModels.AbstractControlModel}
) -> CTModels.AbstractControlModel

Return the control struct.

CTModels.control_componentsMethod
control_components(ocp::CTModels.Model) -> Vector{String}

Return the names of the components of the control.

CTModels.control_constraints_boxMethod
control_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_nameMethod
control_name(ocp::CTModels.Model) -> String

Return the name of the control.

CTModels.criterionMethod
criterion(ocp::CTModels.Model) -> Symbol

Return the type of criterion (:min or :max).

CTModels.dynamicsMethod
dynamics(
    ocp::CTModels.Model{<:CTModels.TimeDependence, <:CTModels.AbstractTimesModel, <:CTModels.AbstractStateModel, <:CTModels.AbstractControlModel, <:CTModels.AbstractVariableModel, D<:Function}
) -> Function

Return the dynamics.

CTModels.final_timeMethod
final_time(
    ocp::CTModels.AbstractModel,
    variable::AbstractVector
) -> Any
CTModels.final_timeMethod
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.

CTModels.final_timeMethod
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.

CTModels.final_timeMethod
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.

CTModels.get_build_examodelMethod
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.

CTModels.get_build_examodelMethod
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.

CTModels.initial_timeMethod
initial_time(
    ocp::CTModels.Model{<:CTModels.TimeDependence, <:CTModels.TimesModel{CTModels.FixedTimeModel{T<:Real}}}
) -> Real

Return the initial time, for a fixed initial time.

CTModels.initial_timeMethod
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.

CTModels.initial_timeMethod
initial_time(
    ocp::CTModels.Model{<:CTModels.TimeDependence, <:CTModels.TimesModel{CTModels.FreeTimeModel}},
    variable::Real
) -> Real

Return the initial time, for a free initial time.

CTModels.is_autonomousMethod
is_autonomous(
    _::CTModels.Model{CTModels.Autonomous, <:CTModels.TimesModel}
) -> Bool

Return true.

CTModels.is_autonomousMethod
is_autonomous(
    _::CTModels.Model{CTModels.NonAutonomous, <:CTModels.TimesModel}
) -> Bool

Return true.

CTModels.isempty_constraintsMethod
isempty_constraints(ocp::CTModels.Model) -> Bool

Return true if the model has constraints or false if not.

CTModels.lagrangeMethod
lagrange(
    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.lagrangeMethod
lagrange(
    ocp::CTModels.Model{<:CTModels.TimeDependence, <:CTModels.AbstractTimesModel, <:CTModels.AbstractStateModel, <:CTModels.AbstractControlModel, <:CTModels.AbstractVariableModel, <:Function, CTModels.LagrangeObjectiveModel{L<:Function}}
) -> Function

Return the Lagrange cost.

CTModels.mayerMethod
mayer(
    ocp::CTModels.Model{<:CTModels.TimeDependence, <:CTModels.AbstractTimesModel, <:CTModels.AbstractStateModel, <:CTModels.AbstractControlModel, <:CTModels.AbstractVariableModel, <:Function, <:CTModels.BolzaObjectiveModel{M<:Function}}
) -> Any

Return the Mayer cost.

CTModels.mayerMethod
mayer(
    ocp::CTModels.Model{<:CTModels.TimeDependence, <:CTModels.AbstractTimesModel, <:CTModels.AbstractStateModel, <:CTModels.AbstractControlModel, <:CTModels.AbstractVariableModel, <:Function, <:CTModels.MayerObjectiveModel{M<:Function}}
) -> Any

Return the Mayer cost.

CTModels.objectiveMethod
objective(
    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_nlMethod
path_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.stateMethod
state(
    ocp::CTModels.Model{<:CTModels.TimeDependence, <:CTModels.TimesModel, T<:CTModels.AbstractStateModel}
) -> CTModels.AbstractStateModel

Return the state struct.

CTModels.state_componentsMethod
state_components(ocp::CTModels.Model) -> Vector{String}

Return the names of the components of the state.

CTModels.state_constraints_boxMethod
state_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_nameMethod
state_name(ocp::CTModels.Model) -> String

Return the name of the state.

CTModels.time_nameMethod
time_name(ocp::CTModels.Model) -> String

Return the name of the time.

CTModels.timesMethod
times(
    ocp::CTModels.Model{<:CTModels.TimeDependence, T<:CTModels.TimesModel}
) -> CTModels.TimesModel

Return the times struct.

CTModels.variableMethod
variable(
    ocp::CTModels.Model{<:CTModels.TimeDependence, <:CTModels.TimesModel, <:CTModels.AbstractStateModel, <:CTModels.AbstractControlModel, T<:CTModels.AbstractVariableModel}
) -> CTModels.AbstractVariableModel

Return the variable struct.

CTModels.variable_componentsMethod
variable_components(ocp::CTModels.Model) -> Vector{String}

Return the names of the components of the variable.

CTModels.variable_constraints_boxMethod
variable_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_nameMethod
variable_name(ocp::CTModels.Model) -> String

Return the name of the variable.