Control

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.componentsMethod
components(
    model::CTModels.ControlModelSolution
) -> Vector{String}

Get the names of the control components from the solution.

Arguments

  • model::ControlModelSolution: The control model solution.

Returns

  • Vector{String}: A list of control component names.
CTModels.componentsMethod
components(model::CTModels.ControlModel) -> Vector{String}

Get the names of the control components.

Arguments

  • model::ControlModel: The control model.

Returns

  • Vector{String}: A list of control component names.

Example

julia> components(controlmodel)
["u₁", "u₂"]
CTModels.control!Method
control!(ocp::CTModels.PreModel, m::Int64)
control!(
    ocp::CTModels.PreModel,
    m::Int64,
    name::Union{String, Symbol}
)
control!(
    ocp::CTModels.PreModel,
    m::Int64,
    name::Union{String, Symbol},
    components_names::Array{T2<:Union{String, Symbol}, 1}
)

Define the control input for a given optimal control problem model.

This function sets the control dimension and optionally allows specifying the control name and the names of its components.

Note

This function should be called only once per model. Calling it again will raise an error.

Arguments

  • ocp::PreModel: The model to which the control will be added.
  • m::Dimension: The control input dimension (must be greater than 0).
  • name::Union{String,Symbol} (optional): The name of the control variable (default: "u").
  • components_names::Vector{<:Union{String,Symbol}} (optional): Names of the control components (default: automatically generated).

Examples

julia> control!(ocp, 1)
julia> control_dimension(ocp)
1
julia> control_components(ocp)
["u"]

julia> control!(ocp, 1, "v")
julia> control_components(ocp)
["v"]

julia> control!(ocp, 2)
julia> control_components(ocp)
["u₁", "u₂"]

julia> control!(ocp, 2, :v)
julia> control_components(ocp)
["v₁", "v₂"]

julia> control!(ocp, 2, "v", ["a", "b"])
julia> control_components(ocp)
["a", "b"]
CTModels.dimensionMethod
dimension(model::CTModels.ControlModelSolution) -> Int64

Get the control input dimension from the solution.

Arguments

  • model::ControlModelSolution: The control model solution.

Returns

  • Dimension: The number of control components.
CTModels.dimensionMethod
dimension(model::CTModels.ControlModel) -> Int64

Get the control input dimension.

Arguments

  • model::ControlModel: The control model.

Returns

  • Dimension: The number of control components.
CTModels.nameMethod
name(model::CTModels.ControlModelSolution) -> String

Get the name of the control variable from the solution.

Arguments

  • model::ControlModelSolution: The control model solution.

Returns

  • String: The name of the control.
CTModels.nameMethod
name(model::CTModels.ControlModel) -> String

Get the name of the control variable.

Arguments

  • model::ControlModel: The control model.

Returns

  • String: The name of the control.

Example

julia> name(controlmodel)
"u"
CTModels.valueMethod
value(
    model::CTModels.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.