Types

Index

Warning

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

Scalar or vector type used in continuous-time models (scalar or vector-valued).

source
CTFlows.AutonomousType
abstract 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).

source
CTFlows.ControlLawType
struct 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])
source
CTFlows.ControlLawMethod
ControlLaw(
    f::Function,
    TD::Type{<:CTFlows.TimeDependence},
    VD::Type{<:CTFlows.VariableDependence}
) -> CTFlows.ControlLaw

Construct a ControlLaw specifying time and variable dependence types.

source
CTFlows.ControlLawMethod
ControlLaw(
    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)
source
CTFlows.DynamicsType
struct 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])
source
CTFlows.DynamicsMethod
Dynamics(
    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.
source
CTFlows.DynamicsMethod
Dynamics(
    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]
source
CTFlows.FeedbackControlType
struct 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])
source
CTFlows.FeedbackControlMethod
FeedbackControl(
    f::Function,
    TD::Type{<:CTFlows.TimeDependence},
    VD::Type{<:CTFlows.VariableDependence}
) -> CTFlows.FeedbackControl

Construct a FeedbackControl specifying time and variable dependence types.

source
CTFlows.FeedbackControlMethod
FeedbackControl(
    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)
source
CTFlows.FixedType
abstract 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.

source
CTFlows.HamiltonianType
struct 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 or NonAutonomous
  • VD: Fixed or NonFixed

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])
source
CTFlows.HamiltonianMethod
Hamiltonian(
    f::Function,
    TD::Type{<:CTFlows.TimeDependence},
    VD::Type{<:CTFlows.VariableDependence}
) -> CTFlows.Hamiltonian

Construct a Hamiltonian function wrapper with explicit time and variable dependence types.

source
CTFlows.HamiltonianMethod
Hamiltonian(
    f::Function;
    autonomous,
    variable
) -> CTFlows.Hamiltonian

Construct a Hamiltonian function wrapper.

  • f: a function representing the Hamiltonian.
  • autonomous: whether f is autonomous (default via __autonomous()).
  • variable: whether f depends on an extra variable argument (default via __variable()).

Returns a Hamiltonian{TF, TD, VD} callable struct.

source
CTFlows.HamiltonianLiftType
struct 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])
source
CTFlows.HamiltonianLiftMethod
HamiltonianLift(
    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.

source
CTFlows.HamiltonianLiftMethod
HamiltonianLift(
    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: whether f is autonomous.
  • variable: whether f depends on an extra variable argument.

Returns a HamiltonianLift wrapping the vector field.

source
CTFlows.HamiltonianVectorFieldType
struct 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])
source
CTFlows.HamiltonianVectorFieldMethod
HamiltonianVectorField(
    f::Function,
    TD::Type{<:CTFlows.TimeDependence},
    VD::Type{<:CTFlows.VariableDependence}
) -> CTFlows.HamiltonianVectorField

Construct a Hamiltonian vector field with explicit time and variable dependence.

source
CTFlows.HamiltonianVectorFieldMethod
HamiltonianVectorField(
    f::Function;
    autonomous,
    variable
) -> CTFlows.HamiltonianVectorField

Construct a Hamiltonian vector field from a function f.

  • autonomous: whether f is autonomous.
  • variable: whether f depends on an extra variable argument.

Returns a HamiltonianVectorField{TF, TD, VD} callable struct.

source
CTFlows.LagrangeType
struct 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])
source
CTFlows.LagrangeMethod
Lagrange(
    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.
source
CTFlows.LagrangeMethod
Lagrange(
    f::Function;
    autonomous,
    variable
) -> CTFlows.Lagrange

Create a Lagrange object representing a Lagrangian cost function.

Arguments

  • f::Function: The Lagrangian function.
  • autonomous::Bool (optional): Whether f is autonomous (time-independent). Defaults to __autonomous().
  • variable::Bool (optional): Whether f 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
source
CTFlows.MayerType
struct 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])
source
CTFlows.MayerMethod
Mayer(
    f::Function,
    VD::Type{<:CTFlows.VariableDependence}
) -> CTFlows.Mayer

Construct a Mayer cost functional wrapper with explicit variable dependence type VD.

source
CTFlows.MayerMethod
Mayer(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 type
  • VD is either Fixed or NonFixed depending on variable.
source
CTFlows.MixedConstraintType
struct 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])
source
CTFlows.MixedConstraintMethod
MixedConstraint(
    f::Function,
    TD::Type{<:CTFlows.TimeDependence},
    VD::Type{<:CTFlows.VariableDependence}
) -> CTFlows.MixedConstraint

Construct a MixedConstraint specifying the time and variable dependence types explicitly.

source
CTFlows.MixedConstraintMethod
MixedConstraint(
    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 of f and time/variable dependence.

Example

julia> mc = MixedConstraint((x, u) -> x + u)
source
CTFlows.MultiplierType
struct 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)
source
CTFlows.MultiplierMethod
Multiplier(
    f::Function,
    TD::Type{<:CTFlows.TimeDependence},
    VD::Type{<:CTFlows.VariableDependence}
) -> CTFlows.Multiplier

Construct a Multiplier specifying time and variable dependence types.

source
CTFlows.MultiplierMethod
Multiplier(
    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)
source
CTFlows.NonAutonomousType
abstract 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).

source
CTFlows.NonFixedType
abstract 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.

source
CTFlows.StateConstraintType
struct 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])
source
CTFlows.StateConstraintMethod
StateConstraint(
    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 or NonAutonomous).
  • VD::Type: The variable dependence type (Fixed or NonFixed).

Returns

  • A StateConstraint instance parameterized accordingly.
source
CTFlows.StateConstraintMethod
StateConstraint(
    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 of f and time/variable dependence.

Example

julia> sc = StateConstraint(x -> x .- 1)  # Autonomous, fixed variable by default
source
CTFlows.TimeDependenceType
abstract type TimeDependence

Base abstract type representing the dependence of a function on time.

Used as a trait to distinguish autonomous vs. non-autonomous functions.

source
CTFlows.VariableDependenceType
abstract 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.

source
CTFlows.VectorFieldType
struct 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])
source
CTFlows.VectorFieldMethod
VectorField(
    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 or NonAutonomous).
  • VD: Type indicating variable dependence (Fixed or NonFixed).

Returns

  • A VectorField{typeof(f),TD,VD} object.
source
CTFlows.VectorFieldMethod
VectorField(
    f::Function;
    autonomous,
    variable
) -> CTFlows.VectorField

Create a VectorField object wrapping the function f.

Arguments

  • f::Function: The vector field function.
  • autonomous::Bool (optional): If true, the vector field is autonomous (time-independent). Defaults to __autonomous().
  • variable::Bool (optional): If true, the vector field depends on control or decision variables (non-fixed). Defaults to __variable().

Returns

  • A VectorField{typeof(f),TD,VD} object where TD encodes time dependence and VD 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]
source