CTModels.jl

The CTModels.jl package is part of the control-toolbox ecosystem.

flowchart TD B(<a href='https://control-toolbox.org/OptimalControl.jl/stable/dev-ctbase.html'>CTBase</a>) M(<a href='https://control-toolbox.org/OptimalControl.jl/stable/dev-ctmodels.html'>CTModels</a>) P(<a href='https://control-toolbox.org/OptimalControl.jl/stable/dev-ctparser.html'>CTParser</a>) O(<a href='https://control-toolbox.org/OptimalControl.jl/stable/dev-optimalcontrol.html'>OptimalControl</a>) D(<a href='https://control-toolbox.org/OptimalControl.jl/stable/dev-ctdirect.html'>CTDirect</a>) F(<a href='https://control-toolbox.org/OptimalControl.jl/stable/dev-ctflows.html'>CTFlows</a>) O --> D O --> M O --> F O --> P F --> M O --> B F --> B D --> B D --> M P --> B M --> B style M fill:#FBF275

Index

Documentation

Public

Private

CTModels.BolzaObjectiveModelType
struct BolzaObjectiveModel{TM<:Function, TL<:Function} <: CTModels.AbstractObjectiveModel

Fields

  • mayer::Function

  • lagrange::Function

  • criterion::Symbol

source
CTModels.ConstraintsModelType
struct ConstraintsModel{TP<:Tuple, TB<:Tuple, TS<:Tuple, TC<:Tuple, TV<:Tuple, TC_ALL<:Dict{Symbol, Tuple{Symbol, Union{Function, OrdinalRange{<:Int64}}, AbstractVector{<:Real}, AbstractVector{<:Real}}}} <: CTModels.AbstractConstraintsModel

Fields

  • path_nl::Tuple

  • boundary_nl::Tuple

  • state_box::Tuple

  • control_box::Tuple

  • variable_box::Tuple

  • dict::Dict{Symbol, Tuple{Symbol, Union{Function, OrdinalRange{<:Int64}}, AbstractVector{<:Real}, AbstractVector{<:Real}}}

source
CTModels.ControlModelSolutionType
struct ControlModelSolution{TS<:Function} <: CTModels.AbstractControlModel

Fields

  • name::String

  • components::Vector{String}

  • value::Function

source
CTModels.DualModelType
struct DualModel{PC<:Function, PC_Dual<:Function, BC<:(AbstractVector{<:Real}), BC_Dual<:(AbstractVector{<:Real}), SC_LB_Dual<:Function, SC_UB_Dual<:Function, CC_LB_Dual<:Function, CC_UB_Dual<:Function, VC_LB_Dual<:(AbstractVector{<:Real}), VC_UB_Dual<:(AbstractVector{<:Real})} <: CTModels.AbstractDualModel

Fields

  • path_constraints::Function

  • path_constraints_dual::Function

  • boundary_constraints::AbstractVector{<:Real}

  • boundary_constraints_dual::AbstractVector{<:Real}

  • state_constraints_lb_dual::Function

  • state_constraints_ub_dual::Function

  • control_constraints_lb_dual::Function

  • control_constraints_ub_dual::Function

  • variable_constraints_lb_dual::AbstractVector{<:Real}

  • variable_constraints_ub_dual::AbstractVector{<:Real}

source
CTModels.InitType

Initial guess for OCP, contains

  • functions of time for the state and control variables
  • vector for optimization variables

Initialization data for each field can be left to default or:

  • vector for optimization variables
  • constant / vector / function for state and control
  • existing solution ('warm start') for all fields

Constructors:

  • Init(): default initialization
  • Init(state, control, variable, time): constant vector, function handles and / or matrices / vectors interpolated along given time grid
  • Init(sol): from existing solution

Examples

julia> init = Init()
julia> init = Init(state=[0.1, 0.2], control=0.3)
julia> init = Init(state=[0.1, 0.2], control=0.3, variable=0.5)
julia> init = Init(state=[0.1, 0.2], controlt=t->sin(t), variable=0.5)
julia> init = Init(state=[[0, 0], [1, 2], [5, -1]], time=[0, .3, 1.], controlt=t->sin(t))
julia> init = Init(sol)
source
CTModels.ModelType
struct Model{TimesModelType<:CTModels.AbstractTimesModel, StateModelType<:CTModels.AbstractStateModel, ControlModelType<:CTModels.AbstractControlModel, VariableModelType<:CTModels.AbstractVariableModel, DynamicsModelType<:Function, ObjectiveModelType<:CTModels.AbstractObjectiveModel, ConstraintsModelType<:CTModels.AbstractConstraintsModel} <: CTModels.AbstractModel

Fields

  • times::CTModels.AbstractTimesModel

  • state::CTModels.AbstractStateModel

  • control::CTModels.AbstractControlModel

  • variable::CTModels.AbstractVariableModel

  • dynamics::Function

  • objective::CTModels.AbstractObjectiveModel

  • constraints::CTModels.AbstractConstraintsModel

  • definition::Expr

source
CTModels.PreModelType
mutable struct PreModel <: CTModels.AbstractModel

