CTBase API
This is just a dump of CTBase API documentation. For more details about CTBase.jl
package, see the documentation.
Index
CTBase.CTBase
CTBase.AbstractHamiltonian
CTBase.AmbiguousDescription
CTBase.Autonomous
CTBase.BoundaryConstraint
CTBase.BoundaryConstraint
CTBase.BoundaryConstraint
CTBase.BoundaryConstraint
CTBase.CTException
CTBase.Control
CTBase.ControlConstraint
CTBase.ControlConstraint
CTBase.ControlConstraint
CTBase.ControlConstraint
CTBase.ControlLaw
CTBase.ControlLaw
CTBase.ControlLaw
CTBase.ControlLaw
CTBase.Controls
CTBase.Costate
CTBase.Costates
CTBase.DCostate
CTBase.DState
CTBase.Description
CTBase.Dimension
CTBase.Dynamics
CTBase.Dynamics
CTBase.Dynamics
CTBase.Dynamics
CTBase.ExtensionError
CTBase.FeedbackControl
CTBase.FeedbackControl
CTBase.FeedbackControl
CTBase.FeedbackControl
CTBase.Fixed
CTBase.Hamiltonian
CTBase.Hamiltonian
CTBase.Hamiltonian
CTBase.Hamiltonian
CTBase.HamiltonianLift
CTBase.HamiltonianLift
CTBase.HamiltonianLift
CTBase.HamiltonianLift
CTBase.HamiltonianVectorField
CTBase.HamiltonianVectorField
CTBase.HamiltonianVectorField
CTBase.HamiltonianVectorField
CTBase.IncorrectArgument
CTBase.IncorrectMethod
CTBase.IncorrectOutput
CTBase.Index
CTBase.Lagrange
CTBase.Lagrange
CTBase.Lagrange
CTBase.Lagrange
CTBase.Mayer
CTBase.Mayer
CTBase.Mayer
CTBase.Mayer
CTBase.MixedConstraint
CTBase.MixedConstraint
CTBase.MixedConstraint
CTBase.MixedConstraint
CTBase.Multiplier
CTBase.Multiplier
CTBase.Multiplier
CTBase.Multiplier
CTBase.NonAutonomous
CTBase.NonFixed
CTBase.NotImplemented
CTBase.OptimalControlInit
CTBase.OptimalControlModel
CTBase.OptimalControlSolution
CTBase.OptimalControlSolution
CTBase.OptimalControlSolution
CTBase.OptimalControlSolution
CTBase.ParsingError
CTBase.State
CTBase.StateConstraint
CTBase.StateConstraint
CTBase.StateConstraint
CTBase.StateConstraint
CTBase.States
CTBase.Time
CTBase.TimeDependence
CTBase.Times
CTBase.TimesDisc
CTBase.UnauthorizedCall
CTBase.Variable
CTBase.VariableConstraint
CTBase.VariableConstraint
CTBase.VariableDependence
CTBase.VectorField
CTBase.VectorField
CTBase.VectorField
CTBase.VectorField
CTBase.ctNumber
CTBase.ctVector
CTBase.:⋅
CTBase.:⋅
CTBase.:⋅
CTBase.Lie
CTBase.Lie
CTBase.Lie
CTBase.Lie
CTBase.Lift
CTBase.Lift
CTBase.Model
CTBase.Model
CTBase.Poisson
CTBase.Poisson
CTBase.Poisson
CTBase.Poisson
CTBase.Poisson
CTBase.Poisson
CTBase.__OCPModel
CTBase.add
CTBase.add
CTBase.boundary_constraints
CTBase.boundary_constraints!
CTBase.constraint
CTBase.constraint!
CTBase.constraint_type
CTBase.constraints
CTBase.constraints_labels
CTBase.control
CTBase.control!
CTBase.control_components_names
CTBase.control_components_names
CTBase.control_constraints
CTBase.control_constraints!
CTBase.control_dimension
CTBase.control_dimension
CTBase.control_discretized
CTBase.control_name
CTBase.control_name
CTBase.costate
CTBase.costate!
CTBase.costate_discretized
CTBase.criterion
CTBase.ct_repl
CTBase.ct_repl_update_model
CTBase.ctgradient
CTBase.ctgradient
CTBase.ctgradient
CTBase.ctindices
CTBase.ctinterpolate
CTBase.ctjacobian
CTBase.ctjacobian
CTBase.ctjacobian
CTBase.ctupperscripts
CTBase.dim_boundary_constraints
CTBase.dim_control_constraints
CTBase.dim_control_range
CTBase.dim_mixed_constraints
CTBase.dim_path_constraints
CTBase.dim_state_constraints
CTBase.dim_state_range
CTBase.dim_variable_constraints
CTBase.dim_variable_range
CTBase.dynamics
CTBase.dynamics!
CTBase.final_time
CTBase.final_time_name
CTBase.final_time_name
CTBase.getFullDescription
CTBase.has_free_final_time
CTBase.has_free_initial_time
CTBase.has_lagrange_cost
CTBase.has_mayer_cost
CTBase.infos
CTBase.infos!
CTBase.initial_time
CTBase.initial_time_name
CTBase.initial_time_name
CTBase.is_autonomous
CTBase.is_fixed
CTBase.is_in_place
CTBase.is_max
CTBase.is_min
CTBase.is_time_dependent
CTBase.is_time_independent
CTBase.is_variable_dependent
CTBase.is_variable_independent
CTBase.iterations
CTBase.iterations!
CTBase.lagrange
CTBase.mayer
CTBase.message
CTBase.message!
CTBase.mixed_constraints
CTBase.mixed_constraints!
CTBase.model_expression
CTBase.model_expression!
CTBase.mult_boundary_constraints
CTBase.mult_boundary_constraints!
CTBase.mult_control_box_lower
CTBase.mult_control_box_lower!
CTBase.mult_control_box_upper
CTBase.mult_control_box_upper!
CTBase.mult_control_constraints
CTBase.mult_control_constraints!
CTBase.mult_mixed_constraints
CTBase.mult_mixed_constraints!
CTBase.mult_state_box_lower
CTBase.mult_state_box_lower!
CTBase.mult_state_box_upper
CTBase.mult_state_box_upper!
CTBase.mult_state_constraints
CTBase.mult_state_constraints!
CTBase.mult_variable_box_lower
CTBase.mult_variable_box_lower!
CTBase.mult_variable_box_upper
CTBase.mult_variable_box_upper!
CTBase.mult_variable_constraints
CTBase.mult_variable_constraints!
CTBase.nlp_constraints!
CTBase.objective
CTBase.objective!
CTBase.objective!
CTBase.remove
CTBase.remove_constraint!
CTBase.replace_call
CTBase.replace_call
CTBase.state
CTBase.state!
CTBase.state_components_names
CTBase.state_components_names
CTBase.state_constraints
CTBase.state_constraints!
CTBase.state_dimension
CTBase.state_dimension
CTBase.state_discretized
CTBase.state_name
CTBase.state_name
CTBase.stopping
CTBase.stopping!
CTBase.success
CTBase.success!
CTBase.time!
CTBase.time_grid
CTBase.time_grid!
CTBase.time_name
CTBase.time_name
CTBase.variable
CTBase.variable!
CTBase.variable_components_names
CTBase.variable_components_names
CTBase.variable_constraints
CTBase.variable_constraints!
CTBase.variable_dimension
CTBase.variable_dimension
CTBase.variable_name
CTBase.variable_name
CTBase.∂ₜ
CTBase.@Lie
CTBase.@Lie
CTBase.@Lie
CTBase.@def
Documentation
CTBase.CTBase
— ModuleCTBase
module.
Lists all the imported modules and packages:
Base
Core
DataStructures
DocStringExtensions
LinearAlgebra
MLStyle
Parameters
PrettyTables
Printf
ReplMaker
SparseArrays
StaticArrays
Unicode
List of all the exported names:
AbstractHamiltonian
AmbiguousDescription
Autonomous
BoundaryConstraint
BoundaryConstraint!
CTException
Control
ControlConstraint
ControlConstraint!
ControlLaw
Controls
Costate
Costates
DCostate
DState
Description
Dimension
Dynamics
Dynamics!
ExtensionError
FeedbackControl
Fixed
Hamiltonian
HamiltonianLift
HamiltonianVectorField
IncorrectArgument
IncorrectMethod
IncorrectOutput
Index
Lagrange
Lagrange!
@Lie
Lie
Lift
Mayer
Mayer!
MixedConstraint
MixedConstraint!
Model
Multiplier
NonAutonomous
NonFixed
NotImplemented
OptimalControlInit
OptimalControlModel
OptimalControlSolution
ParsingError
Poisson
State
StateConstraint
StateConstraint!
States
Time
TimeDependence
Times
TimesDisc
UnauthorizedCall
Variable
VariableConstraint
VariableConstraint!
VariableDependence
VectorField
__OCPModel
__constraint
__dynamics
__lagrange
__mayer
add
boundary_constraints
boundary_constraints!
constraint
constraint!
constraint_type
constraints
constraints_labels
control
control!
control_components_names
control_constraints
control_constraints!
control_dimension
control_discretized
control_name
costate
costate!
costate_discretized
criterion
ctNumber
ctVector
ct_repl
ct_repl_update_model
ctgradient
ctindices
ctinterpolate
ctjacobian
ctupperscripts
@def
dim_boundary_constraints
dim_control_constraints
dim_control_range
dim_mixed_constraints
dim_path_constraints
dim_state_constraints
dim_state_range
dim_variable_constraints
dim_variable_range
dynamics
dynamics!
export_ocp_solution
final_time
final_time_name
getFullDescription
has_free_final_time
has_free_initial_time
has_lagrange_cost
has_mayer_cost
import_ocp_solution
infos
infos!
initial_time
initial_time_name
is_autonomous
is_fixed
is_in_place
is_max
is_min
is_time_dependent
is_time_independent
is_variable_dependent
is_variable_independent
iterations
iterations!
lagrange
mayer
message
message!
mixed_constraints
mixed_constraints!
model_expression
model_expression!
mult_boundary_constraints
mult_boundary_constraints!
mult_control_box_lower
mult_control_box_lower!
mult_control_box_upper
mult_control_box_upper!
mult_control_constraints
mult_control_constraints!
mult_mixed_constraints
mult_mixed_constraints!
mult_state_box_lower
mult_state_box_lower!
mult_state_box_upper
mult_state_box_upper!
mult_state_constraints
mult_state_constraints!
mult_variable_box_lower
mult_variable_box_lower!
mult_variable_box_upper
mult_variable_box_upper!
mult_variable_constraints
mult_variable_constraints!
nlp_constraints!
objective
objective!
remove
remove_constraint!
replace_call
set_AD_backend
state
state!
state_components_names
state_constraints
state_constraints!
state_dimension
state_discretized
state_name
stopping
stopping!
success
success!
time!
time_grid
time_grid!
time_name
variable
variable!
variable_components_names
variable_constraints
variable_constraints!
variable_dimension
variable_name
∂ₜ
⋅
CTBase.Control
— TypeType alias for a control in Rᵐ.
julia> const Control = ctVector
CTBase.Costate
— TypeType alias for a costate in Rⁿ.
julia> const Costate = ctVector
CTBase.DCostate
— TypeType alias for a tangent vector to the costate space.
julia> const DCostate = ctVector
CTBase.DState
— TypeType alias for a tangent vector to the state space.
julia> const DState = ctVector
CTBase.State
— TypeType alias for a state in Rⁿ.
julia> const State = ctVector
CTBase.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}
CTBase.Variable
— TypeType alias for a variable in Rᵏ.
julia> const Variable = ctVector
CTBase.ctVector
— TypeType alias for a vector of real numbers.
julia> const ctVector = Union{ctNumber, AbstractVector{<:ctNumber}}
CTBase.AbstractHamiltonian
— Typeabstract type AbstractHamiltonian{TD<:TimeDependence, VD<:VariableDependence}
Abstract type for hamiltonians.
CTBase.AmbiguousDescription
— Typestruct AmbiguousDescription <: CTException
Exception thrown when the description is ambiguous / incorrect.
Fields
var::Tuple{Vararg{Symbol}}
CTBase.Autonomous
— Typeabstract type Autonomous <: TimeDependence
CTBase.BoundaryConstraint
— Typestruct BoundaryConstraint{TF<:Function, VD<:VariableDependence}
Fields
f::Function
The default value for variable_dependence
is Fixed
.
Constructor
The constructor BoundaryConstraint
returns a BoundaryConstraint
of a function. The function must take 2 or 3 arguments (x0, xf)
or (x0, xf, v)
, if the function is variable, it must be specified. Dependencies are specified with a boolean, variable
, false
by default or with a DataType
, NonFixed/Fixed
, Fixed
by default.
Examples
julia> B = BoundaryConstraint((x0, xf) -> [xf[2]-x0[1], 2xf[1]+x0[2]^2])
julia> B = BoundaryConstraint((x0, xf, v) -> [v[3]+xf[2]-x0[1], v[1]-v[2]+2xf[1]+x0[2]^2], variable=true)
julia> B = BoundaryConstraint((x0, xf, v) -> [v[3]+xf[2]-x0[1], v[1]-v[2]+2xf[1]+x0[2]^2], NonFixed)
When the state is of dimension 1, consider x0
and xf
as a scalar. When the constraint is dimension 1, return a scalar.
Call
The call returns the evaluation of the BoundaryConstraint
for given values. If a variable is given for a non variable dependent boundary constraint, it will be ignored.
Examples
julia> B = BoundaryConstraint((x0, xf) -> [xf[2]-x0[1], 2xf[1]+x0[2]^2])
julia> B([0, 0], [1, 1])
[1, 2]
julia> B = BoundaryConstraint((x0, xf) -> [xf[2]-x0[1], 2xf[1]+x0[2]^2])
julia> B([0, 0], [1, 1],Real[])
[1, 2]
julia> B = BoundaryConstraint((x0, xf, v) -> [v[3]+xf[2]-x0[1], v[1]-v[2]+2xf[1]+x0[2]^2], variable=true)
julia> B([0, 0], [1, 1], [1, 2, 3])
[4, 1]
CTBase.BoundaryConstraint
— MethodBoundaryConstraint(
f::Function,
VD::Type{<:VariableDependence}
) -> BoundaryConstraint
Return a BoundaryConstraint
of a function. Dependencies are specified with a DataType, NonFixed/Fixed, Fixed by default.
julia> B = BoundaryConstraint((x0, xf) -> [xf[2]-x0[1], 2xf[1]+x0[2]^2])
julia> B = BoundaryConstraint((x0, xf, v) -> [v[3]+xf[2]-x0[1], v[1]-v[2]+2xf[1]+x0[2]^2], NonFixed)
CTBase.BoundaryConstraint
— MethodBoundaryConstraint(
f::Function;
variable
) -> BoundaryConstraint
Return a BoundaryConstraint
of a function. Dependencies are specified with a boolean, variable, false by default.
julia> B = BoundaryConstraint((x0, xf) -> [xf[2]-x0[1], 2xf[1]+x0[2]^2])
julia> B = BoundaryConstraint((x0, xf, v) -> [v[3]+xf[2]-x0[1], v[1]-v[2]+2xf[1]+x0[2]^2], variable=true)
CTBase.BoundaryConstraint
— MethodReturn the evaluation of the BoundaryConstraint.
julia> B = BoundaryConstraint((x0, xf) -> [xf[2]-x0[1], 2xf[1]+x0[2]^2])
julia> B([0, 0], [1, 1])
[1, 2]
julia> B = BoundaryConstraint((x0, xf) -> [xf[2]-x0[1], 2xf[1]+x0[2]^2])
julia> B([0, 0], [1, 1],Real[])
[1, 2]
julia> B = BoundaryConstraint((x0, xf, v) -> [v[3]+xf[2]-x0[1], v[1]-v[2]+2xf[1]+x0[2]^2], variable=true)
julia> B([0, 0], [1, 1], [1, 2, 3])
[4, 1]
CTBase.CTException
— Typeabstract type CTException <: Exception
Abstract type for exceptions.
CTBase.ControlConstraint
— Typestruct ControlConstraint{TF<:Function, TD<:TimeDependence, VD<:VariableDependence}
Fields
f::Function
Similar to VectorField
in the usage, but the dimension of the output of the function f
is arbitrary.
The default values for time_dependence
and variable_dependence
are Autonomous
and Fixed
respectively.
Constructor
The constructor ControlConstraint
returns a ControlConstraint
of a function. The function must take 1 to 3 arguments, u
to (t, u, v)
, if the function is variable or non autonomous, it must be specified. Dependencies are specified either with :
- booleans,
autonomous
andvariable
, respectivelytrue
andfalse
by default DataType
,Autonomous
/NonAutonomous
andNonFixed
/Fixed
, respectivelyAutonomous
andFixed
by default.
Examples
julia> IncorrectArgument ControlConstraint(u -> [u[1]^2, 2u[2]], Int64)
julia> IncorrectArgument ControlConstraint(u -> [u[1]^2, 2u[2]], Int64)
julia> C = ControlConstraint(u -> [u[1]^2, 2u[2]], Autonomous, Fixed)
julia> C = ControlConstraint((u, v) -> [u[1]^2, 2u[2]+v[3]], Autonomous, NonFixed)
julia> C = ControlConstraint((t, u) -> [t+u[1]^2, 2u[2]], NonAutonomous, Fixed)
julia> C = ControlConstraint((t, u, v) -> [t+u[1]^2, 2u[2]+v[3]], NonAutonomous, NonFixed)
julia> C = ControlConstraint(u -> [u[1]^2, 2u[2]], autonomous=true, variable=false)
julia> C = ControlConstraint((u, v) -> [u[1]^2, 2u[2]+v[3]], autonomous=true, variable=true)
julia> C = ControlConstraint((t, u) -> [t+u[1]^2, 2u[2]], autonomous=false, variable=false)
julia> C = ControlConstraint((t, u, v) -> [t+u[1]^2, 2u[2]+v[3]], autonomous=false, variable=true)
When the control is of dimension 1, consider u
as a scalar.
Call
The call returns the evaluation of the ControlConstraint
for given values.
Examples
julia> C = ControlConstraint(u -> [u[1]^2, 2u[2]], autonomous=true, variable=false)
julia> C([1, -1])
[1, -2]
julia> t = 1
julia> v = Real[]
julia> C(t, [1, -1], v)
[1, -2]
julia> C = ControlConstraint((u, v) -> [u[1]^2, 2u[2]+v[3]], autonomous=true, variable=true)
julia> C([1, -1], [1, 2, 3])
[1, 1]
julia> C(t, [1, -1], [1, 2, 3])
[1, 1]
julia> C = ControlConstraint((t, u) -> [t+u[1]^2, 2u[2]], autonomous=false, variable=false)
julia> C(1, [1, -1])
[2, -2]
julia> C(1, [1, -1], v)
[2, -2]
julia> C = ControlConstraint((t, u, v) -> [t+u[1]^2, 2u[2]+v[3]], autonomous=false, variable=true)
julia> C(1, [1, -1], [1, 2, 3])
[2, 1]
CTBase.ControlConstraint
— MethodControlConstraint(
f::Function,
TD::Type{<:TimeDependence},
VD::Type{<:VariableDependence}
) -> ControlConstraint
Return the StateConstraint
of a function. Dependencies are specified with DataType, Autonomous, NonAutonomous and Fixed, NonFixed.
julia> C = ControlConstraint(u -> [u[1]^2, 2u[2]], Autonomous, Fixed)
julia> C = ControlConstraint((u, v) -> [u[1]^2, 2u[2]+v[3]], Autonomous, NonFixed)
julia> C = ControlConstraint((t, u) -> [t+u[1]^2, 2u[2]], NonAutonomous, Fixed)
julia> C = ControlConstraint((t, u, v) -> [t+u[1]^2, 2u[2]+v[3]], NonAutonomous, NonFixed)
CTBase.ControlConstraint
— MethodControlConstraint(
f::Function;
autonomous,
variable
) -> ControlConstraint
Return the ControlConstraint
of a function. Dependencies are specified with a boolean, variable, false by default, autonomous, true by default.
julia> C = ControlConstraint(u -> [u[1]^2, 2u[2]], autonomous=true, variable=false)
julia> C = ControlConstraint((u, v) -> [u[1]^2, 2u[2]+v[3]], autonomous=true, variable=true)
julia> C = ControlConstraint((t, u) -> [t+u[1]^2, 2u[2]], autonomous=false, variable=false)
julia> C = ControlConstraint((t, u, v) -> [t+u[1]^2, 2u[2]+v[3]], autonomous=false, variable=true)
CTBase.ControlConstraint
— MethodReturn the value of the ControlConstraint function.
julia> C = ControlConstraint(u -> [u[1]^2, 2u[2]], autonomous=true, variable=false)
julia> C([1, -1])
[1, -2]
julia> t = 1
julia> v = Real[]
julia> C(t, [1, -1], v)
[1, -2]
julia> C = ControlConstraint((u, v) -> [u[1]^2, 2u[2]+v[3]], autonomous=true, variable=true)
julia> C([1, -1], [1, 2, 3])
[1, 1]
julia> C(t, [1, -1], [1, 2, 3])
[1, 1]
julia> C = ControlConstraint((t, u) -> [t+u[1]^2, 2u[2]], autonomous=false, variable=false)
julia> C(1, [1, -1])
[2, -2]
julia> C(1, [1, -1], v)
[2, -2]
julia> C = ControlConstraint((t, u, v) -> [t+u[1]^2, 2u[2]+v[3]], autonomous=false, variable=true)
julia> C(1, [1, -1], [1, 2, 3])
[2, 1]
CTBase.ControlLaw
— Typestruct ControlLaw{TF<:Function, TD<:TimeDependence, VD<:VariableDependence}
Fields
f::Function
Similar to Hamiltonian
in the usage, but the dimension of the output of the function f
is arbitrary.
The default values for time_dependence
and variable_dependence
are Autonomous
and Fixed
respectively.
Constructor
The constructor ControlLaw
returns a ControlLaw
of a function. The function must take 2 to 4 arguments, (x, p)
to (t, x, p, v)
, if the function is variable or non autonomous, it must be specified. Dependencies are specified either with :
- booleans,
autonomous
andvariable
, respectivelytrue
andfalse
by default DataType
,Autonomous
/NonAutonomous
andNonFixed
/Fixed
, respectivelyAutonomous
andFixed
by default.
Examples
julia> ControlLaw((x, p) -> x[1]^2+2p[2], Int64)
IncorrectArgument
julia> ControlLaw((x, p) -> x[1]^2+2p[2], Int64)
IncorrectArgument
julia> u = ControlLaw((x, p) -> x[1]^2+2p[2], Autonomous, Fixed)
julia> u = ControlLaw((x, p, v) -> x[1]^2+2p[2]+v[3], Autonomous, NonFixed)
julia> u = ControlLaw((t, x, p) -> t+x[1]^2+2p[2], NonAutonomous, Fixed)
julia> u = ControlLaw((t, x, p, v) -> t+x[1]^2+2p[2]+v[3], NonAutonomous, NonFixed)
julia> u = ControlLaw((x, p) -> x[1]^2+2p[2], autonomous=true, variable=false)
julia> u = ControlLaw((x, p, v) -> x[1]^2+2p[2]+v[3], autonomous=true, variable=true)
julia> u = ControlLaw((t, x, p) -> t+x[1]^2+2p[2], autonomous=false, variable=false)
julia> u = ControlLaw((t, x, p, v) -> t+x[1]^2+2p[2]+v[3], autonomous=false, variable=true)
When the state and costate are of dimension 1, consider x
and p
as scalars.
Call
The call returns the evaluation of the ControlLaw
for given values.
Examples
julia> u = ControlLaw((x, p) -> x[1]^2+2p[2], autonomous=true, variable=false)
julia> u([1, 0], [0, 1])
3
julia> t = 1
julia> v = Real[]
julia> u(t, [1, 0], [0, 1])
MethodError
julia> u([1, 0], [0, 1], v)
MethodError
julia> u(t, [1, 0], [0, 1], v)
3
julia> u = ControlLaw((x, p, v) -> x[1]^2+2p[2]+v[3], autonomous=true, variable=true)
julia> u([1, 0], [0, 1], [1, 2, 3])
6
julia> u(t, [1, 0], [0, 1], [1, 2, 3])
6
julia> u = ControlLaw((t, x, p) -> t+x[1]^2+2p[2], autonomous=false, variable=false)
julia> u(1, [1, 0], [0, 1])
4
julia> u(1, [1, 0], [0, 1], v)
4
julia> u = ControlLaw((t, x, p, v) -> t+x[1]^2+2p[2]+v[3], autonomous=false, variable=true)
julia> u(1, [1, 0], [0, 1], [1, 2, 3])
7
CTBase.ControlLaw
— MethodControlLaw(
f::Function,
TD::Type{<:TimeDependence},
VD::Type{<:VariableDependence}
) -> ControlLaw
Return the ControlLaw
of a function. Dependencies are specified with DataType, Autonomous, NonAutonomous and Fixed, NonFixed.
julia> u = ControlLaw((x, p) -> x[1]^2+2p[2], Autonomous, Fixed)
julia> u = ControlLaw((x, p, v) -> x[1]^2+2p[2]+v[3], Autonomous, NonFixed)
julia> u = ControlLaw((t, x, p) -> t+x[1]^2+2p[2], NonAutonomous, Fixed)
julia> u = ControlLaw((t, x, p, v) -> t+x[1]^2+2p[2]+v[3], NonAutonomous, NonFixed)
CTBase.ControlLaw
— MethodControlLaw(f::Function; autonomous, variable) -> ControlLaw
Return the ControlLaw
of a function. Dependencies are specified with a boolean, variable, false by default, autonomous, true by default.
julia> u = ControlLaw((x, p) -> x[1]^2+2p[2], autonomous=true, variable=false)
julia> u = ControlLaw((x, p, v) -> x[1]^2+2p[2]+v[3], autonomous=true, variable=true)
julia> u = ControlLaw((t, x, p) -> t+x[1]^2+2p[2], autonomous=false, variable=false)
julia> u = ControlLaw((t, x, p, v) -> t+x[1]^2+2p[2]+v[3], autonomous=false, variable=true)
CTBase.ControlLaw
— MethodReturn the value of the ControlLaw function.
julia> u = ControlLaw((x, p) -> x[1]^2+2p[2], autonomous=true, variable=false)
julia> u([1, 0], [0, 1])
3
julia> t = 1
julia> v = Real[]
julia> u(t, [1, 0], [0, 1])
MethodError
julia> u([1, 0], [0, 1], v)
MethodError
julia> u(t, [1, 0], [0, 1], v)
3
julia> u = ControlLaw((x, p, v) -> x[1]^2+2p[2]+v[3], autonomous=true, variable=true)
julia> u([1, 0], [0, 1], [1, 2, 3])
6
julia> u(t, [1, 0], [0, 1], [1, 2, 3])
6
julia> u = ControlLaw((t, x, p) -> t+x[1]^2+2p[2], autonomous=false, variable=false)
julia> u(1, [1, 0], [0, 1])
4
julia> u(1, [1, 0], [0, 1], v)
4
julia> u = ControlLaw((t, x, p, v) -> t+x[1]^2+2p[2]+v[3], autonomous=false, variable=true)
julia> u(1, [1, 0], [0, 1], [1, 2, 3])
7
CTBase.Controls
— TypeType alias for a vector of controls.
julia> const Controls = AbstractVector{<:Control}
CTBase.Costates
— TypeType alias for a vector of costates.
julia> const Costates = AbstractVector{<:Costate}
CTBase.Description
— TypeA description is a tuple of symbols. Description
is a type alias for a tuple of symbols.
julia> const Description = Tuple{DescVarArg}
See also: DescVarArg
.
Example
Base.show
is overloaded for descriptions, that is tuple of descriptions are printed as follows:
julia> display( ( (:a, :b), (:b, :c) ) )
(:a, :b)
(:b, :c)
CTBase.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 = Int
CTBase.Dynamics
— Typestruct Dynamics{TF<:Function, TD<:TimeDependence, VD<:VariableDependence}
Fields
f::Function
The default value for time_dependence
and variable_dependence
are Autonomous
and Fixed
respectively.
Constructor
The constructor Dynamics
returns a Dynamics
of a function. The function must take 2 to 4 arguments, (x, u)
to (t, x, u, v)
, if the function is variable or non autonomous, it must be specified. Dependencies are specified either with :
- booleans,
autonomous
andvariable
, respectivelytrue
andfalse
by default DataType
,Autonomous
/NonAutonomous
andNonFixed
/Fixed
, respectivelyAutonomous
andFixed
by default.
Examples
julia> Dynamics((x, u) -> [2x[2]-u^2, x[1]], Int64)
IncorrectArgument
julia> Dynamics((x, u) -> [2x[2]-u^2, x[1]], Int64)
IncorrectArgument
julia> D = Dynamics((x, u) -> [2x[2]-u^2, x[1]], Autonomous, Fixed)
julia> D = Dynamics((x, u, v) -> [2x[2]-u^2+v[3], x[1]], Autonomous, NonFixed)
julia> D = Dynamics((t, x, u) -> [t+2x[2]-u^2, x[1]], NonAutonomous, Fixed)
julia> D = Dynamics((t, x, u, v) -> [t+2x[2]-u^2+v[3], x[1]], NonAutonomous, NonFixed)
julia> D = Dynamics((x, u) -> [2x[2]-u^2, x[1]], autonomous=true, variable=false)
julia> D = Dynamics((x, u, v) -> [2x[2]-u^2+v[3], x[1]], autonomous=true, variable=true)
julia> D = Dynamics((t, x, u) -> [t+2x[2]-u^2, x[1]], autonomous=false, variable=false)
julia> D = Dynamics((t, x, u, v) -> [t+2x[2]-u^2+v[3], x[1]], autonomous=false, variable=true)
When the state is of dimension 1, consider x
as a scalar. Same for the control.
Call
The call returns the evaluation of the Dynamics
for given values.
Examples
julia> D = Dynamics((x, u) -> [2x[2]-u^2, x[1]], autonomous=true, variable=false)
julia> D([1, 0], 1)
[-1, 1]
julia> t = 1
julia> v = Real[]
julia> D(t, [1, 0], 1, v)
[-1, 1]
julia> D = Dynamics((x, u, v) -> [2x[2]-u^2+v[3], x[1]], autonomous=true, variable=true)
julia> D([1, 0], 1, [1, 2, 3])
[2, 1]
julia> D(t, [1, 0], 1, [1, 2, 3])
[2, 1]
julia> D = Dynamics((t, x, u) -> [t+2x[2]-u^2, x[1]], autonomous=false, variable=false)
julia> D(1, [1, 0], 1)
[0, 1]
julia> D(1, [1, 0], 1, v)
[0, 1]
julia> D = Dynamics((t, x, u, v) -> [t+2x[2]-u^2+v[3], x[1]], autonomous=false, variable=true)
julia> D(1, [1, 0], 1, [1, 2, 3])
[3, 1]
CTBase.Dynamics
— MethodDynamics(
f::Function,
TD::Type{<:TimeDependence},
VD::Type{<:VariableDependence}
) -> Dynamics
Return the Dynamics
of a function. Dependencies are specified with DataType, Autonomous, NonAutonomous and Fixed, NonFixed.
julia> D = Dynamics((x, u) -> [2x[2]-u^2, x[1]], Autonomous, Fixed)
julia> D = Dynamics((x, u, v) -> [2x[2]-u^2+v[3], x[1]], Autonomous, NonFixed)
julia> D = Dynamics((t, x, u) -> [t+2x[2]-u^2, x[1]], NonAutonomous, Fixed)
julia> D = Dynamics((t, x, u, v) -> [t+2x[2]-u^2+v[3], x[1]], NonAutonomous, NonFixed)
CTBase.Dynamics
— MethodDynamics(f::Function; autonomous, variable) -> Dynamics
Return the Dynamics
of a function. Dependencies are specified with a boolean, variable, false by default, autonomous, true by default.
julia> D = Dynamics((x, u) -> [2x[2]-u^2, x[1]], autonomous=true, variable=false)
julia> D = Dynamics((x, u, v) -> [2x[2]-u^2+v[3], x[1]], autonomous=true, variable=true)
julia> D = Dynamics((t, x, u) -> [t+2x[2]-u^2, x[1]], autonomous=false, variable=false)
julia> D = Dynamics((t, x, u, v) -> [t+2x[2]-u^2+v[3], x[1]], autonomous=false, variable=true)
CTBase.Dynamics
— MethodReturn the value of the Dynamics function.
julia> D = Dynamics((x, u) -> [2x[2]-u^2, x[1]], autonomous=true, variable=false)
julia> D([1, 0], 1)
[-1, 1]
julia> t = 1
julia> v = Real[]
julia> D(t, [1, 0], 1, v)
[-1, 1]
julia> D = Dynamics((x, u, v) -> [2x[2]-u^2+v[3], x[1]], autonomous=true, variable=true)
julia> D([1, 0], 1, [1, 2, 3])
[2, 1]
julia> D(t, [1, 0], 1, [1, 2, 3])
[2, 1]
julia> D = Dynamics((t, x, u) -> [t+2x[2]-u^2, x[1]], autonomous=false, variable=false)
julia> D(1, [1, 0], 1)
[0, 1]
julia> D(1, [1, 0], 1, v)
[0, 1]
julia> D = Dynamics((t, x, u, v) -> [t+2x[2]-u^2+v[3], x[1]], autonomous=false, variable=true)
julia> D(1, [1, 0], 1, [1, 2, 3])
[3, 1]
CTBase.ExtensionError
— Typemutable struct ExtensionError <: CTException
Exception thrown when an extension is not loaded but the user tries to call a function of it.
Fields
weakdeps::Tuple{Vararg{Symbol}}
CTBase.FeedbackControl
— Typestruct FeedbackControl{TF<:Function, TD<:TimeDependence, VD<:VariableDependence}
Fields
f::Function
Similar to VectorField
in the usage, but the dimension of the output of the function f
is arbitrary.
The default values for time_dependence
and variable_dependence
are Autonomous
and Fixed
respectively.
Constructor
The constructor FeedbackControl
returns a FeedbackControl
of a function. The function must take 1 to 3 arguments, x
to (t, x, v)
, if the function is variable or non autonomous, it must be specified. Dependencies are specified either with :
- booleans,
autonomous
andvariable
, respectivelytrue
andfalse
by default DataType
,Autonomous
/NonAutonomous
andNonFixed
/Fixed
, respectivelyAutonomous
andFixed
by default.
Examples
julia> FeedbackControl(x -> x[1]^2+2x[2], Int64)
IncorrectArgument
julia> FeedbackControl(x -> x[1]^2+2x[2], Int64)
IncorrectArgument
julia> u = FeedbackControl(x -> x[1]^2+2x[2], Autonomous, Fixed)
julia> u = FeedbackControl((x, v) -> x[1]^2+2x[2]+v[3], Autonomous, NonFixed)
julia> u = FeedbackControl((t, x) -> t+x[1]^2+2x[2], NonAutonomous, Fixed)
julia> u = FeedbackControl((t, x, v) -> t+x[1]^2+2x[2]+v[3], NonAutonomous, NonFixed)
julia> u = FeedbackControl(x -> x[1]^2+2x[2], autonomous=true, variable=false)
julia> u = FeedbackControl((x, v) -> x[1]^2+2x[2]+v[3], autonomous=true, variable=true)
julia> u = FeedbackControl((t, x) -> t+x[1]^2+2x[2], autonomous=false, variable=false)
julia> u = FeedbackControl((t, x, v) -> t+x[1]^2+2x[2]+v[3], autonomous=false, variable=true)
When the state is of dimension 1, consider x
as a scalar.
Call
The call returns the evaluation of the FeedbackControl
for given values.
Examples
julia> u = FeedbackControl(x -> x[1]^2+2x[2], autonomous=true, variable=false)
julia> u([1, 0])
1
julia> t = 1
julia> v = Real[]
julia> u(t, [1, 0])
MethodError
julia> u([1, 0], v)
MethodError
julia> u(t, [1, 0], v)
1
julia> u = FeedbackControl((x, v) -> x[1]^2+2x[2]+v[3], autonomous=true, variable=true)
julia> u([1, 0], [1, 2, 3])
4
julia> u(t, [1, 0], [1, 2, 3])
4
julia> u = FeedbackControl((t, x) -> t+x[1]^2+2x[2], autonomous=false, variable=false)
julia> u(1, [1, 0])
2
julia> u(1, [1, 0], v)
2
julia> u = FeedbackControl((t, x, v) -> t+x[1]^2+2x[2]+v[3], autonomous=false, variable=true)
julia> u(1, [1, 0], [1, 2, 3])
5
CTBase.FeedbackControl
— MethodFeedbackControl(
f::Function,
TD::Type{<:TimeDependence},
VD::Type{<:VariableDependence}
) -> FeedbackControl
Return the FeedbackControl
of a function. Dependencies are specified with DataType, Autonomous, NonAutonomous and Fixed, NonFixed.
julia> u = FeedbackControl(x -> x[1]^2+2x[2], Autonomous, Fixed)
julia> u = FeedbackControl((x, v) -> x[1]^2+2x[2]+v[3], Autonomous, NonFixed)
julia> u = FeedbackControl((t, x) -> t+x[1]^2+2x[2], NonAutonomous, Fixed)
julia> u = FeedbackControl((t, x, v) -> t+x[1]^2+2x[2]+v[3], NonAutonomous, NonFixed)
CTBase.FeedbackControl
— MethodFeedbackControl(
f::Function;
autonomous,
variable
) -> FeedbackControl
Return the FeedbackControl
of a function. Dependencies are specified with a boolean, variable, false by default, autonomous, true by default.
julia> u = FeedbackControl(x -> x[1]^2+2x[2], autonomous=true, variable=false)
julia> u = FeedbackControl((x, v) -> x[1]^2+2x[2]+v[3], autonomous=true, variable=true)
julia> u = FeedbackControl((t, x) -> t+x[1]^2+2x[2], autonomous=false, variable=false)
julia> u = FeedbackControl((t, x, v) -> t+x[1]^2+2x[2]+v[3], autonomous=false, variable=true)
CTBase.FeedbackControl
— MethodReturn the value of the FeedbackControl function.
julia> u = FeedbackControl(x -> x[1]^2+2x[2], autonomous=true, variable=false)
julia> u([1, 0])
1
julia> t = 1
julia> v = Real[]
julia> u(t, [1, 0])
MethodError
julia> u([1, 0], v)
MethodError
julia> u(t, [1, 0], v)
1
julia> u = FeedbackControl((x, v) -> x[1]^2+2x[2]+v[3], autonomous=true, variable=true)
julia> u([1, 0], [1, 2, 3])
4
julia> u(t, [1, 0], [1, 2, 3])
4
julia> u = FeedbackControl((t, x) -> t+x[1]^2+2x[2], autonomous=false, variable=false)
julia> u(1, [1, 0])
2
julia> u(1, [1, 0], v)
2
julia> u = FeedbackControl((t, x, v) -> t+x[1]^2+2x[2]+v[3], autonomous=false, variable=true)
julia> u(1, [1, 0], [1, 2, 3])
5
CTBase.Fixed
— Typeabstract type Fixed <: VariableDependence
CTBase.Hamiltonian
— Typestruct Hamiltonian{TF<:Function, TD<:TimeDependence, VD<:VariableDependence} <: AbstractHamiltonian{TD<:TimeDependence, VD<:VariableDependence}
Fields
f::Function
The default values for time_dependence
and variable_dependence
are Autonomous
and Fixed
respectively.
Constructor
The constructor Hamiltonian
returns a Hamiltonian
of a function. The function must take 2 to 4 arguments, (x, p)
to (t, x, p, v)
, if the function is variable or non autonomous, it must be specified. Dependencies are specified either with :
- booleans,
autonomous
andvariable
, respectivelytrue
andfalse
by default DataType
,Autonomous
/NonAutonomous
andNonFixed
/Fixed
, respectivelyAutonomous
andFixed
by default.
Examples
julia> Hamiltonian((x, p) -> x + p, Int64)
IncorrectArgument
julia> Hamiltonian((x, p) -> x + p, Int64)
IncorrectArgument
julia> H = Hamiltonian((x, p) -> x[1]^2+2p[2])
julia> H = Hamiltonian((t, x, p, v) -> [t+x[1]^2+2p[2]+v[3]], autonomous=false, variable=true)
julia> H = Hamiltonian((t, x, p, v) -> [t+x[1]^2+2p[2]+v[3]], NonAutonomous, NonFixed)
When the state and costate are of dimension 1, consider x
and p
as scalars.
Call
The call returns the evaluation of the Hamiltonian
for given values.
Examples
julia> H = Hamiltonian((x, p) -> [x[1]^2+2p[2]]) # autonomous=true, variable=false
julia> H([1, 0], [0, 1])
MethodError # H must return a scalar
julia> H = Hamiltonian((x, p) -> x[1]^2+2p[2])
julia> H([1, 0], [0, 1])
3
julia> t = 1
julia> v = Real[]
julia> H(t, [1, 0], [0, 1])
MethodError
julia> H([1, 0], [0, 1], v)
MethodError
julia> H(t, [1, 0], [0, 1], v)
3
julia> H = Hamiltonian((x, p, v) -> x[1]^2+2p[2]+v[3], variable=true)
julia> H([1, 0], [0, 1], [1, 2, 3])
6
julia> H(t, [1, 0], [0, 1], [1, 2, 3])
6
julia> H = Hamiltonian((t, x, p) -> t+x[1]^2+2p[2], autonomous=false)
julia> H(1, [1, 0], [0, 1])
4
julia> H(1, [1, 0], [0, 1], v)
4
julia> H = Hamiltonian((t, x, p, v) -> t+x[1]^2+2p[2]+v[3], autonomous=false, variable=true)
julia> H(1, [1, 0], [0, 1], [1, 2, 3])
7
CTBase.Hamiltonian
— MethodHamiltonian(
f::Function,
TD::Type{<:TimeDependence},
VD::Type{<:VariableDependence}
) -> Hamiltonian
Return an Hamiltonian
of a function. Dependencies are specified with DataType, Autonomous, NonAutonomous and Fixed, NonFixed.
julia> H = Hamiltonian((x, p) -> x[1]^2+2p[2])
julia> H = Hamiltonian((t, x, p, v) -> [t+x[1]^2+2p[2]+v[3]], NonAutonomous, NonFixed)
CTBase.Hamiltonian
— MethodHamiltonian(
f::Function;
autonomous,
variable
) -> Hamiltonian
Return an Hamiltonian
of a function. Dependencies are specified with a boolean, variable, false by default, autonomous, true by default.
julia> H = Hamiltonian((x, p) -> x[1]^2+2p[2])
julia> H = Hamiltonian((t, x, p, v) -> [t+x[1]^2+2p[2]+v[3]], autonomous=false, variable=true)
CTBase.Hamiltonian
— MethodReturn the value of the Hamiltonian.
julia> H = Hamiltonian((x, p) -> [x[1]^2+2p[2]]) # autonomous=true, variable=false
julia> H([1, 0], [0, 1])
MethodError # H must return a scalar
julia> H = Hamiltonian((x, p) -> x[1]^2+2p[2])
julia> H([1, 0], [0, 1])
3
julia> t = 1
julia> v = Real[]
julia> H(t, [1, 0], [0, 1])
MethodError
julia> H([1, 0], [0, 1], v)
MethodError
julia> H(t, [1, 0], [0, 1], v)
3
julia> H = Hamiltonian((x, p, v) -> x[1]^2+2p[2]+v[3], variable=true)
julia> H([1, 0], [0, 1], [1, 2, 3])
6
julia> H(t, [1, 0], [0, 1], [1, 2, 3])
6
julia> H = Hamiltonian((t, x, p) -> t+x[1]^2+2p[2], autonomous=false)
julia> H(1, [1, 0], [0, 1])
4
julia> H(1, [1, 0], [0, 1], v)
4
julia> H = Hamiltonian((t, x, p, v) -> t+x[1]^2+2p[2]+v[3], autonomous=false, variable=true)
julia> H(1, [1, 0], [0, 1], [1, 2, 3])
7
CTBase.HamiltonianLift
— Typestruct HamiltonianLift{TV<:VectorField, TD<:TimeDependence, VD<:VariableDependence} <: AbstractHamiltonian{TD<:TimeDependence, VD<:VariableDependence}
Lifts
X::VectorField
The values for time_dependence
and variable_dependence
are deternimed by the values of those for the VectorField.
Constructor
The constructor HamiltonianLift
returns a HamiltonianLift
of a VectorField
.
Examples
julia> H = HamiltonianLift(VectorField(x -> [x[1]^2, 2x[2]]))
julia> H = HamiltonianLift(VectorField((x, v) -> [x[1]^2, 2x[2]+v[3]], variable=true))
julia> H = HamiltonianLift(VectorField((t, x) -> [t+x[1]^2, 2x[2]], autonomous=false))
julia> H = HamiltonianLift(VectorField((t, x, v) -> [t+x[1]^2, 2x[2]+v[3]], autonomous=false, variable=true))
julia> H = HamiltonianLift(VectorField(x -> [x[1]^2, 2x[2]]))
julia> H = HamiltonianLift(VectorField((x, v) -> [x[1]^2, 2x[2]+v[3]], NonFixed))
julia> H = HamiltonianLift(VectorField((t, x) -> [t+x[1]^2, 2x[2]], NonAutonomous))
julia> H = HamiltonianLift(VectorField((t, x, v) -> [t+x[1]^2, 2x[2]+v[3]], NonAutonomous, NonFixed))
When the state and costate are of dimension 1, consider x
and p
as scalars.
Call
The call returns the evaluation of the HamiltonianLift
for given values.
Examples
julia> H = HamiltonianLift(VectorField(x -> [x[1]^2, 2x[2]]))
julia> H([1, 2], [1, 1])
5
julia> t = 1
julia> v = Real[]
julia> H(t, [1, 0], [0, 1])
MethodError
julia> H([1, 0], [0, 1], v)
MethodError
julia> H(t, [1, 0], [0, 1], v)
5
julia> H = HamiltonianLift(VectorField((x, v) -> [x[1]^2, 2x[2]+v[3]], variable=true))
julia> H([1, 0], [0, 1], [1, 2, 3])
3
julia> H(t, [1, 0], [0, 1], [1, 2, 3])
3
julia> H = HamiltonianLift(VectorField((t, x) -> [t+x[1]^2, 2x[2]], autonomous=false))
julia> H(1, [1, 2], [1, 1])
6
julia> H(1, [1, 0], [0, 1], v)
6
julia> H = HamiltonianLift(VectorField((t, x, v) -> [t+x[1]^2, 2x[2]+v[3]], autonomous=false, variable=true))
julia> H(1, [1, 0], [0, 1], [1, 2, 3])
3
Alternatively, it is possible to construct the HamiltonianLift
from a Function
being the VectorField
.
julia> HL1 = HamiltonianLift((x, v) -> [x[1]^2,x[2]^2+v], autonomous=true, variable=true)
julia> HL2 = HamiltonianLift(VectorField((x, v) -> [x[1]^2,x[2]^2+v], autonomous=true, variable=true))
julia> HL1([1, 0], [0, 1], 1) == HL2([1, 0], [0, 1], 1)
true
CTBase.HamiltonianLift
— MethodHamiltonianLift(
f::Function,
TD::Type{<:TimeDependence},
VD::Type{<:VariableDependence}
) -> HamiltonianLift{VectorField{TF, TD, VD}} where {TF<:Function, TD<:TimeDependence, VD<:VariableDependence}
Return an HamiltonianLift
of a function. Dependencies are specified with DataType, Autonomous, NonAutonomous and Fixed, NonFixed.
julia> HL = HamiltonianLift(x -> [x[1]^2,x[2]^2], Autonomous, Fixed)
julia> HL = HamiltonianLift((x, v) -> [x[1]^2,x[2]^2+v], Autonomous, NonFixed)
julia> HL = HamiltonianLift((t, x) -> [t+x[1]^2,x[2]^2], NonAutonomous, Fixed)
julia> HL = HamiltonianLift((t, x, v) -> [t+x[1]^2,x[2]^2+v], NonAutonomous, NonFixed)
CTBase.HamiltonianLift
— MethodHamiltonianLift(
f::Function;
autonomous,
variable
) -> HamiltonianLift{VectorField{TF, TD, VD}} where {TF<:Function, TD<:TimeDependence, VD<:VariableDependence}
Return an HamiltonianLift
of a function. Dependencies are specified with a boolean, variable, false by default, autonomous, true by default.
julia> HL = HamiltonianLift(x -> [x[1]^2,x[2]^2], autonomous=true, variable=false)
julia> HL = HamiltonianLift((x, v) -> [x[1]^2,x[2]^2+v], autonomous=true, variable=true)
julia> HL = HamiltonianLift((t, x) -> [t+x[1]^2,x[2]^2], autonomous=false, variable=false)
julia> HL = HamiltonianLift((t, x, v) -> [t+x[1]^2,x[2]^2+v], autonomous=false, variable=true)
CTBase.HamiltonianLift
— MethodReturn the value of the HamiltonianLift.
Examples
julia> H = HamiltonianLift(VectorField(x -> [x[1]^2, 2x[2]]))
julia> H([1, 2], [1, 1])
5
julia> t = 1
julia> v = Real[]
julia> H(t, [1, 0], [0, 1])
MethodError
julia> H([1, 0], [0, 1], v)
MethodError
julia> H(t, [1, 0], [0, 1], v)
5
julia> H = HamiltonianLift(VectorField((x, v) -> [x[1]^2, 2x[2]+v[3]], variable=true))
julia> H([1, 0], [0, 1], [1, 2, 3])
3
julia> H(t, [1, 0], [0, 1], [1, 2, 3])
3
julia> H = HamiltonianLift(VectorField((t, x) -> [t+x[1]^2, 2x[2]], autonomous=false))
julia> H(1, [1, 2], [1, 1])
6
julia> H(1, [1, 0], [0, 1], v)
6
julia> H = HamiltonianLift(VectorField((t, x, v) -> [t+x[1]^2, 2x[2]+v[3]], autonomous=false, variable=true))
julia> H(1, [1, 0], [0, 1], [1, 2, 3])
3
CTBase.HamiltonianVectorField
— Typestruct HamiltonianVectorField{TF<:Function, TD<:TimeDependence, VD<:VariableDependence} <: CTBase.AbstractVectorField{TD<:TimeDependence, VD<:VariableDependence}
Fields
f::Function
The default values for time_dependence
and variable_dependence
are Autonomous
and Fixed
respectively.
Constructor
The constructor HamiltonianVectorField
returns a HamiltonianVectorField
of a function. The function must take 2 to 4 arguments, (x, p)
to (t, x, p, v)
, if the function is variable or non autonomous, it must be specified. Dependencies are specified either with :
- booleans,
autonomous
andvariable
, respectivelytrue
andfalse
by default DataType
,Autonomous
/NonAutonomous
andNonFixed
/Fixed
, respectivelyAutonomous
andFixed
by default.
Examples
julia> HamiltonianVectorField((x, p) -> [x[1]^2+2p[2], x[2]-3p[2]^2], Int64)
IncorrectArgument
julia> HamiltonianVectorField((x, p) -> [x[1]^2+2p[2], x[2]-3p[2]^2], Int64)
IncorrectArgument
julia> Hv = HamiltonianVectorField((x, p) -> [x[1]^2+2p[2], x[2]-3p[2]^2]) # autonomous=true, variable=false
julia> Hv = HamiltonianVectorField((x, p, v) -> [x[1]^2+2p[2]+v[3], x[2]-3p[2]^2+v[4]], variable=true)
julia> Hv = HamiltonianVectorField((t, x, p) -> [t+x[1]^2+2p[2], x[2]-3p[2]^2], autonomous=false)
julia> Hv = HamiltonianVectorField((t, x, p, v) -> [t+x[1]^2+2p[2]+v[3], x[2]-3p[2]^2+v[4]], autonomous=false, variable=true)
julia> Hv = HamiltonianVectorField((x, p, v) -> [x[1]^2+2p[2]+v[3], x[2]-3p[2]^2+v[4]], NonFixed)
julia> Hv = HamiltonianVectorField((t, x, p) -> [t+x[1]^2+2p[2], x[2]-3p[2]^2], NonAutonomous)
julia> Hv = HamiltonianVectorField((t, x, p, v) -> [t+x[1]^2+2p[2]+v[3], x[2]-3p[2]^2+v[4]], NonAutonomous, NonFixed)
When the state and costate are of dimension 1, consider x
and p
as scalars.
Call
The call returns the evaluation of the HamiltonianVectorField
for given values.
Examples
julia> Hv = HamiltonianVectorField((x, p) -> [x[1]^2+2p[2], x[2]-3p[2]^2]) # autonomous=true, variable=false
julia> Hv([1, 0], [0, 1])
[3, -3]
julia> t = 1
julia> v = Real[]
julia> Hv(t, [1, 0], [0, 1])
MethodError
julia> Hv([1, 0], [0, 1], v)
MethodError
julia> Hv(t, [1, 0], [0, 1], v)
[3, -3]
julia> Hv = HamiltonianVectorField((x, p, v) -> [x[1]^2+2p[2]+v[3], x[2]-3p[2]^2+v[4]], variable=true)
julia> Hv([1, 0], [0, 1], [1, 2, 3, 4])
[6, -3]
julia> Hv(t, [1, 0], [0, 1], [1, 2, 3, 4])
[6, -3]
julia> Hv = HamiltonianVectorField((t, x, p) -> [t+x[1]^2+2p[2], x[2]-3p[2]^2], autonomous=false)
julia> Hv(1, [1, 0], [0, 1])
[4, -3]
julia> Hv(1, [1, 0], [0, 1], v)
[4, -3]
julia> Hv = HamiltonianVectorField((t, x, p, v) -> [t+x[1]^2+2p[2]+v[3], x[2]-3p[2]^2+v[4]], autonomous=false, variable=true)
julia> Hv(1, [1, 0], [0, 1], [1, 2, 3, 4])
[7, -3]
CTBase.HamiltonianVectorField
— MethodHamiltonianVectorField(
f::Function,
TD::Type{<:TimeDependence},
VD::Type{<:VariableDependence}
) -> HamiltonianVectorField
Return an HamiltonianVectorField
of a function. Dependencies are specified with DataType, Autonomous, NonAutonomous and Fixed, NonFixed.
julia> Hv = HamiltonianVectorField((x, p) -> [x[1]^2+2p[2], x[2]-3p[2]^2]) # autonomous=true, variable=false
julia> Hv = HamiltonianVectorField((x, p, v) -> [x[1]^2+2p[2]+v[3], x[2]-3p[2]^2+v[4]], NonFixed)
julia> Hv = HamiltonianVectorField((t, x, p) -> [t+x[1]^2+2p[2], x[2]-3p[2]^2], NonAutonomous)
julia> Hv = HamiltonianVectorField((t, x, p, v) -> [t+x[1]^2+2p[2]+v[3], x[2]-3p[2]^2+v[4]], NonAutonomous, NonFixed)
CTBase.HamiltonianVectorField
— MethodHamiltonianVectorField(
f::Function;
autonomous,
variable
) -> HamiltonianVectorField
Return an HamiltonianVectorField
of a function. Dependencies are specified with a boolean, variable, false by default, autonomous, true by default.
julia> Hv = HamiltonianVectorField((x, p) -> [x[1]^2+2p[2], x[2]-3p[2]^2]) # autonomous=true, variable=false
julia> Hv = HamiltonianVectorField((x, p, v) -> [x[1]^2+2p[2]+v[3], x[2]-3p[2]^2+v[4]], variable=true)
julia> Hv = HamiltonianVectorField((t, x, p) -> [t+x[1]^2+2p[2], x[2]-3p[2]^2], autonomous=false)
julia> Hv = HamiltonianVectorField((t, x, p, v) -> [t+x[1]^2+2p[2]+v[3], x[2]-3p[2]^2+v[4]], autonomous=false, variable=true)
CTBase.HamiltonianVectorField
— MethodReturn the value of the HamiltonianVectorField.
Examples
julia> Hv = HamiltonianVectorField((x, p) -> [x[1]^2+2p[2], x[2]-3p[2]^2]) # autonomous=true, variable=false
julia> Hv([1, 0], [0, 1])
[3, -3]
julia> t = 1
julia> v = Real[]
julia> Hv(t, [1, 0], [0, 1])
MethodError
julia> Hv([1, 0], [0, 1], v)
MethodError
julia> Hv(t, [1, 0], [0, 1], v)
[3, -3]
julia> Hv = HamiltonianVectorField((x, p, v) -> [x[1]^2+2p[2]+v[3], x[2]-3p[2]^2+v[4]], variable=true)
julia> Hv([1, 0], [0, 1], [1, 2, 3, 4])
[6, -3]
julia> Hv(t, [1, 0], [0, 1], [1, 2, 3, 4])
[6, -3]
julia> Hv = HamiltonianVectorField((t, x, p) -> [t+x[1]^2+2p[2], x[2]-3p[2]^2], autonomous=false)
julia> Hv(1, [1, 0], [0, 1])
[4, -3]
julia> Hv(1, [1, 0], [0, 1], v)
[4, -3]
julia> Hv = HamiltonianVectorField((t, x, p, v) -> [t+x[1]^2+2p[2]+v[3], x[2]-3p[2]^2+v[4]], autonomous=false, variable=true)
julia> Hv(1, [1, 0], [0, 1], [1, 2, 3, 4])
[7, -3]
CTBase.IncorrectArgument
— Typestruct IncorrectArgument <: CTException
Exception thrown when an argument is inconsistent.
Fields
var::String
CTBase.IncorrectMethod
— Typestruct IncorrectMethod <: CTException
Exception thrown when a method is incorrect.
Fields
var::Symbol
CTBase.IncorrectOutput
— Typestruct IncorrectOutput <: CTException
Exception thrown when the output is incorrect.
Fields
var::String
CTBase.Index
— Typemutable struct Index
Fields
val::Int64
CTBase.Lagrange
— Typestruct Lagrange{TF<:Function, TD<:TimeDependence, VD<:VariableDependence}
Fields
f::Function
The default value for time_dependence
and variable_dependence
are Autonomous
and Fixed
respectively.
Constructor
The constructor Lagrange
returns a Lagrange
cost of a function. The function must take 2 to 4 arguments, (x, u)
to (t, x, u, v)
, if the function is variable or non autonomous, it must be specified. Dependencies are specified either with :
- booleans,
autonomous
andvariable
, respectivelytrue
andfalse
by default DataType
,Autonomous
/NonAutonomous
andNonFixed
/Fixed
, respectivelyAutonomous
andFixed
by default.
Examples
julia> Lagrange((x, u) -> 2x[2]-u[1]^2, Int64)
IncorrectArgument
julia> Lagrange((x, u) -> 2x[2]-u[1]^2, Int64)
IncorrectArgument
julia> L = Lagrange((x, u) -> [2x[2]-u[1]^2], autonomous=true, variable=false)
julia> L = Lagrange((x, u) -> 2x[2]-u[1]^2, autonomous=true, variable=false)
julia> L = Lagrange((x, u, v) -> 2x[2]-u[1]^2+v[3], autonomous=true, variable=true)
julia> L = Lagrange((t, x, u) -> t+2x[2]-u[1]^2, autonomous=false, variable=false)
julia> L = Lagrange((t, x, u, v) -> t+2x[2]-u[1]^2+v[3], autonomous=false, variable=true)
julia> L = Lagrange((x, u) -> [2x[2]-u[1]^2], Autonomous, Fixed)
julia> L = Lagrange((x, u) -> 2x[2]-u[1]^2, Autonomous, Fixed)
julia> L = Lagrange((x, u, v) -> 2x[2]-u[1]^2+v[3], Autonomous, NonFixed)
julia> L = Lagrange((t, x, u) -> t+2x[2]-u[1]^2, autonomous=false, Fixed)
julia> L = Lagrange((t, x, u, v) -> t+2x[2]-u[1]^2+v[3], autonomous=false, NonFixed)
When the state is of dimension 1, consider x
as a scalar. Same for the control.
Call
The call returns the evaluation of the Lagrange
cost for given values.
Examples
julia> L = Lagrange((x, u) -> [2x[2]-u[1]^2], autonomous=true, variable=false)
julia> L([1, 0], [1])
MethodError
julia> L = Lagrange((x, u) -> 2x[2]-u[1]^2, autonomous=true, variable=false)
julia> L([1, 0], [1])
-1
julia> t = 1
julia> v = Real[]
julia> L(t, [1, 0], [1])
MethodError
julia> L([1, 0], [1], v)
MethodError
julia> L(t, [1, 0], [1], v)
-1
julia> L = Lagrange((x, u, v) -> 2x[2]-u[1]^2+v[3], autonomous=true, variable=true)
julia> L([1, 0], [1], [1, 2, 3])
2
julia> L(t, [1, 0], [1], [1, 2, 3])
2
julia> L = Lagrange((t, x, u) -> t+2x[2]-u[1]^2, autonomous=false, variable=false)
julia> L(1, [1, 0], [1])
0
julia> L(1, [1, 0], [1], v)
0
julia> L = Lagrange((t, x, u, v) -> t+2x[2]-u[1]^2+v[3], autonomous=false, variable=true)
julia> L(1, [1, 0], [1], [1, 2, 3])
3
CTBase.Lagrange
— MethodLagrange(
f::Function,
TD::Type{<:TimeDependence},
VD::Type{<:VariableDependence}
) -> Lagrange
Return a Lagrange
cost of a function. Dependencies are specified with DataType, Autonomous, NonAutonomous and Fixed, NonFixed.
julia> L = Lagrange((x, u) -> [2x[2]-u[1]^2], autonomous=true, variable=false)
julia> L = Lagrange((x, u) -> 2x[2]-u[1]^2, autonomous=true, variable=false)
julia> L = Lagrange((x, u, v) -> 2x[2]-u[1]^2+v[3], autonomous=true, variable=true)
julia> L = Lagrange((t, x, u) -> t+2x[2]-u[1]^2, autonomous=false, variable=false)
julia> L = Lagrange((t, x, u, v) -> t+2x[2]-u[1]^2+v[3], autonomous=false, variable=true)
CTBase.Lagrange
— MethodLagrange(f::Function; autonomous, variable) -> Lagrange
Return a Lagrange
cost of a function. Dependencies are specified with a boolean, variable, false by default, autonomous, true by default.
julia> L = Lagrange((x, u) -> [2x[2]-u[1]^2], autonomous=true, variable=false)
julia> L = Lagrange((x, u) -> 2x[2]-u[1]^2, autonomous=true, variable=false)
julia> L = Lagrange((x, u, v) -> 2x[2]-u[1]^2+v[3], autonomous=true, variable=true)
julia> L = Lagrange((t, x, u) -> t+2x[2]-u[1]^2, autonomous=false, variable=false)
julia> L = Lagrange((t, x, u, v) -> t+2x[2]-u[1]^2+v[3], autonomous=false, variable=true)
CTBase.Lagrange
— MethodReturn the value of the Lagrange function.
Examples
julia> L = Lagrange((x, u) -> [2x[2]-u[1]^2], autonomous=true, variable=false)
julia> L([1, 0], [1])
MethodError
julia> L = Lagrange((x, u) -> 2x[2]-u[1]^2, autonomous=true, variable=false)
julia> L([1, 0], [1])
-1
julia> t = 1
julia> v = Real[]
julia> L(t, [1, 0], [1])
MethodError
julia> L([1, 0], [1], v)
MethodError
julia> L(t, [1, 0], [1], v)
-1
julia> L = Lagrange((x, u, v) -> 2x[2]-u[1]^2+v[3], autonomous=true, variable=true)
julia> L([1, 0], [1], [1, 2, 3])
2
julia> L(t, [1, 0], [1], [1, 2, 3])
2
julia> L = Lagrange((t, x, u) -> t+2x[2]-u[1]^2, autonomous=false, variable=false)
julia> L(1, [1, 0], [1])
0
julia> L(1, [1, 0], [1], v)
0
julia> L = Lagrange((t, x, u, v) -> t+2x[2]-u[1]^2+v[3], autonomous=false, variable=true)
julia> L(1, [1, 0], [1], [1, 2, 3])
3
CTBase.Mayer
— Typestruct Mayer{TF<:Function, VD<:VariableDependence}
Fields
f::Function
The default value for variable_dependence
is Fixed
.
Constructor
The constructor Mayer
returns a Mayer
cost of a function. The function must take 2 or 3 arguments (x0, xf)
or (x0, xf, v)
, if the function is variable, it must be specified. Dependencies are specified with a boolean, variable
, false
by default or with a DataType
, NonFixed/Fixed
, Fixed
by default.
Examples
julia> G = Mayer((x0, xf) -> xf[2]-x0[1])
julia> G = Mayer((x0, xf, v) -> v[3]+xf[2]-x0[1], variable=true)
julia> G = Mayer((x0, xf, v) -> v[3]+xf[2]-x0[1], NonFixed)
When the state is of dimension 1, consider x0
and xf
as a scalar.
Call
The call returns the evaluation of the Mayer
cost for given values. If a variable is given for a non variable dependent Mayer cost, it will be ignored.
Examples
julia> G = Mayer((x0, xf) -> xf[2]-x0[1])
julia> G([0, 0], [1, 1])
1
julia> G = Mayer((x0, xf) -> xf[2]-x0[1])
julia> G([0, 0], [1, 1],Real[])
1
julia> G = Mayer((x0, xf, v) -> v[3]+xf[2]-x0[1], variable=true)
julia> G([0, 0], [1, 1], [1, 2, 3])
4
CTBase.Mayer
— MethodMayer(f::Function, VD::Type{<:VariableDependence}) -> Mayer
Return a Mayer
cost of a function. Dependencies are specified with a DataType, NonFixed/Fixed, Fixed by default.
julia> G = Mayer((x0, xf) -> xf[2]-x0[1])
julia> G = Mayer((x0, xf, v) -> v[3]+xf[2]-x0[1], NonFixed)
CTBase.Mayer
— MethodMayer(f::Function; variable) -> Mayer
Return a Mayer
cost of a function. Dependencies are specified with a boolean, variable, false by default.
julia> G = Mayer((x0, xf) -> xf[2]-x0[1])
julia> G = Mayer((x0, xf, v) -> v[3]+xf[2]-x0[1], variable=true)
CTBase.Mayer
— MethodReturn the evaluation of the Mayer cost.
julia> G = Mayer((x0, xf) -> xf[2]-x0[1])
julia> G([0, 0], [1, 1])
1
julia> G = Mayer((x0, xf) -> xf[2]-x0[1])
julia> G([0, 0], [1, 1], Real[])
1
julia> G = Mayer((x0, xf, v) -> v[3]+xf[2]-x0[1], variable=true)
julia> G([0, 0], [1, 1], [1, 2, 3])
4
CTBase.MixedConstraint
— Typestruct MixedConstraint{TF<:Function, TD<:TimeDependence, VD<:VariableDependence}
Fields
f::Function
Similar to Lagrange
in the usage, but the dimension of the output of the function f
is arbitrary.
The default value for time_dependence
and variable_dependence
are Autonomous
and Fixed
respectively.
Constructor
The constructor MixedConstraint
returns a MixedConstraint
of a function. The function must take 2 to 4 arguments, (x, u)
to (t, x, u, v)
, if the function is variable or non autonomous, it must be specified. Dependencies are specified either with :
- booleans,
autonomous
andvariable
, respectivelytrue
andfalse
by default DataType
,Autonomous
/NonAutonomous
andNonFixed
/Fixed
, respectivelyAutonomous
andFixed
by default.
Examples
julia> MixedConstraint((x, u) -> [2x[2]-u^2, x[1]], Int64)
IncorrectArgument
julia> MixedConstraint((x, u) -> [2x[2]-u^2, x[1]], Int64)
IncorrectArgument
julia> M = MixedConstraint((x, u) -> [2x[2]-u^2, x[1]], Autonomous, Fixed)
julia> M = MixedConstraint((x, u, v) -> [2x[2]-u^2+v[3], x[1]], Autonomous, NonFixed)
julia> M = MixedConstraint((t, x, u) -> [t+2x[2]-u^2, x[1]], NonAutonomous, Fixed)
julia> M = MixedConstraint((t, x, u, v) -> [t+2x[2]-u^2+v[3], x[1]], NonAutonomous, NonFixed)
julia> M = MixedConstraint((x, u) -> [2x[2]-u^2, x[1]], autonomous=true, variable=false)
julia> M = MixedConstraint((x, u, v) -> [2x[2]-u^2+v[3], x[1]], autonomous=true, variable=true)
julia> M = MixedConstraint((t, x, u) -> [t+2x[2]-u^2, x[1]], autonomous=false, variable=false)
julia> M = MixedConstraint((t, x, u, v) -> [t+2x[2]-u^2+v[3], x[1]], autonomous=false, variable=true)
When the state is of dimension 1, consider x
as a scalar. Same for the control.
Call
The call returns the evaluation of the MixedConstraint
for given values.
Examples
julia> MixedConstraint((x, u) -> [2x[2]-u^2, x[1]], Int64)
IncorrectArgument
julia> MixedConstraint((x, u) -> [2x[2]-u^2, x[1]], Int64)
IncorrectArgument
julia> M = MixedConstraint((x, u) -> [2x[2]-u^2, x[1]], autonomous=true, variable=false)
julia> M([1, 0], 1)
[-1, 1]
julia> t = 1
julia> v = Real[]
julia> MethodError M(t, [1, 0], 1)
julia> MethodError M([1, 0], 1, v)
julia> M(t, [1, 0], 1, v)
[-1, 1]
julia> M = MixedConstraint((x, u, v) -> [2x[2]-u^2+v[3], x[1]], autonomous=true, variable=true)
julia> M([1, 0], 1, [1, 2, 3])
[2, 1]
julia> M(t, [1, 0], 1, [1, 2, 3])
[2, 1]
julia> M = MixedConstraint((t, x, u) -> [t+2x[2]-u^2, x[1]], autonomous=false, variable=false)
julia> M(1, [1, 0], 1)
[0, 1]
julia> M(1, [1, 0], 1, v)
[0, 1]
julia> M = MixedConstraint((t, x, u, v) -> [t+2x[2]-u^2+v[3], x[1]], autonomous=false, variable=true)
julia> M(1, [1, 0], 1, [1, 2, 3])
[3, 1]
CTBase.MixedConstraint
— MethodMixedConstraint(
f::Function,
TD::Type{<:TimeDependence},
VD::Type{<:VariableDependence}
) -> MixedConstraint
Return the MixedConstraint
of a function. Dependencies are specified with DataType, Autonomous, NonAutonomous and Fixed, NonFixed.
julia> M = MixedConstraint((x, u) -> [2x[2]-u^2, x[1]], Autonomous, Fixed)
julia> M = MixedConstraint((x, u, v) -> [2x[2]-u^2+v[3], x[1]], Autonomous, NonFixed)
julia> M = MixedConstraint((t, x, u) -> [t+2x[2]-u^2, x[1]], NonAutonomous, Fixed)
julia> M = MixedConstraint((t, x, u, v) -> [t+2x[2]-u^2+v[3], x[1]], NonAutonomous, NonFixed)
CTBase.MixedConstraint
— MethodMixedConstraint(
f::Function;
autonomous,
variable
) -> MixedConstraint
Return the MixedConstraint
of a function. Dependencies are specified with a boolean, variable, false by default, autonomous, true by default.
julia> M = MixedConstraint((x, u) -> [2x[2]-u^2, x[1]], autonomous=true, variable=false)
julia> M = MixedConstraint((x, u, v) -> [2x[2]-u^2+v[3], x[1]], autonomous=true, variable=true)
julia> M = MixedConstraint((t, x, u) -> [t+2x[2]-u^2, x[1]], autonomous=false, variable=false)
julia> M = MixedConstraint((t, x, u, v) -> [t+2x[2]-u^2+v[3], x[1]], autonomous=false, variable=true)
CTBase.MixedConstraint
— MethodReturn the value of the MixedConstraint function.
julia> M = MixedConstraint((x, u) -> [2x[2]-u^2, x[1]], autonomous=true, variable=false)
julia> M([1, 0], 1)
[-1, 1]
julia> t = 1
julia> v = Real[]
julia> MethodError M(t, [1, 0], 1)
julia> MethodError M([1, 0], 1, v)
julia> M(t, [1, 0], 1, v)
[-1, 1]
julia> M = MixedConstraint((x, u, v) -> [2x[2]-u^2+v[3], x[1]], autonomous=true, variable=true)
julia> M([1, 0], 1, [1, 2, 3])
[2, 1]
julia> M(t, [1, 0], 1, [1, 2, 3])
[2, 1]
julia> M = MixedConstraint((t, x, u) -> [t+2x[2]-u^2, x[1]], autonomous=false, variable=false)
julia> M(1, [1, 0], 1)
[0, 1]
julia> M(1, [1, 0], 1, v)
[0, 1]
julia> M = MixedConstraint((t, x, u, v) -> [t+2x[2]-u^2+v[3], x[1]], autonomous=false, variable=true)
julia> M(1, [1, 0], 1, [1, 2, 3])
[3, 1]
CTBase.Multiplier
— Typestruct Multiplier{TF<:Function, TD<:TimeDependence, VD<:VariableDependence}
Fields
f::Function
Similar to ControlLaw
in the usage.
The default values for time_dependence
and variable_dependence
are Autonomous
and Fixed
respectively.
Constructor
The constructor Multiplier
returns a Multiplier
of a function. The function must take 2 to 4 arguments, (x, p)
to (t, x, p, v)
, if the function is variable or non autonomous, it must be specified. Dependencies are specified either with :
- booleans,
autonomous
andvariable
, respectivelytrue
andfalse
by default DataType
,Autonomous
/NonAutonomous
andNonFixed
/Fixed
, respectivelyAutonomous
andFixed
by default.
Examples
julia> Multiplier((x, p) -> x[1]^2+2p[2], Int64)
IncorrectArgument
julia> Multiplier((x, p) -> x[1]^2+2p[2], Int64)
IncorrectArgument
julia> μ = Multiplier((x, p) -> x[1]^2+2p[2], Autonomous, Fixed)
julia> μ = Multiplier((x, p, v) -> x[1]^2+2p[2]+v[3], Autonomous, NonFixed)
julia> μ = Multiplier((t, x, p) -> t+x[1]^2+2p[2], NonAutonomous, Fixed)
julia> μ = Multiplier((t, x, p, v) -> t+x[1]^2+2p[2]+v[3], NonAutonomous, NonFixed)
julia> μ = Multiplier((x, p) -> x[1]^2+2p[2], autonomous=true, variable=false)
julia> μ = Multiplier((x, p, v) -> x[1]^2+2p[2]+v[3], autonomous=true, variable=true)
julia> μ = Multiplier((t, x, p) -> t+x[1]^2+2p[2], autonomous=false, variable=false)
julia> μ = Multiplier((t, x, p, v) -> t+x[1]^2+2p[2]+v[3], autonomous=false, variable=true)
When the state and costate are of dimension 1, consider x
and p
as scalars.
Call
The call returns the evaluation of the Multiplier
for given values.
Examples
julia> μ = Multiplier((x, p) -> x[1]^2+2p[2], autonomous=true, variable=false)
julia> μ([1, 0], [0, 1])
3
julia> t = 1
julia> v = Real[]
julia> μ(t, [1, 0], [0, 1])
MethodError
julia> μ([1, 0], [0, 1], v)
MethodError
julia> μ(t, [1, 0], [0, 1], v)
3
julia> μ = Multiplier((x, p, v) -> x[1]^2+2p[2]+v[3], autonomous=true, variable=true)
julia> μ([1, 0], [0, 1], [1, 2, 3])
6
julia> μ(t, [1, 0], [0, 1], [1, 2, 3])
6
julia> μ = Multiplier((t, x, p) -> t+x[1]^2+2p[2], autonomous=false, variable=false)
julia> μ(1, [1, 0], [0, 1])
4
julia> μ(1, [1, 0], [0, 1], v)
4
julia> μ = Multiplier((t, x, p, v) -> t+x[1]^2+2p[2]+v[3], autonomous=false, variable=true)
julia> μ(1, [1, 0], [0, 1], [1, 2, 3])
7
CTBase.Multiplier
— MethodMultiplier(
f::Function,
TD::Type{<:TimeDependence},
VD::Type{<:VariableDependence}
) -> Multiplier
Return the Multiplier
of a function. Dependencies are specified with DataType, Autonomous, NonAutonomous and Fixed, NonFixed.
julia> μ = Multiplier((x, p) -> x[1]^2+2p[2], Autonomous, Fixed)
julia> μ = Multiplier((x, p, v) -> x[1]^2+2p[2]+v[3], Autonomous, NonFixed)
julia> μ = Multiplier((t, x, p) -> t+x[1]^2+2p[2], NonAutonomous, Fixed)
julia> μ = Multiplier((t, x, p, v) -> t+x[1]^2+2p[2]+v[3], NonAutonomous, NonFixed)
CTBase.Multiplier
— MethodMultiplier(f::Function; autonomous, variable) -> Multiplier
Return the Multiplier
of a function. Dependencies are specified with a boolean, variable, false by default, autonomous, true by default.
julia> μ = Multiplier((x, p) -> x[1]^2+2p[2], autonomous=true, variable=false)
julia> μ = Multiplier((x, p, v) -> x[1]^2+2p[2]+v[3], autonomous=true, variable=true)
julia> μ = Multiplier((t, x, p) -> t+x[1]^2+2p[2], autonomous=false, variable=false)
julia> μ = Multiplier((t, x, p, v) -> t+x[1]^2+2p[2]+v[3], autonomous=false, variable=true)
CTBase.Multiplier
— MethodReturn the value of the Multiplier function.
julia> μ = Multiplier((x, p) -> x[1]^2+2p[2], autonomous=true, variable=false)
julia> μ([1, 0], [0, 1])
3
julia> t = 1
julia> v = Real[]
julia> μ(t, [1, 0], [0, 1])
MethodError
julia> μ([1, 0], [0, 1], v)
MethodError
julia> μ(t, [1, 0], [0, 1], v)
3
julia> μ = Multiplier((x, p, v) -> x[1]^2+2p[2]+v[3], autonomous=true, variable=true)
julia> μ([1, 0], [0, 1], [1, 2, 3])
6
julia> μ(t, [1, 0], [0, 1], [1, 2, 3])
6
julia> μ = Multiplier((t, x, p) -> t+x[1]^2+2p[2], autonomous=false, variable=false)
julia> μ(1, [1, 0], [0, 1])
4
julia> μ(1, [1, 0], [0, 1], v)
4
julia> μ = Multiplier((t, x, p, v) -> t+x[1]^2+2p[2]+v[3], autonomous=false, variable=true)
julia> μ(1, [1, 0], [0, 1], [1, 2, 3])
7
CTBase.NonAutonomous
— Typeabstract type NonAutonomous <: TimeDependence
CTBase.NonFixed
— Typeabstract type NonFixed <: VariableDependence
CTBase.NotImplemented
— Typestruct NotImplemented <: CTException
Exception thrown when a method is not implemented.
Fields
var::String
CTBase.OptimalControlInit
— 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:
OptimalControlInit()
: default initializationOptimalControlInit(state, control, variable, time)
: constant vector, function handles and / or matrices / vectors interpolated along given time gridOptimalControlInit(sol)
: from existing solution
Examples
julia> init = OptimalControlInit()
julia> init = OptimalControlInit(state=[0.1, 0.2], control=0.3)
julia> init = OptimalControlInit(state=[0.1, 0.2], control=0.3, variable=0.5)
julia> init = OptimalControlInit(state=[0.1, 0.2], controlt=t->sin(t), variable=0.5)
julia> init = OptimalControlInit(state=[[0, 0], [1, 2], [5, -1]], time=[0, .3, 1.], controlt=t->sin(t))
julia> init = OptimalControlInit(sol)
CTBase.OptimalControlModel
— Typemutable struct OptimalControlModel{time_dependence<:TimeDependence, variable_dependence<:VariableDependence} <: CTBase.AbstractOptimalControlModel
Fields
model_expression::Union{Nothing, Expr}
: Default: nothinginitial_time::Union{Nothing, Index, Real}
: Default: nothinginitial_time_name::Union{Nothing, String}
: Default: nothingfinal_time::Union{Nothing, Index, Real}
: Default: nothingfinal_time_name::Union{Nothing, String}
: Default: nothingtime_name::Union{Nothing, String}
: Default: nothingcontrol_dimension::Union{Nothing, Int64}
: Default: nothingcontrol_components_names::Union{Nothing, Vector{String}}
: Default: nothingcontrol_name::Union{Nothing, String}
: Default: nothingstate_dimension::Union{Nothing, Int64}
: Default: nothingstate_components_names::Union{Nothing, Vector{String}}
: Default: nothingstate_name::Union{Nothing, String}
: Default: nothingvariable_dimension::Union{Nothing, Int64}
: Default: nothingvariable_components_names::Union{Nothing, Vector{String}}
: Default: nothingvariable_name::Union{Nothing, String}
: Default: nothinglagrange::Union{Nothing, Lagrange, Lagrange!}
: Default: nothingmayer::Union{Nothing, Mayer, Mayer!}
: Default: nothingcriterion::Union{Nothing, Symbol}
: Default: nothingdynamics::Union{Nothing, Dynamics, Dynamics!}
: Default: nothingconstraints::Dict{Symbol, Tuple}
: Default: Dict{Symbol, Tuple{Vararg{Any}}}()dim_control_constraints::Union{Nothing, Int64}
: Default: nothingdim_state_constraints::Union{Nothing, Int64}
: Default: nothingdim_mixed_constraints::Union{Nothing, Int64}
: Default: nothingdim_boundary_constraints::Union{Nothing, Int64}
: Default: nothingdim_variable_constraints::Union{Nothing, Int64}
: Default: nothingdim_control_range::Union{Nothing, Int64}
: Default: nothingdim_state_range::Union{Nothing, Int64}
: Default: nothingdim_variable_range::Union{Nothing, Int64}
: Default: nothingin_place::Union{Nothing, Bool}
: Default: nothing
CTBase.OptimalControlSolution
— Typemutable struct OptimalControlSolution <: CTBase.AbstractOptimalControlSolution
Type of an optimal control solution.
Fields
time_grid::Union{Nothing, StepRangeLen, AbstractVector{<:Real}}
: Default: nothingtime_name::Union{Nothing, String}
: Default: nothinginitial_time_name::Union{Nothing, String}
: Default: nothingfinal_time_name::Union{Nothing, String}
: Default: nothingcontrol_dimension::Union{Nothing, Int64}
: Default: nothingcontrol_components_names::Union{Nothing, Vector{String}}
: Default: nothingcontrol_name::Union{Nothing, String}
: Default: nothingcontrol::Union{Nothing, Function}
: Default: nothingstate_dimension::Union{Nothing, Int64}
: Default: nothingstate_components_names::Union{Nothing, Vector{String}}
: Default: nothingstate_name::Union{Nothing, String}
: Default: nothingstate::Union{Nothing, Function}
: Default: nothingvariable_dimension::Union{Nothing, Int64}
: Default: nothingvariable_components_names::Union{Nothing, Vector{String}}
: Default: nothingvariable_name::Union{Nothing, String}
: Default: nothingvariable::Union{Nothing, Real, AbstractVector{<:Real}}
: Default: nothingcostate::Union{Nothing, Function}
: Default: nothingobjective::Union{Nothing, Real}
: Default: nothingiterations::Union{Nothing, Int64}
: Default: nothingstopping::Union{Nothing, Symbol}
: Default: nothingmessage::Union{Nothing, String}
: Default: nothingsuccess::Union{Nothing, Bool}
: Default: nothinginfos::Dict{Symbol, Any}
: Default: Dict{Symbol, Any}()boundary_constraints::Union{Nothing, Real, AbstractVector{<:Real}}
: Default: nothingmult_boundary_constraints::Union{Nothing, Real, AbstractVector{<:Real}}
: Default: nothingvariable_constraints::Union{Nothing, Real, AbstractVector{<:Real}}
: Default: nothingmult_variable_constraints::Union{Nothing, Real, AbstractVector{<:Real}}
: Default: nothingmult_variable_box_lower::Union{Nothing, Real, AbstractVector{<:Real}}
: Default: nothingmult_variable_box_upper::Union{Nothing, Real, AbstractVector{<:Real}}
: Default: nothingcontrol_constraints::Union{Nothing, Function}
: Default: nothingmult_control_constraints::Union{Nothing, Function}
: Default: nothingstate_constraints::Union{Nothing, Function}
: Default: nothingmult_state_constraints::Union{Nothing, Function}
: Default: nothingmixed_constraints::Union{Nothing, Function}
: Default: nothingmult_mixed_constraints::Union{Nothing, Function}
: Default: nothingmult_state_box_lower::Union{Nothing, Function}
: Default: nothingmult_state_box_upper::Union{Nothing, Function}
: Default: nothingmult_control_box_lower::Union{Nothing, Function}
: Default: nothingmult_control_box_upper::Union{Nothing, Function}
: Default: nothing
CTBase.OptimalControlSolution
— MethodOptimalControlSolution(
ocp::OptimalControlModel,
T,
X,
U,
v,
P;
objective,
iterations,
constraints_violation,
message,
stopping,
success,
constraints_types,
constraints_mult,
box_multipliers
) -> OptimalControlSolution
Build OCP functional solution from discrete solution (given as raw variables and multipliers plus some optional infos)
CTBase.OptimalControlSolution
— MethodOptimalControlSolution(
ocp::OptimalControlModel{<:TimeDependence, Fixed};
state,
control,
objective,
variable,
costate,
time_grid,
iterations,
stopping,
message,
success,
infos,
boundary_constraints,
mult_boundary_constraints,
variable_constraints,
mult_variable_constraints,
mult_variable_box_lower,
mult_variable_box_upper,
control_constraints,
mult_control_constraints,
state_constraints,
mult_state_constraints,
mixed_constraints,
mult_mixed_constraints,
mult_state_box_lower,
mult_state_box_upper,
mult_control_box_lower,
mult_control_box_upper
)
Constructor from an optimal control problem for a Fixed ocp.
CTBase.OptimalControlSolution
— MethodOptimalControlSolution(
ocp::OptimalControlModel{<:TimeDependence, NonFixed};
state,
control,
objective,
variable,
costate,
time_grid,
iterations,
stopping,
message,
success,
infos,
boundary_constraints,
mult_boundary_constraints,
variable_constraints,
mult_variable_constraints,
mult_variable_box_lower,
mult_variable_box_upper,
control_constraints,
mult_control_constraints,
state_constraints,
mult_state_constraints,
mixed_constraints,
mult_mixed_constraints,
mult_state_box_lower,
mult_state_box_upper,
mult_control_box_lower,
mult_control_box_upper
)
Constructor from an optimal control problem for a NonFixed ocp.
CTBase.ParsingError
— Typestruct ParsingError <: CTException
Exception thrown for syntax error during abstract parsing.
Fields
var::String
CTBase.StateConstraint
— Typestruct StateConstraint{TF<:Function, TD<:TimeDependence, VD<:VariableDependence}
Fields
f::Function
Similar to VectorField
in the usage, but the dimension of the output of the function f
is arbitrary.
The default values for time_dependence
and variable_dependence
are Autonomous
and Fixed
respectively.
Constructor
The constructor StateConstraint
returns a StateConstraint
of a function. The function must take 1 to 3 arguments, x
to (t, x, v)
, if the function is variable or non autonomous, it must be specified. Dependencies are specified either with :
- booleans,
autonomous
andvariable
, respectivelytrue
andfalse
by default DataType
,Autonomous
/NonAutonomous
andNonFixed
/Fixed
, respectivelyAutonomous
andFixed
by default.
Examples
julia> StateConstraint(x -> [x[1]^2, 2x[2]], Int64)
IncorrectArgument
julia> StateConstraint(x -> [x[1]^2, 2x[2]], Int64)
IncorrectArgument
julia> S = StateConstraint(x -> [x[1]^2, 2x[2]], Autonomous, Fixed)
julia> S = StateConstraint((x, v) -> [x[1]^2, 2x[2]+v[3]], Autonomous, NonFixed)
julia> S = StateConstraint((t, x) -> [t+x[1]^2, 2x[2]], NonAutonomous, Fixed)
julia> S = StateConstraint((t, x, v) -> [t+x[1]^2, 2x[2]+v[3]], NonAutonomous, NonFixed)
julia> S = StateConstraint(x -> [x[1]^2, 2x[2]], autonomous=true, variable=false)
julia> S = StateConstraint((x, v) -> [x[1]^2, 2x[2]+v[3]], autonomous=true, variable=true)
julia> S = StateConstraint((t, x) -> [t+x[1]^2, 2x[2]], autonomous=false, variable=false)
julia> S = StateConstraint((t, x, v) -> [t+x[1]^2, 2x[2]+v[3]], autonomous=false, variable=true)
When the state is of dimension 1, consider x
as a scalar.
Call
The call returns the evaluation of the StateConstraint
for given values.
Examples
julia> StateConstraint(x -> [x[1]^2, 2x[2]], Int64)
IncorrectArgument
julia> StateConstraint(x -> [x[1]^2, 2x[2]], Int64)
IncorrectArgument
julia> S = StateConstraint(x -> [x[1]^2, 2x[2]], autonomous=true, variable=false)
julia> S([1, -1])
[1, -2]
julia> t = 1
julia> v = Real[]
julia> S(t, [1, -1], v)
[1, -2]
julia> S = StateConstraint((x, v) -> [x[1]^2, 2x[2]+v[3]], autonomous=true, variable=true)
julia> S([1, -1], [1, 2, 3])
[1, 1]
julia> S(t, [1, -1], [1, 2, 3])
[1, 1]
julia> S = StateConstraint((t, x) -> [t+x[1]^2, 2x[2]], autonomous=false, variable=false)
julia> S(1, [1, -1])
[2, -2]
julia> S(1, [1, -1], v)
[2, -2]
julia> S = StateConstraint((t, x, v) -> [t+x[1]^2, 2x[2]+v[3]], autonomous=false, variable=true)
julia> S(1, [1, -1], [1, 2, 3])
[2, 1]
CTBase.StateConstraint
— MethodStateConstraint(
f::Function,
TD::Type{<:TimeDependence},
VD::Type{<:VariableDependence}
) -> StateConstraint
Return the StateConstraint
of a function. Dependencies are specified with DataType, Autonomous, NonAutonomous and Fixed, NonFixed.
julia> S = StateConstraint(x -> [x[1]^2, 2x[2]], Autonomous, Fixed)
julia> S = StateConstraint((x, v) -> [x[1]^2, 2x[2]+v[3]], Autonomous, NonFixed)
julia> S = StateConstraint((t, x) -> [t+x[1]^2, 2x[2]], NonAutonomous, Fixed)
julia> S = StateConstraint((t, x, v) -> [t+x[1]^2, 2x[2]+v[3]], NonAutonomous, NonFixed)
CTBase.StateConstraint
— MethodStateConstraint(
f::Function;
autonomous,
variable
) -> StateConstraint
Return the StateConstraint
of a function. Dependencies are specified with a boolean, variable, false by default, autonomous, true by default.
julia> S = StateConstraint(x -> [x[1]^2, 2x[2]], autonomous=true, variable=false)
julia> S = StateConstraint((x, v) -> [x[1]^2, 2x[2]+v[3]], autonomous=true, variable=true)
julia> S = StateConstraint((t, x) -> [t+x[1]^2, 2x[2]], autonomous=false, variable=false)
julia> S = StateConstraint((t, x, v) -> [t+x[1]^2, 2x[2]+v[3]], autonomous=false, variable=true)
CTBase.StateConstraint
— MethodReturn the value of the StateConstraint function.
julia> S = StateConstraint(x -> [x[1]^2, 2x[2]], autonomous=true, variable=false)
julia> S([1, -1])
[1, -2]
julia> t = 1
julia> v = Real[]
julia> S(t, [1, -1], v)
[1, -2]
julia> S = StateConstraint((x, v) -> [x[1]^2, 2x[2]+v[3]], autonomous=true, variable=true)
julia> S([1, -1], [1, 2, 3])
[1, 1]
julia> S(t, [1, -1], [1, 2, 3])
[1, 1]
julia> S = StateConstraint((t, x) -> [t+x[1]^2, 2x[2]], autonomous=false, variable=false)
julia> S(1, [1, -1])
[2, -2]
julia> S(1, [1, -1], v)
[2, -2]
julia> S = StateConstraint((t, x, v) -> [t+x[1]^2, 2x[2]+v[3]], autonomous=false, variable=true)
julia> S(1, [1, -1], [1, 2, 3])
[2, 1]
CTBase.States
— TypeType alias for a vector of states.
julia> const States = AbstractVector{<:State}
CTBase.Time
— TypeCTBase.TimeDependence
— Typeabstract type TimeDependence
CTBase.Times
— TypeType alias for a vector of times.
julia> const Times = AbstractVector{<:Time}
CTBase.UnauthorizedCall
— Typestruct UnauthorizedCall <: CTException
Exception thrown when a call to a function is not authorized.
Fields
var::String
CTBase.VariableConstraint
— Typestruct VariableConstraint{TF<:Function}
Fields
f::Function
The default values for time_dependence
and variable_dependence
are Autonomous
and Fixed
respectively.
Constructor
The constructor VariableConstraint
returns a VariableConstraint
of a function. The function must take 1 argument, v
.
Examples
julia> V = VariableConstraint(v -> [v[1]^2, 2v[2]])
When the variable is of dimension 1, consider v
as a scalar.
Call
The call returns the evaluation of the VariableConstraint
for given values.
Examples
julia> V = VariableConstraint(v -> [v[1]^2, 2v[2]])
julia> V([1, -1])
[1, -2]
CTBase.VariableConstraint
— MethodReturn the value of the VariableConstraint function.
julia> V = VariableConstraint(v -> [v[1]^2, 2v[2]])
julia> V([1, -1])
[1, -2]
CTBase.VariableDependence
— Typeabstract type VariableDependence
CTBase.VectorField
— Typestruct VectorField{TF<:Function, TD<:TimeDependence, VD<:VariableDependence} <: CTBase.AbstractVectorField{TD<:TimeDependence, VD<:VariableDependence}
Fields
f::Function
The default values for time_dependence
and variable_dependence
are Autonomous
and Fixed
respectively.
Constructor
The constructor VectorField
returns a VectorField
of a function. The function must take 1 to 3 arguments, x
to (t, x, v)
, if the function is variable or non autonomous, it must be specified. Dependencies are specified either with :
- booleans,
autonomous
andvariable
, respectivelytrue
andfalse
by default DataType
,Autonomous
/NonAutonomous
andNonFixed
/Fixed
, respectivelyAutonomous
andFixed
by default.
Examples
julia> VectorField(x -> [x[1]^2, 2x[2]], Int64)
IncorrectArgument
julia> VectorField(x -> [x[1]^2, 2x[2]], Int64)
IncorrectArgument
julia> V = VectorField(x -> [x[1]^2, 2x[2]]) # autonomous=true, variable=false
julia> V = VectorField((x, v) -> [x[1]^2, 2x[2]+v[3]], variable=true)
julia> V = VectorField((t, x) -> [t+x[1]^2, 2x[2]], autonomous=false)
julia> V = VectorField((t, x, v) -> [t+x[1]^2, 2x[2]+v[3]], autonomous=false, variable=true)
julia> V = VectorField((x, v) -> [x[1]^2, 2x[2]+v[3]], NonFixed)
julia> V = VectorField((t, x) -> [t+x[1]^2, 2x[2]], NonAutonomous)
julia> V = VectorField((t, x, v) -> [t+x[1]^2, 2x[2]+v[3]], NonAutonomous, NonFixed)
When the state is of dimension 1, consider x
as a scalar.
Call
The call returns the evaluation of the VectorField
for given values.
Examples
julia> V = VectorField(x -> [x[1]^2, 2x[2]]) # autonomous=true, variable=false
julia> V([1, -1])
[1, -2]
julia> t = 1
julia> v = Real[]
julia> V(t, [1, -1])
MethodError
julia> V([1, -1], v)
MethodError
julia> V(t, [1, -1], v)
[1, -2]
julia> V = VectorField((x, v) -> [x[1]^2, 2x[2]+v[3]], variable=true)
julia> V([1, -1], [1, 2, 3])
[1, 1]
julia> V(t, [1, -1], [1, 2, 3])
[1, 1]
julia> V = VectorField((t, x) -> [t+x[1]^2, 2x[2]], autonomous=false)
julia> V(1, [1, -1])
[2, -2]
julia> V(1, [1, -1], v)
[2, -2]
julia> V = VectorField((t, x, v) -> [t+x[1]^2, 2x[2]+v[3]], autonomous=false, variable=true)
julia> V(1, [1, -1], [1, 2, 3])
[2, 1]
CTBase.VectorField
— MethodVectorField(
f::Function,
TD::Type{<:TimeDependence},
VD::Type{<:VariableDependence}
) -> VectorField
Return a VectorField
of a function. Dependencies are specified with DataType, Autonomous, NonAutonomous and Fixed, NonFixed.
julia> V = VectorField(x -> [x[1]^2, 2x[2]]) # autonomous=true, variable=false
julia> V = VectorField((x, v) -> [x[1]^2, 2x[2]+v[3]], NonFixed)
julia> V = VectorField((t, x) -> [t+x[1]^2, 2x[2]], NonAutonomous)
julia> V = VectorField((t, x, v) -> [t+x[1]^2, 2x[2]+v[3]], NonAutonomous, NonFixed)
CTBase.VectorField
— MethodVectorField(
f::Function;
autonomous,
variable
) -> VectorField
Return a VectorField
of a function. Dependencies are specified with a boolean, variable, false by default, autonomous, true by default.
julia> V = VectorField(x -> [x[1]^2, 2x[2]]) # autonomous=true, variable=false
julia> V = VectorField((x, v) -> [x[1]^2, 2x[2]+v[3]], variable=true)
julia> V = VectorField((t, x) -> [t+x[1]^2, 2x[2]], autonomous=false)
julia> V = VectorField((t, x, v) -> [t+x[1]^2, 2x[2]+v[3]], autonomous=false, variable=true)
CTBase.VectorField
— MethodReturn the value of the VectorField.
Examples
julia> V = VectorField(x -> [x[1]^2, 2x[2]]) # autonomous=true, variable=false
julia> V([1, -1])
[1, -2]
julia> t = 1
julia> v = Real[]
julia> V(t, [1, -1])
MethodError
julia> V([1, -1], v)
MethodError
julia> V(t, [1, -1], v)
[1, -2]
julia> V = VectorField((x, v) -> [x[1]^2, 2x[2]+v[3]], variable=true)
julia> V([1, -1], [1, 2, 3])
[1, 1]
julia> V(t, [1, -1], [1, 2, 3])
[1, 1]
julia> V = VectorField((t, x) -> [t+x[1]^2, 2x[2]], autonomous=false)
julia> V(1, [1, -1])
[2, -2]
julia> V(1, [1, -1], v)
[2, -2]
julia> V = VectorField((t, x, v) -> [t+x[1]^2, 2x[2]+v[3]], autonomous=false, variable=true)
julia> V(1, [1, -1], [1, 2, 3])
[2, 1]
CTBase.ctNumber
— TypeType alias for a real number.
julia> const ctNumber = Real
CTBase.:⋅
— Method⋅(
X::Function,
f::Function
) -> CTBase.var"#168#170"{VectorField{var"#s182", Autonomous, Fixed}, <:Function} where var"#s182"<:Function
Lie derivative of a scalar function along a function. In this case both functions will be considered autonomous and non-variable.
Example
julia> φ = x -> [x[2], -x[1]]
julia> f = x -> x[1]^2 + x[2]^2
julia> (φ⋅f)([1, 2])
0
julia> φ = (t, x, v) -> [t + x[2] + v[1], -x[1] + v[2]]
julia> f = (t, x, v) -> t + x[1]^2 + x[2]^2
julia> (φ⋅f)(1, [1, 2], [2, 1])
MethodError
CTBase.:⋅
— Method⋅(
X::VectorField{<:Function, Autonomous},
f::Function
) -> CTBase.var"#168#170"{VectorField{var"#s285", Autonomous, var"#s284"}, <:Function} where {var"#s285"<:Function, var"#s284"<:VariableDependence}
Lie derivative of a scalar function along a vector field : L_X(f) = X⋅f, in autonomous case
Example
julia> φ = x -> [x[2], -x[1]]
julia> X = VectorField(φ)
julia> f = x -> x[1]^2 + x[2]^2
julia> (X⋅f)([1, 2])
0
CTBase.:⋅
— Method⋅(
X::VectorField{<:Function, NonAutonomous},
f::Function
) -> CTBase.var"#172#174"{VectorField{var"#s285", NonAutonomous, var"#s284"}, <:Function} where {var"#s285"<:Function, var"#s284"<:VariableDependence}
Lie derivative of a scalar function along a vector field : L_X(f) = X⋅f, in nonautonomous case
Example
julia> φ = (t, x, v) -> [t + x[2] + v[1], -x[1] + v[2]]
julia> X = VectorField(φ, NonAutonomous, NonFixed)
julia> f = (t, x, v) -> t + x[1]^2 + x[2]^2
julia> (X⋅f)(1, [1, 2], [2, 1])
10
CTBase.Lie
— MethodLie(
X::Function,
f::Function;
autonomous,
variable
) -> Union{CTBase.var"#168#170"{VectorField{var"#s285", Autonomous, var"#s284"}, <:Function} where {var"#s285"<:Function, var"#s284"<:VariableDependence}, CTBase.var"#172#174"{VectorField{var"#s285", NonAutonomous, var"#s284"}, <:Function} where {var"#s285"<:Function, var"#s284"<:VariableDependence}}
Lie derivative of a scalar function along a function. Dependencies are specified with boolean : autonomous and variable.
Example
julia> φ = x -> [x[2], -x[1]]
julia> f = x -> x[1]^2 + x[2]^2
julia> Lie(φ,f)([1, 2])
0
julia> φ = (t, x, v) -> [t + x[2] + v[1], -x[1] + v[2]]
julia> f = (t, x, v) -> t + x[1]^2 + x[2]^2
julia> Lie(φ, f, autonomous=false, variable=true)(1, [1, 2], [2, 1])
10
CTBase.Lie
— MethodLie(
X::VectorField,
f::Function
) -> Union{CTBase.var"#168#170"{VectorField{var"#s285", Autonomous, var"#s284"}, <:Function} where {var"#s285"<:Function, var"#s284"<:VariableDependence}, CTBase.var"#172#174"{VectorField{var"#s285", NonAutonomous, var"#s284"}, <:Function} where {var"#s285"<:Function, var"#s284"<:VariableDependence}}
Lie derivative of a scalar function along a vector field.
Example
julia> φ = x -> [x[2], -x[1]]
julia> X = VectorField(φ)
julia> f = x -> x[1]^2 + x[2]^2
julia> Lie(X,f)([1, 2])
0
julia> φ = (t, x, v) -> [t + x[2] + v[1], -x[1] + v[2]]
julia> X = VectorField(φ, NonAutonomous, NonFixed)
julia> f = (t, x, v) -> t + x[1]^2 + x[2]^2
julia> Lie(X, f)(1, [1, 2], [2, 1])
10
CTBase.Lie
— MethodLie(
X::VectorField{<:Function, Autonomous, V<:VariableDependence},
Y::VectorField{<:Function, Autonomous, V<:VariableDependence}
) -> Any
Lie bracket of two vector fields: [X, Y] = Lie(X, Y), autonomous case
Example
julia> f = x -> [x[2], 2x[1]]
julia> g = x -> [3x[2], -x[1]]
julia> X = VectorField(f)
julia> Y = VectorField(g)
julia> Lie(X, Y)([1, 2])
[7, -14]
CTBase.Lie
— MethodLie(
X::VectorField{<:Function, NonAutonomous, V<:VariableDependence},
Y::VectorField{<:Function, NonAutonomous, V<:VariableDependence}
) -> Any
Lie bracket of two vector fields: [X, Y] = Lie(X, Y), nonautonomous case
Example
julia> f = (t, x, v) -> [t + x[2] + v, -2x[1] - v]
julia> g = (t, x, v) -> [t + 3x[2] + v, -x[1] - v]
julia> X = VectorField(f, NonAutonomous, NonFixed)
julia> Y = VectorField(g, NonAutonomous, NonFixed)
julia> Lie(X, Y)(1, [1, 2], 1)
[-7,12]
CTBase.Lift
— MethodLift(
X::Function;
autonomous,
variable
) -> CTBase.var"#160#164"{<:Function}
Return the Lift of a function. Dependencies are specified with boolean : autonomous and variable.
Example
julia> H = Lift(x -> 2x)
julia> H(1, 1)
2
julia> H = Lift((t, x, v) -> 2x + t - v, autonomous=false, variable=true)
julia> H(1, 1, 1, 1)
2
CTBase.Lift
— MethodLift(
X::VectorField
) -> HamiltonianLift{VectorField{TF, TD, VD}} where {TF<:Function, TD<:TimeDependence, VD<:VariableDependence}
Return the HamiltonianLift of a VectorField.
Example
julia> HL = Lift(VectorField(x -> [x[1]^2,x[2]^2], autonomous=true, variable=false))
julia> HL([1, 0], [0, 1])
0
julia> HL = Lift(VectorField((t, x, v) -> [t+x[1]^2,x[2]^2+v], autonomous=false, variable=true))
julia> HL(1, [1, 0], [0, 1], 1)
1
julia> H = Lift(x -> 2x)
julia> H(1, 1)
2
julia> H = Lift((t, x, v) -> 2x + t - v, autonomous=false, variable=true)
julia> H(1, 1, 1, 1)
2
julia> H = Lift((t, x, v) -> 2x + t - v, NonAutonomous, NonFixed)
julia> H(1, 1, 1, 1)
2
CTBase.Model
— MethodModel(
dependencies::DataType...;
in_place
) -> OptimalControlModel{Autonomous, Fixed}
Return a new OptimalControlModel
instance, that is a model of an optimal control problem.
The model is defined by the following argument:
dependencies
: eitherAutonomous
orNonAutonomous
. Default isAutonomous
. And eitherNonFixed
orFixed
. Default isFixed
.
Examples
julia> ocp = Model()
julia> ocp = Model(NonAutonomous)
julia> ocp = Model(Autonomous, NonFixed)
- If the time dependence of the model is defined as nonautonomous, then, the dynamics function, the lagrange cost and the path constraints must be defined as functions of time and state, and possibly control. If the model is defined as autonomous, then, the dynamics function, the lagrange cost and the path constraints must be defined as functions of state, and possibly control.
CTBase.Model
— MethodModel(
;
autonomous,
variable,
in_place
) -> OptimalControlModel{Autonomous, Fixed}
Return a new OptimalControlModel
instance, that is a model of an optimal control problem.
The model is defined by the following optional keyword argument:
autonomous
: eithertrue
orfalse
. Default istrue
.variable
: eithertrue
orfalse
. Default isfalse
.
Examples
julia> ocp = Model()
julia> ocp = Model(autonomous=false)
julia> ocp = Model(autonomous=false, variable=true)
- If the time dependence of the model is defined as nonautonomous, then, the dynamics function, the lagrange cost and the path constraints must be defined as functions of time and state, and possibly control. If the model is defined as autonomous, then, the dynamics function, the lagrange cost and the path constraints must be defined as functions of state, and possibly control.
CTBase.Poisson
— MethodPoisson(
f::Function,
g::Function;
autonomous,
variable
) -> Hamiltonian
Poisson bracket of two functions : {f, g} = Poisson(f, g) Dependencies are specified with boolean : autonomous and variable.
Example
julia> f = (x, p) -> x[2]^2 + 2x[1]^2 + p[1]^2
julia> g = (x, p) -> 3x[2]^2 + -x[1]^2 + p[2]^2 + p[1]
julia> Poisson(f, g)([1, 2], [2, 1])
-20
julia> f = (t, x, p, v) -> t*v[1]*x[2]^2 + 2x[1]^2 + p[1]^2 + v[2]
julia> g = (t, x, p, v) -> 3x[2]^2 + -x[1]^2 + p[2]^2 + p[1] + t - v[2]
julia> Poisson(f, g, autonomous=false, variable=true)(2, [1, 2], [2, 1], [4, 4])
-76
CTBase.Poisson
— MethodPoisson(
f::AbstractHamiltonian{TD<:TimeDependence, VD<:VariableDependence},
g::Function
) -> Hamiltonian
Poisson bracket of an Hamiltonian function (subtype of AbstractHamiltonian) and a function : {f, g} = Poisson(f, g), autonomous case
Example
julia> f = (x, p) -> x[2]^2 + 2x[1]^2 + p[1]^2
julia> g = (x, p) -> 3x[2]^2 + -x[1]^2 + p[2]^2 + p[1]
julia> F = Hamiltonian(f)
julia> Poisson(F, g)([1, 2], [2, 1])
-20
julia> f = (t, x, p, v) -> t*v[1]*x[2]^2 + 2x[1]^2 + p[1]^2 + v[2]
julia> g = (t, x, p, v) -> 3x[2]^2 + -x[1]^2 + p[2]^2 + p[1] + t - v[2]
julia> F = Hamiltonian(f, autonomous=false, variable=true)
julia> Poisson(F, g)(2, [1, 2], [2, 1], [4, 4])
-76
CTBase.Poisson
— MethodPoisson(
f::Function,
g::AbstractHamiltonian{TD<:TimeDependence, VD<:VariableDependence}
) -> Hamiltonian
Poisson bracket of a function and an Hamiltonian function (subtype of AbstractHamiltonian) : {f, g} = Poisson(f, g)
Example
julia> f = (x, p) -> x[2]^2 + 2x[1]^2 + p[1]^2
julia> g = (x, p) -> 3x[2]^2 + -x[1]^2 + p[2]^2 + p[1]
julia> G = Hamiltonian(g)
julia> Poisson(f, G)([1, 2], [2, 1])
-20
julia> f = (t, x, p, v) -> t*v[1]*x[2]^2 + 2x[1]^2 + p[1]^2 + v[2]
julia> g = (t, x, p, v) -> 3x[2]^2 + -x[1]^2 + p[2]^2 + p[1] + t - v[2]
julia> G = Hamiltonian(g, autonomous=false, variable=true)
julia> Poisson(f, G)(2, [1, 2], [2, 1], [4, 4])
-76
CTBase.Poisson
— MethodPoisson(
f::AbstractHamiltonian{Autonomous, V<:VariableDependence},
g::AbstractHamiltonian{Autonomous, V<:VariableDependence}
) -> Any
Poisson bracket of two Hamiltonian functions (subtype of AbstractHamiltonian) : {f, g} = Poisson(f, g), autonomous case
Example
julia> f = (x, p) -> x[2]^2 + 2x[1]^2 + p[1]^2
julia> g = (x, p) -> 3x[2]^2 + -x[1]^2 + p[2]^2 + p[1]
julia> F = Hamiltonian(f)
julia> G = Hamiltonian(g)
julia> Poisson(f, g)([1, 2], [2, 1])
-20
julia> Poisson(f, G)([1, 2], [2, 1])
-20
julia> Poisson(F, g)([1, 2], [2, 1])
-20
CTBase.Poisson
— MethodPoisson(
f::AbstractHamiltonian{NonAutonomous, V<:VariableDependence},
g::AbstractHamiltonian{NonAutonomous, V<:VariableDependence}
) -> Any
Poisson bracket of two Hamiltonian functions (subtype of AbstractHamiltonian) : {f, g} = Poisson(f, g), non autonomous case
Example
julia> f = (t, x, p, v) -> t*v[1]*x[2]^2 + 2x[1]^2 + p[1]^2 + v[2]
julia> g = (t, x, p, v) -> 3x[2]^2 + -x[1]^2 + p[2]^2 + p[1] + t - v[2]
julia> F = Hamiltonian(f, autonomous=false, variable=true)
julia> G = Hamiltonian(g, autonomous=false, variable=true)
julia> Poisson(F, G)(2, [1, 2], [2, 1], [4, 4])
-76
julia> Poisson(f, g, NonAutonomous, NonFixed)(2, [1, 2], [2, 1], [4, 4])
-76
CTBase.Poisson
— MethodPoisson(
f::HamiltonianLift{T<:TimeDependence, V<:VariableDependence},
g::HamiltonianLift{T<:TimeDependence, V<:VariableDependence}
)
Poisson bracket of two HamiltonianLift functions : {f, g} = Poisson(f, g)
Example
julia> f = x -> [x[1]^2+x[2]^2, 2x[1]^2]
julia> g = x -> [3x[2]^2, x[2]-x[1]^2]
julia> F = Lift(f)
julia> G = Lift(g)
julia> Poisson(F, G)([1, 2], [2, 1])
-64
julia> f = (t, x, v) -> [t*v[1]*x[2]^2, 2x[1]^2 + + v[2]]
julia> g = (t, x, v) -> [3x[2]^2 + -x[1]^2, t - v[2]]
julia> F = Lift(f, NonAutonomous, NonFixed)
julia> G = Lift(g, NonAutonomous, NonFixed)
julia> Poisson(F, G)(2, [1, 2], [2, 1], [4, 4])
100
CTBase.__OCPModel
— Method__OCPModel(args...; kwargs...) -> OptimalControlModel
Redirection to Model
to avoid confusion with other functions Model from other packages if imported. This function is used by @def
.
CTBase.add
— Methodadd(
x::Tuple{Vararg{Tuple{Vararg{Symbol}}}},
y::Tuple{Vararg{Symbol}}
) -> Tuple{Tuple{Vararg{Symbol}}}
Concatenate the description y
to the tuple of descriptions x
if x
does not contain y
and return the new tuple of descriptions. Throw an error if the description y
is already contained in x
.
Example
julia> descriptions = ()
julia> descriptions = add(descriptions, (:a,))
(:a,)
julia> descriptions = add(descriptions, (:b,))
(:a,)
(:b,)
julia> descriptions = add(descriptions, (:b,))
ERROR: IncorrectArgument: the description (:b,) is already in ((:a,), (:b,))
CTBase.add
— Methodadd(
x::Tuple{},
y::Tuple{Vararg{Symbol}}
) -> Tuple{Tuple{Vararg{Symbol}}}
Return a tuple containing only the description y
.
Example
julia> descriptions = ()
julia> descriptions = add(descriptions, (:a,))
(:a,)
julia> print(descriptions)
((:a,),)
julia> descriptions[1]
(:a,)
CTBase.boundary_constraints!
— Methodboundary_constraints!(
sol::OptimalControlSolution,
boundary_constraints::Union{Real, AbstractVector{<:Real}}
)
Set the boundary constraints.
CTBase.boundary_constraints
— Methodboundary_constraints(
sol::OptimalControlSolution
) -> Union{Nothing, Real, AbstractVector{<:Real}}
Return the boundary constraints of the optimal control solution or nothing
.
CTBase.constraint!
— Methodconstraint!(
ocp::OptimalControlModel{T<:TimeDependence, V<:VariableDependence},
type::Symbol;
rg,
f,
lb,
ub,
val,
label
)
Add a constraint to an optimal control problem, denoted ocp
.
- The state, control and variable dimensions must be set before. Use state!, control! and variable!.
- The initial and final times must be set before. Use time!.
- When an element is of dimension 1, consider it as a scalar.
You can add an :initial
, :final
, :control
, :state
or :variable
box constraint (whole range).
Range constraint on the state, control or variable
You can add an :initial
, :final
, :control
, :state
or :variable
box constraint on a range of it, that is only on some components. If not range is specified, then the constraint is on the whole range. We denote by x
, u
and v
respectively the state, control and variable. We denote by n
, m
and q
respectively the dimension of the state, control and variable. The range of the constraint must be contained in 1:n if the constraint is on the state, or 1:m if the constraint is on the control, or 1:q if the constraint is on the variable.
Examples
julia> constraint!(ocp, :initial; rg=1:2:5, lb=[ 0, 0, 0 ], ub=[ 1, 2, 1 ])
julia> constraint!(ocp, :initial; rg=2:3, lb=[ 0, 0 ], ub=[ 1, 2 ])
julia> constraint!(ocp, :final; rg=1, lb=0, ub=2)
julia> constraint!(ocp, :control; rg=1, lb=0, ub=2)
julia> constraint!(ocp, :state; rg=2:3, lb=[ 0, 0 ], ub=[ 1, 2 ])
julia> constraint!(ocp, :variable; rg=1:2, lb=[ 0, 0 ], ub=[ 1, 2 ])
julia> constraint!(ocp, :initial; lb=[ 0, 0, 0 ]) # [ 0, 0, 0 ] ≤ x(t0), dim(x) = 3
julia> constraint!(ocp, :initial; lb=[ 0, 0, 0 ], ub=[ 1, 2, 1 ]) # [ 0, 0, 0 ] ≤ x(t0) ≤ [ 1, 2, 1 ], dim(x) = 3
julia> constraint!(ocp, :final; lb=-1, ub=1) # -1 ≤ x(tf) ≤ 1, dim(x) = 1
julia> constraint!(ocp, :control; lb=0, ub=2) # 0 ≤ u(t) ≤ 2, t ∈ [t0, tf], dim(u) = 1
julia> constraint!(ocp, :state; lb=[ 0, 0 ], ub=[ 1, 2 ]) # [ 0, 0 ] ≤ x(t) ≤ [ 1, 2 ], t ∈ [t0, tf], dim(x) = 2
julia> constraint!(ocp, :variable; lb=[ 0, 0 ], ub=[ 1, 2 ]) # [ 0, 0 ] ≤ v ≤ [ 1, 2 ], dim(v) = 2
Functional constraint
You can add a :boundary
, :control
, :state
, :mixed
or :variable
box functional constraint.
Examples
# variable independent ocp
julia> constraint!(ocp, :boundary; f = (x0, xf) -> x0[3]+xf[2], lb=0, ub=1)
# variable dependent ocp
julia> constraint!(ocp, :boundary; f = (x0, xf, v) -> x0[3]+xf[2]*v[1], lb=0, ub=1)
# time independent and variable independent ocp
julia> constraint!(ocp, :control; f = u -> 2u, lb=0, ub=1)
julia> constraint!(ocp, :state; f = x -> x-1, lb=[ 0, 0, 0 ], ub=[ 1, 2, 1 ])
julia> constraint!(ocp, :mixed; f = (x, u) -> x[1]-u, lb=0, ub=1)
# time dependent and variable independent ocp
julia> constraint!(ocp, :control; f = (t, u) -> 2u, lb=0, ub=1)
julia> constraint!(ocp, :state; f = (t, x) -> t * x, lb=[ 0, 0, 0 ], ub=[ 1, 2, 1 ])
julia> constraint!(ocp, :mixed; f = (t, x, u) -> x[1]-u, lb=0, ub=1)
# time independent and variable dependent ocp
julia> constraint!(ocp, :control; f = (u, v) -> 2u * v[1], lb=0, ub=1)
julia> constraint!(ocp, :state; f = (x, v) -> x * v[1], lb=[ 0, 0, 0 ], ub=[ 1, 2, 1 ])
julia> constraint!(ocp, :mixed; f = (x, u, v) -> x[1]-v[2]*u, lb=0, ub=1)
# time dependent and variable dependent ocp
julia> constraint!(ocp, :control; f = (t, u, v) -> 2u+v[2], lb=0, ub=1)
julia> constraint!(ocp, :state; f = (t, x, v) -> x-t*v[1], lb=[ 0, 0, 0 ], ub=[ 1, 2, 1 ])
julia> constraint!(ocp, :mixed; f = (t, x, u, v) -> x[1]*v[2]-u, lb=0, ub=1)
CTBase.constraint
— Methodconstraint(
ocp::OptimalControlModel{T<:TimeDependence, V<:VariableDependence},
label::Symbol
) -> Any
Retrieve a labeled constraint. The result is a function associated with the constraint computation (not taking into account provided value / bounds).
Example
julia> constraint!(ocp, :initial, 0, :c0)
julia> c = constraint(ocp, :c0)
julia> c(1)
1
CTBase.constraint_type
— Methodconstraint_type(
e,
t,
t0,
tf,
x,
u,
v
) -> Union{Symbol, Tuple{Symbol, Any}}
Return the type constraint among :initial
, :final
, :boundary
, :control_range
, :control_fun
, :state_range
, :state_fun
, :mixed
, :variable_range
, :variable_fun
(:other
otherwise), together with the appropriate value (range, updated expression...) Expressions like u(t0)
where u
is the control and t0
the initial time return :other
.
Example
julia> t = :t; t0 = 0; tf = :tf; x = :x; u = :u; v = :v
julia> constraint_type(:( ẏ(t) ), t, t0, tf, x, u, v)
:other
julia> constraint_type(:( ẋ(s) ), t, t0, tf, x, u, v)
:other
julia> constraint_type(:( x(0)' ), t, t0, tf, x, u, v)
:boundary
julia> constraint_type(:( x(t)' ), t, t0, tf, x, u, v)
:state_fun
julia> constraint_type(:( x(0) ), t, t0, tf, x, u, v)
(:initial, nothing)
julia> constraint_type(:( x[1:2:5](0) ), t, t0, tf, x, u, v)
(:initial, 1:2:5)
julia> constraint_type(:( x[1:2](0) ), t, t0, tf, x, u, v)
(:initial, 1:2)
julia> constraint_type(:( x[1](0) ), t, t0, tf, x, u, v)
(:initial, 1)
julia> constraint_type(:( 2x[1](0)^2 ), t, t0, tf, x, u, v)
:boundary
julia> constraint_type(:( x(tf) ), t, t0, tf, x, u, v)
(:final, nothing)
j
julia> constraint_type(:( x[1:2:5](tf) ), t, t0, tf, x, u, v)
(:final, 1:2:5)
julia> constraint_type(:( x[1:2](tf) ), t, t0, tf, x, u, v)
(:final, 1:2)
julia> constraint_type(:( x[1](tf) ), t, t0, tf, x, u, v)
(:final, 1)
julia> constraint_type(:( 2x[1](tf)^2 ), t, t0, tf, x, u, v)
:boundary
julia> constraint_type(:( x[1](tf) - x[2](0) ), t, t0, tf, x, u, v)
:boundary
julia> constraint_type(:( u[1:2:5](t) ), t, t0, tf, x, u, v)
(:control_range, 1:2:5)
julia> constraint_type(:( u[1:2](t) ), t, t0, tf, x, u, v)
(:control_range, 1:2)
julia> constraint_type(:( u[1](t) ), t, t0, tf, x, u, v)
(:control_range, 1)
julia> constraint_type(:( u(t) ), t, t0, tf, x, u, v)
(:control_range, nothing)
julia> constraint_type(:( 2u[1](t)^2 ), t, t0, tf, x, u, v)
:control_fun
julia> constraint_type(:( x[1:2:5](t) ), t, t0, tf, x, u, v)
(:state_range, 1:2:5)
julia> constraint_type(:( x[1:2](t) ), t, t0, tf, x, u, v)
(:state_range, 1:2)
julia> constraint_type(:( x[1](t) ), t, t0, tf, x, u, v)
(:state_range, 1)
julia> constraint_type(:( x(t) ), t, t0, tf, x, u, v)
(:state_range, nothing)
julia> constraint_type(:( 2x[1](t)^2 ), t, t0, tf, x, u, v)
:state_fun
julia> constraint_type(:( 2u[1](t)^2 * x(t) ), t, t0, tf, x, u, v)
:mixed
julia> constraint_type(:( 2u[1](0)^2 * x(t) ), t, t0, tf, x, u, v)
:other
julia> constraint_type(:( 2u[1](0)^2 * x(t) ), t, t0, tf, x, u, v)
:other
julia> constraint_type(:( 2u[1](t)^2 * x(t) + v ), t, t0, tf, x, u, v)
:mixed
julia> constraint_type(:( v[1:2:10] ), t, t0, tf, x, u, v)
(:variable_range, 1:2:9)
julia> constraint_type(:( v[1:10] ), t, t0, tf, x, u, v)
(:variable_range, 1:10)
julia> constraint_type(:( v[2] ), t, t0, tf, x, u, v)
(:variable_range, 2)
julia> constraint_type(:( v ), t, t0, tf, x, u, v)
(:variable_range, nothing)
julia> constraint_type(:( v^2 + 1 ), t, t0, tf, x, u, v)
:variable_fun
julia> constraint_type(:( v[2]^2 + 1 ), t, t0, tf, x, u, v)
:variable_fun
CTBase.constraints
— Methodconstraints(ocp::OptimalControlModel) -> Dict{Symbol, Tuple}
Return the constraints of the ocp or nothing.
CTBase.constraints_labels
— Methodconstraints_labels(
ocp::OptimalControlModel
) -> Base.KeySet{Symbol, Dict{Symbol, Tuple}}
Return the labels of the constraints as a Base.keys
.
CTBase.control!
— Functioncontrol!(ocp::OptimalControlModel, m::Int64)
control!(ocp::OptimalControlModel, m::Int64, name::String)
control!(
ocp::OptimalControlModel,
m::Int64,
name::String,
components_names::Vector{String}
)
Define the control dimension and possibly the names of each coordinate.
You must use control! only once to set the control dimension.
Examples
julia> control!(ocp, 1)
julia> control_dimension(ocp)
1
julia> control_components_names(ocp)
["u"]
julia> control!(ocp, 1, "v")
julia> control_dimension(ocp)
1
julia> control_components_names(ocp)
["v"]
julia> control!(ocp, 2)
julia> control_dimension(ocp)
2
julia> control_components_names(ocp)
["u₁", "u₂"]
julia> control!(ocp, 2, :v)
julia> control_dimension(ocp)
2
julia> control_components_names(ocp)
["v₁", "v₂"]
julia> control!(ocp, 2, "v")
julia> control_dimension(ocp)
2
julia> control_components_names(ocp)
["v₁", "v₂"]
CTBase.control
— Methodcontrol(
sol::OptimalControlSolution
) -> Union{Nothing, Function}
Return the control (function of time) of the optimal control solution or nothing
.
julia> t0 = time_grid(sol)[1]
julia> u = control(sol)
julia> u0 = u(t0) # control at initial time
CTBase.control_components_names
— Methodcontrol_components_names(
ocp::OptimalControlModel
) -> Union{Nothing, Vector{String}}
Return the names of the components of the control of the optimal control problem or nothing
.
CTBase.control_components_names
— Methodcontrol_components_names(
sol::OptimalControlSolution
) -> Union{Nothing, Vector{String}}
Return the names of the components of the control of the optimal control solution or nothing
.
CTBase.control_constraints!
— Methodcontrol_constraints!(
sol::OptimalControlSolution,
control_constraints::Function
)
Set the control constraints.
CTBase.control_constraints
— Methodcontrol_constraints(
sol::OptimalControlSolution
) -> Union{Nothing, Function}
Return the control constraints of the optimal control solution or nothing
.
CTBase.control_dimension
— Methodcontrol_dimension(
ocp::OptimalControlModel
) -> Union{Nothing, Int64}
Return the dimention of the control of the optimal control problem or nothing
.
CTBase.control_dimension
— Methodcontrol_dimension(
sol::OptimalControlSolution
) -> Union{Nothing, Int64}
Return the dimension of the control of the optimal control solution or nothing
.
CTBase.control_discretized
— Methodcontrol_discretized(sol::OptimalControlSolution) -> Any
Return the control values at times time_grid(sol)
of the optimal control solution or nothing
.
julia> u = control_discretized(sol)
julia> u0 = u[1] # control at initial time
CTBase.control_name
— Methodcontrol_name(
ocp::OptimalControlModel
) -> Union{Nothing, String}
Return the name of the control of the optimal control problem or nothing
.
CTBase.control_name
— Methodcontrol_name(
sol::OptimalControlSolution
) -> Union{Nothing, String}
Return the name of the control of the optimal control solution or nothing
.
CTBase.costate!
— Methodcostate!(sol::OptimalControlSolution, costate::Function)
Set the costate.
CTBase.costate
— Methodcostate(
sol::OptimalControlSolution
) -> Union{Nothing, Function}
Return the costate of the optimal control solution or nothing
.
julia> t0 = time_grid(sol)[1]
julia> p = costate(sol)
julia> p0 = p(t0)
CTBase.costate_discretized
— Methodcostate_discretized(sol::OptimalControlSolution) -> Any
Return the costate values at times time_grid(sol)
of the optimal control solution or nothing
.
julia> p = costate_discretized(sol)
julia> p0 = p[1] # costate at initial time
CTBase.criterion
— Methodcriterion(
ocp::OptimalControlModel
) -> Union{Nothing, Symbol}
Return the criterion (:min
or :max
) of the optimal control problem or nothing
.
CTBase.ct_repl
— Methodct_repl(; debug, verbose)
Create a ct REPL.
CTBase.ct_repl_update_model
— Methodct_repl_update_model(e::Expr)
Update the model adding the expression e. It must be public since in the ct repl, this function is quoted each time an expression is parsed and is valid.
CTBase.ctgradient
— Methodctgradient(f::Function, x; backend) -> Any
Return the gradient of f
at x
.
CTBase.ctgradient
— Methodctgradient(f::Function, x::Real; backend) -> Any
Return the gradient of f
at x
.
CTBase.ctgradient
— Methodctgradient(X::VectorField, x) -> Any
Return the gradient of X
at x
.
CTBase.ctindices
— Methodctindices(i::Int64) -> String
Return i
> 0 as a subscript.
CTBase.ctinterpolate
— Methodctinterpolate(x, f) -> Any
Return the interpolation of f
at x
.
CTBase.ctjacobian
— Methodctjacobian(f::Function, x; backend) -> Any
Return the Jacobian of f
at x
.
CTBase.ctjacobian
— Methodctjacobian(f::Function, x::Real; backend) -> Any
Return the Jacobian of f
at x
.
CTBase.ctjacobian
— Methodctjacobian(X::VectorField, x) -> Any
Return the Jacobian of X
at x
.
CTBase.ctupperscripts
— Methodctupperscripts(i::Int64) -> String
Return i
> 0 as an upperscript.
CTBase.dim_boundary_constraints
— Methoddim_boundary_constraints(
ocp::OptimalControlModel
) -> Union{Nothing, Int64}
Return the dimension of the boundary constraints (nothing
if not knonw). Information is updated after nlp_constraints!
is called.
CTBase.dim_control_constraints
— Methoddim_control_constraints(
ocp::OptimalControlModel
) -> Union{Nothing, Int64}
Return the dimension of nonlinear control constraints (nothing
if not knonw). Information is updated after nlp_constraints!
is called.
CTBase.dim_control_range
— Methoddim_control_range(
ocp::OptimalControlModel
) -> Union{Nothing, Int64}
Return the dimension of range constraints on control (nothing
if not knonw). Information is updated after nlp_constraints!
is called.
CTBase.dim_mixed_constraints
— Methoddim_mixed_constraints(
ocp::OptimalControlModel
) -> Union{Nothing, Int64}
Return the dimension of nonlinear mixed constraints (nothing
if not knonw). Information is updated after nlp_constraints!
is called.
CTBase.dim_path_constraints
— Methoddim_path_constraints(
ocp::OptimalControlModel
) -> Union{Nothing, Int64}
Return the dimension of nonlinear path (state + control + mixed) constraints (nothing
if one of them is not knonw). Information is updated after nlp_constraints!
is called.
CTBase.dim_state_constraints
— Methoddim_state_constraints(
ocp::OptimalControlModel
) -> Union{Nothing, Int64}
Return the dimension of nonlinear state constraints (nothing
if not knonw). Information is updated after nlp_constraints!
is called.
CTBase.dim_state_range
— Methoddim_state_range(
ocp::OptimalControlModel
) -> Union{Nothing, Int64}
Return the dimension of range constraints on state (nothing
if not knonw). Information is updated after nlp_constraints!
is called.
CTBase.dim_variable_constraints
— Methoddim_variable_constraints(
ocp::OptimalControlModel
) -> Union{Nothing, Int64}
Return the dimension of nonlinear variable constraints (nothing
if not knonw). Information is updated after nlp_constraints!
is called.
CTBase.dim_variable_range
— Methoddim_variable_range(
ocp::OptimalControlModel
) -> Union{Nothing, Int64}
Return the dimension of range constraints on variable (nothing
if not knonw). Information is updated after nlp_constraints!
is called.
CTBase.dynamics!
— Methoddynamics!(
ocp::OptimalControlModel{T<:TimeDependence, V<:VariableDependence},
f::Function
)
Set the dynamics.
You can use dynamics! only once to define the dynamics.
- The state, control and variable dimensions must be set before. Use state!, control! and variable!.
- The times must be set before. Use time!.
- When an element is of dimension 1, consider it as a scalar.
Example
julia> dynamics!(ocp, f)
CTBase.dynamics
— Methoddynamics(
ocp::OptimalControlModel
) -> Union{Nothing, Dynamics, Dynamics!}
Return the dynamics of the optimal control problem or nothing
.
CTBase.final_time
— Methodfinal_time(
ocp::OptimalControlModel
) -> Union{Nothing, Index, Real}
Return the final time of the optimal control problem or nothing
.
CTBase.final_time_name
— Methodfinal_time_name(
ocp::OptimalControlModel
) -> Union{Nothing, String}
Return the name of the final time of the optimal control problem or nothing
.
CTBase.final_time_name
— Methodfinal_time_name(
sol::OptimalControlSolution
) -> Union{Nothing, String}
Return the name of final time of the optimal control solution or nothing
.
CTBase.getFullDescription
— MethodgetFullDescription(
desc::Tuple{Vararg{Symbol}},
desc_list::Tuple{Vararg{Tuple{Vararg{Symbol}}}}
) -> Tuple{Vararg{Symbol}}
Return a complete description from an incomplete description desc
and a list of complete descriptions desc_list
. If several complete descriptions are possible, then the first one is returned.
Example
julia> desc_list = ((:a, :b), (:b, :c), (:a, :c))
(:a, :b)
(:b, :c)
(:a, :c)
julia> getFullDescription((:a,), desc_list)
(:a, :b)
CTBase.has_free_final_time
— Methodhas_free_final_time(ocp::OptimalControlModel) -> Bool
Return true
if the model has been defined with free final time.
CTBase.has_free_initial_time
— Methodhas_free_initial_time(ocp::OptimalControlModel) -> Bool
Return true
if the model has been defined with free initial time.
CTBase.has_lagrange_cost
— Methodhas_lagrange_cost(ocp::OptimalControlModel) -> Bool
Return true
if the model has been defined with lagrange cost.
CTBase.has_mayer_cost
— Methodhas_mayer_cost(ocp::OptimalControlModel) -> Bool
Return true
if the model has been defined with mayer cost.
CTBase.infos!
— Methodinfos!(
sol::OptimalControlSolution,
infos::Dict{Symbol, Any}
)
Set the additional infos.
CTBase.infos
— Methodinfos(sol::OptimalControlSolution) -> Dict{Symbol, Any}
Return a dictionary of additional infos depending on the solver or nothing
.
CTBase.initial_time
— Methodinitial_time(
ocp::OptimalControlModel
) -> Union{Nothing, Index, Real}
Return the initial time of the optimal control problem or nothing
.
CTBase.initial_time_name
— Methodinitial_time_name(
ocp::OptimalControlModel
) -> Union{Nothing, String}
Return the name of the initial time of the optimal control problem or nothing
.
CTBase.initial_time_name
— Methodinitial_time_name(
sol::OptimalControlSolution
) -> Union{Nothing, String}
Return the name of the initial time of the optimal control solution or nothing
.
CTBase.is_autonomous
— Methodis_autonomous(ocp::OptimalControlModel{Autonomous}) -> Bool
Return true
if the model is autonomous.
CTBase.is_fixed
— Methodis_fixed(
ocp::OptimalControlModel{<:TimeDependence, Fixed}
) -> Bool
Return true
if the model is fixed (= has no variable).
CTBase.is_in_place
— Methodis_in_place(
ocp::OptimalControlModel
) -> Union{Nothing, Bool}
Return true
if functions defining the ocp are in-place. Return nothing if this information has not yet been set.
CTBase.is_max
— Methodis_max(ocp::OptimalControlModel) -> Bool
Return true
if the criterion type of ocp
is :max
.
CTBase.is_min
— Methodis_min(ocp::OptimalControlModel) -> Bool
Return true
if the criterion type of ocp
is :min
.
CTBase.is_time_dependent
— Methodis_time_dependent(ocp::OptimalControlModel) -> Bool
Return true
if the model has been defined as time dependent.
CTBase.is_time_independent
— Methodis_time_independent(ocp::OptimalControlModel) -> Bool
Return true
if the model has been defined as time independent.
CTBase.is_variable_dependent
— Methodis_variable_dependent(ocp::OptimalControlModel) -> Bool
Return true
if the model has been defined as variable dependent.
CTBase.is_variable_independent
— Methodis_variable_independent(ocp::OptimalControlModel) -> Bool
Return true
if the model has been defined as variable independent.
CTBase.iterations!
— Methoditerations!(sol::OptimalControlSolution, iterations::Int64)
Set the number of iterations.
CTBase.iterations
— Methoditerations(
sol::OptimalControlSolution
) -> Union{Nothing, Int64}
Return the number of iterations (if solved by an iterative method) of the optimal control solution or nothing
.
CTBase.lagrange
— Methodlagrange(
ocp::OptimalControlModel
) -> Union{Nothing, Lagrange, Lagrange!}
Return the Lagrange part of the cost of the optimal control problem or nothing
.
CTBase.mayer
— Methodmayer(
ocp::OptimalControlModel
) -> Union{Nothing, Mayer, Mayer!}
Return the Mayer part of the cost of the optimal control problem or nothing
.
CTBase.message!
— Methodmessage!(sol::OptimalControlSolution, message::String)
Set the message of stopping.
CTBase.message
— Methodmessage(
sol::OptimalControlSolution
) -> Union{Nothing, String}
Return the message associated to the stopping criterion of the optimal control solution or nothing
.
CTBase.mixed_constraints!
— Methodmixed_constraints!(
sol::OptimalControlSolution,
mixed_constraints::Function
)
Set the mixed state/control constraints.
CTBase.mixed_constraints
— Methodmixed_constraints(
sol::OptimalControlSolution
) -> Union{Nothing, Function}
Return the mixed state-control constraints of the optimal control solution or nothing
.
CTBase.model_expression!
— Methodmodel_expression!(
ocp::OptimalControlModel,
model_expression::Expr
)
Set the model expression of the optimal control problem or nothing
.
CTBase.model_expression
— Methodmodel_expression(
ocp::OptimalControlModel
) -> Union{Nothing, Expr}
Return the model expression of the optimal control problem or nothing
.
CTBase.mult_boundary_constraints!
— Methodmult_boundary_constraints!(
sol::OptimalControlSolution,
mult_boundary_constraints::Union{Real, AbstractVector{<:Real}}
)
Set the multipliers to the boundary constraints.
CTBase.mult_boundary_constraints
— Methodmult_boundary_constraints(
sol::OptimalControlSolution
) -> Union{Nothing, Real, AbstractVector{<:Real}}
Return the multipliers to the boundary constraints of the optimal control solution or nothing
.
CTBase.mult_control_box_lower!
— Methodmult_control_box_lower!(
sol::OptimalControlSolution,
mult_control_box_lower::Function
)
Set the multipliers to the control lower bounds.
CTBase.mult_control_box_lower
— Methodmult_control_box_lower(
sol::OptimalControlSolution
) -> Union{Nothing, Function}
Return the multipliers to the control lower bounds of the optimal control solution or nothing
.
CTBase.mult_control_box_upper!
— Methodmult_control_box_upper!(
sol::OptimalControlSolution,
mult_control_box_upper::Function
)
Set the multipliers to the control upper bounds.
CTBase.mult_control_box_upper
— Methodmult_control_box_upper(
sol::OptimalControlSolution
) -> Union{Nothing, Function}
Return the multipliers to the control upper bounds of the optimal control solution or nothing
.
CTBase.mult_control_constraints!
— Methodmult_control_constraints!(
sol::OptimalControlSolution,
mult_control_constraints::Function
)
Set the multipliers to the control constraints.
CTBase.mult_control_constraints
— Methodmult_control_constraints(
sol::OptimalControlSolution
) -> Union{Nothing, Function}
Return the multipliers to the control constraints of the optimal control solution or nothing
.
CTBase.mult_mixed_constraints!
— Methodmult_mixed_constraints!(
sol::OptimalControlSolution,
mult_mixed_constraints::Function
)
Set the multipliers to the mixed state/control constraints.
CTBase.mult_mixed_constraints
— Methodmult_mixed_constraints(
sol::OptimalControlSolution
) -> Union{Nothing, Function}
Return the multipliers to the mixed state-control constraints of the optimal control solution or nothing
.
CTBase.mult_state_box_lower!
— Methodmult_state_box_lower!(
sol::OptimalControlSolution,
mult_state_box_lower::Function
)
Set the multipliers to the state lower bounds.
CTBase.mult_state_box_lower
— Methodmult_state_box_lower(
sol::OptimalControlSolution
) -> Union{Nothing, Function}
Return the multipliers to the state lower bounds of the optimal control solution or nothing
.
CTBase.mult_state_box_upper!
— Methodmult_state_box_upper!(
sol::OptimalControlSolution,
mult_state_box_upper::Function
)
Set the multipliers to the state upper bounds.
CTBase.mult_state_box_upper
— Methodmult_state_box_upper(
sol::OptimalControlSolution
) -> Union{Nothing, Function}
Return the multipliers to the state upper bounds of the optimal control solution or nothing
.
CTBase.mult_state_constraints!
— Methodmult_state_constraints!(
sol::OptimalControlSolution,
mult_state_constraints::Function
)
Set the multipliers to the state constraints.
CTBase.mult_state_constraints
— Methodmult_state_constraints(
sol::OptimalControlSolution
) -> Union{Nothing, Function}
Return the multipliers to the state constraints of the optimal control solution or nothing
.
CTBase.mult_variable_box_lower!
— Methodmult_variable_box_lower!(
sol::OptimalControlSolution,
mult_variable_box_lower::Union{Real, AbstractVector{<:Real}}
)
Set the multipliers to the variable lower bounds.
CTBase.mult_variable_box_lower
— Methodmult_variable_box_lower(
sol::OptimalControlSolution
) -> Union{Nothing, Real, AbstractVector{<:Real}}
Return the multipliers to the variable lower bounds of the optimal control solution or nothing
.
CTBase.mult_variable_box_upper!
— Methodmult_variable_box_upper!(
sol::OptimalControlSolution,
mult_variable_box_upper::Union{Real, AbstractVector{<:Real}}
)
Set the multipliers to the variable upper bounds.
CTBase.mult_variable_box_upper
— Methodmult_variable_box_upper(
sol::OptimalControlSolution
) -> Union{Nothing, Real, AbstractVector{<:Real}}
Return the multipliers to the variable upper bounds of the optimal control solution or nothing
.
CTBase.mult_variable_constraints!
— Methodmult_variable_constraints!(
sol::OptimalControlSolution,
mult_variable_constraints::Union{Real, AbstractVector{<:Real}}
)
Set the multipliers to the variable constraints.
CTBase.mult_variable_constraints
— Methodmult_variable_constraints(
sol::OptimalControlSolution
) -> Union{Nothing, Real, AbstractVector{<:Real}}
Return the multipliers to the variable constraints of the optimal control solution or nothing
.
CTBase.nlp_constraints!
— Methodnlp_constraints!(
ocp::OptimalControlModel
) -> Tuple{Tuple{Any, Union{CTBase.var"#ξ!#53", CTBase.var"#ξ#52"}, Vector{Real}}, Tuple{Any, Union{CTBase.var"#η!#55", CTBase.var"#η#54"}, Vector{Real}}, Tuple{Any, Union{CTBase.var"#ψ!#57", CTBase.var"#ψ#56"}, Vector{Real}}, Tuple{Any, Union{CTBase.var"#ϕ!#59", CTBase.var"#ϕ#58"}, Vector{Real}}, Tuple{Any, Union{CTBase.var"#θ!#61", CTBase.var"#θ#60"}, Vector{Real}}, Tuple{Vector{Real}, Vector{Int64}, Vector{Real}}, Tuple{Vector{Real}, Vector{Int64}, Vector{Real}}, Tuple{Vector{Real}, Vector{Int64}, Vector{Real}}}
Return a 6-tuple of tuples:
(ξl, ξ, ξu)
are control constraints(ηl, η, ηu)
are state constraints(ψl, ψ, ψu)
are mixed constraints(ϕl, ϕ, ϕu)
are boundary constraints(θl, θ, θu)
are variable constraints(ul, uind, uu)
are control linear constraints of a subset of indices(xl, xind, xu)
are state linear constraints of a subset of indices(vl, vind, vu)
are variable linear constraints of a subset of indices
and update information about constraints dimensions of ocp
. Functions ξ
, η
, ψ
, ϕ
, θ
are used to evaluate the constraints at given time and state, control, or variable values. These functions are in place when the problem is defined as in place, that is when is_in_place(ocp)
.
- The dimensions of the state and control must be set before calling
nlp_constraints!
. - For a
Fixed
problem, dimensions associated with constraints on the variable are set to zero.
Example
julia> (ξl, ξ, ξu), (ηl, η, ηu), (ψl, ψ, ψu), (ϕl, ϕ, ϕu), (θl, θ, θu),
(ul, uind, uu), (xl, xind, xu), (vl, vind, vu) = nlp_constraints!(ocp)
CTBase.objective!
— Methodobjective!(
ocp::OptimalControlModel{T<:TimeDependence, V<:VariableDependence},
type::Symbol,
g::Function,
f⁰::Function
)
objective!(
ocp::OptimalControlModel{T<:TimeDependence, V<:VariableDependence},
type::Symbol,
g::Function,
f⁰::Function,
criterion::Symbol
)
Set the criterion to the function g
and f⁰
. Type can be :bolza
. Criterion is :min
or :max
.
You can use objective! only once to define the objective.
- The state, control and variable dimensions must be set before. Use state!, control! and variable!.
- The times must be set before. Use time!.
- When an element is of dimension 1, consider it as a scalar.
Example
julia> objective!(ocp, :bolza, (x0, xf) -> x0[1] + xf[2], (x, u) -> x[1]^2 + u^2) # the control is of dimension 1
CTBase.objective!
— Methodobjective!(
ocp::OptimalControlModel{T<:TimeDependence, V<:VariableDependence},
type::Symbol,
f::Function
)
objective!(
ocp::OptimalControlModel{T<:TimeDependence, V<:VariableDependence},
type::Symbol,
f::Function,
criterion::Symbol
)
Set the criterion to the function f
. Type can be :mayer
or :lagrange
. Criterion is :min
or :max
.
You can use objective! only once to define the objective.
- The state, control and variable dimensions must be set before. Use state!, control! and variable!.
- The times must be set before. Use time!.
- When an element is of dimension 1, consider it as a scalar.
Examples
julia> objective!(ocp, :mayer, (x0, xf) -> x0[1] + xf[2])
julia> objective!(ocp, :lagrange, (x, u) -> x[1]^2 + u^2) # the control is of dimension 1
If you set twice the objective, only the last one will be taken into account.
CTBase.objective
— Methodobjective(
sol::OptimalControlSolution
) -> Union{Nothing, Real}
Return the objective value of the optimal control solution or nothing
.
CTBase.remove
— Methodremove(
x::Tuple{Vararg{Symbol}},
y::Tuple{Vararg{Symbol}}
) -> Tuple{Vararg{Symbol}}
Return the difference between the description x
and the description y
.
Example
julia> remove((:a, :b), (:a,))
(:b,)
CTBase.remove_constraint!
— Methodremove_constraint!(ocp::OptimalControlModel, label::Symbol)
Remove a labeled constraint.
Example
julia> remove_constraint!(ocp, :con)
CTBase.replace_call
— Methodreplace_call(e, x::Symbol, t, y) -> Any
Replace calls in e of the form (...x...)(t)
by (...y...)
.
Example
julia> t = :t; t0 = 0; tf = :tf; x = :x; u = :u;
julia> e = :( x[1](0) * 2x(tf) - x[2](tf) * 2x(0) )
:((x[1])(0) * (2 * x(tf)) - (x[2])(tf) * (2 * x(0)))
julia> x0 = Symbol(x, 0); e = replace_call(e, x, t0, x0)
:(x0[1] * (2 * x(tf)) - (x[2])(tf) * (2x0))
julia> xf = Symbol(x, "f"); replace_call(ans, x, tf, xf)
:(x0[1] * (2xf) - xf[2] * (2x0))
julia> e = :( A*x(t) + B*u(t) ); replace_call(replace_call(e, x, t, x), u, t, u)
:(A * x + B * u)
julia> e = :( F0(x(t)) + u(t)*F1(x(t)) ); replace_call(replace_call(e, x, t, x), u, t, u)
:(F0(x) + u * F1(x))
julia> e = :( 0.5u(t)^2 ); replace_call(e, u, t, u)
:(0.5 * u ^ 2)
CTBase.replace_call
— Methodreplace_call(e, x::Vector{Symbol}, t, y) -> Any
Replace calls in e of the form (...x1...x2...)(t)
by (...y1...y2...)
for all symbols x1
, x2
... in the vector x
.
Example
julia> t = :t; t0 = 0; tf = :tf; x = :x; u = :u;
julia> e = :( (x^2 + u[1])(t) ); replace_call(e, [ x, u ], t , [ :xx, :uu ])
:(xx ^ 2 + uu[1])
julia> e = :( ((x^2)(t) + u[1])(t) ); replace_call(e, [ x, u ], t , [ :xx, :uu ])
:(xx ^ 2 + uu[1])
julia> e = :( ((x^2)(t0) + u[1])(t) ); replace_call(e, [ x, u ], t , [ :xx, :uu ])
:((xx ^ 2)(t0) + uu[1])
CTBase.state!
— Functionstate!(ocp::OptimalControlModel, n::Int64)
state!(ocp::OptimalControlModel, n::Int64, name::String)
state!(
ocp::OptimalControlModel,
n::Int64,
name::String,
components_names::Vector{String}
)
Define the state dimension and possibly the names of each component.
You must use state! only once to set the state dimension.
Examples
julia> state!(ocp, 1)
julia> state_dimension(ocp)
1
julia> state_components_names(ocp)
["x"]
julia> state!(ocp, 1, "y")
julia> state_dimension(ocp)
1
julia> state_components_names(ocp)
["y"]
julia> state!(ocp, 2)
julia> state_dimension(ocp)
2
julia> state_components_names(ocp)
["x₁", "x₂"]
julia> state!(ocp, 2, :y)
julia> state_dimension(ocp)
2
julia> state_components_names(ocp)
["y₁", "y₂"]
julia> state!(ocp, 2, "y")
julia> state_dimension(ocp)
2
julia> state_components_names(ocp)
["y₁", "y₂"]
CTBase.state
— Methodstate(
sol::OptimalControlSolution
) -> Union{Nothing, Function}
Return the state (function of time) of the optimal control solution or nothing
.
julia> t0 = time_grid(sol)[1]
julia> x = state(sol)
julia> x0 = x(t0)
CTBase.state_components_names
— Methodstate_components_names(
ocp::OptimalControlModel
) -> Union{Nothing, Vector{String}}
Return the names of the components of the state of the optimal control problem or nothing
.
CTBase.state_components_names
— Methodstate_components_names(
sol::OptimalControlSolution
) -> Union{Nothing, Vector{String}}
Return the names of the components of the state of the optimal control solution or nothing
.
CTBase.state_constraints!
— Methodstate_constraints!(
sol::OptimalControlSolution,
state_constraints::Function
)
Set the state constraints.
CTBase.state_constraints
— Methodstate_constraints(
sol::OptimalControlSolution
) -> Union{Nothing, Function}
Return the state constraints of the optimal control solution or nothing
.
CTBase.state_dimension
— Methodstate_dimension(
ocp::OptimalControlModel
) -> Union{Nothing, Int64}
Return the dimension of the state of the optimal control problem or nothing
.
CTBase.state_dimension
— Methodstate_dimension(
sol::OptimalControlSolution
) -> Union{Nothing, Int64}
Return the dimension of the state of the optimal control solution or nothing
.
CTBase.state_discretized
— Methodstate_discretized(sol::OptimalControlSolution) -> Any
Return the state values at times time_grid(sol)
of the optimal control solution or nothing
.
julia> x = state_discretized(sol)
julia> x0 = x[1] # state at initial time
CTBase.state_name
— Methodstate_name(
ocp::OptimalControlModel
) -> Union{Nothing, String}
Return the name of the state of the optimal control problem or nothing
.
CTBase.state_name
— Methodstate_name(
sol::OptimalControlSolution
) -> Union{Nothing, String}
Return the name of the state of the optimal control solution or nothing
.
CTBase.stopping!
— Methodstopping!(sol::OptimalControlSolution, stopping::Symbol)
Set the stopping criterion.
CTBase.stopping
— Methodstopping(
sol::OptimalControlSolution
) -> Union{Nothing, Symbol}
Return the stopping criterion (a Symbol) of the optimal control solution or nothing
.
CTBase.success!
— Methodsuccess!(sol::OptimalControlSolution, success::Bool)
Set the success.
CTBase.success
— Methodsuccess(sol::OptimalControlSolution) -> Union{Nothing, Bool}
Return the true if the solver has finished successfully of false if not, or nothing
.
CTBase.time!
— Methodtime!(
ocp::OptimalControlModel{<:TimeDependence, VT};
t0,
tf,
ind0,
indf,
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.
You must use time! only once to set either the initial or the final time, or both.
Examples
julia> time!(ocp, t0=0, tf=1 ) # Fixed t0 and fixed tf
julia> time!(ocp, t0=0, indf=2) # Fixed t0 and free tf
julia> time!(ocp, ind0=2, tf=1 ) # Free t0 and fixed tf
julia> time!(ocp, ind0=2, indf=3) # Free t0 and free tf
When you plot a solution of an optimal control problem, the name of the time variable appears. By default, the name is "t". Consider you want to set the name of the time variable to "s".
julia> time!(ocp, t0=0, tf=1, name="s") # name is a String
# or
julia> time!(ocp, t0=0, tf=1, name=:s ) # name is a Symbol
CTBase.time_grid!
— Methodtime_grid!(
sol::OptimalControlSolution,
time_grid::Union{StepRangeLen, AbstractVector{<:Real}}
)
Set the time grid.
CTBase.time_grid
— Methodtime_grid(
sol::OptimalControlSolution
) -> Union{Nothing, StepRangeLen, AbstractVector{<:Real}}
Return the time grid of the optimal control solution or nothing
.
CTBase.time_name
— Methodtime_name(
ocp::OptimalControlModel
) -> Union{Nothing, String}
Return the name of the time component of the optimal control problem or nothing
.
CTBase.time_name
— Methodtime_name(
sol::OptimalControlSolution
) -> Union{Nothing, String}
Return the name of the time component of the optimal control solution or nothing
.
CTBase.variable!
— Functionvariable!(ocp::OptimalControlModel, q::Int64)
variable!(ocp::OptimalControlModel, q::Int64, name::String)
variable!(
ocp::OptimalControlModel,
q::Int64,
name::String,
components_names::Vector{String}
)
Define the variable dimension and possibly the names of each component.
You can use variable! once to set the variable dimension when the model is NonFixed
.
Examples
julia> variable!(ocp, 1, "v")
julia> variable!(ocp, 2, "v", [ "v₁", "v₂" ])
CTBase.variable
— Methodvariable(
sol::OptimalControlSolution
) -> Union{Nothing, Real, AbstractVector{<:Real}}
Return the variable of the optimal control solution or nothing
.
julia> v = variable(sol)
CTBase.variable_components_names
— Methodvariable_components_names(
ocp::OptimalControlModel
) -> Union{Nothing, Vector{String}}
Return the names of the components of the variable of the optimal control problem or nothing
.
CTBase.variable_components_names
— Methodvariable_components_names(
sol::OptimalControlSolution
) -> Union{Nothing, Vector{String}}
Return the names of the components of the variable of the optimal control solution or nothing
.
CTBase.variable_constraints!
— Methodvariable_constraints!(
sol::OptimalControlSolution,
variable_constraints::Union{Real, AbstractVector{<:Real}}
)
Set the variable constraints.
CTBase.variable_constraints
— Methodvariable_constraints(
sol::OptimalControlSolution
) -> Union{Nothing, Real, AbstractVector{<:Real}}
Return the variable constraints of the optimal control solution or nothing
.
CTBase.variable_dimension
— Methodvariable_dimension(
ocp::OptimalControlModel
) -> Union{Nothing, Int64}
Return the dimension of the variable of the optimal control problem or nothing
.
CTBase.variable_dimension
— Methodvariable_dimension(
sol::OptimalControlSolution
) -> Union{Nothing, Int64}
Return the dimension of the variable of the optimal control solution or nothing
.
CTBase.variable_name
— Methodvariable_name(
ocp::OptimalControlModel
) -> Union{Nothing, String}
Return the name of the variable of the optimal control problem or nothing
.
CTBase.variable_name
— Methodvariable_name(
sol::OptimalControlSolution
) -> Union{Nothing, String}
Return the name of the variable of the optimal control solution or nothing
.
CTBase.∂ₜ
— Method∂ₜ(f) -> CTBase.var"#177#179"
Partial derivative wrt time of a function.
Example
julia> ∂ₜ((t,x) -> t*x)(0,8)
8
CTBase.@Lie
— MacroMacros for Poisson brackets
Example
julia> H0 = (x, p) -> 0.5*(x[1]^2+x[2]^2+p[1]^2)
julia> H1 = (x, p) -> 0.5*(x[1]^2+x[2]^2+p[2]^2)
julia> @Lie {H0, H1}([1, 2, 3], [1, 0, 7]) autonomous=true variable=false
#
julia> H0 = (t, x, p) -> 0.5*(x[1]^2+x[2]^2+p[1]^2)
julia> H1 = (t, x, p) -> 0.5*(x[1]^2+x[2]^2+p[2]^2)
julia> @Lie {H0, H1}(1, [1, 2, 3], [1, 0, 7]) autonomous=false variable=false
#
julia> H0 = (x, p, v) -> 0.5*(x[1]^2+x[2]^2+p[1]^2+v)
julia> H1 = (x, p, v) -> 0.5*(x[1]^2+x[2]^2+p[2]^2+v)
julia> @Lie {H0, H1}([1, 2, 3], [1, 0, 7], 2) autonomous=true variable=true
#
julia> H0 = (t, x, p, v) -> 0.5*(x[1]^2+x[2]^2+p[1]^2+v)
julia> H1 = (t, x, p, v) -> 0.5*(x[1]^2+x[2]^2+p[2]^2+v)
julia> @Lie {H0, H1}(1, [1, 2, 3], [1, 0, 7], 2) autonomous=false variable=true
CTBase.@Lie
— MacroMacros for Lie and Poisson brackets
Example
julia> H0 = (t, x, p) -> 0.5*(x[1]^2+x[2]^2+p[1]^2)
julia> H1 = (t, x, p) -> 0.5*(x[1]^2+x[2]^2+p[2]^2)
julia> @Lie {H0, H1}(1, [1, 2, 3], [1, 0, 7]) autonomous=false
#
julia> H0 = (x, p, v) -> 0.5*(x[1]^2+x[2]^2+p[1]^2+v)
julia> H1 = (x, p, v) -> 0.5*(x[1]^2+x[2]^2+p[2]^2+v)
julia> @Lie {H0, H1}([1, 2, 3], [1, 0, 7], 2) variable=true
#
CTBase.@Lie
— MacroMacros for Lie and Poisson brackets
Example
julia> F0 = VectorField(x -> [x[1], x[2], (1-x[3])])
julia> F1 = VectorField(x -> [0, -x[3], x[2]])
julia> @Lie [F0, F1]([1, 2, 3])
[0, 5, 4]
#
julia> F0 = VectorField((t, x) -> [t+x[1], x[2], (1-x[3])], autonomous=false)
julia> F1 = VectorField((t, x) -> [t, -x[3], x[2]], autonomous=false)
julia> @Lie [F0, F1](1, [1, 2, 3])
#
julia> F0 = VectorField((x, v) -> [x[1]+v, x[2], (1-x[3])], variable=true)
julia> F1 = VectorField((x, v) -> [0, -x[3]-v, x[2]], variable=true)
julia> @Lie [F0, F1]([1, 2, 3], 2)
#
julia> F0 = VectorField((t, x, v) -> [t+x[1]+v, x[2], (1-x[3])], autonomous=false, variable=true)
julia> F1 = VectorField((t, x, v) -> [t, -x[3]-v, x[2]], autonomous=false, variable=true)
julia> @Lie [F0, F1](1, [1, 2, 3], 2)
#
julia> H0 = Hamiltonian((x, p) -> 0.5*(2x[1]^2+x[2]^2+p[1]^2))
julia> H1 = Hamiltonian((x, p) -> 0.5*(3x[1]^2+x[2]^2+p[2]^2))
julia> @Lie {H0, H1}([1, 2, 3], [1, 0, 7])
3.0
#
julia> H0 = Hamiltonian((t, x, p) -> 0.5*(x[1]^2+x[2]^2+p[1]^2), autonomous=false)
julia> H1 = Hamiltonian((t, x, p) -> 0.5*(x[1]^2+x[2]^2+p[2]^2), autonomous=false)
julia> @Lie {H0, H1}(1, [1, 2, 3], [1, 0, 7])
#
julia> H0 = Hamiltonian((x, p, v) -> 0.5*(x[1]^2+x[2]^2+p[1]^2+v), variable=true)
julia> H1 = Hamiltonian((x, p, v) -> 0.5*(x[1]^2+x[2]^2+p[2]^2+v), variable=true)
julia> @Lie {H0, H1}([1, 2, 3], [1, 0, 7], 2)
#
julia> H0 = Hamiltonian((t, x, p, v) -> 0.5*(x[1]^2+x[2]^2+p[1]^2+v), autonomous=false, variable=true)
julia> H1 = Hamiltonian((t, x, p, v) -> 0.5*(x[1]^2+x[2]^2+p[2]^2+v), autonomous=false, variable=true)
julia> @Lie {H0, H1}(1, [1, 2, 3], [1, 0, 7], 2)
#
CTBase.@def
— MacroDefine an optimal control problem. One pass parsing of the definition. Can be used writing either ocp = @def begin ... end
or @def ocp begin ... end
. In the second case, setting log
to true
will display the parsing steps.
Example
ocp = @def begin
tf ∈ R, variable
t ∈ [ 0, tf ], time
x ∈ R², state
u ∈ R, control
tf ≥ 0
-1 ≤ u(t) ≤ 1
q = x₁
v = x₂
q(0) == 1
v(0) == 2
q(tf) == 0
v(tf) == 0
0 ≤ q(t) ≤ 5, (1)
-2 ≤ v(t) ≤ 3, (2)
ẋ(t) == [ v(t), u(t) ]
tf → min
end
@def ocp begin
tf ∈ R, variable
t ∈ [ 0, tf ], time
x ∈ R², state
u ∈ R, control
tf ≥ 0
-1 ≤ u(t) ≤ 1
q = x₁
v = x₂
q(0) == 1
v(0) == 2
q(tf) == 0
v(tf) == 0
0 ≤ q(t) ≤ 5, (1)
-2 ≤ v(t) ≤ 3, (2)
ẋ(t) == [ v(t), u(t) ]
tf → min
end true # final boolean to show parsing log