API

This page is a dump of all the docstrings found in the code.

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

Fields

  • mayer::Function

  • lagrange::Function

  • criterion::Symbol

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}}}

CTModels.ControlModelType
struct ControlModel <: CTModels.AbstractControlModel

Fields

  • name::String

  • components::Vector{String}

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

Fields

  • name::String

  • components::Vector{String}

  • value::Function

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}

CTModels.FixedTimeModelType
struct FixedTimeModel{T<:Real} <: CTModels.AbstractTimeModel

Fields

  • time::Real

  • name::String

CTModels.FreeTimeModelType
struct FreeTimeModel <: CTModels.AbstractTimeModel

Fields

  • index::Int64

  • name::String

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)
CTModels.LagrangeObjectiveModelType
struct LagrangeObjectiveModel{TL<:Function} <: CTModels.AbstractObjectiveModel

Fields

  • lagrange::Function

  • criterion::Symbol

CTModels.MayerObjectiveModelType
struct MayerObjectiveModel{TM<:Function} <: CTModels.AbstractObjectiveModel

Fields

  • mayer::Function

  • criterion::Symbol

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

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

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

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}

CTModels.StateModelType
struct StateModel <: CTModels.AbstractStateModel

Fields

  • name::String

  • components::Vector{String}

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

Fields

  • name::String

  • components::Vector{String}

  • value::Function

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

Fields

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

Fields

  • initial::CTModels.AbstractTimeModel

  • final::CTModels.AbstractTimeModel

  • time_name::String

CTModels.VariableModelType
struct VariableModel <: CTModels.AbstractVariableModel

Fields

  • name::String

  • components::Vector{String}

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

Fields

  • name::String

  • components::Vector{String}

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

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

Return if the constraints model is not empty.

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

Print the optimal control problem.

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

Print the optimal control problem.

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

Prints the solution.

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.

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.

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.

CTModels.__control_nameMethod
__control_name() -> String

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

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.

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.

CTModels.__state_nameMethod
__state_name() -> String

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

CTModels.__time_nameMethod
__time_name() -> String

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

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.

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".

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

Return the boundary constraints of the optimal control solution.

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

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

CTModels.boundary_constraints_nlMethod
boundary_constraints_nl(
    model::CTModels.ConstraintsModel{<:Tuple, TB}
) -> Any

Get the nonlinear boundary constraints from the model.