Fields

  • times::Union{Nothing, CTModels.AbstractTimesModel}: Default: nothing

  • state::Union{Nothing, CTModels.AbstractStateModel}: Default: nothing

  • control::Union{Nothing, CTModels.AbstractControlModel}: Default: nothing

  • variable::CTModels.AbstractVariableModel: Default: EmptyVariableModel()

  • dynamics::Union{Nothing, Function}: Default: nothing

  • objective::Union{Nothing, CTModels.AbstractObjectiveModel}: Default: nothing

  • constraints::Dict{Symbol, Tuple{Symbol, Union{Function, OrdinalRange{<:Int64}}, AbstractVector{<:Real}, AbstractVector{<:Real}}}: Default: ConstraintsDictType()

  • definition::Union{Nothing, Expr}: Default: nothing

source
CTModels.SolutionType
struct Solution{TimeGridModelType<:CTModels.AbstractTimeGridModel, TimesModelType<:CTModels.AbstractTimesModel, StateModelType<:CTModels.AbstractStateModel, ControlModelType<:CTModels.AbstractControlModel, VariableModelType<:CTModels.AbstractVariableModel, CostateModelType<:Function, ObjectiveValueType<:Real, DualModelType<:CTModels.AbstractDualModel, SolverInfosType<:CTModels.AbstractSolverInfos} <: CTModels.AbstractSolution

Fields

  • time_grid::CTModels.AbstractTimeGridModel

  • times::CTModels.AbstractTimesModel

  • state::CTModels.AbstractStateModel

  • control::CTModels.AbstractControlModel

  • variable::CTModels.AbstractVariableModel

  • costate::Function

  • objective::Real

  • dual::CTModels.AbstractDualModel

  • solver_infos::CTModels.AbstractSolverInfos

source
CTModels.SolverInfosType
struct SolverInfos{TI<:Dict{Symbol, Any}} <: CTModels.AbstractSolverInfos

Fields

  • iterations::Int64

  • stopping::Symbol

  • message::String

  • success::Bool

  • constraints_violation::Float64

  • infos::Dict{Symbol, Any}

source
CTModels.StateModelType
struct StateModel <: CTModels.AbstractStateModel

Fields

  • name::String

  • components::Vector{String}

source
CTModels.StateModelSolutionType
struct StateModelSolution{TS<:Function} <: CTModels.AbstractStateModel

Fields

  • name::String

  • components::Vector{String}

  • value::Function

source
CTModels.TimeGridModelType
struct TimeGridModel{T<:Union{StepRangeLen, AbstractVector{<:Real}}} <: CTModels.AbstractTimeGridModel

Fields

  • value::Union{StepRangeLen, AbstractVector{<:Real}}
source
CTModels.TimesModelType
struct TimesModel{TI<:CTModels.AbstractTimeModel, TF<:CTModels.AbstractTimeModel} <: CTModels.AbstractTimesModel

Fields

  • initial::CTModels.AbstractTimeModel

  • final::CTModels.AbstractTimeModel

  • time_name::String

source
CTModels.VariableModelSolutionType
struct VariableModelSolution{TS<:Union{Real, AbstractVector{<:Real}}} <: CTModels.AbstractVariableModel

Fields

  • name::String

  • components::Vector{String}

  • value::Union{Real, AbstractVector{<:Real}}

source
Base.isemptyMethod
isempty(model::CTModels.ConstraintsModel) -> Bool

Return if the constraints model is not empty.

source
Base.showMethod
show(
    io::IO,
    _::MIME{Symbol("text/plain")},
    ocp::CTModels.PreModel
)

Print the optimal control problem.

source
Base.showMethod
show(
    io::IO,
    _::MIME{Symbol("text/plain")},
    sol::CTModels.Solution
)

Prints the solution.

source
Base.showMethod
show(io::IO, _::MIME{Symbol("text/plain")}, ocp::Model)

Print the optimal control problem.

source
CTModels.__constraint!Method
__constraint!(
    ocp_constraints::Dict{Symbol, Tuple{Symbol, Union{Function, OrdinalRange{<:Int64}}, AbstractVector{<:Real}, AbstractVector{<:Real}}},
    type::Symbol,
    n::Int64,
    m::Int64,
    q::Int64;
    rg,
    f,
    lb,
    ub,
    label
)

Add a constraint to a dictionary of constraints.

source
CTModels.__constraint_labelMethod
__constraint_label() -> Symbol

Used to set the default value of the label of a constraint. A unique value is given to each constraint using the gensym function and prefixing by :unamed.

source
CTModels.__control_componentsMethod
__control_components(
    m::Int64,
    name::String
) -> Vector{String}

Used to set the default value of the names of the controls. The default value is ["u"] for a one dimensional control, and ["u₁", "u₂", ...] for a multi dimensional control.

source
CTModels.__control_nameMethod
__control_name() -> String

Used to set the default value of the names of the control. The default value is "u".

source
CTModels.__criterion_typeMethod
__criterion_type() -> Symbol

Used to set the default value of the type of criterion. Either :min or :max. The default value is :min. The other possible criterion type is :max.

source
CTModels.__state_componentsMethod
__state_components(n::Int64, name::String) -> Vector{String}

Used to set the default value of the names of the states. The default value is ["x"] for a one dimensional state, and ["x₁", "x₂", ...] for a multi dimensional state.

source
CTModels.__state_nameMethod
__state_name() -> String

Used to set the default value of the name of the state. The default value is "x".

source
CTModels.__time_nameMethod
__time_name() -> String

Used to set the default value of the name of the time. The default value is t.

source
CTModels.__variable_componentsMethod
__variable_components(
    q::Int64,
    name::String
) -> Vector{String}

