Constraints
Index
CTModels.__constraint!
CTModels.boundary_constraints_nl
CTModels.constraint
CTModels.constraint!
CTModels.control_constraints_box
CTModels.dim_boundary_constraints_nl
CTModels.dim_control_constraints_box
CTModels.dim_path_constraints_nl
CTModels.dim_state_constraints_box
CTModels.dim_variable_constraints_box
CTModels.path_constraints_nl
CTModels.state_constraints_box
CTModels.variable_constraints_box
Base.isempty
In the examples in the documentation below, the methods are not prefixed by the module name even if they are private.
julia> using CTModels
julia> x = 1
julia> private_fun(x) # throw an error
must be replaced by
julia> using CTModels
julia> x = 1
julia> CTModels.private_fun(x)
However, if the method is reexported by another package, then, there is no need of prefixing.
julia> module OptimalControl
import CTModels: private_fun
export private_fun
end
julia> using OptimalControl
julia> x = 1
julia> private_fun(x)
Documentation
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
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()
julia> __constraint!(ocp_constraints, :state, 3, 2, 1, lb=[0.0], ub=[1.0], label=:my_constraint)
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.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::CTModels.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, lb
is the lower bound and ub
is the upper bound.
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.
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.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_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_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_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_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.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.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.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)