CTModels.boundary_constraints_nlMethod
boundary_constraints_nl(
    ocp::CTModels.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.

CTModels.buildFunctionalInitMethod
buildFunctionalInit(data, time, dim) -> CTModels.var"#14#15"

Build functional initialization: general interpolation case

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

Build functional initialization: function case

CTModels.buildFunctionalInitMethod
buildFunctionalInit(
    data::Nothing,
    time,
    dim
) -> CTModels.var"#14#15"

Build functional initialization: default case

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

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.

CTModels.build_modelMethod
build_model(
    pre_ocp::CTModels.PreModel
) -> CTModels.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.

CTModels.build_solutionMethod
build_solution(
    ocp::CTModels.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.
CTModels.checkDimMethod
checkDim(actual_dim, target_dim)

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

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

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

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

Get the components names of the control from the model.

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

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

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

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

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

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

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

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

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

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

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

Add a constraint to a pre-model.

CTModels.constraintMethod
constraint(ocp::CTModels.Model, label::Symbol) -> Tuple

Get a labelled constraint from the model.

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

Get the constraints from the model.

CTModels.constraints_violationMethod
constraints_violation(sol::CTModels.Solution) -> Float64

Return the constraints violation of the optimal control solution.

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"]
CTModels.controlMethod
control(
    ocp::CTModels.Model{<:CTModels.TimesModel, <:CTModels.AbstractStateModel, T<:CTModels.AbstractControlModel}
) -> CTModels.AbstractControlModel

Get the control from the model.

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
CTModels.control_componentsMethod
control_components(ocp::CTModels.Model) -> Vector{String}

Get the components names of the control from the model.

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

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

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

Get the control box constraints from the model.

CTModels.control_constraints_boxMethod
control_constraints_box(
    ocp::CTModels.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.

CTModels.control_constraints_lb_dualMethod
control_constraints_lb_dual(
    sol::CTModels.Solution
) -> Function

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

CTModels.control_constraints_ub_dualMethod
control_constraints_ub_dual(
    sol::CTModels.Solution
) -> Function

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

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

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

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

Get the name of the control from the model.

CTModels.control_nameMethod
control_name(sol::CTModels.Solution) -> String

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

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)
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
CTModels.criterionMethod
criterion(model::CTModels.BolzaObjectiveModel) -> Symbol

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

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

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

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

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

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

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

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

Set the model definition of the optimal control problem.

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

Return the model definition of the optimal control problem.

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

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

CTModels.dim_path_constraints_nlMethod
dim_path_constraints_nl(
    model::CTModels.ConstraintsModel
) -> Int64

Return the dimension of nonlinear path constraints.

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

Get the control dimension from the model solution.

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

Get the control dimension from the model.

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

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

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

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

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

Get the dimension of the state from the state model.

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

Get the variable dimension from the variable model solution.

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

Get the variable dimension from the variable model.

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

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

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

Get the dynamics from the model.

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

Get the final time from the times model.

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

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

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.

CTModels.final_timeMethod
final_time(
    ocp::CTModels.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.

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.

CTModels.final_time_nameMethod
final_time_name(ocp::CTModels.Model) -> String

Get the name of the final time from the model.

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

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

CTModels.final_time_nameMethod
final_time_name(model::CTModels.TimesModel) -> String

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

CTModels.formatDataMethod
formatData(data) -> Any

Convert matrix to vector of vectors (could be expanded)

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.

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.

CTModels.has_fixed_initial_timeMethod
has_fixed_initial_time(
    times::CTModels.TimesModel{CTModels.FreeTimeModel}
) -> Bool

Check if the initial time is free. Return false.

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.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Get the initial time from the times model.

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

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

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.

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

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

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.

CTModels.initial_time_nameMethod
initial_time_name(ocp::CTModels.Model) -> String

Get the name of the initial time from the model.

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

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

CTModels.initial_time_nameMethod
initial_time_name(model::CTModels.TimesModel) -> String

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

CTModels.is_empty_time_gridMethod
is_empty_time_grid(sol::CTModels.Solution) -> Bool

Check if the time grid is empty from the solution.

CTModels.isaVectVectMethod
isaVectVect(data) -> Bool

Return true if argument is a vector of vectors

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

Return if the constraints from the model are not empty.

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

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

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

Get the Lagrange function of the Bolza objective model.

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

Get the Lagrange function of the Lagrange objective model.

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

Get the Lagrange cost from the model.

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

Get the Lagrange cost from the model.

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.

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

Get the Mayer function of the Bolza objective model.

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

Get the Mayer function of the Mayer objective model.

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

Get the Mayer cost from the model.

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

Get the Mayer cost from the model.

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

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

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

Get the name of the control from the model solution.

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

Get the name of the control from the model.

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

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

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

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

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

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

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

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

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

Get the name of the state from the state model.

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

Get the variable name from the variable model solution.

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

Get the variable name from the variable model.

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)

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

Get the objective from the model.

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.

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

Return the path constraints of the optimal control solution.

CTModels.path_constraints_dualMethod
path_constraints_dual(sol::CTModels.Solution) -> Function

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

CTModels.path_constraints_nlMethod
path_constraints_nl(
    model::CTModels.ConstraintsModel{TP}
) -> Any

Get the nonlinear path constraints from the model.

CTModels.path_constraints_nlMethod
path_constraints_nl(
    ocp::CTModels.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.

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"]
CTModels.stateMethod
state(
    ocp::CTModels.Model{<:CTModels.TimesModel, T<:CTModels.AbstractStateModel}
) -> CTModels.AbstractStateModel

Get the state from the model.

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)
CTModels.state_componentsMethod
state_components(ocp::CTModels.Model) -> Vector{String}

Get the components names of the state from the model.

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

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

CTModels.state_constraints_boxMethod
state_constraints_box(
    model::CTModels.ConstraintsModel{<:Tuple, <:Tuple, TS}
) -> Any

Get the state box constraints from the model.

CTModels.state_constraints_boxMethod
state_constraints_box(
    ocp::CTModels.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.

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.

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.

CTModels.state_dimensionMethod
state_dimension(ocp::CTModels.Model) -> Int64

Get the state dimension from the model.

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

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

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

Get the name of the state from the model.

CTModels.state_nameMethod
state_name(sol::CTModels.Solution) -> String

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

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

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

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

Return the success status of the optimal control solution.

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  
CTModels.timeMethod
time(model::CTModels.FixedTimeModel{T<:Real}) -> Real

Get the time from the fixed time model.

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

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

Get the name of the time from the model.

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

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

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

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

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

Get the times from the model.

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

Get the control function value from the model solution.

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

Get the state function from the state model solution.

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

Get the variable from the variable model solution.

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₂" ])
CTModels.variableMethod
variable(
    ocp::CTModels.Model{<:CTModels.TimesModel, <:CTModels.AbstractStateModel, <:CTModels.AbstractControlModel, T<:CTModels.AbstractVariableModel}
) -> CTModels.AbstractVariableModel

Get the variable from the model.

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)
CTModels.variable_componentsMethod
variable_components(ocp::CTModels.Model) -> Vector{String}

Get the components names of the variable from the model.

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

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

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

Get the variable box constraints from the model.

CTModels.variable_constraints_boxMethod
variable_constraints_box(
    ocp::CTModels.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.

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.

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.

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

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

CTModels.variable_nameMethod
variable_name(ocp::CTModels.Model) -> String

Get the name of the variable from the model.

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

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