Used to set the default value of the names of the variables. The default value is ["v"] for a one dimensional variable, and ["v₁", "v₂", ...] for a multi dimensional variable.

source
CTModels.__variable_nameMethod
__variable_name(q::Int64) -> String

Used to set the default value of the names of the variables. The default value is "v".

source
CTModels.boundary_constraintsMethod
boundary_constraints(
    sol::CTModels.Solution
) -> AbstractVector{<:Real}

Return the boundary constraints of the optimal control solution.

source
CTModels.boundary_constraints_dualMethod
boundary_constraints_dual(
    sol::CTModels.Solution
) -> AbstractVector{<:Real}

Return the dual of the boundary constraints of the optimal control solution.

source
CTModels.boundary_constraints_nlMethod
boundary_constraints_nl(
    ocp::Model{<:CTModels.TimesModel, <:CTModels.AbstractStateModel, <:CTModels.AbstractControlModel, <:CTModels.AbstractVariableModel, <:Function, <:CTModels.AbstractObjectiveModel, <:CTModels.ConstraintsModel{<:Tuple, TB<:Tuple}}
) -> Any

Get the nonlinear boundary constraints from the model.

source
CTModels.buildFunctionalInitMethod
buildFunctionalInit(
    data::Function,
    time,
    dim
) -> CTModels.var"#16#17"{<:Function}

Build functional initialization: function case

source
CTModels.buildFunctionalInitMethod
buildFunctionalInit(
    data::Union{Real, AbstractVector{<:Real}},
    time,
    dim
) -> Union{CTModels.var"#18#20", CTModels.var"#19#21"}

Build functional initialization: constant / 1D interpolation

source
CTModels.build_constraintsMethod
build_constraints(
    constraints::Dict{Symbol, Tuple{Symbol, Union{Function, OrdinalRange{<:Int64}}, AbstractVector{<:Real}, AbstractVector{<:Real}}}
) -> CTModels.ConstraintsModel{TP, TB, Tuple{Vector{Real}, Vector{Int64}, Vector{Real}}, Tuple{Vector{Real}, Vector{Int64}, Vector{Real}}, Tuple{Vector{Real}, Vector{Int64}, Vector{Real}}, Dict{Symbol, Tuple{Symbol, Union{Function, OrdinalRange{<:Int64}}, AbstractVector{<:Real}, AbstractVector{<:Real}}}} where {TP<:Tuple{Vector{Real}, Any, Vector{Real}}, TB<:Tuple{Vector{Real}, Any, Vector{Real}}}

Build a concrete type constraints model from a dictionary of constraints.

source
CTModels.build_modelMethod
build_model(
    pre_ocp::CTModels.PreModel
) -> Model{TimesModelType, StateModelType, ControlModelType, VariableModelType, DynamicsModelType, ObjectiveModelType, ConstraintsModelType} where {TimesModelType<:CTModels.AbstractTimesModel, StateModelType<:CTModels.AbstractStateModel, ControlModelType<:CTModels.AbstractControlModel, VariableModelType<:CTModels.AbstractVariableModel, DynamicsModelType<:Function, ObjectiveModelType<:CTModels.AbstractObjectiveModel, ConstraintsModelType<:(CTModels.ConstraintsModel{TP, TB, Tuple{Vector{Real}, Vector{Int64}, Vector{Real}}, Tuple{Vector{Real}, Vector{Int64}, Vector{Real}}, Tuple{Vector{Real}, Vector{Int64}, Vector{Real}}, Dict{Symbol, Tuple{Symbol, Union{Function, OrdinalRange{<:Int64}}, AbstractVector{<:Real}, AbstractVector{<:Real}}}} where {TP<:Tuple{Vector{Real}, Any, Vector{Real}}, TB<:Tuple{Vector{Real}, Any, Vector{Real}}})}

Build a concrete type model from a pre-model.

source
CTModels.build_solutionMethod
build_solution(
    ocp::Model,
    T::Vector{Float64},
    X::Union{Function, Matrix{Float64}},
    U::Union{Function, Matrix{Float64}},
    v::Vector{Float64},
    P::Union{Function, Matrix{Float64}};
    objective,
    iterations,
    constraints_violation,
    message,
    stopping,
    success,
    path_constraints,
    path_constraints_dual,
    boundary_constraints,
    boundary_constraints_dual,
    state_constraints_lb_dual,
    state_constraints_ub_dual,
    control_constraints_lb_dual,
    control_constraints_ub_dual,
    variable_constraints_lb_dual,
    variable_constraints_ub_dual
)

Build a solution from the optimal control problem, the time grid, the state, control, variable, and dual variables.

Arguments

  • ocp::Model: the optimal control problem.
  • T::Vector{Float64}: the time grid.
  • X::Matrix{Float64}: the state trajectory.
  • U::Matrix{Float64}: the control trajectory.
  • v::Vector{Float64}: the variable trajectory.
  • P::Matrix{Float64}: the costate trajectory.
  • objective::Float64: the objective value.
  • iterations::Int: the number of iterations.
  • constraints_violation::Float64: the constraints violation.
  • message::String: the message associated to the stopping criterion.
  • stopping::Symbol: the stopping criterion.
  • success::Bool: the success status.
  • path_constraints::Matrix{Float64}: the path constraints.
  • path_constraints_dual::Matrix{Float64}: the dual of the path constraints.
  • boundary_constraints::Vector{Float64}: the boundary constraints.
  • boundary_constraints_dual::Vector{Float64}: the dual of the boundary constraints.
  • state_constraints_lb_dual::Matrix{Float64}: the lower bound dual of the state constraints.
  • state_constraints_ub_dual::Matrix{Float64}: the upper bound dual of the state constraints.
  • control_constraints_lb_dual::Matrix{Float64}: the lower bound dual of the control constraints.
  • control_constraints_ub_dual::Matrix{Float64}: the upper bound dual of the control constraints.
  • variable_constraints_lb_dual::Vector{Float64}: the lower bound dual of the variable constraints.
  • variable_constraints_ub_dual::Vector{Float64}: the upper bound dual of the variable constraints.

