CTModels.jl
The CTModels.jl package is part of the control-toolbox ecosystem.
Index
CTModels.CTModels
CTModels.AbstractConstraintsModel
CTModels.AbstractControlModel
CTModels.AbstractDualModel
CTModels.AbstractModel
CTModels.AbstractObjectiveModel
CTModels.AbstractSolution
CTModels.AbstractSolverInfos
CTModels.AbstractStateModel
CTModels.AbstractTag
CTModels.AbstractTimeGridModel
CTModels.AbstractTimeModel
CTModels.AbstractTimesModel
CTModels.AbstractVariableModel
CTModels.Autonomous
CTModels.BolzaObjectiveModel
CTModels.ConstraintsDictType
CTModels.ConstraintsModel
CTModels.ControlModel
CTModels.ControlModelSolution
CTModels.Dimension
CTModels.DualModel
CTModels.EmptyTimeGridModel
CTModels.EmptyVariableModel
CTModels.FixedTimeModel
CTModels.FreeTimeModel
CTModels.Init
CTModels.JLD2Tag
CTModels.JSON3Tag
CTModels.LagrangeObjectiveModel
CTModels.MayerObjectiveModel
CTModels.Model
CTModels.NonAutonomous
CTModels.PreModel
CTModels.Solution
CTModels.SolverInfos
CTModels.StateModel
CTModels.StateModelSolution
CTModels.Time
CTModels.TimeDependence
CTModels.TimeGridModel
CTModels.Times
CTModels.TimesDisc
CTModels.TimesModel
CTModels.VariableModel
CTModels.VariableModelSolution
CTModels.ctNumber
CTModels.ctVector
CTModels.__build_dynamics_from_parts
CTModels.__constraint!
CTModels.__constraint_label
CTModels.__constraints
CTModels.__control_components
CTModels.__control_name
CTModels.__criterion_type
CTModels.__filename_export_import
CTModels.__format
CTModels.__is_autonomous_set
CTModels.__is_complete
CTModels.__is_consistent
CTModels.__is_control_set
CTModels.__is_control_set
CTModels.__is_definition_set
CTModels.__is_definition_set
CTModels.__is_dynamics_complete
CTModels.__is_dynamics_set
CTModels.__is_dynamics_set
CTModels.__is_empty
CTModels.__is_objective_set
CTModels.__is_objective_set
CTModels.__is_set
CTModels.__is_state_set
CTModels.__is_state_set
CTModels.__is_times_set
CTModels.__is_times_set
CTModels.__is_variable_empty
CTModels.__is_variable_set
CTModels.__is_variable_set
CTModels.__matrix_dimension_storage
CTModels.__state_components
CTModels.__state_name
CTModels.__time_name
CTModels.__variable_components
CTModels.__variable_name
CTModels.append_box_constraints!
CTModels.boundary_constraints_dual
CTModels.boundary_constraints_dual
CTModels.boundary_constraints_nl
CTModels.boundary_constraints_nl
CTModels.build
CTModels.build
CTModels.buildFunctionalInit
CTModels.buildFunctionalInit
CTModels.buildFunctionalInit
CTModels.buildFunctionalInit
CTModels.buildVectorInit
CTModels.build_solution
CTModels.checkDim
CTModels.components
CTModels.components
CTModels.components
CTModels.components
CTModels.components
CTModels.components
CTModels.components
CTModels.constraint
CTModels.constraint!
CTModels.constraints
CTModels.constraints_violation
CTModels.control
CTModels.control
CTModels.control!
CTModels.control_components
CTModels.control_components
CTModels.control_constraints_box
CTModels.control_constraints_box
CTModels.control_constraints_lb_dual
CTModels.control_constraints_lb_dual
CTModels.control_constraints_ub_dual
CTModels.control_constraints_ub_dual
CTModels.control_dimension
CTModels.control_dimension
CTModels.control_name
CTModels.control_name
CTModels.costate
CTModels.criterion
CTModels.criterion
CTModels.criterion
CTModels.criterion
CTModels.ctinterpolate
CTModels.definition
CTModels.definition
CTModels.definition!
CTModels.dim_boundary_constraints_nl
CTModels.dim_boundary_constraints_nl
CTModels.dim_control_constraints_box
CTModels.dim_control_constraints_box
CTModels.dim_path_constraints_nl
CTModels.dim_path_constraints_nl
CTModels.dim_state_constraints_box
CTModels.dim_state_constraints_box
CTModels.dim_variable_constraints_box
CTModels.dim_variable_constraints_box
CTModels.dimension
CTModels.dimension
CTModels.dimension
CTModels.dimension
CTModels.dimension
CTModels.dimension
CTModels.dimension
CTModels.dual
CTModels.dual_model
CTModels.dynamics
CTModels.dynamics!
CTModels.dynamics!
CTModels.dynamics!
CTModels.export_ocp_solution
CTModels.export_ocp_solution
CTModels.export_ocp_solution
CTModels.final
CTModels.final_time
CTModels.final_time
CTModels.final_time
CTModels.final_time
CTModels.final_time
CTModels.final_time
CTModels.final_time
CTModels.final_time_name
CTModels.final_time_name
CTModels.final_time_name
CTModels.formatData
CTModels.formatTimeGrid
CTModels.get_build_examodel
CTModels.get_build_examodel
CTModels.has_fixed_final_time
CTModels.has_fixed_final_time
CTModels.has_fixed_final_time
CTModels.has_fixed_initial_time
CTModels.has_fixed_initial_time
CTModels.has_fixed_initial_time
CTModels.has_free_final_time
CTModels.has_free_final_time
CTModels.has_free_initial_time
CTModels.has_free_initial_time
CTModels.has_lagrange_cost
CTModels.has_lagrange_cost
CTModels.has_lagrange_cost
CTModels.has_lagrange_cost
CTModels.has_mayer_cost
CTModels.has_mayer_cost
CTModels.has_mayer_cost
CTModels.has_mayer_cost
CTModels.import_ocp_solution
CTModels.import_ocp_solution
CTModels.import_ocp_solution
CTModels.index
CTModels.infos
CTModels.initial
CTModels.initial_time
CTModels.initial_time
CTModels.initial_time
CTModels.initial_time
CTModels.initial_time
CTModels.initial_time_name
CTModels.initial_time_name
CTModels.initial_time_name
CTModels.is_autonomous
CTModels.is_empty_time_grid
CTModels.isaVectVect
CTModels.isempty_constraints
CTModels.iterations
CTModels.lagrange
CTModels.lagrange
CTModels.lagrange
CTModels.lagrange
CTModels.matrix2vec
CTModels.mayer
CTModels.mayer
CTModels.mayer
CTModels.mayer
CTModels.message
CTModels.model
CTModels.name
CTModels.name
CTModels.name
CTModels.name
CTModels.name
CTModels.name
CTModels.name
CTModels.name
CTModels.name
CTModels.objective
CTModels.objective
CTModels.objective!
CTModels.path_constraints_dual
CTModels.path_constraints_dual
CTModels.path_constraints_nl
CTModels.path_constraints_nl
CTModels.state
CTModels.state
CTModels.state!
CTModels.state_components
CTModels.state_components
CTModels.state_constraints_box
CTModels.state_constraints_box
CTModels.state_constraints_lb_dual
CTModels.state_constraints_lb_dual
CTModels.state_constraints_ub_dual
CTModels.state_constraints_ub_dual
CTModels.state_dimension
CTModels.state_dimension
CTModels.state_dimension
CTModels.state_name
CTModels.state_name
CTModels.stopping
CTModels.success
CTModels.time
CTModels.time
CTModels.time!
CTModels.time_grid
CTModels.time_name
CTModels.time_name
CTModels.time_name
CTModels.times
CTModels.to_out_of_place
CTModels.value
CTModels.value
CTModels.value
CTModels.variable
CTModels.variable
CTModels.variable!
CTModels.variable_components
CTModels.variable_components
CTModels.variable_constraints_box
CTModels.variable_constraints_box
CTModels.variable_constraints_lb_dual
CTModels.variable_constraints_lb_dual
CTModels.variable_constraints_ub_dual
CTModels.variable_constraints_ub_dual
CTModels.variable_dimension
CTModels.variable_dimension
CTModels.variable_name
CTModels.variable_name
CTModels.@ensure
Documentation
Public
CTModels.CTModels
— ModuleCTModels
module.
Lists all the imported modules and packages:
Base
Core
DocStringExtensions
Interpolations
MLStyle
Parameters
PrettyTables
List of all the exported names:
RecipesBase.plot
— Methodplot(
sol::CTModels.AbstractSolution,
description::Symbol...;
kwargs...
)
Plot a solution from an optimal control problem.
This function dispatches on a solution type that inherits from AbstractSolution
. It is intended to visualize various components of the solution (such as state trajectories, controls, costates, or any other variables defined in the model).
This function requires the Plots.jl
package to be available. If it is not loaded, a CTBase.ExtensionError(:Plots)
is thrown.
Arguments
sol::AbstractSolution
: A solution object returned by solving a control problem.description::Symbol...
: Optional symbols specifying what to plot (e.g.,:state
,:control
,:costate
, etc.). If empty, a default set of components is plotted.kwargs...
: Additional keyword arguments passed to the underlying plotting routines (e.g.,xlabel
,ylabel
,legend
, etc.).
Returns
- A plot object (if
Plots.jl
is available) visualizing the selected components of the solution.
Example
julia> using Plots
julia> plot(sol, :state, :control, xlabel = "Time", layout = (2,1))
Throws
CTBase.ExtensionError
if thePlots
package is not available or not loaded.
Private
CTModels.TimesDisc
— TypeType alias for a grid of times. This is used to define a discretization of time interval given to solvers.
julia> const TimesDisc = Union{Times, StepRangeLen}
CTModels.AbstractConstraintsModel
— Typeabstract type AbstractConstraintsModel
CTModels.AbstractControlModel
— Typeabstract type AbstractControlModel
CTModels.AbstractDualModel
— Typeabstract type AbstractDualModel
CTModels.AbstractModel
— Typeabstract type AbstractModel
CTModels.AbstractObjectiveModel
— Typeabstract type AbstractObjectiveModel
CTModels.AbstractSolution
— Typeabstract type AbstractSolution
CTModels.AbstractSolverInfos
— Typeabstract type AbstractSolverInfos
CTModels.AbstractStateModel
— Typeabstract type AbstractStateModel
CTModels.AbstractTag
— Typeabstract type AbstractTag
Abstract type for export/import functions, used to choose between JSON or JLD extensions.
CTModels.AbstractTimeGridModel
— Typeabstract type AbstractTimeGridModel
CTModels.AbstractTimeModel
— Typeabstract type AbstractTimeModel
CTModels.AbstractTimesModel
— Typeabstract type AbstractTimesModel
CTModels.AbstractVariableModel
— Typeabstract type AbstractVariableModel
CTModels.Autonomous
— Typeabstract type Autonomous <: CTModels.TimeDependence
CTModels.BolzaObjectiveModel
— Typestruct BolzaObjectiveModel{TM<:Function, TL<:Function} <: CTModels.AbstractObjectiveModel
Fields
mayer::Function
lagrange::Function
criterion::Symbol
CTModels.ConstraintsDictType
— TypeType alias for a dictionnary of constraints. This is used to store constraints before building the model.
julia> const TimesDisc = Union{Times, StepRangeLen}
See also: ConstraintsModel
, PreModel
and Model
.
CTModels.ConstraintsModel
— Typestruct ConstraintsModel{TP<:Tuple, TB<:Tuple, TS<:Tuple, TC<:Tuple, TV<:Tuple} <: CTModels.AbstractConstraintsModel
Fields
path_nl::Tuple
boundary_nl::Tuple
state_box::Tuple
control_box::Tuple
variable_box::Tuple
CTModels.ControlModel
— Typestruct ControlModel <: CTModels.AbstractControlModel
Fields
name::String
components::Vector{String}
CTModels.ControlModelSolution
— Typestruct ControlModelSolution{TS<:Function} <: CTModels.AbstractControlModel
Fields
name::String
components::Vector{String}
value::Function
CTModels.Dimension
— TypeType alias for a dimension. This is used to define the dimension of the state space, the costate space, the control space, etc.
julia> const Dimension = Integer
CTModels.DualModel
— Typestruct DualModel{PC_Dual<:Union{Nothing, Function}, BC_Dual<:Union{Nothing, AbstractVector{<:Real}}, SC_LB_Dual<:Union{Nothing, Function}, SC_UB_Dual<:Union{Nothing, Function}, CC_LB_Dual<:Union{Nothing, Function}, CC_UB_Dual<:Union{Nothing, Function}, VC_LB_Dual<:Union{Nothing, AbstractVector{<:Real}}, VC_UB_Dual<:Union{Nothing, AbstractVector{<:Real}}} <: CTModels.AbstractDualModel
Fields
path_constraints_dual::Union{Nothing, Function}
boundary_constraints_dual::Union{Nothing, AbstractVector{<:Real}}
state_constraints_lb_dual::Union{Nothing, Function}
state_constraints_ub_dual::Union{Nothing, Function}
control_constraints_lb_dual::Union{Nothing, Function}
control_constraints_ub_dual::Union{Nothing, Function}
variable_constraints_lb_dual::Union{Nothing, AbstractVector{<:Real}}
variable_constraints_ub_dual::Union{Nothing, AbstractVector{<:Real}}
CTModels.EmptyTimeGridModel
— Typestruct EmptyTimeGridModel <: CTModels.AbstractTimeGridModel
Fields
CTModels.EmptyVariableModel
— Typestruct EmptyVariableModel <: CTModels.AbstractVariableModel
Fields
CTModels.FixedTimeModel
— Typestruct FixedTimeModel{T<:Real} <: CTModels.AbstractTimeModel
Fields
time::Real
name::String
CTModels.FreeTimeModel
— Typestruct FreeTimeModel <: CTModels.AbstractTimeModel
Fields
index::Int64
name::String
CTModels.Init
— TypeInitial 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 initializationInit(state, control, variable, time)
: constant vector, function handles and / or matrices / vectors interpolated along given time gridInit(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.JLD2Tag
— Typestruct JLD2Tag <: CTModels.AbstractTag
JLD tag for export/import functions.
CTModels.JSON3Tag
— Typestruct JSON3Tag <: CTModels.AbstractTag
JSON tag for export/import functions.
CTModels.LagrangeObjectiveModel
— Typestruct LagrangeObjectiveModel{TL<:Function} <: CTModels.AbstractObjectiveModel
Fields
lagrange::Function
criterion::Symbol
CTModels.MayerObjectiveModel
— Typestruct MayerObjectiveModel{TM<:Function} <: CTModels.AbstractObjectiveModel
Fields
mayer::Function
criterion::Symbol
CTModels.Model
— Typestruct Model{TD<:CTModels.TimeDependence, TimesModelType<:CTModels.AbstractTimesModel, StateModelType<:CTModels.AbstractStateModel, ControlModelType<:CTModels.AbstractControlModel, VariableModelType<:CTModels.AbstractVariableModel, DynamicsModelType<:Function, ObjectiveModelType<:CTModels.AbstractObjectiveModel, ConstraintsModelType<:CTModels.AbstractConstraintsModel, BuildExaModelType<:Union{Nothing, Function}} <: 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
build_examodel::Union{Nothing, Function}
CTModels.NonAutonomous
— Typeabstract type NonAutonomous <: CTModels.TimeDependence
CTModels.PreModel
— Typemutable struct PreModel <: CTModels.AbstractModel
Fields
times::Union{Nothing, CTModels.AbstractTimesModel}
: Default: nothingstate::Union{Nothing, CTModels.AbstractStateModel}
: Default: nothingcontrol::Union{Nothing, CTModels.AbstractControlModel}
: Default: nothingvariable::CTModels.AbstractVariableModel
: Default: EmptyVariableModel()dynamics::Union{Nothing, Function, Vector{<:Tuple{var"#s52", var"#s53"} where {var"#s52"<:(AbstractRange{<:Int64}), var"#s53"<:Function}}}
: Default: nothingobjective::Union{Nothing, CTModels.AbstractObjectiveModel}
: Default: nothingconstraints::OrderedCollections.OrderedDict{Symbol, Tuple{Symbol, Union{Function, OrdinalRange{<:Int64}}, AbstractVector{<:Real}, AbstractVector{<:Real}}}
: Default: ConstraintsDictType()definition::Union{Nothing, Expr}
: Default: nothingautonomous::Union{Nothing, Bool}
: Default: nothing
CTModels.Solution
— Typestruct 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, ModelType<:CTModels.AbstractModel} <: 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
model::CTModels.AbstractModel
CTModels.SolverInfos
— Typestruct SolverInfos{TI<:Dict{Symbol, Any}} <: CTModels.AbstractSolverInfos
Fields
iterations::Int64
stopping::Symbol
message::String
success::Bool
constraints_violation::Float64
infos::Dict{Symbol, Any}
CTModels.StateModel
— Typestruct StateModel <: CTModels.AbstractStateModel
Fields
name::String
components::Vector{String}
CTModels.StateModelSolution
— Typestruct StateModelSolution{TS<:Function} <: CTModels.AbstractStateModel
Fields
name::String
components::Vector{String}
value::Function
CTModels.Time
— TypeCTModels.TimeDependence
— Typeabstract type TimeDependence
CTModels.TimeGridModel
— Typestruct TimeGridModel{T<:Union{StepRangeLen, AbstractVector{<:Real}}} <: CTModels.AbstractTimeGridModel
Fields
value::Union{StepRangeLen, AbstractVector{<:Real}}
CTModels.Times
— TypeType alias for a vector of times.
julia> const Times = AbstractVector{<:Time}
CTModels.TimesModel
— Typestruct TimesModel{TI<:CTModels.AbstractTimeModel, TF<:CTModels.AbstractTimeModel} <: CTModels.AbstractTimesModel
Fields
initial::CTModels.AbstractTimeModel
final::CTModels.AbstractTimeModel
time_name::String
CTModels.VariableModel
— Typestruct VariableModel <: CTModels.AbstractVariableModel
Fields
name::String
components::Vector{String}
CTModels.VariableModelSolution
— Typestruct VariableModelSolution{TS<:Union{Real, AbstractVector{<:Real}}} <: CTModels.AbstractVariableModel
Fields
name::String
components::Vector{String}
value::Union{Real, AbstractVector{<:Real}}
CTModels.ctNumber
— TypeType alias for a real number.
julia> const ctNumber = Real
CTModels.ctVector
— TypeType alias for a vector of real numbers.
julia> const ctVector = AbstractVector{<:ctNumber}
See also: ctNumber
.
Base.isempty
— Methodisempty(model::CTModels.ConstraintsModel) -> Bool
Return if the constraints model is empty or not.
Arguments
model
: The constraints model to check for emptiness.
Returns
Bool
: Returnstrue
if the model has no constraints,false
otherwise.
Example
# Example of checking if a constraints model is empty
julia> model = ConstraintsModel(...)
julia> isempty(model) # Returns true if there are no constraints
Base.show
— Methodshow(
io::IO,
_::MIME{Symbol("text/plain")},
ocp::CTModels.PreModel
)
Print the optimal control problem.
Base.show
— Methodshow(
io::IO,
_::MIME{Symbol("text/plain")},
sol::CTModels.Solution
)
Prints the solution.
Base.show
— Methodshow(io::IO, _::MIME{Symbol("text/plain")}, ocp::Model)
Print the optimal control problem.
Base.show_default
— Methodshow_default(io::IO, ocp::CTModels.PreModel)
CTModels.__build_dynamics_from_parts
— Method__build_dynamics_from_parts(
parts::Vector{<:Tuple{var"#s53", var"#s52"} where {var"#s53"<:(AbstractRange{<:Int64}), var"#s52"<:Function}}
) -> CTModels.var"#dyn!#64"{Vector{var"#s54"}} where var"#s54"<:(Tuple{var"#s53", var"#s52"} where {var"#s53"<:(AbstractRange{<:Int64}), var"#s52"<:Function})
Build a combined dynamics function from multiple parts.
This function constructs an in-place dynamics function dyn!
by composing several sub-functions, each responsible for updating a specific segment of the output vector.
Arguments
parts::Vector{<:Tuple{<:AbstractRange{<:Int}, <:Function}}
: A vector of tuples, where each tuple contains:- A range specifying the indices in the output vector
val
that the corresponding function updates. - A function
f
with the signature(output_segment, t, x, u, v)
, which updates the slice ofval
indicated by the range.
- A range specifying the indices in the output vector
Returns
dyn!
: A function with signature(val, t, x, u, v)
that updates the full output vectorval
in-place by applying each part function to its assigned segment.
Details
- The returned
dyn!
function calls each part function with a view ofval
restricted to the assigned range. This avoids unnecessary copying and allows efficient updates of sub-vectors. - Each part function is expected to modify its output segment in-place.
Example
# Define two sub-dynamics functions
julia> f1(out, t, x, u, v) = out .= x[1:2] .+ u[1:2]
julia> f2(out, t, x, u, v) = out .= x[3] * v
# Combine them into one dynamics function affecting different parts of the output vector
julia> parts = [(1:2, f1), (3:3, f2)]
julia> dyn! = __build_dynamics_from_parts(parts)
val = zeros(3)
julia> dyn!(val, 0.0, [1.0, 2.0, 3.0], [0.5, 0.5], 2.0)
julia> println(val) # prints [1.5, 2.5, 6.0]
CTModels.__constraint!
— Method__constraint!(
ocp_constraints::OrderedCollections.OrderedDict{Symbol, Tuple{Symbol, Union{Function, OrdinalRange{<:Int64}}, AbstractVector{<:Real}, AbstractVector{<:Real}}},
type::Symbol,
n::Int64,
m::Int64,
q::Int64;
rg,
f,
lb,
ub,
label,
codim_f
)
Add a constraint to a dictionary of constraints.
Arguments
ocp_constraints
: The dictionary of constraints to which the constraint will be added.type
: The type of the constraint. It can be:state
,:control
,:variable
,:boundary
, or:path
.n
: The dimension of the state.m
: The dimension of the control.q
: The dimension of the variable.rg
: The range of the constraint. It can be an integer or a range of integers.f
: The function that defines the constraint. It must return a vector of the same dimension as the constraint.lb
: The lower bound of the constraint. It can be a number or a vector.ub
: The upper bound of the constraint. It can be a number or a vector.label
: The label of the constraint. It must be unique in the dictionary of constraints.
Requirements
- The constraint must not be set before.
- The lower bound
lb
and the upper boundub
cannot be bothnothing
. - The lower bound
lb
and the upper boundub
must have the same length, if both provided.
If rg
and f
are not provided then,
type
must be:state
,:control
, or:variable
.lb
andub
must be of dimensionn
,m
, orq
respectively, when provided.
If rg
is provided, then:
f
must not be provided.type
must be:state
,:control
, or:variable
.rg
must be a range of integers, and must be contained in1:n
,1:m
, or1:q
respectively.
If f
is provided, then:
rg
must not be provided.type
must be:boundary
or:path
.f
must be a function that returns a vector of the same dimension as the constraint.lb
andub
must be of the same dimension as the output off
, when provided.
Example
# Example of adding a state constraint
julia> ocp_constraints = Dict()
__constraint!(ocp_constraints, :state, 3, 2, 1, lb=[0.0], ub=[1.0], label=:my_constraint)
CTModels.__constraint_label
— Method__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.__constraints
— Method__constraints()
Used to set the default value for the constraints.
CTModels.__control_components
— Method__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_name
— Method__control_name() -> String
Used to set the default value of the names of the control. The default value is "u"
.
CTModels.__criterion_type
— Method__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.__filename_export_import
— Method__filename_export_import() -> String
CTModels.__format
— Method__format() -> Symbol
Used to set the default value of the format of the file to be used for export and import.
CTModels.__is_autonomous_set
— Method__is_autonomous_set(ocp::CTModels.PreModel) -> Bool
CTModels.__is_complete
— Method__is_complete(ocp::CTModels.PreModel) -> Bool
Return true if the PreModel can be built into a Model.
CTModels.__is_consistent
— Method__is_consistent(ocp::CTModels.PreModel) -> Bool
Return true if all the required fields are set in the PreModel.
CTModels.__is_control_set
— Method__is_control_set(ocp::CTModels.PreModel) -> Bool
CTModels.__is_control_set
— Method__is_control_set(ocp::Model) -> Bool
CTModels.__is_definition_set
— Method__is_definition_set(ocp::CTModels.PreModel) -> Bool
CTModels.__is_definition_set
— Method__is_definition_set(ocp::Model) -> Bool
CTModels.__is_dynamics_complete
— Method__is_dynamics_complete(ocp::CTModels.PreModel) -> Bool
CTModels.__is_dynamics_set
— Method__is_dynamics_set(ocp::CTModels.PreModel) -> Bool
CTModels.__is_dynamics_set
— Method__is_dynamics_set(ocp::Model) -> Bool
CTModels.__is_empty
— Method__is_empty(ocp::CTModels.PreModel) -> Bool
Return true if nothing has been set.
CTModels.__is_objective_set
— Method__is_objective_set(ocp::CTModels.PreModel) -> Bool
CTModels.__is_objective_set
— Method__is_objective_set(ocp::Model) -> Bool
CTModels.__is_set
— Method__is_set(x) -> Bool
CTModels.__is_state_set
— Method__is_state_set(ocp::CTModels.PreModel) -> Bool
CTModels.__is_state_set
— Method__is_state_set(ocp::Model) -> Bool
CTModels.__is_times_set
— Method__is_times_set(ocp::CTModels.PreModel) -> Bool
CTModels.__is_times_set
— Method__is_times_set(ocp::Model) -> Bool
CTModels.__is_variable_empty
— Method__is_variable_empty(v) -> Bool
CTModels.__is_variable_set
— Method__is_variable_set(ocp::CTModels.PreModel) -> Bool
CTModels.__is_variable_set
— Method__is_variable_set(ocp::Model) -> Bool
CTModels.__matrix_dimension_storage
— Method__matrix_dimension_storage() -> Int64
Used to set the default value of the storage of elements in a matrix. The default value is 1
.
CTModels.__state_components
— Method__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_name
— Method__state_name() -> String
Used to set the default value of the name of the state. The default value is "x"
.
CTModels.__time_name
— Method__time_name() -> String
Used to set the default value of the name of the time. The default value is t
.
CTModels.__variable_components
— Method__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_name
— Method__variable_name(q::Int64) -> String
Used to set the default value of the names of the variables. The default value is "v"
.
CTModels.append_box_constraints!
— Methodappend_box_constraints!(
inds,
lbs,
ubs,
labels,
rg,
lb,
ub,
label
)
Appends box constraint data to the provided vectors.
Arguments
inds::Vector{Int}
: Vector of indices to which the rangerg
will be appended.lbs::Vector{<:Real}
: Vector of lower bounds to whichlb
will be appended.ubs::Vector{<:Real}
: Vector of upper bounds to whichub
will be appended.labels::Vector{String}
: Vector of labels to which thelabel
will be repeated and appended.rg::AbstractVector{Int}
: Index range corresponding to the constraint variables.lb::AbstractVector{<:Real}
: Lower bounds associated withrg
.ub::AbstractVector{<:Real}
: Upper bounds associated withrg
.label::String
: Label describing the constraint block (e.g., "state", "control").
Notes
- All input vectors (
rg
,lb
,ub
) must have the same length. - The function modifies the
inds
,lbs
,ubs
, andlabels
vectors in-place.
CTModels.boundary_constraints_dual
— Methodboundary_constraints_dual(
sol::CTModels.Solution
) -> Union{Nothing, AbstractVector{<:Real}}
Return the dual of the boundary constraints of the optimal control solution.
CTModels.boundary_constraints_dual
— Methodboundary_constraints_dual(
model::CTModels.DualModel{<:Union{Nothing, Function}, BC_Dual<:Union{Nothing, AbstractVector{<:Real}}}
) -> Union{Nothing, AbstractVector{<:Real}}
Return the dual vector associated with the boundary constraints.
Arguments
model::DualModel
: A model including dual variables for boundary constraints.
Returns
A vector of dual values, or nothing
if not set.
CTModels.boundary_constraints_nl
— Methodboundary_constraints_nl(
model::CTModels.ConstraintsModel{<:Tuple, TB}
) -> Any
Get the nonlinear boundary constraints from the model.
Arguments
model
: The constraints model from which to retrieve the boundary constraints.
Returns
- The nonlinear boundary constraints.
Example
# Example of retrieving nonlinear boundary constraints
julia> model = ConstraintsModel(...)
julia> boundary_constraints = boundary_constraints_nl(model)
CTModels.boundary_constraints_nl
— Methodboundary_constraints_nl(
ocp::Model{<:CTModels.TimeDependence, <: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.build
— Methodbuild(
pre_ocp::CTModels.PreModel;
build_examodel
) -> 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
pre_ocp = PreModel()
times!(pre_ocp, 0.0, 1.0, 100)
state!(pre_ocp, 2, "x", ["x1", "x2"])
control!(pre_ocp, 1, "u", ["u1"])
dynamics!(pre_ocp, (dx, t, x, u, v) -> dx .= x + u)
model = build(pre_ocp)
CTModels.build
— Methodbuild(
constraints::OrderedCollections.OrderedDict{Symbol, Tuple{Symbol, Union{Function, OrdinalRange{<:Int64}}, AbstractVector{<:Real}, AbstractVector{<:Real}}}
) -> CTModels.ConstraintsModel{TP, TB, Tuple{Vector{Float64}, Vector{Int64}, Vector{Float64}, Vector{Symbol}}, Tuple{Vector{Float64}, Vector{Int64}, Vector{Float64}, Vector{Symbol}}, Tuple{Vector{Float64}, Vector{Int64}, Vector{Float64}, Vector{Symbol}}} where {TP<:Tuple{Vector{Float64}, Any, Vector{Float64}, Vector{Symbol}}, TB<:Tuple{Vector{Float64}, Any, Vector{Float64}, Vector{Symbol}}}
Constructs a ConstraintsModel
from a dictionary of constraints.
This function processes a dictionary where each entry defines a constraint with its type, function or index range, lower and upper bounds, and label. It categorizes constraints into path, boundary, state, control, and variable constraints, assembling them into a structured ConstraintsModel
.
Arguments
constraints::ConstraintsDictType
: A dictionary mapping constraint labels to tuples of the form(type, function_or_range, lower_bound, upper_bound)
.
Returns
ConstraintsModel
: A structured model encapsulating all provided constraints.
Example
constraints = OrderedDict(
:c1 => (:path, f1, [0.0], [1.0]),
:c2 => (:state, 1:2, [-1.0, -1.0], [1.0, 1.0])
)
model = build(constraints)
CTModels.buildFunctionalInit
— MethodbuildFunctionalInit(data, time, dim) -> CTModels.var"#25#26"
Build functional initialization: general interpolation case
CTModels.buildFunctionalInit
— MethodbuildFunctionalInit(
data::Function,
time,
dim
) -> CTModels.var"#27#28"{<:Function}
Build functional initialization: function case
CTModels.buildFunctionalInit
— MethodbuildFunctionalInit(
data::Nothing,
time,
dim
) -> CTModels.var"#25#26"
Build functional initialization: default case
CTModels.buildFunctionalInit
— MethodbuildFunctionalInit(
data::Union{Real, AbstractVector{<:Real}},
time,
dim
) -> Union{CTModels.var"#29#31", CTModels.var"#30#32"}
Build functional initialization: constant / 1D interpolation
CTModels.buildVectorInit
— MethodbuildVectorInit(data, dim) -> Any
Build vector initialization: default / vector case
CTModels.build_solution
— Methodbuild_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_dual,
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_dual::Matrix{Float64}
: the dual of the path 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.checkDim
— MethodcheckDim(actual_dim, target_dim)
Check if actual dimension is equal to target dimension, error otherwise
CTModels.components
— Methodcomponents(
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.components
— Methodcomponents(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.components
— Methodcomponents(_::CTModels.EmptyVariableModel) -> Vector{String}
Return an empty vector since there are no variable components defined.
CTModels.components
— Methodcomponents(
model::CTModels.StateModelSolution
) -> Vector{String}
Get the components names of the state from the state model solution.
CTModels.components
— Methodcomponents(model::CTModels.StateModel) -> Vector{String}
Get the components names of the state from the state model.
CTModels.components
— Methodcomponents(
model::CTModels.VariableModelSolution
) -> Vector{String}
Return the names of the components from the variable solution.
CTModels.components
— Methodcomponents(model::CTModels.VariableModel) -> Vector{String}
Return the names of the components of the variable.
CTModels.constraint!
— Methodconstraint!(
ocp::CTModels.PreModel,
type::Symbol;
rg,
f,
lb,
ub,
label,
codim_f
)
Add a constraint to a pre-model. See __constraint! for more details.
Arguments
ocp
: The pre-model to which the constraint will be added.type
: The type of the constraint. It can be:state
,:control
,:variable
,:boundary
, or:path
.rg
: The range of the constraint. It can be an integer or a range of integers.f
: The function that defines the constraint. It must return a vector of the same dimension as the constraint.lb
: The lower bound of the constraint. It can be a number or a vector.ub
: The upper bound of the constraint. It can be a number or a vector.label
: The label of the constraint. It must be unique in the pre-model.
Example
# Example of adding a control constraint to a pre-model
julia> ocp = PreModel()
julia> constraint!(ocp, :control, rg=1:2, lb=[0.0], ub=[1.0], label=:control_constraint)
CTModels.constraint
— Methodconstraint(
model::Model,
label::Symbol
) -> Tuple{Symbol, Any, Any, Any}
Get a labelled constraint from the model. Returns a tuple of the form (type, f, lb, ub)
where type
is the type of the constraint, f
is the function of the constraint, lb
is the lower bound of the constraint and ub
is the upper bound of the constraint.
The function returns an exception if the label is not found in the model.
Arguments
model
: The model from which to retrieve the constraint.label
: The label of the constraint to retrieve.
Returns
Tuple
: A tuple containing the type, function, lower bound, and upper bound of the constraint.
Example
julia> # Example of getting a labelled constraint from the model
julia> model = Model(...)
julia> constraint_info = constraint(model, :my_constraint)
CTModels.constraints
— Methodconstraints(
ocp::Model{<:CTModels.TimeDependence, <:CTModels.AbstractTimesModel, <:CTModels.AbstractStateModel, <:CTModels.AbstractControlModel, <:CTModels.AbstractVariableModel, <:Function, <:CTModels.AbstractObjectiveModel, C<:CTModels.AbstractConstraintsModel}
) -> CTModels.AbstractConstraintsModel
Get the constraints from the model.
CTModels.constraints_violation
— Methodconstraints_violation(sol::CTModels.Solution) -> Float64
Return the constraints violation of the optimal control solution.
CTModels.control!
— Methodcontrol!(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.
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.control
— Methodcontrol(
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
— Methodcontrol(
ocp::Model{<:CTModels.TimeDependence, <:CTModels.TimesModel, <:CTModels.AbstractStateModel, T<:CTModels.AbstractControlModel}
) -> CTModels.AbstractControlModel
Get the control from the model.
CTModels.control_components
— Methodcontrol_components(sol::CTModels.Solution) -> Vector{String}
Return the names of the components of the control of the optimal control solution.
CTModels.control_components
— Methodcontrol_components(ocp::Model) -> Vector{String}
Get the components names of the control from the model.
CTModels.control_constraints_box
— Methodcontrol_constraints_box(
model::CTModels.ConstraintsModel{<:Tuple, <:Tuple, <:Tuple, TC}
) -> Any
Get the control box constraints from the model.
Arguments
model
: The constraints model from which to retrieve the control box constraints.
Returns
- The control box constraints.
Example
# Example of retrieving control box constraints
julia> model = ConstraintsModel(...)
julia> control_constraints = control_constraints_box(model)
CTModels.control_constraints_box
— Methodcontrol_constraints_box(
ocp::Model{<:CTModels.TimeDependence, <: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_dual
— Methodcontrol_constraints_lb_dual(
sol::CTModels.Solution
) -> Union{Nothing, Function}
Return the lower bound dual of the control constraints of the optimal control solution.
CTModels.control_constraints_lb_dual
— Methodcontrol_constraints_lb_dual(
model::CTModels.DualModel{<:Union{Nothing, Function}, <:Union{Nothing, AbstractVector{<:Real}}, <:Union{Nothing, Function}, <:Union{Nothing, Function}, CC_LB_Dual<:Union{Nothing, Function}}
) -> Union{Nothing, Function}
Return the dual function associated with the lower bounds of control constraints.
Arguments
model::DualModel
: A model including dual variables for control lower bounds.
Returns
A function mapping time t
to a vector of dual values, or nothing
if not set.
CTModels.control_constraints_ub_dual
— Methodcontrol_constraints_ub_dual(
sol::CTModels.Solution
) -> Union{Nothing, Function}
Return the upper bound dual of the control constraints of the optimal control solution.
CTModels.control_constraints_ub_dual
— Methodcontrol_constraints_ub_dual(
model::CTModels.DualModel{<:Union{Nothing, Function}, <:Union{Nothing, AbstractVector{<:Real}}, <:Union{Nothing, Function}, <:Union{Nothing, Function}, <:Union{Nothing, Function}, CC_UB_Dual<:Union{Nothing, Function}}
) -> Union{Nothing, Function}
Return the dual function associated with the upper bounds of control constraints.
Arguments
model::DualModel
: A model including dual variables for control upper bounds.
Returns
A function mapping time t
to a vector of dual values, or nothing
if not set.
CTModels.control_dimension
— Methodcontrol_dimension(sol::CTModels.Solution) -> Int64
Return the dimension of the control of the optimal control solution.
CTModels.control_dimension
— Methodcontrol_dimension(ocp::Model) -> Int64
Get the control dimension from the model.
CTModels.control_name
— Methodcontrol_name(sol::CTModels.Solution) -> String
Return the name of the control of the optimal control solution.
CTModels.control_name
— Methodcontrol_name(ocp::Model) -> String
Get the name of the control from the model.
CTModels.costate
— Methodcostate(
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.criterion
— Methodcriterion(model::CTModels.BolzaObjectiveModel) -> Symbol
Get the criterion (:min or :max) of the Bolza objective model.
CTModels.criterion
— Methodcriterion(model::CTModels.LagrangeObjectiveModel) -> Symbol
Get the criterion (:min or :max) of the Lagrange objective model.
CTModels.criterion
— Methodcriterion(model::CTModels.MayerObjectiveModel) -> Symbol
Get the criterion (:min or :max) of the Mayer objective model.
CTModels.criterion
— Methodcriterion(ocp::Model) -> Symbol
Get the type of criterion (:min or :max) from the model.
CTModels.ctinterpolate
— Methodctinterpolate(x, f) -> Any
Return a linear interpolation function for the data f
defined at points x
.
This function creates a one-dimensional linear interpolant using the Interpolations.jl
package, with linear extrapolation beyond the bounds of x
.
Arguments
x
: A vector of points at which the valuesf
are defined.f
: A vector of values to interpolate.
Returns
A callable interpolation object that can be evaluated at new points.
Example
julia> x = 0:0.5:2
julia> f = [0.0, 1.0, 0.0, -1.0, 0.0]
julia> interp = ctinterpolate(x, f)
julia> interp(1.2)
CTModels.definition!
— Methoddefinition!(ocp::CTModels.PreModel, definition::Expr)
Set the model definition of the optimal control problem.
CTModels.definition
— Methoddefinition(ocp::CTModels.PreModel) -> Union{Nothing, Expr}
Return the model definition of the optimal control problem or nothing
.
CTModels.definition
— Methoddefinition(ocp::Model) -> Expr
Return the model definition of the optimal control problem.
CTModels.dim_boundary_constraints_nl
— Methoddim_boundary_constraints_nl(
model::CTModels.ConstraintsModel
) -> Int64
Return the dimension of nonlinear boundary constraints.
Arguments
model
: The constraints model from which to retrieve the dimension of boundary constraints.
Returns
Dimension
: The dimension of the nonlinear boundary constraints.
Example
# Example of getting the dimension of nonlinear boundary constraints
julia> model = ConstraintsModel(...)
julia> dim_boundary = dim_boundary_constraints_nl(model)
CTModels.dim_boundary_constraints_nl
— Methoddim_boundary_constraints_nl(ocp::Model) -> Int64
Return the dimension of the boundary constraints.
CTModels.dim_control_constraints_box
— Methoddim_control_constraints_box(
model::CTModels.ConstraintsModel
) -> Int64
Return the dimension of control box constraints.
Arguments
model
: The constraints model from which to retrieve the dimension of control box constraints.
Returns
Dimension
: The dimension of the control box constraints.
Example
julia> # Example of getting the dimension of control box constraints
julia> model = ConstraintsModel(...)
julia> dim_control = dim_control_constraints_box(model)
CTModels.dim_control_constraints_box
— Methoddim_control_constraints_box(ocp::Model) -> Int64
Return the dimension of box constraints on control.
CTModels.dim_path_constraints_nl
— Methoddim_path_constraints_nl(
model::CTModels.ConstraintsModel
) -> Int64
Return the dimension of nonlinear path constraints.
Arguments
model
: The constraints model from which to retrieve the dimension of path constraints.
Returns
Dimension
: The dimension of the nonlinear path constraints.
Example
# Example of getting the dimension of nonlinear path constraints
julia> model = ConstraintsModel(...)
julia> dim_path = dim_path_constraints_nl(model)
CTModels.dim_path_constraints_nl
— Methoddim_path_constraints_nl(ocp::Model) -> Int64
Return the dimension of nonlinear path constraints.
CTModels.dim_state_constraints_box
— Methoddim_state_constraints_box(
model::CTModels.ConstraintsModel
) -> Int64
Return the dimension of state box constraints.
Arguments
model
: The constraints model from which to retrieve the dimension of state box constraints.
Returns
Dimension
: The dimension of the state box constraints.
Example
julia> # Example of getting the dimension of state box constraints
julia> model = ConstraintsModel(...)
julia> dim_state = dim_state_constraints_box(model)
CTModels.dim_state_constraints_box
— Methoddim_state_constraints_box(ocp::Model) -> Int64
Return the dimension of box constraints on state.
CTModels.dim_variable_constraints_box
— Methoddim_variable_constraints_box(
model::CTModels.ConstraintsModel
) -> Int64
Return the dimension of variable box constraints.
Arguments
model
: The constraints model from which to retrieve the dimension of variable box constraints.
Returns
Dimension
: The dimension of the variable box constraints.
Example
julia> # Example of getting the dimension of variable box constraints
julia> model = ConstraintsModel(...)
julia> dim_variable = dim_variable_constraints_box(model)
CTModels.dim_variable_constraints_box
— Methoddim_variable_constraints_box(ocp::Model) -> Int64
Return the dimension of box constraints on variable.
CTModels.dimension
— Methoddimension(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.dimension
— Methoddimension(model::CTModels.ControlModel) -> Int64
Get the control input dimension.
Arguments
model::ControlModel
: The control model.
Returns
Dimension
: The number of control components.
CTModels.dimension
— Methoddimension(_::CTModels.EmptyVariableModel) -> Int64
Return 0
since no variable is defined.
CTModels.dimension
— Methoddimension(model::CTModels.StateModelSolution) -> Int64
Get the dimension of the state from the state model solution.
CTModels.dimension
— Methoddimension(model::CTModels.StateModel) -> Int64
Get the dimension of the state from the state model.
CTModels.dimension
— Methoddimension(model::CTModels.VariableModelSolution) -> Int64
Return the number of components in the variable solution.
CTModels.dimension
— Methoddimension(model::CTModels.VariableModel) -> Int64
Return the dimension (number of components) of the variable.
CTModels.dual
— Methoddual(
sol::CTModels.Solution,
model::Model,
label::Symbol
) -> Any
Return the dual variable associated with a constraint identified by its label
.
Searches through all constraint types (path, boundary, state, control, and variable constraints) defined in the model and returns the corresponding dual value(s) from the solution. If the label is found multiple times, a vector of values is returned.
Arguments
sol::Solution
: Solution object containing dual variables.model::Model
: Model containing constraint definitions.label::Symbol
: Symbol corresponding to a constraint label.
Returns
A function of time t
for time-dependent constraints, or a scalar/vector for time-invariant duals. If the label is not found, throws an IncorrectArgument
exception.
Examples
julia> dual_fun = dual(sol, model, :velocity_limit)
julia> dual_value_at_t1 = dual_fun(1.0)
CTModels.dual_model
— Methoddual_model(
sol::CTModels.Solution{<:CTModels.AbstractTimeGridModel, <:CTModels.AbstractTimesModel, <:CTModels.AbstractStateModel, <:CTModels.AbstractControlModel, <:CTModels.AbstractVariableModel, <:Function, <:Real, DM<:CTModels.AbstractDualModel}
) -> CTModels.AbstractDualModel
CTModels.dynamics!
— Methoddynamics!(
ocp::CTModels.PreModel,
rg::AbstractRange{<:Int64},
f::Function
)
Add a partial dynamics function f
to the optimal control problem ocp
, applying to the subset of state indices specified by the range rg
.
Arguments
ocp::PreModel
: The optimal control problem being defined.rg::AbstractRange{<:Int}
: Range of state indices to whichf
applies.f::Function
: A function describing the dynamics over the specified state indices.
Preconditions
- The state, control, and times must be set before calling this function.
- The full dynamics must not yet be complete.
- No overlap is allowed between
rg
and existing dynamics index ranges.
Behavior
This function appends the tuple (rg, f)
to the list of partial dynamics. It ensures that the specified indices are not already covered and that the system is in a valid configuration for adding partial dynamics.
Errors
Throws CTBase.UnauthorizedCall
if:
- The state, control, or times are not yet set.
- The dynamics are already defined completely.
- Any index in
rg
overlaps with an existing dynamics range.
Example
julia> dynamics!(ocp, 1:2, (out, t, x, u, v) -> out .= x[1:2] .+ u[1:2])
julia> dynamics!(ocp, 3:3, (out, t, x, u, v) -> out .= x[3] * v[1])
CTModels.dynamics!
— Methoddynamics!(ocp::CTModels.PreModel, f::Function)
Set the full dynamics of the optimal control problem ocp
using the function f
.
Arguments
ocp::PreModel
: The optimal control problem being defined.f::Function
: A function that defines the complete system dynamics.
Preconditions
- The state, control, and times must be set before calling this function.
- No dynamics must have been set previously.
Behavior
This function assigns f
as the complete dynamics of the system. It throws an error if any of the required fields (state
, control
, times
) are not yet set, or if dynamics have already been set.
Errors
Throws CTBase.UnauthorizedCall
if called out of order or in an invalid state.
CTModels.dynamics!
— Methoddynamics!(ocp::CTModels.PreModel, i::Integer, f::Function)
Define partial dynamics for a single state variable index in an optimal control problem.
This is a convenience method for defining dynamics affecting only one element of the state vector. It wraps the scalar index i
into a range i:i
and delegates to the general partial dynamics method.
Arguments
ocp::PreModel
: The optimal control problem being defined.i::Integer
: The index of the state variable to which the functionf
applies.f::Function
: A function of the form(out, t, x, u, v) -> ...
, which updates the scalar outputout[1]
in-place.
Behavior
This is equivalent to calling:
julia> dynamics!(ocp, i:i, f)
Errors
Throws the same errors as the range-based method if:
- The model is not properly initialized.
- The index
i
overlaps with existing dynamics. - A full dynamics function is already defined.
Example
julia> dynamics!(ocp, 3, (out, t, x, u, v) -> out[1] = x[3]^2 + u[1])
CTModels.dynamics
— Methoddynamics(
ocp::Model{<:CTModels.TimeDependence, <:CTModels.AbstractTimesModel, <:CTModels.AbstractStateModel, <:CTModels.AbstractControlModel, <:CTModels.AbstractVariableModel, D<:Function}
) -> Function
Get the dynamics from the model.
CTModels.export_ocp_solution
— Methodexport_ocp_solution(
sol::CTModels.AbstractSolution;
format,
filename
)
Export a solution in JLD or JSON formats.
Examples
julia> CTModels.export_ocp_solution(sol; filename="solution", format=:JSON)
julia> CTModels.export_ocp_solution(sol; filename="solution", format=:JLD)
CTModels.export_ocp_solution
— Methodexport_ocp_solution(
::CTModels.JLD2Tag,
::CTModels.AbstractSolution;
filename
)
Export a solution in JLD format.
CTModels.export_ocp_solution
— Methodexport_ocp_solution(
::CTModels.JSON3Tag,
::CTModels.AbstractSolution;
filename
)
Export a solution in JSON format.
CTModels.final
— Methodfinal(
model::CTModels.TimesModel{<:CTModels.AbstractTimeModel, TF<:CTModels.AbstractTimeModel}
) -> CTModels.AbstractTimeModel
Get the final time from the times model.
CTModels.final_time
— Methodfinal_time(
ocp::CTModels.AbstractModel,
variable::AbstractVector
) -> Any
CTModels.final_time
— Methodfinal_time(ocp::CTModels.AbstractModel) -> Real
CTModels.final_time
— Methodfinal_time(
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_time
— Methodfinal_time(
ocp::Model{<:CTModels.TimeDependence, <:CTModels.TimesModel{<:CTModels.AbstractTimeModel, CTModels.FixedTimeModel{T<:Real}}}
) -> Real
Get the final time from the model, for a fixed final time.
CTModels.final_time
— Methodfinal_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
— Methodfinal_time(
ocp::Model{<:CTModels.TimeDependence, <: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_time
— Methodfinal_time(
ocp::Model{<:CTModels.TimeDependence, <:CTModels.TimesModel{<:CTModels.AbstractTimeModel, CTModels.FreeTimeModel}},
variable::Real
) -> Real
Get the final time from the model, for a free final time.
CTModels.final_time_name
— Methodfinal_time_name(sol::CTModels.Solution) -> String
Return the name of the final time of the optimal control solution.
CTModels.final_time_name
— Methodfinal_time_name(model::CTModels.TimesModel) -> String
Get the name of the final time from the times model.
CTModels.final_time_name
— Methodfinal_time_name(ocp::Model) -> String
Get the name of the final time from the model.
CTModels.formatData
— MethodformatData(data) -> Any
Convert matrix to vector of vectors (could be expanded)
CTModels.formatTimeGrid
— MethodformatTimeGrid(time) -> Any
Convert matrix time-grid to vector
CTModels.get_build_examodel
— Methodget_build_examodel(
ocp::Model{<:CTModels.TimeDependence, <:CTModels.AbstractTimesModel, <:CTModels.AbstractStateModel, <:CTModels.AbstractControlModel, <:CTModels.AbstractVariableModel, <:Function, <:CTModels.AbstractObjectiveModel, <:CTModels.AbstractConstraintsModel, <:Function}
) -> Function
Get the build_examodel from the model.
CTModels.get_build_examodel
— Methodget_build_examodel(
_::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.has_fixed_final_time
— Methodhas_fixed_final_time(
times::CTModels.TimesModel{<:CTModels.AbstractTimeModel, CTModels.FreeTimeModel}
) -> Bool
Check if the final time is free. Return false.
CTModels.has_fixed_final_time
— Methodhas_fixed_final_time(ocp::Model) -> Bool
Check if the final time is fixed.
CTModels.has_fixed_final_time
— Methodhas_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_time
— Methodhas_fixed_initial_time(
times::CTModels.TimesModel{CTModels.FreeTimeModel}
) -> Bool
Check if the initial time is free. Return false.
CTModels.has_fixed_initial_time
— Methodhas_fixed_initial_time(ocp::Model) -> Bool
Check if the initial time is fixed.
CTModels.has_fixed_initial_time
— Methodhas_fixed_initial_time(
times::CTModels.TimesModel{<:CTModels.FixedTimeModel{T<:Real}}
) -> Bool
Check if the initial time is fixed. Return true.
CTModels.has_free_final_time
— Methodhas_free_final_time(times::CTModels.TimesModel) -> Bool
Check if the final time is free.
CTModels.has_free_final_time
— Methodhas_free_final_time(ocp::Model) -> Bool
Check if the final time is free.
CTModels.has_free_initial_time
— Methodhas_free_initial_time(times::CTModels.TimesModel) -> Bool
Check if the final time is free.
CTModels.has_free_initial_time
— Methodhas_free_initial_time(ocp::Model) -> Bool
Check if the initial time is free.
CTModels.has_lagrange_cost
— Methodhas_lagrange_cost(
model::CTModels.BolzaObjectiveModel
) -> Bool
Check if the Bolza objective model has a Lagrange function. Return true.
CTModels.has_lagrange_cost
— Methodhas_lagrange_cost(
model::CTModels.LagrangeObjectiveModel
) -> Bool
Check if the Lagrange objective model has a Lagrange function. Return true.
CTModels.has_lagrange_cost
— Methodhas_lagrange_cost(
model::CTModels.MayerObjectiveModel
) -> Bool
Check if the Mayer objective model has a Lagrange function. Return false.
CTModels.has_lagrange_cost
— Methodhas_lagrange_cost(ocp::Model) -> Bool
Check if the model has a Lagrange cost.
CTModels.has_mayer_cost
— Methodhas_mayer_cost(model::CTModels.BolzaObjectiveModel) -> Bool
Check if the Bolza objective model has a Mayer function. Return true.
CTModels.has_mayer_cost
— Methodhas_mayer_cost(
model::CTModels.LagrangeObjectiveModel
) -> Bool
Check if the Lagrange objective model has a Mayer function. Return false.
CTModels.has_mayer_cost
— Methodhas_mayer_cost(model::CTModels.MayerObjectiveModel) -> Bool
Check if the Mayer objective model has a Mayer function. Return true.
CTModels.has_mayer_cost
— Methodhas_mayer_cost(ocp::Model) -> Bool
Check if the model has a Mayer cost.
CTModels.import_ocp_solution
— Methodimport_ocp_solution(
ocp::CTModels.AbstractModel;
format,
filename
)
Import a solution from a JLD or JSON file.
Examples
julia> sol = CTModels.import_ocp_solution(ocp; filename="solution", format=:JSON)
julia> sol = CTModels.import_ocp_solution(ocp; filename="solution", format=:JLD)
CTModels.import_ocp_solution
— Methodimport_ocp_solution(
::CTModels.JLD2Tag,
::CTModels.AbstractModel;
filename
)
Import a solution from a JLD file.
CTModels.import_ocp_solution
— Methodimport_ocp_solution(
::CTModels.JSON3Tag,
::CTModels.AbstractModel;
filename
)
Import a solution from a JLD file.
CTModels.index
— Methodindex(model::CTModels.FreeTimeModel) -> Int64
Get the index of the time variable from the free time model.
CTModels.infos
— Methodinfos(sol::CTModels.Solution) -> Dict{Symbol, Any}
Return a dictionary of additional infos depending on the solver or nothing
.
CTModels.initial
— Methodinitial(
model::CTModels.TimesModel{TI<:CTModels.AbstractTimeModel}
) -> CTModels.AbstractTimeModel
Get the initial time from the times model.
CTModels.initial_time
— Methodinitial_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_time
— Methodinitial_time(
ocp::Model{<:CTModels.TimeDependence, <:CTModels.TimesModel{CTModels.FixedTimeModel{T<:Real}}}
) -> Real
Get the initial time from the model, for a fixed initial time.
CTModels.initial_time
— Methodinitial_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
— Methodinitial_time(
ocp::Model{<:CTModels.TimeDependence, <:CTModels.TimesModel{CTModels.FreeTimeModel}},
variable::AbstractArray{T<:Real, 1}
) -> Any
Get the initial time from the model, for a free initial time.
CTModels.initial_time
— Methodinitial_time(
ocp::Model{<:CTModels.TimeDependence, <:CTModels.TimesModel{CTModels.FreeTimeModel}},
variable::Real
) -> Real
Get the initial time from the model, for a free initial time.
CTModels.initial_time_name
— Methodinitial_time_name(sol::CTModels.Solution) -> String
Return the name of the initial time of the optimal control solution.
CTModels.initial_time_name
— Methodinitial_time_name(model::CTModels.TimesModel) -> String
Get the name of the initial time from the times model.
CTModels.initial_time_name
— Methodinitial_time_name(ocp::Model) -> String
Get the name of the initial time from the model.
CTModels.is_autonomous
— Methodis_autonomous(
_::Model{CTModels.Autonomous, <:CTModels.TimesModel}
) -> Bool
Return true
if the model is autonomous.
CTModels.is_empty_time_grid
— Methodis_empty_time_grid(sol::CTModels.Solution) -> Bool
Check if the time grid is empty from the solution.
CTModels.isaVectVect
— MethodisaVectVect(data) -> Bool
Return true if argument is a vector of vectors
CTModels.isempty_constraints
— Methodisempty_constraints(ocp::Model) -> Bool
Return true if the model has constraints or false if not.
CTModels.iterations
— Methoditerations(sol::CTModels.Solution) -> Int64
Return the number of iterations (if solved by an iterative method) of the optimal control solution.
CTModels.lagrange
— Methodlagrange(
model::CTModels.BolzaObjectiveModel{<:Function, L<:Function}
) -> Function
Get the Lagrange function of the Bolza objective model.
CTModels.lagrange
— Methodlagrange(
model::CTModels.LagrangeObjectiveModel{L<:Function}
) -> Function
Get the Lagrange function of the Lagrange objective model.
CTModels.lagrange
— Methodlagrange(
ocp::Model{<:CTModels.TimeDependence, <:CTModels.AbstractTimesModel, <:CTModels.AbstractStateModel, <:CTModels.AbstractControlModel, <:CTModels.AbstractVariableModel, <:Function, <:CTModels.BolzaObjectiveModel{<:Function, L<:Function}}
) -> Any
Get the Lagrange cost from the model.
CTModels.lagrange
— Methodlagrange(
ocp::Model{<:CTModels.TimeDependence, <:CTModels.AbstractTimesModel, <:CTModels.AbstractStateModel, <:CTModels.AbstractControlModel, <:CTModels.AbstractVariableModel, <:Function, CTModels.LagrangeObjectiveModel{L<:Function}}
) -> Function
Get the Lagrange cost from the model.
CTModels.matrix2vec
— Functionmatrix2vec(A::Matrix{<:Real}) -> Vector{<:Vector{<:Real}}
matrix2vec(
A::Matrix{<:Real},
dim::Int64
) -> Vector{<:Vector{<:Real}}
Transform a matrix into a vector of vectors along the specified dimension.
Each row or column of the matrix A
is extracted and stored as an individual vector, depending on dim
.
Arguments
A
: A matrix of elements of type<:ctNumber
.dim
: The dimension along which to split the matrix (1
for rows,2
for columns). Defaults to1
.
Returns
A Vector
of Vector
s extracted from the rows or columns of A
.
Note
This is useful when data needs to be represented as a sequence of state or control vectors in optimal control problems.
Example
julia> A = [1 2 3; 4 5 6]
julia> matrix2vec(A, 1) # splits into rows: [[1, 2, 3], [4, 5, 6]]
julia> matrix2vec(A, 2) # splits into columns: [[1, 4], [2, 5], [3, 6]]
CTModels.mayer
— Methodmayer(
model::CTModels.BolzaObjectiveModel{M<:Function}
) -> Function
Get the Mayer function of the Bolza objective model.
CTModels.mayer
— Methodmayer(
model::CTModels.MayerObjectiveModel{M<:Function}
) -> Function
Get the Mayer function of the Mayer objective model.
CTModels.mayer
— Methodmayer(
ocp::Model{<:CTModels.TimeDependence, <:CTModels.AbstractTimesModel, <:CTModels.AbstractStateModel, <:CTModels.AbstractControlModel, <:CTModels.AbstractVariableModel, <:Function, <:CTModels.BolzaObjectiveModel{M<:Function}}
) -> Any
Get the Mayer cost from the model.
CTModels.mayer
— Methodmayer(
ocp::Model{<:CTModels.TimeDependence, <:CTModels.AbstractTimesModel, <:CTModels.AbstractStateModel, <:CTModels.AbstractControlModel, <:CTModels.AbstractVariableModel, <:Function, <:CTModels.MayerObjectiveModel{M<:Function}}
) -> Any
Get the Mayer cost from the model.
CTModels.message
— Methodmessage(sol::CTModels.Solution) -> String
Return the message associated to the stopping criterion of the optimal control solution.
CTModels.model
— Methodmodel(
sol::CTModels.Solution{<:CTModels.AbstractTimeGridModel, <:CTModels.AbstractTimesModel, <:CTModels.AbstractStateModel, <:CTModels.AbstractControlModel, <:CTModels.AbstractVariableModel, <:Function, <:Real, <:CTModels.AbstractDualModel, <:CTModels.AbstractSolverInfos, TM<:CTModels.AbstractModel}
) -> CTModels.AbstractModel
CTModels.name
— Methodname(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.name
— Methodname(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.name
— Methodname(_::CTModels.EmptyVariableModel) -> String
Return an empty string, since no variable is defined.
CTModels.name
— Methodname(model::CTModels.FixedTimeModel) -> String
Get the name of the time from the fixed time model.
CTModels.name
— Methodname(model::CTModels.FreeTimeModel) -> String
Get the name of the time from the free time model.
CTModels.name
— Methodname(model::CTModels.StateModelSolution) -> String
Get the name of the state from the state model solution.
CTModels.name
— Methodname(model::CTModels.StateModel) -> String
Get the name of the state from the state model.
CTModels.name
— Methodname(model::CTModels.VariableModelSolution) -> String
Return the name of the variable stored in the model solution.
CTModels.name
— Methodname(model::CTModels.VariableModel) -> String
Return the name of the variable stored in the model.
CTModels.objective!
— Functionobjective!(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.
- 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
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.objective
— Methodobjective(
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.objective
— Methodobjective(
ocp::Model{<:CTModels.TimeDependence, <:CTModels.AbstractTimesModel, <:CTModels.AbstractStateModel, <:CTModels.AbstractControlModel, <:CTModels.AbstractVariableModel, <:Function, O<:CTModels.AbstractObjectiveModel}
) -> CTModels.AbstractObjectiveModel
Get the objective from the model.
CTModels.path_constraints_dual
— Methodpath_constraints_dual(
sol::CTModels.Solution
) -> Union{Nothing, Function}
Return the dual of the path constraints of the optimal control solution.
CTModels.path_constraints_dual
— Methodpath_constraints_dual(
model::CTModels.DualModel{PC_Dual<:Union{Nothing, Function}}
) -> Union{Nothing, Function}
Return the dual function associated with the nonlinear path constraints.
Arguments
model::DualModel
: A model including dual variables for path constraints.
Returns
A function mapping time t
to the vector of dual values, or nothing
if not set.
CTModels.path_constraints_nl
— Methodpath_constraints_nl(
model::CTModels.ConstraintsModel{TP}
) -> Any
Get the nonlinear path constraints from the model.
Arguments
model
: The constraints model from which to retrieve the path constraints.
Returns
- The nonlinear path constraints.
Example
# Example of retrieving nonlinear path constraints
julia> model = ConstraintsModel(...)
julia> path_constraints = path_constraints_nl(model)
CTModels.path_constraints_nl
— Methodpath_constraints_nl(
ocp::Model{<:CTModels.TimeDependence, <: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!
— Methodstate!(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.
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.state
— Methodstate(
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
— Methodstate(
ocp::Model{<:CTModels.TimeDependence, <:CTModels.TimesModel, T<:CTModels.AbstractStateModel}
) -> CTModels.AbstractStateModel
Get the state from the model.
CTModels.state_components
— Methodstate_components(sol::CTModels.Solution) -> Vector{String}
Return the names of the components of the state of the optimal control solution.
CTModels.state_components
— Methodstate_components(ocp::Model) -> Vector{String}
Get the components names of the state from the model.
CTModels.state_constraints_box
— Methodstate_constraints_box(
model::CTModels.ConstraintsModel{<:Tuple, <:Tuple, TS}
) -> Any
Get the state box constraints from the model.
Arguments
model
: The constraints model from which to retrieve the state box constraints.
Returns
- The state box constraints.
Example
# Example of retrieving state box constraints
julia> model = ConstraintsModel(...)
julia> state_constraints = state_constraints_box(model)
CTModels.state_constraints_box
— Methodstate_constraints_box(
ocp::Model{<:CTModels.TimeDependence, <: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_dual
— Methodstate_constraints_lb_dual(
sol::CTModels.Solution
) -> Union{Nothing, Function}
Return the lower bound dual of the state constraints of the optimal control solution.
CTModels.state_constraints_lb_dual
— Methodstate_constraints_lb_dual(
model::CTModels.DualModel{<:Union{Nothing, Function}, <:Union{Nothing, AbstractVector{<:Real}}, SC_LB_Dual<:Union{Nothing, Function}}
) -> Union{Nothing, Function}
Return the dual function associated with the lower bounds of state constraints.
Arguments
model::DualModel
: A model including dual variables for state lower bounds.
Returns
A function mapping time t
to a vector of dual values, or nothing
if not set.
CTModels.state_constraints_ub_dual
— Methodstate_constraints_ub_dual(
sol::CTModels.Solution
) -> Union{Nothing, Function}
Return the upper bound dual of the state constraints of the optimal control solution.
CTModels.state_constraints_ub_dual
— Methodstate_constraints_ub_dual(
model::CTModels.DualModel{<:Union{Nothing, Function}, <:Union{Nothing, AbstractVector{<:Real}}, <:Union{Nothing, Function}, SC_UB_Dual<:Union{Nothing, Function}}
) -> Union{Nothing, Function}
Return the dual function associated with the upper bounds of state constraints.
Arguments
model::DualModel
: A model including dual variables for state upper bounds.
Returns
A function mapping time t
to a vector of dual values, or nothing
if not set.
CTModels.state_dimension
— Methodstate_dimension(ocp::CTModels.PreModel) -> Int64
CTModels.state_dimension
— Methodstate_dimension(sol::CTModels.Solution) -> Int64
Return the dimension of the state of the optimal control solution.
CTModels.state_dimension
— Methodstate_dimension(ocp::Model) -> Int64
Get the state dimension from the model.
CTModels.state_name
— Methodstate_name(sol::CTModels.Solution) -> String
Return the name of the state of the optimal control solution.
CTModels.state_name
— Methodstate_name(ocp::Model) -> String
Get the name of the state from the model.
CTModels.stopping
— Methodstopping(sol::CTModels.Solution) -> Symbol
Return the stopping criterion (a Symbol) of the optimal control solution.
CTModels.success
— Methodsuccess(sol::CTModels.Solution) -> Bool
Return the success status of the optimal control solution.
CTModels.time!
— Methodtime!(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.
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, time_name="s") # time_name is a String
# or
julia> time!(ocp, t0=0, tf=1, time_name=:s ) # time_name is a Symbol
CTModels.time
— Methodtime(model::CTModels.FixedTimeModel{T<:Real}) -> Real
Get the time from the fixed time model.
CTModels.time
— Methodtime(
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_grid
— Methodtime_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_name
— Methodtime_name(sol::CTModels.Solution) -> String
Return the name of the time component of the optimal control solution.
CTModels.time_name
— Methodtime_name(model::CTModels.TimesModel) -> String
Get the name of the time variable from the times model.
CTModels.time_name
— Methodtime_name(ocp::Model) -> String
Get the name of the time from the model.
CTModels.times
— Methodtimes(
ocp::Model{<:CTModels.TimeDependence, T<:CTModels.TimesModel}
) -> CTModels.TimesModel
Get the times from the model.
CTModels.to_out_of_place
— Methodto_out_of_place(
f!,
n;
T
) -> Union{Nothing, CTModels.var"#f#13"{CTModels.var"#f#12#14"{DataType, _A, _B}} where {_A, _B}}
Convert an in-place function f!
to an out-of-place function f
.
The resulting function f
returns a vector of type T
and length n
by first allocating memory and then calling f!
to fill it.
Arguments
f!
: An in-place function of the formf!(result, args...)
.n
: The length of the output vector.T
: The element type of the output vector (default isFloat64
).
Returns
An out-of-place function f(args...; kwargs...)
that returns the result as a vector or scalar, depending on n
.
Example
julia> f!(r, x) = (r[1] = sin(x); r[2] = cos(x))
julia> f = to_out_of_place(f!, 2)
julia> f(π/4) # returns approximately [0.707, 0.707]
CTModels.value
— Methodvalue(
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.
CTModels.value
— Methodvalue(
model::CTModels.StateModelSolution{TS<:Function}
) -> Function
Get the state function from the state model solution.
CTModels.value
— Methodvalue(
model::CTModels.VariableModelSolution{TS<:Union{Real, AbstractVector{<:Real}}}
) -> Union{Real, AbstractVector{<:Real}}
Return the value stored in the variable solution model.
CTModels.variable!
— Methodvariable!(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 a new variable in the optimal control problem ocp
with dimension q
.
This function registers a named variable (e.g. "state", "control", or other) to be used in the problem definition. You may optionally specify a name and individual component names.
Arguments
ocp
: ThePreModel
where the variable is registered.q
: The dimension of the variable (number of components).name
: A name for the variable (default: auto-generated fromq
).components_names
: A vector of strings or symbols for each component (default:["v₁", "v₂", ...]
).
Examples
variable!(ocp, 1, "v")
variable!(ocp, 2, "v", ["v₁", "v₂"])
CTModels.variable
— Methodvariable(
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
— Methodvariable(
ocp::Model{<:CTModels.TimeDependence, <:CTModels.TimesModel, <:CTModels.AbstractStateModel, <:CTModels.AbstractControlModel, T<:CTModels.AbstractVariableModel}
) -> CTModels.AbstractVariableModel
Get the variable from the model.
CTModels.variable_components
— Methodvariable_components(
sol::CTModels.Solution
) -> Vector{String}
Return the names of the components of the variable of the optimal control solution.
CTModels.variable_components
— Methodvariable_components(ocp::Model) -> Vector{String}
Get the components names of the variable from the model.
CTModels.variable_constraints_box
— Methodvariable_constraints_box(
model::CTModels.ConstraintsModel{<:Tuple, <:Tuple, <:Tuple, <:Tuple, TV}
) -> Any
Get the variable box constraints from the model.
Arguments
model
: The constraints model from which to retrieve the variable box constraints.
Returns
- The variable box constraints.
Example
# Example of retrieving variable box constraints
julia> model = ConstraintsModel(...)
julia> variable_constraints = variable_constraints_box(model)
CTModels.variable_constraints_box
— Methodvariable_constraints_box(
ocp::Model{<:CTModels.TimeDependence, <: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_dual
— Methodvariable_constraints_lb_dual(
sol::CTModels.Solution
) -> Union{Nothing, AbstractVector{<:Real}}
Return the lower bound dual of the variable constraints of the optimal control solution.
CTModels.variable_constraints_lb_dual
— Methodvariable_constraints_lb_dual(
model::CTModels.DualModel{<:Union{Nothing, Function}, <:Union{Nothing, AbstractVector{<:Real}}, <:Union{Nothing, Function}, <:Union{Nothing, Function}, <:Union{Nothing, Function}, <:Union{Nothing, Function}, VC_LB_Dual<:Union{Nothing, AbstractVector{<:Real}}}
) -> Union{Nothing, AbstractVector{<:Real}}
Return the dual vector associated with the lower bounds of variable constraints.
Arguments
model::DualModel
: A model including dual variables for variable lower bounds.
Returns
A vector of dual values, or nothing
if not set.
CTModels.variable_constraints_ub_dual
— Methodvariable_constraints_ub_dual(
sol::CTModels.Solution
) -> Union{Nothing, AbstractVector{<:Real}}
Return the upper bound dual of the variable constraints of the optimal control solution.
CTModels.variable_constraints_ub_dual
— Methodvariable_constraints_ub_dual(
model::CTModels.DualModel{<:Union{Nothing, Function}, <:Union{Nothing, AbstractVector{<:Real}}, <:Union{Nothing, Function}, <:Union{Nothing, Function}, <:Union{Nothing, Function}, <:Union{Nothing, Function}, <:Union{Nothing, AbstractVector{<:Real}}, VC_UB_Dual<:Union{Nothing, AbstractVector{<:Real}}}
) -> Union{Nothing, AbstractVector{<:Real}}
Return the dual vector associated with the upper bounds of variable constraints.
Arguments
model::DualModel
: A model including dual variables for variable upper bounds.
Returns
A vector of dual values, or nothing
if not set.
CTModels.variable_dimension
— Methodvariable_dimension(sol::CTModels.Solution) -> Int64
Return the dimension of the variable of the optimal control solution.
CTModels.variable_dimension
— Methodvariable_dimension(ocp::Model) -> Int64
Get the variable dimension from the model.
CTModels.variable_name
— Methodvariable_name(sol::CTModels.Solution) -> String
Return the name of the variable of the optimal control solution.
CTModels.variable_name
— Methodvariable_name(ocp::Model) -> String
Get the name of the variable from the model.
CTModels.@ensure
— Macro@ensure condition exception
Throws the provided exception
if condition
is false.
Usage
julia> @ensure x > 0 CTBase.IncorrectArgument("x must be positive")
Arguments
condition
: A Boolean expression to test.exception
: An instance of an exception to throw ifcondition
is false.
Throws
- The provided
exception
if the condition is not satisfied.