Types
Index
CTFlows.AbstractHamiltonian
CTFlows.AbstractVectorField
CTFlows.Autonomous
CTFlows.Control
CTFlows.ControlLaw
CTFlows.ControlLaw
CTFlows.ControlLaw
CTFlows.Costate
CTFlows.DCostate
CTFlows.DState
CTFlows.Dynamics
CTFlows.Dynamics
CTFlows.Dynamics
CTFlows.FeedbackControl
CTFlows.FeedbackControl
CTFlows.FeedbackControl
CTFlows.Fixed
CTFlows.Hamiltonian
CTFlows.Hamiltonian
CTFlows.Hamiltonian
CTFlows.HamiltonianLift
CTFlows.HamiltonianLift
CTFlows.HamiltonianLift
CTFlows.HamiltonianVectorField
CTFlows.HamiltonianVectorField
CTFlows.HamiltonianVectorField
CTFlows.Lagrange
CTFlows.Lagrange
CTFlows.Lagrange
CTFlows.Mayer
CTFlows.Mayer
CTFlows.Mayer
CTFlows.MixedConstraint
CTFlows.MixedConstraint
CTFlows.MixedConstraint
CTFlows.Multiplier
CTFlows.Multiplier
CTFlows.Multiplier
CTFlows.NonAutonomous
CTFlows.NonFixed
CTFlows.State
CTFlows.StateConstraint
CTFlows.StateConstraint
CTFlows.StateConstraint
CTFlows.Time
CTFlows.TimeDependence
CTFlows.Times
CTFlows.Variable
CTFlows.VariableDependence
CTFlows.VectorField
CTFlows.VectorField
CTFlows.VectorField
CTFlows.ctNumber
CTFlows.ctVector
In the examples in the documentation below, the methods are not prefixed by the module name even if they are private.
julia> using CTFlows
julia> x = 1
julia> private_fun(x) # throw an error
must be replaced by
julia> using CTFlows
julia> x = 1
julia> CTFlows.private_fun(x)
However, if the method is reexported by another package, then, there is no need of prefixing.
julia> module OptimalControl
import CTFlows: private_fun
export private_fun
end
julia> using OptimalControl
julia> x = 1
julia> private_fun(x)
Documentation
CTFlows.Control
— TypeAlias for control input variables (scalar or vector).
CTFlows.Costate
— TypeAlias for the costate (adjoint) variable (scalar or vector).
CTFlows.DCostate
— TypeAlias for derivatives of the costate (scalar or vector).
CTFlows.DState
— TypeAlias for derivatives of the state (scalar or vector).
CTFlows.State
— TypeAlias for the system state (scalar or vector).
CTFlows.Variable
— TypeAlias for generic variables (scalar or vector).
CTFlows.ctVector
— TypeScalar or vector type used in continuous-time models (scalar or vector-valued).
CTFlows.AbstractHamiltonian
— Typeabstract type AbstractHamiltonian{TD<:CTFlows.TimeDependence, VD<:CTFlows.VariableDependence}
CTFlows.AbstractVectorField
— Typeabstract type AbstractVectorField{TD<:CTFlows.TimeDependence, VD<:CTFlows.VariableDependence}
CTFlows.Autonomous
— Typeabstract type Autonomous <: CTFlows.TimeDependence
Indicates the function is autonomous: it does not explicitly depend on time t
.
For example, dynamics of the form f(x, u, p)
.
CTFlows.ControlLaw
— Typestruct ControlLaw{TF<:Function, TD<:CTFlows.TimeDependence, VD<:CTFlows.VariableDependence}
Represents a generic open-loop or closed-loop control law.
Example
julia> f(t, x) = -x * exp(-t)
julia> u = ControlLaw{typeof(f), NonAutonomous, Fixed}(f)
julia> u(1.0, [2.0])
CTFlows.ControlLaw
— MethodControlLaw(
f::Function,
TD::Type{<:CTFlows.TimeDependence},
VD::Type{<:CTFlows.VariableDependence}
) -> CTFlows.ControlLaw
Construct a ControlLaw
specifying time and variable dependence types.
CTFlows.ControlLaw
— MethodControlLaw(
f::Function;
autonomous,
variable
) -> CTFlows.ControlLaw
Construct a ControlLaw
wrapping the function f
.
Arguments
f::Function
: The function defining the control law.autonomous::Bool
: Whether the system is autonomous.variable::Bool
: Whether the function depends on additional variables.
Returns
- A
ControlLaw
instance parameterized accordingly.
Example
julia> cl = ControlLaw((x, p) -> -p)
CTFlows.Dynamics
— Typestruct Dynamics{TF<:Function, TD<:CTFlows.TimeDependence, VD<:CTFlows.VariableDependence}
Represents the system dynamics dx/dt = f(...)
.
Fields
f
: a callable of the form:f(x, u)
f(t, x, u)
f(x, u, v)
f(t, x, u, v)
Example
julia> f(x, u) = x + u
julia> dyn = Dynamics{typeof(f), Autonomous, Fixed}(f)
julia> dyn([1.0], [2.0])
CTFlows.Dynamics
— MethodDynamics(
f::Function,
TD::Type{<:CTFlows.TimeDependence},
VD::Type{<:CTFlows.VariableDependence}
) -> CTFlows.Dynamics
Create a Dynamics
object with explicit time and variable dependence.
Arguments
f::Function
: The dynamics function.TD
: Type indicating time dependence.VD
: Type indicating variable dependence.
Returns
- A
Dynamics{typeof(f),TD,VD}
object.
CTFlows.Dynamics
— MethodDynamics(
f::Function;
autonomous,
variable
) -> CTFlows.Dynamics
Create a Dynamics
object representing system dynamics.
Arguments
f::Function
: The dynamics function.autonomous::Bool
(optional): Whether the dynamics are autonomous (time-independent). Defaults to__autonomous()
.variable::Bool
(optional): Whether the dynamics depend on variables (non-fixed). Defaults to__variable()
.
Returns
- A
Dynamics{typeof(f),TD,VD}
object.
Details
The Dynamics
object can be called with various signatures depending on time and variable dependence.
Examples
julia> f(x, u) = [x[2], -x[1] + u[1]]
julia> dyn = Dynamics(f, autonomous=true, variable=false)
julia> dyn([1.0, 0.0], [0.0]) # returns [0.0, -1.0]
CTFlows.FeedbackControl
— Typestruct FeedbackControl{TF<:Function, TD<:CTFlows.TimeDependence, VD<:CTFlows.VariableDependence}
Represents a feedback control law: u = f(x)
or u = f(t, x)
.
Example
julia> f(x) = -x
julia> u = FeedbackControl{typeof(f), Autonomous, Fixed}(f)
julia> u([1.0, -1.0])
CTFlows.FeedbackControl
— MethodFeedbackControl(
f::Function,
TD::Type{<:CTFlows.TimeDependence},
VD::Type{<:CTFlows.VariableDependence}
) -> CTFlows.FeedbackControl
Construct a FeedbackControl
specifying time and variable dependence types.
CTFlows.FeedbackControl
— MethodFeedbackControl(
f::Function;
autonomous,
variable
) -> CTFlows.FeedbackControl
Construct a FeedbackControl
wrapping the function f
.
Arguments
f::Function
: The function defining the feedback control.autonomous::Bool
: Whether the system is autonomous.variable::Bool
: Whether the function depends on additional variables.
Returns
- A
FeedbackControl
instance parameterized accordingly.
Example
julia> fb = FeedbackControl(x -> -x)
CTFlows.Fixed
— Typeabstract type Fixed <: CTFlows.VariableDependence
Indicates the function has fixed standard arguments only.
For example, functions of the form f(t, x, p)
without any extra variable argument.
CTFlows.Hamiltonian
— Typestruct Hamiltonian{TF<:Function, TD<:CTFlows.TimeDependence, VD<:CTFlows.VariableDependence} <: CTFlows.AbstractHamiltonian{TD<:CTFlows.TimeDependence, VD<:CTFlows.VariableDependence}
Encodes the Hamiltonian function H = ⟨p, f⟩ + L
in optimal control.
Fields
f
: a callable of the form:f(x, p)
f(t, x, p)
f(x, p, v)
f(t, x, p, v)
Type Parameters
TD
:Autonomous
orNonAutonomous
VD
:Fixed
orNonFixed
Example
julia> Hf(x, p) = dot(p, [x[2], -x[1]])
julia> H = Hamiltonian{typeof(Hf), Autonomous, Fixed}(Hf)
julia> H([1.0, 0.0], [1.0, 1.0])
CTFlows.Hamiltonian
— MethodHamiltonian(
f::Function,
TD::Type{<:CTFlows.TimeDependence},
VD::Type{<:CTFlows.VariableDependence}
) -> CTFlows.Hamiltonian
Construct a Hamiltonian function wrapper with explicit time and variable dependence types.
CTFlows.Hamiltonian
— MethodHamiltonian(
f::Function;
autonomous,
variable
) -> CTFlows.Hamiltonian
Construct a Hamiltonian function wrapper.
f
: a function representing the Hamiltonian.autonomous
: whetherf
is autonomous (default via__autonomous()
).variable
: whetherf
depends on an extra variable argument (default via__variable()
).
Returns a Hamiltonian{TF, TD, VD}
callable struct.
CTFlows.HamiltonianLift
— Typestruct HamiltonianLift{TV<:CTFlows.VectorField, TD<:CTFlows.TimeDependence, VD<:CTFlows.VariableDependence} <: CTFlows.AbstractHamiltonian{TD<:CTFlows.TimeDependence, VD<:CTFlows.VariableDependence}
Lifts a vector field X
into a Hamiltonian function using the canonical symplectic structure.
This is useful to convert a vector field into a Hamiltonian via the identity: H(x, p) = ⟨p, X(x)⟩
.
Constructor
Use HamiltonianLift(X::VectorField)
where X
is a VectorField{...}
.
Example
f(x) = [x[2], -x[1]]
julia> X = VectorField{typeof(f), Autonomous, Fixed}(f)
julia> H = HamiltonianLift(X)
julia> H([1.0, 0.0], [0.5, 0.5])
CTFlows.HamiltonianLift
— MethodHamiltonianLift(
f::Function,
TD::Type{<:CTFlows.TimeDependence},
VD::Type{<:CTFlows.VariableDependence}
) -> CTFlows.HamiltonianLift{CTFlows.VectorField{TF, TD, VD}} where {TF<:Function, TD<:CTFlows.TimeDependence, VD<:CTFlows.VariableDependence}
Construct a HamiltonianLift with explicit time and variable dependence types.
CTFlows.HamiltonianLift
— MethodHamiltonianLift(
f::Function;
autonomous,
variable
) -> CTFlows.HamiltonianLift{CTFlows.VectorField{TF, TD, VD}} where {TF<:Function, TD<:CTFlows.TimeDependence, VD<:CTFlows.VariableDependence}
Construct a HamiltonianLift from a vector field function.
f
: function defining the vector field.autonomous
: whetherf
is autonomous.variable
: whetherf
depends on an extra variable argument.
Returns a HamiltonianLift
wrapping the vector field.
CTFlows.HamiltonianVectorField
— Typestruct HamiltonianVectorField{TF<:Function, TD<:CTFlows.TimeDependence, VD<:CTFlows.VariableDependence} <: CTFlows.AbstractVectorField{TD<:CTFlows.TimeDependence, VD<:CTFlows.VariableDependence}
Represents the Hamiltonian vector field associated to a Hamiltonian function, typically defined as (∂H/∂p, -∂H/∂x)
.
Fields
f
: a callable implementing the Hamiltonian vector field.
Example
julia> f(x, p) = [p[2], -p[1], -x[1], -x[2]]
julia> XH = HamiltonianVectorField{typeof(f), Autonomous, Fixed}(f)
julia> XH([1.0, 0.0], [0.5, 0.5])
CTFlows.HamiltonianVectorField
— MethodHamiltonianVectorField(
f::Function,
TD::Type{<:CTFlows.TimeDependence},
VD::Type{<:CTFlows.VariableDependence}
) -> CTFlows.HamiltonianVectorField
Construct a Hamiltonian vector field with explicit time and variable dependence.
CTFlows.HamiltonianVectorField
— MethodHamiltonianVectorField(
f::Function;
autonomous,
variable
) -> CTFlows.HamiltonianVectorField
Construct a Hamiltonian vector field from a function f
.
autonomous
: whetherf
is autonomous.variable
: whetherf
depends on an extra variable argument.
Returns a HamiltonianVectorField{TF, TD, VD}
callable struct.
CTFlows.Lagrange
— Typestruct Lagrange{TF<:Function, TD<:CTFlows.TimeDependence, VD<:CTFlows.VariableDependence}
Encodes the integrand L(t, x, u, ...)
of the cost functional in Bolza optimal control problems.
Fields
f
: a callable such as:f(x, u)
f(t, x, u)
f(x, u, v)
f(t, x, u, v)
Example
julia> L(x, u) = dot(x, x) + dot(u, u)
julia> lag = Lagrange{typeof(L), Autonomous, Fixed}(L)
julia> lag([1.0, 2.0], [0.5, 0.5])
CTFlows.Lagrange
— MethodLagrange(
f::Function,
TD::Type{<:CTFlows.TimeDependence},
VD::Type{<:CTFlows.VariableDependence}
) -> CTFlows.Lagrange
Create a Lagrange
object with explicit time and variable dependence.
Arguments
f::Function
: The Lagrangian function.TD
: Type indicating time dependence.VD
: Type indicating variable dependence.
Returns
- A
Lagrange{typeof(f),TD,VD}
object.
CTFlows.Lagrange
— MethodLagrange(
f::Function;
autonomous,
variable
) -> CTFlows.Lagrange
Create a Lagrange
object representing a Lagrangian cost function.
Arguments
f::Function
: The Lagrangian function.autonomous::Bool
(optional): Whetherf
is autonomous (time-independent). Defaults to__autonomous()
.variable::Bool
(optional): Whetherf
depends on variables (non-fixed). Defaults to__variable()
.
Returns
- A
Lagrange{typeof(f),TD,VD}
object.
Details
The Lagrange
object can be called with different argument signatures depending on the time and variable dependence.
Examples
julia> f(x, u) = sum(abs2, x) + sum(abs2, u)
julia> lag = Lagrange(f, autonomous=true, variable=false)
julia> lag([1.0, 2.0], [0.5, 0.5]) # returns 5.25
CTFlows.Mayer
— Typestruct Mayer{TF<:Function, VD<:CTFlows.VariableDependence}
Encodes the Mayer cost function in optimal control problems.
This terminal cost term is usually of the form φ(x(tf))
or φ(t, x(tf), v)
, depending on whether it's autonomous and/or variable-dependent.
Fields
f
: a callable of the form:f(x)
f(x, v)
f(t, x)
f(t, x, v)
depending on time and variable dependency.
Example
julia> φ(x) = norm(x)^2
julia> m = Mayer{typeof(φ), Fixed}(φ)
julia> m([1.0, 2.0])
CTFlows.Mayer
— MethodMayer(
f::Function,
VD::Type{<:CTFlows.VariableDependence}
) -> CTFlows.Mayer
Construct a Mayer cost functional wrapper with explicit variable dependence type VD
.
CTFlows.Mayer
— MethodMayer(f::Function; variable) -> CTFlows.Mayer
Construct a Mayer cost functional wrapper.
f
: a function representing the Mayer cost.variable
: whether the function depends on an extra variable argument (default via__variable()
).
Returns a Mayer{TF, VD}
callable struct where:
TF
is the function typeVD
is eitherFixed
orNonFixed
depending onvariable
.
CTFlows.MixedConstraint
— Typestruct MixedConstraint{TF<:Function, TD<:CTFlows.TimeDependence, VD<:CTFlows.VariableDependence}
Encodes a constraint on both state and control: g(x, u) = 0
or g(t, x, u) = 0
.
Example
julia> g(x, u) = x[1] + u[1] - 1
julia> mc = MixedConstraint{typeof(g), Autonomous, Fixed}(g)
julia> mc([0.3], [0.7])
CTFlows.MixedConstraint
— MethodMixedConstraint(
f::Function,
TD::Type{<:CTFlows.TimeDependence},
VD::Type{<:CTFlows.VariableDependence}
) -> CTFlows.MixedConstraint
Construct a MixedConstraint
specifying the time and variable dependence types explicitly.
CTFlows.MixedConstraint
— MethodMixedConstraint(
f::Function;
autonomous,
variable
) -> CTFlows.MixedConstraint
Construct a MixedConstraint
object wrapping the function f
.
Arguments
f::Function
: The function defining the mixed constraint.autonomous::Bool
: Whether the system is autonomous.variable::Bool
: Whether the function depends on additional variables.
Returns
- A
MixedConstraint
instance parameterized by the type off
and time/variable dependence.
Example
julia> mc = MixedConstraint((x, u) -> x + u)
CTFlows.Multiplier
— Typestruct Multiplier{TF<:Function, TD<:CTFlows.TimeDependence, VD<:CTFlows.VariableDependence}
Encodes a Lagrange multiplier associated with a constraint.
Example
julia> λ(t) = [sin(t), cos(t)]
julia> μ = Multiplier{typeof(λ), NonAutonomous, Fixed}(λ)
julia> μ(π / 2)
CTFlows.Multiplier
— MethodMultiplier(
f::Function,
TD::Type{<:CTFlows.TimeDependence},
VD::Type{<:CTFlows.VariableDependence}
) -> CTFlows.Multiplier
Construct a Multiplier
specifying time and variable dependence types.
CTFlows.Multiplier
— MethodMultiplier(
f::Function;
autonomous,
variable
) -> CTFlows.Multiplier
Construct a Multiplier
wrapping the function f
.
Arguments
f::Function
: The function defining the multiplier.autonomous::Bool
: Whether the system is autonomous.variable::Bool
: Whether the function depends on additional variables.
Returns
- A
Multiplier
instance parameterized accordingly.
Example
julia> m = Multiplier((x, p) -> p .* x)
CTFlows.NonAutonomous
— Typeabstract type NonAutonomous <: CTFlows.TimeDependence
Indicates the function is non-autonomous: it explicitly depends on time t
.
For example, dynamics of the form f(t, x, u, p)
.
CTFlows.NonFixed
— Typeabstract type NonFixed <: CTFlows.VariableDependence
Indicates the function has an additional variable argument v
.
For example, functions of the form f(t, x, p, v)
where v
is a multiplier or auxiliary parameter.
CTFlows.StateConstraint
— Typestruct StateConstraint{TF<:Function, TD<:CTFlows.TimeDependence, VD<:CTFlows.VariableDependence}
Encodes a pure state constraint g(x) = 0
or g(t, x) = 0
.
Fields
f
: a callable depending on time or not, with or without variable dependency.
Example
julia> g(x) = x[1]^2 + x[2]^2 - 1
julia> c = StateConstraint{typeof(g), Autonomous, Fixed}(g)
julia> c([1.0, 0.0])
CTFlows.StateConstraint
— MethodStateConstraint(
f::Function,
TD::Type{<:CTFlows.TimeDependence},
VD::Type{<:CTFlows.VariableDependence}
) -> CTFlows.StateConstraint
Construct a StateConstraint
specifying the time and variable dependence types explicitly.
Arguments
f::Function
: The function defining the state constraint.TD::Type
: The time dependence type (Autonomous
orNonAutonomous
).VD::Type
: The variable dependence type (Fixed
orNonFixed
).
Returns
- A
StateConstraint
instance parameterized accordingly.
CTFlows.StateConstraint
— MethodStateConstraint(
f::Function;
autonomous,
variable
) -> CTFlows.StateConstraint
Construct a StateConstraint
object wrapping the function f
.
Arguments
f::Function
: The function defining the state constraint.autonomous::Bool
: Whether the system is autonomous (default uses__autonomous()
).variable::Bool
: Whether the function depends on additional variables (default uses__variable()
).
Returns
- A
StateConstraint
instance parameterized by the type off
and time/variable dependence.
Example
julia> sc = StateConstraint(x -> x .- 1) # Autonomous, fixed variable by default
CTFlows.Time
— TypeAlias for scalar time variables.
CTFlows.TimeDependence
— Typeabstract type TimeDependence
Base abstract type representing the dependence of a function on time.
Used as a trait to distinguish autonomous vs. non-autonomous functions.
CTFlows.Times
— TypeAlias for a vector of time points.
CTFlows.VariableDependence
— Typeabstract type VariableDependence
Base abstract type representing whether a function depends on an additional variable argument.
Used to distinguish fixed-argument functions from those with auxiliary parameters.
CTFlows.VectorField
— Typestruct VectorField{TF<:Function, TD<:CTFlows.TimeDependence, VD<:CTFlows.VariableDependence} <: CTFlows.AbstractVectorField{TD<:CTFlows.TimeDependence, VD<:CTFlows.VariableDependence}
Represents a dynamical system dx/dt = f(...)
as a vector field.
Fields
f
: a callable of the form:f(x)
f(t, x)
f(x, v)
f(t, x, v)
Example
f(x) = [x[2], -x[1]]
vf = VectorField{typeof(f), Autonomous, Fixed}(f)
vf([1.0, 0.0])
CTFlows.VectorField
— MethodVectorField(
f::Function,
TD::Type{<:CTFlows.TimeDependence},
VD::Type{<:CTFlows.VariableDependence}
) -> CTFlows.VectorField
Create a VectorField
object with explicit time and variable dependence types.
Arguments
f::Function
: The vector field function.TD
: Type indicating time dependence (Autonomous
orNonAutonomous
).VD
: Type indicating variable dependence (Fixed
orNonFixed
).
Returns
- A
VectorField{typeof(f),TD,VD}
object.
CTFlows.VectorField
— MethodVectorField(
f::Function;
autonomous,
variable
) -> CTFlows.VectorField
Create a VectorField
object wrapping the function f
.
Arguments
f::Function
: The vector field function.autonomous::Bool
(optional): Iftrue
, the vector field is autonomous (time-independent). Defaults to__autonomous()
.variable::Bool
(optional): Iftrue
, the vector field depends on control or decision variables (non-fixed). Defaults to__variable()
.
Returns
- A
VectorField{typeof(f),TD,VD}
object whereTD
encodes time dependence andVD
encodes variable dependence.
Details
The VectorField
object can be called with different argument signatures depending on the time and variable dependence.
Examples
julia> f(x) = [-x[2], x[1]]
julia> vf = VectorField(f, autonomous=true, variable=false)
julia> vf([1.0, 0.0]) # returns [-0.0, 1.0]
CTFlows.ctNumber
— TypeBase scalar type used in continuous-time models, e.g. Float64 or Dual numbers.