Returns

  • sol::Solution: the optimal control solution.
source
CTModels.checkDimMethod
checkDim(actual_dim, target_dim)

Check if actual dimension is equal to target dimension, error otherwise

source
CTModels.componentsMethod
components(
    model::CTModels.ControlModelSolution
) -> Vector{String}

Get the components names of the control from the model solution.

source
CTModels.componentsMethod
components(model::CTModels.ControlModel) -> Vector{String}

Get the components names of the control from the model.

source
CTModels.componentsMethod
components(_::CTModels.EmptyVariableModel) -> Vector{String}

Get the components names of the variable from the empty variable model. Return an empty vector.

source
CTModels.componentsMethod
components(
    model::CTModels.StateModelSolution
) -> Vector{String}

Get the components names of the state from the state model solution.

source
CTModels.componentsMethod
components(model::CTModels.StateModel) -> Vector{String}

Get the components names of the state from the state model.

source
CTModels.componentsMethod
components(
    model::CTModels.VariableModelSolution
) -> Vector{String}

Get the components names of the variable from the variable model solution.

source
CTModels.componentsMethod
components(model::CTModels.VariableModel) -> Vector{String}

Get the components names of the variable from the variable model.

source
CTModels.constraint!Method
constraint!(
    ocp::CTModels.PreModel,
    type::Symbol;
    rg,
    f,
    lb,
    ub,
    label
)

Add a constraint to a pre-model.

source
CTModels.constraintsMethod
constraints(
    ocp::Model{<:CTModels.AbstractTimesModel, <:CTModels.AbstractStateModel, <:CTModels.AbstractControlModel, <:CTModels.AbstractVariableModel, <:Function, <:CTModels.AbstractObjectiveModel, C<:CTModels.AbstractConstraintsModel}
) -> CTModels.AbstractConstraintsModel

Get the constraints from the model.

source
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 dimension and possibly the names of each coordinate.

Note

You must use control! only once to set the control dimension.

Examples

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

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

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

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

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

julia> control!(ocp, 2, "v", ["a", "b"])
julia> control_dimension(ocp)
2
julia> control_components(ocp)
["a", "b"]

julia> control!(ocp, 2, "v", [:a, :b])
julia> control_dimension(ocp)
2
julia> control_components(ocp)
["a", "b"]
source
CTModels.controlMethod
control(
    sol::CTModels.Solution{<:CTModels.AbstractTimeGridModel, <:CTModels.AbstractTimesModel, <:CTModels.AbstractStateModel, <:CTModels.ControlModelSolution{TS<:Function}}
) -> Function

Return the control (function of time) of the optimal control solution.

julia> t0 = time_grid(sol)[1]
julia> u  = control(sol)
julia> u0 = u(t0) # control at initial time
source
CTModels.controlMethod
control(
    ocp::Model{<:CTModels.TimesModel, <:CTModels.AbstractStateModel, T<:CTModels.AbstractControlModel}
) -> CTModels.AbstractControlModel

Get the control from the model.

source
CTModels.control_componentsMethod
control_components(sol::CTModels.Solution) -> Vector{String}

Return the names of the components of the control of the optimal control solution.

source
CTModels.control_constraints_boxMethod
control_constraints_box(
    model::CTModels.ConstraintsModel{<:Tuple, <:Tuple, <:Tuple, TC}
) -> Any

Get the control box constraints from the model.

source
CTModels.control_constraints_boxMethod
control_constraints_box(
    ocp::Model{<:CTModels.TimesModel, <:CTModels.AbstractStateModel, <:CTModels.AbstractControlModel, <:CTModels.AbstractVariableModel, <:Function, <:CTModels.AbstractObjectiveModel, <:CTModels.ConstraintsModel{<:Tuple, <:Tuple, <:Tuple, TC<:Tuple}}
) -> Any

Get the box constraints on control from the model.

source
CTModels.control_dimensionMethod
control_dimension(sol::CTModels.Solution) -> Int64

Return the dimension of the control of the optimal control solution.

source
CTModels.control_discretizedMethod
control_discretized(sol::CTModels.Solution) -> Any

Return the control values at times time_grid(sol) of the optimal control solution or nothing.

julia> u  = control_discretized(sol)
julia> u0 = u[1] # control at initial time
source
CTModels.control_nameMethod
control_name(sol::CTModels.Solution) -> String

Return the name of the control of the optimal control solution.

source
CTModels.costateMethod
costate(
    sol::CTModels.Solution{<:CTModels.AbstractTimeGridModel, <:CTModels.AbstractTimesModel, <:CTModels.AbstractStateModel, <:CTModels.AbstractControlModel, <:CTModels.AbstractVariableModel, Co<:Function}
) -> Function

Return the costate of the optimal control solution.

julia> t0 = time_grid(sol)[1]
julia> p  = costate(sol)
julia> p0 = p(t0)
source
CTModels.costate_discretizedMethod
costate_discretized(sol::CTModels.Solution) -> Any

Return the costate values at times time_grid(sol) of the optimal control solution or nothing.

julia> p  = costate_discretized(sol)
julia> p0 = p[1] # costate at initial time
source
CTModels.criterionMethod
criterion(model::CTModels.BolzaObjectiveModel) -> Symbol

Get the criterion (:min or :max) of the Bolza objective model.

source
CTModels.criterionMethod
criterion(model::CTModels.LagrangeObjectiveModel) -> Symbol

Get the criterion (:min or :max) of the Lagrange objective model.

source
CTModels.criterionMethod
criterion(model::CTModels.MayerObjectiveModel) -> Symbol

Get the criterion (:min or :max) of the Mayer objective model.

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

Get the type of criterion (:min or :max) from the model.

source
CTModels.definition!Method
definition!(ocp::CTModels.PreModel, definition::Expr)

Set the model definition of the optimal control problem.

source
CTModels.definitionMethod
definition(ocp::CTModels.PreModel) -> Union{Nothing, Expr}

Return the model definition of the optimal control problem or nothing.

source
CTModels.definitionMethod
definition(ocp::Model) -> Expr

Return the model definition of the optimal control problem.

source
CTModels.dimensionMethod
dimension(model::CTModels.ControlModelSolution) -> Int64

Get the control dimension from the model solution.

source
CTModels.dimensionMethod
dimension(model::CTModels.ControlModel) -> Int64

Get the control dimension from the model.

source
CTModels.dimensionMethod
dimension(_::CTModels.EmptyVariableModel) -> Int64

Get the variable dimension from the empty variable model. Return 0.

source
CTModels.dimensionMethod
dimension(model::CTModels.StateModelSolution) -> Int64

Get the dimension of the state from the state model solution.

source
CTModels.dimensionMethod
dimension(model::CTModels.StateModel) -> Int64

Get the dimension of the state from the state model.

source
CTModels.dimensionMethod
dimension(model::CTModels.VariableModelSolution) -> Int64

Get the variable dimension from the variable model solution.

source
CTModels.dimensionMethod
dimension(model::CTModels.VariableModel) -> Int64

Get the variable dimension from the variable model.

source
CTModels.dynamics!Method
dynamics!(ocp::CTModels.PreModel, f::Function)

Set the dynamics of the optimal control problem, in a pre-model.

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

Get the dynamics from the model.

source
CTModels.finalMethod
final(
    model::CTModels.TimesModel{<:CTModels.AbstractTimeModel, TF<:CTModels.AbstractTimeModel}
) -> CTModels.AbstractTimeModel

Get the final time from the times model.

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

source
CTModels.final_timeMethod
final_time(
    ocp::Model{<:CTModels.TimesModel{<:CTModels.AbstractTimeModel, CTModels.FixedTimeModel{T<:Real}}}
) -> Real

Get the final time from the model, for a fixed final time.

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

source
CTModels.final_timeMethod
final_time(
    ocp::Model{<:CTModels.TimesModel{<:CTModels.AbstractTimeModel, CTModels.FreeTimeModel}},
    variable::AbstractArray{T<:Real, 1}
) -> Any

Get the final time from the model, for a free final time.

source
CTModels.final_time_nameMethod
final_time_name(sol::CTModels.Solution) -> String

Return the name of the final time of the optimal control solution.

source
CTModels.has_fixed_final_timeMethod
has_fixed_final_time(
    times::CTModels.TimesModel{<:CTModels.AbstractTimeModel, CTModels.FreeTimeModel}
) -> Bool

Check if the final time is free. Return false.

source
CTModels.has_fixed_final_timeMethod
has_fixed_final_time(
    times::CTModels.TimesModel{<:CTModels.AbstractTimeModel, <:CTModels.FixedTimeModel{T<:Real}}
) -> Bool

Check if the final time is fixed. Return true.

source
CTModels.has_fixed_initial_timeMethod
has_fixed_initial_time(
    times::CTModels.TimesModel{<:CTModels.FixedTimeModel{T<:Real}}
) -> Bool

Check if the initial time is fixed. Return true.

source
CTModels.has_lagrange_costMethod
has_lagrange_cost(
    model::CTModels.BolzaObjectiveModel
) -> Bool

Check if the Bolza objective model has a Lagrange function. Return true.

source
CTModels.has_lagrange_costMethod
has_lagrange_cost(
    model::CTModels.LagrangeObjectiveModel
) -> Bool

Check if the Lagrange objective model has a Lagrange function. Return true.

source
CTModels.has_lagrange_costMethod
has_lagrange_cost(
    model::CTModels.MayerObjectiveModel
) -> Bool

Check if the Mayer objective model has a Lagrange function. Return false.

source
CTModels.has_mayer_costMethod
has_mayer_cost(model::CTModels.BolzaObjectiveModel) -> Bool

Check if the Bolza objective model has a Mayer function. Return true.

source
CTModels.has_mayer_costMethod
has_mayer_cost(
    model::CTModels.LagrangeObjectiveModel
) -> Bool

Check if the Lagrange objective model has a Mayer function. Return false.

source
CTModels.has_mayer_costMethod
has_mayer_cost(model::CTModels.MayerObjectiveModel) -> Bool

Check if the Mayer objective model has a Mayer function. Return true.

source
CTModels.indexMethod
index(model::CTModels.FreeTimeModel) -> Int64

Get the index of the time variable from the free time model.

source
CTModels.infosMethod
infos(sol::CTModels.Solution) -> Dict{Symbol, Any}

Return a dictionary of additional infos depending on the solver or nothing.

source
CTModels.initialMethod
initial(
    model::CTModels.TimesModel{TI<:CTModels.AbstractTimeModel}
) -> CTModels.AbstractTimeModel

Get the initial time from the times model.

source
CTModels.initial_timeMethod
initial_time(
    model::CTModels.TimesModel{<:CTModels.FixedTimeModel{T<:Real}}
) -> Real

Get the initial time from the times model, from a fixed initial time model.

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

Get the initial time from the model, for a fixed initial time.

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

source
CTModels.initial_timeMethod
initial_time(
    ocp::Model{<:CTModels.TimesModel{CTModels.FreeTimeModel}},
    variable::AbstractArray{T<:Real, 1}
) -> Any

Get the initial time from the model, for a free initial time.

source
CTModels.initial_time_nameMethod
initial_time_name(sol::CTModels.Solution) -> String

Return the name of the initial time of the optimal control solution.

source
CTModels.iterationsMethod
iterations(sol::CTModels.Solution) -> Int64

Return the number of iterations (if solved by an iterative method) of the optimal control solution.

source
CTModels.lagrangeMethod
lagrange(
    model::CTModels.BolzaObjectiveModel{<:Function, L<:Function}
) -> Function

Get the Lagrange function of the Bolza objective model.

source
CTModels.lagrangeMethod
lagrange(
    model::CTModels.LagrangeObjectiveModel{L<:Function}
) -> Function

Get the Lagrange function of the Lagrange objective model.

source
CTModels.lagrangeMethod
lagrange(
    ocp::Model{<:CTModels.AbstractTimesModel, <:CTModels.AbstractStateModel, <:CTModels.AbstractControlModel, <:CTModels.AbstractVariableModel, <:Function, <:CTModels.BolzaObjectiveModel{<:Function, L<:Function}}
) -> Any

Get the Lagrange cost from the model.

source
CTModels.lagrangeMethod
lagrange(
    ocp::Model{<:CTModels.AbstractTimesModel, <:CTModels.AbstractStateModel, <:CTModels.AbstractControlModel, <:CTModels.AbstractVariableModel, <:Function, CTModels.LagrangeObjectiveModel{L<:Function}}
) -> Function

Get the Lagrange cost from the model.

source
CTModels.matrix2vecFunction
matrix2vec(x::Matrix{<:Real}) -> Vector{<:Vector{<:Real}}
matrix2vec(
    x::Matrix{<:Real},
    dim::Int64
) -> Vector{<:Vector{<:Real}}

Transforms x to a Vector{<:Vector{<:ctNumber}}.

Note. dim ∈ {1, 2} is the dimension along which the matrix is transformed.

source
CTModels.mayerMethod
mayer(
    model::CTModels.BolzaObjectiveModel{M<:Function}
) -> Function

Get the Mayer function of the Bolza objective model.

source
CTModels.mayerMethod
mayer(
    model::CTModels.MayerObjectiveModel{M<:Function}
) -> Function

Get the Mayer function of the Mayer objective model.

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

Get the Mayer cost from the model.

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

Get the Mayer cost from the model.

source
CTModels.messageMethod
message(sol::CTModels.Solution) -> String

Return the message associated to the stopping criterion of the optimal control solution.

source
CTModels.nameMethod
name(model::CTModels.ControlModelSolution) -> String

Get the name of the control from the model solution.

source
CTModels.nameMethod
name(model::CTModels.ControlModel) -> String

Get the name of the control from the model.

source
CTModels.nameMethod
name(_::CTModels.EmptyVariableModel) -> String

Get the variable name from the empty variable model. Return an empty string.

source
CTModels.nameMethod
name(model::CTModels.FixedTimeModel) -> String

Get the name of the time from the fixed time model.

source
CTModels.nameMethod
name(model::CTModels.FreeTimeModel) -> String

Get the name of the time from the free time model.

source
CTModels.nameMethod
name(model::CTModels.StateModelSolution) -> String

Get the name of the state from the state model solution.

source
CTModels.nameMethod
name(model::CTModels.StateModel) -> String

Get the name of the state from the state model.

source
CTModels.nameMethod
name(model::CTModels.VariableModelSolution) -> String

Get the variable name from the variable model solution.

source
CTModels.nameMethod
name(model::CTModels.VariableModel) -> String

Get the variable name from the variable model.

source
CTModels.objective!Function
objective!(ocp::CTModels.PreModel; ...)
objective!(
    ocp::CTModels.PreModel,
    criterion::Symbol;
    mayer,
    lagrange
)

Set the objective of the optimal control problem.

Arguments

  • ocp::PreModel: the optimal control problem.
  • criterion::Symbol: the type of criterion. Either :min or :max. Default is :min.
  • mayer::Union{Function, Nothing}: the Mayer function (inplace). Default is nothing.
  • lagrange::Union{Function, Nothing}: the Lagrange function (inplace). Default is nothing.
Note
  • The state, control and variable must be set before the objective.
  • The objective must not be set before.
  • At least one of the two functions must be given. Please provide a Mayer or a Lagrange function.

Examples

```@example julia> function mayer(x0, xf, v) return x0[1] + xf[1] + v[1] end juila> function lagrange(t, x, u, v) return x[1] + u[1] + v[1] end julia> objective!(ocp, :min, mayer=mayer, lagrange=lagrange)

source
CTModels.objectiveMethod
objective(
    sol::CTModels.Solution{<:CTModels.AbstractTimeGridModel, <:CTModels.AbstractTimesModel, <:CTModels.AbstractStateModel, <:CTModels.AbstractControlModel, <:CTModels.AbstractVariableModel, <:Function, O<:Real}
) -> Real

Return the objective value of the optimal control solution.

source
CTModels.objectiveMethod
objective(
    ocp::Model{<:CTModels.AbstractTimesModel, <:CTModels.AbstractStateModel, <:CTModels.AbstractControlModel, <:CTModels.AbstractVariableModel, <:Function, O<:CTModels.AbstractObjectiveModel}
) -> CTModels.AbstractObjectiveModel

Get the objective from the model.

source
CTModels.path_constraintsMethod
path_constraints(sol::CTModels.Solution) -> Function

Return the path constraints of the optimal control solution.

source
CTModels.path_constraints_nlMethod
path_constraints_nl(
    ocp::Model{<:CTModels.TimesModel, <:CTModels.AbstractStateModel, <:CTModels.AbstractControlModel, <:CTModels.AbstractVariableModel, <:Function, <:CTModels.AbstractObjectiveModel, <:CTModels.ConstraintsModel{TP<:Tuple}}
) -> Any

Get the nonlinear path constraints from the model.

source
CTModels.state!Method
state!(ocp::CTModels.PreModel, n::Int64)
state!(
    ocp::CTModels.PreModel,
    n::Int64,
    name::Union{String, Symbol}
)
state!(
    ocp::CTModels.PreModel,
    n::Int64,
    name::Union{String, Symbol},
    components_names::Array{T2<:Union{String, Symbol}, 1}
)

Define the state dimension and possibly the names of each component.

Note

You must use state! only once to set the state dimension.

Examples

julia> state!(ocp, 1)
julia> state_dimension(ocp)
1
julia> state_components(ocp)
["x"]

julia> state!(ocp, 1, "y")
julia> state_dimension(ocp)
1
julia> state_components(ocp)
["y"]

julia> state!(ocp, 2)
julia> state_dimension(ocp)
2
julia> state_components(ocp)
["x₁", "x₂"]

julia> state!(ocp, 2, :y)
julia> state_dimension(ocp)
2
julia> state_components(ocp)
["y₁", "y₂"]

julia> state!(ocp, 2, "y")
julia> state_dimension(ocp)
2
julia> state_components(ocp)
["y₁", "y₂"]

julia> state!(ocp, 2, "y", ["u", "v"])
julia> state_dimension(ocp)
2
julia> state_components(ocp)
["u", "v"]

julia> state!(ocp, 2, "y", [:u, :v])
julia> state_dimension(ocp)
2
julia> state_components(ocp)
["u", "v"]
source
CTModels.stateMethod
state(
    sol::CTModels.Solution{<:CTModels.AbstractTimeGridModel, <:CTModels.AbstractTimesModel, <:CTModels.StateModelSolution{TS<:Function}}
) -> Function

Return the state (function of time) of the optimal control solution.

julia> t0 = time_grid(sol)[1]
julia> x  = state(sol)
julia> x0 = x(t0)
source
CTModels.stateMethod
state(
    ocp::Model{<:CTModels.TimesModel, T<:CTModels.AbstractStateModel}
) -> CTModels.AbstractStateModel

Get the state from the model.

source
CTModels.state_componentsMethod
state_components(sol::CTModels.Solution) -> Vector{String}

Return the names of the components of the state of the optimal control solution.

source
CTModels.state_constraints_boxMethod
state_constraints_box(
    ocp::Model{<:CTModels.TimesModel, <:CTModels.AbstractStateModel, <:CTModels.AbstractControlModel, <:CTModels.AbstractVariableModel, <:Function, <:CTModels.AbstractObjectiveModel, <:CTModels.ConstraintsModel{<:Tuple, <:Tuple, TS<:Tuple}}
) -> Any

Get the box constraints on state from the model.

source
CTModels.state_constraints_lb_dualMethod
state_constraints_lb_dual(
    sol::CTModels.Solution
) -> Function

Return the lower bound dual of the state constraints of the optimal control solution.

source
CTModels.state_constraints_ub_dualMethod
state_constraints_ub_dual(
    sol::CTModels.Solution
) -> Function

Return the upper bound dual of the state constraints of the optimal control solution.

source
CTModels.state_dimensionMethod
state_dimension(sol::CTModels.Solution) -> Int64

Return the dimension of the state of the optimal control solution.

source
CTModels.state_discretizedMethod
state_discretized(sol::CTModels.Solution) -> Any

Return the state values at times time_grid(sol) of the optimal control solution or nothing.

julia> x  = state_discretized(sol)
julia> x0 = x[1] # state at initial time
source
CTModels.state_nameMethod
state_name(sol::CTModels.Solution) -> String

Return the name of the state of the optimal control solution.

source
CTModels.stoppingMethod
stopping(sol::CTModels.Solution) -> Symbol

Return the stopping criterion (a Symbol) of the optimal control solution.

source
CTModels.successMethod
success(sol::CTModels.Solution) -> Bool

Return the success status of the optimal control solution.

source
CTModels.time!Method
time!(ocp::CTModels.PreModel; t0, tf, ind0, indf, time_name)

Set the initial and final times. We denote by t0 the initial time and tf the final time. The optimal control problem is denoted ocp. When a time is free, then, one must provide the corresponding index of the ocp variable.

Note

You must use time! only once to set either the initial or the final time, or both.

Examples

julia> time!(ocp, t0=0,   tf=1  ) # Fixed t0 and fixed tf
julia> time!(ocp, t0=0,   indf=2) # Fixed t0 and free  tf
julia> time!(ocp, ind0=2, tf=1  ) # Free  t0 and fixed tf
julia> time!(ocp, ind0=2, indf=3) # Free  t0 and free  tf

When you plot a solution of an optimal control problem, the name of the time variable appears. By default, the name is "t". Consider you want to set the name of the time variable to "s".

julia> time!(ocp, t0=0, tf=1, name="s") # name is a String
# or
julia> time!(ocp, t0=0, tf=1, name=:s ) # name is a Symbol  
source
CTModels.timeMethod
time(model::CTModels.FixedTimeModel{T<:Real}) -> Real

Get the time from the fixed time model.

source
CTModels.timeMethod
time(
    model::CTModels.FreeTimeModel,
    variable::AbstractArray{T<:Real, 1}
) -> Any

Get the time from the free time model.

Exceptions

  • If the index of the time variable is not in [1, length(variable)], throw an error.
source
CTModels.time_gridMethod
time_grid(
    sol::CTModels.Solution{<:CTModels.TimeGridModel{T<:Union{StepRangeLen, AbstractVector{<:Real}}}}
) -> Union{StepRangeLen, AbstractVector{<:Real}}

Return the time grid of the optimal control solution.

source
CTModels.time_nameMethod
time_name(sol::CTModels.Solution) -> String

Return the name of the time component of the optimal control solution.

source
CTModels.time_nameMethod
time_name(model::CTModels.TimesModel) -> String

Get the name of the time variable from the times model.

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

Get the times from the model.

source
CTModels.valueMethod
value(
    model::CTModels.ControlModelSolution{TS<:Function}
) -> Function

Get the control function value from the model solution.

source
CTModels.valueMethod
value(
    model::CTModels.StateModelSolution{TS<:Function}
) -> Function

Get the state function from the state model solution.

source
CTModels.valueMethod
value(
    model::CTModels.VariableModelSolution{TS<:Union{Real, AbstractVector{<:Real}}}
) -> Union{Real, AbstractVector{<:Real}}

Get the variable from the variable model solution.

source
CTModels.variable!Method
variable!(ocp::CTModels.PreModel, q::Int64)
variable!(
    ocp::CTModels.PreModel,
    q::Int64,
    name::Union{String, Symbol}
)
variable!(
    ocp::CTModels.PreModel,
    q::Int64,
    name::Union{String, Symbol},
    components_names::Array{T2<:Union{String, Symbol}, 1}
)

Define the variable dimension and possibly the names of each component.

Note

You can use variable! once to set the variable dimension.

Examples

julia> variable!(ocp, 1, "v")
julia> variable!(ocp, 2, "v", [ "v₁", "v₂" ])
source
CTModels.variableMethod
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 of the optimal control solution or nothing.

julia> v  = variable(sol)
source
CTModels.variableMethod
variable(
    ocp::Model{<:CTModels.TimesModel, <:CTModels.AbstractStateModel, <:CTModels.AbstractControlModel, T<:CTModels.AbstractVariableModel}
) -> CTModels.AbstractVariableModel

Get the variable from the model.

source
CTModels.variable_componentsMethod
variable_components(
    sol::CTModels.Solution
) -> Vector{String}

Return the names of the components of the variable of the optimal control solution.

source
CTModels.variable_constraints_boxMethod
variable_constraints_box(
    model::CTModels.ConstraintsModel{<:Tuple, <:Tuple, <:Tuple, <:Tuple, TV}
) -> Any

Get the variable box constraints from the model.

source
CTModels.variable_constraints_boxMethod
variable_constraints_box(
    ocp::Model{<:CTModels.TimesModel, <:CTModels.AbstractStateModel, <:CTModels.AbstractControlModel, <:CTModels.AbstractVariableModel, <:Function, <:CTModels.AbstractObjectiveModel, <:CTModels.ConstraintsModel{<:Tuple, <:Tuple, <:Tuple, <:Tuple, TV<:Tuple}}
) -> Any

Get the box constraints on variable from the model.

source
CTModels.variable_constraints_lb_dualMethod
variable_constraints_lb_dual(
    sol::CTModels.Solution
) -> AbstractVector{<:Real}

Return the lower bound dual of the variable constraints of the optimal control solution.

source
CTModels.variable_constraints_ub_dualMethod
variable_constraints_ub_dual(
    sol::CTModels.Solution
) -> AbstractVector{<:Real}

Return the upper bound dual of the variable constraints of the optimal control solution.

source
CTModels.variable_dimensionMethod
variable_dimension(sol::CTModels.Solution) -> Int64

Return the dimension of the variable of the optimal control solution.

source
CTModels.variable_nameMethod
variable_name(sol::CTModels.Solution) -> String

Return the name of the variable of the optimal control solution.

source