API

Index

Documentation

CTBase.CTBaseModule

CTBase 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:

source
CTBase.TimesDiscType

Type 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}

See also: Time, Times.

source
CTBase.AmbiguousDescriptionType
struct AmbiguousDescription <: CTException

Exception thrown when the description is ambiguous / incorrect.

Fields

  • var::Tuple{Vararg{Symbol}}
source
CTBase.BoundaryConstraintType
struct 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)
Warning

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]
source
CTBase.BoundaryConstraintMethod
BoundaryConstraint(
    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)
source
CTBase.BoundaryConstraintMethod
BoundaryConstraint(
    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)
source
CTBase.BoundaryConstraintMethod

Return 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]
source
CTBase.ControlConstraintType
struct 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 and variable, respectively true and false by default
  • DataType, Autonomous/NonAutonomous and NonFixed/Fixed, respectively Autonomous and Fixed 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)
Warning

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]
source
CTBase.ControlConstraintMethod
ControlConstraint(
    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)
source
CTBase.ControlConstraintMethod
ControlConstraint(
    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)
source
CTBase.ControlConstraintMethod

Return 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]
source
CTBase.ControlLawType
struct 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 and variable, respectively true and false by default
  • DataType, Autonomous/NonAutonomous and NonFixed/Fixed, respectively Autonomous and Fixed 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)
Warning

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
source
CTBase.ControlLawMethod
ControlLaw(
    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)
source
CTBase.ControlLawMethod
ControlLaw(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)
source
CTBase.ControlLawMethod

Return 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
source
CTBase.DescriptionType

A 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)
source
CTBase.DimensionType

Type alias for a dimension. This is used to define the dimension of the state space, the costate space, the control space, etc.

julia> const Dimension = Integer
source
CTBase.DynamicsType
struct 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 and variable, respectively true and false by default
  • DataType, Autonomous/NonAutonomous and NonFixed/Fixed, respectively Autonomous and Fixed 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)
Warning

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]
source
CTBase.DynamicsMethod
Dynamics(
    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)
source
CTBase.DynamicsMethod
Dynamics(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)
source
CTBase.DynamicsMethod

Return 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]
source
CTBase.ExtensionErrorType
mutable 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}}
source
CTBase.FeedbackControlType
struct 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 and variable, respectively true and false by default
  • DataType, Autonomous/NonAutonomous and NonFixed/Fixed, respectively Autonomous and Fixed 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)
Warning

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
source
CTBase.FeedbackControlMethod
FeedbackControl(
    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)
source
CTBase.FeedbackControlMethod
FeedbackControl(
    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)
source
CTBase.FeedbackControlMethod

Return 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
source
CTBase.HamiltonianType
struct 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 and variable, respectively true and false by default
  • DataType, Autonomous/NonAutonomous and NonFixed/Fixed, respectively Autonomous and Fixed 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)
Warning

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
source
CTBase.HamiltonianMethod
Hamiltonian(
    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)
source
CTBase.HamiltonianMethod
Hamiltonian(
    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)
source
CTBase.HamiltonianMethod

Return 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
source
CTBase.HamiltonianLiftType
struct 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))
Warning

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
source
CTBase.HamiltonianLiftMethod
HamiltonianLift(
    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)
source
CTBase.HamiltonianLiftMethod
HamiltonianLift(
    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)
source
CTBase.HamiltonianLiftMethod

Return 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
source
CTBase.HamiltonianVectorFieldType
struct 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 and variable, respectively true and false by default
  • DataType, Autonomous/NonAutonomous and NonFixed/Fixed, respectively Autonomous and Fixed 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)
Warning

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]
source
CTBase.HamiltonianVectorFieldMethod
HamiltonianVectorField(
    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)
source
CTBase.HamiltonianVectorFieldMethod
HamiltonianVectorField(
    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)
source
CTBase.HamiltonianVectorFieldMethod

Return 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]
source
CTBase.LagrangeType
struct 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 and variable, respectively true and false by default
  • DataType, Autonomous/NonAutonomous and NonFixed/Fixed, respectively Autonomous and Fixed 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)
Warning

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
source
CTBase.LagrangeMethod
Lagrange(
    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)
source
CTBase.LagrangeMethod
Lagrange(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)
source
CTBase.LagrangeMethod

Return 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
source
CTBase.MayerType
struct 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)
Warning

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
source
CTBase.MayerMethod
Mayer(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)
source
CTBase.MayerMethod
Mayer(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)
source
CTBase.MayerMethod

Return 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
source
CTBase.MixedConstraintType
struct 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 and variable, respectively true and false by default
  • DataType, Autonomous/NonAutonomous and NonFixed/Fixed, respectively Autonomous and Fixed 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)
Warning

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]
source
CTBase.MixedConstraintMethod
MixedConstraint(
    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)
source
CTBase.MixedConstraintMethod
MixedConstraint(
    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)
source
CTBase.MixedConstraintMethod

Return 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]
source
CTBase.MultiplierType
struct 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 and variable, respectively true and false by default
  • DataType, Autonomous/NonAutonomous and NonFixed/Fixed, respectively Autonomous and Fixed 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)
Warning

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
source
CTBase.MultiplierMethod
Multiplier(
    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)
source
CTBase.MultiplierMethod
Multiplier(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)
source
CTBase.MultiplierMethod

Return 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
source
CTBase.NotImplementedType
struct NotImplemented <: CTException

Exception thrown when a method is not implemented.

Fields

  • var::String
source
CTBase.OptimalControlInitType

Initial 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 initialization
  • OptimalControlInit(state, control, variable, time): constant vector, function handles and / or matrices / vectors interpolated along given time grid
  • OptimalControlInit(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)
source
CTBase.OptimalControlModelType
mutable struct OptimalControlModel{time_dependence<:TimeDependence, variable_dependence<:VariableDependence} <: CTBase.AbstractOptimalControlModel

Fields

  • model_expression::Union{Nothing, Expr}: Default: nothing

  • initial_time::Union{Nothing, Index, Real}: Default: nothing

  • initial_time_name::Union{Nothing, String}: Default: nothing

  • final_time::Union{Nothing, Index, Real}: Default: nothing

  • final_time_name::Union{Nothing, String}: Default: nothing

  • time_name::Union{Nothing, String}: Default: nothing

  • control_dimension::Union{Nothing, Integer}: Default: nothing

  • control_components_names::Union{Nothing, Vector{String}}: Default: nothing

  • control_name::Union{Nothing, String}: Default: nothing

  • state_dimension::Union{Nothing, Integer}: Default: nothing

  • state_components_names::Union{Nothing, Vector{String}}: Default: nothing

  • state_name::Union{Nothing, String}: Default: nothing

  • variable_dimension::Union{Nothing, Integer}: Default: nothing

  • variable_components_names::Union{Nothing, Vector{String}}: Default: nothing

  • variable_name::Union{Nothing, String}: Default: nothing

  • lagrange::Union{Nothing, Lagrange, Lagrange!}: Default: nothing

  • mayer::Union{Nothing, Mayer, Mayer!}: Default: nothing

  • criterion::Union{Nothing, Symbol}: Default: nothing

  • dynamics::Union{Nothing, Dynamics, Dynamics!}: Default: nothing

  • constraints::Dict{Symbol, Tuple}: Default: Dict{Symbol, Tuple{Vararg{Any}}}()

  • dim_control_constraints::Union{Nothing, Integer}: Default: nothing

  • dim_state_constraints::Union{Nothing, Integer}: Default: nothing

  • dim_mixed_constraints::Union{Nothing, Integer}: Default: nothing

  • dim_boundary_constraints::Union{Nothing, Integer}: Default: nothing

  • dim_variable_constraints::Union{Nothing, Integer}: Default: nothing

  • dim_control_range::Union{Nothing, Integer}: Default: nothing

  • dim_state_range::Union{Nothing, Integer}: Default: nothing

  • dim_variable_range::Union{Nothing, Integer}: Default: nothing

  • in_place::Union{Nothing, Bool}: Default: nothing

source
CTBase.OptimalControlSolutionType
mutable struct OptimalControlSolution <: CTBase.AbstractOptimalControlSolution

Type of an optimal control solution.

Fields

  • time_grid::Union{Nothing, StepRangeLen, AbstractVector{<:Real}}: Default: nothing

  • time_name::Union{Nothing, String}: Default: nothing

  • initial_time_name::Union{Nothing, String}: Default: nothing

  • final_time_name::Union{Nothing, String}: Default: nothing

  • control_dimension::Union{Nothing, Integer}: Default: nothing

  • control_components_names::Union{Nothing, Vector{String}}: Default: nothing

  • control_name::Union{Nothing, String}: Default: nothing

  • control::Union{Nothing, Function}: Default: nothing

  • state_dimension::Union{Nothing, Integer}: Default: nothing

  • state_components_names::Union{Nothing, Vector{String}}: Default: nothing

  • state_name::Union{Nothing, String}: Default: nothing

  • state::Union{Nothing, Function}: Default: nothing

  • variable_dimension::Union{Nothing, Integer}: Default: nothing

  • variable_components_names::Union{Nothing, Vector{String}}: Default: nothing

  • variable_name::Union{Nothing, String}: Default: nothing

  • variable::Union{Nothing, Real, AbstractVector{<:Real}}: Default: nothing

  • costate::Union{Nothing, Function}: Default: nothing

  • objective::Union{Nothing, Real}: Default: nothing

  • iterations::Union{Nothing, Int64}: Default: nothing

  • stopping::Union{Nothing, Symbol}: Default: nothing

  • message::Union{Nothing, String}: Default: nothing

  • success::Union{Nothing, Bool}: Default: nothing

  • infos::Dict{Symbol, Any}: Default: Dict{Symbol, Any}()

  • boundary_constraints::Union{Nothing, Real, AbstractVector{<:Real}}: Default: nothing

  • mult_boundary_constraints::Union{Nothing, Real, AbstractVector{<:Real}}: Default: nothing

  • variable_constraints::Union{Nothing, Real, AbstractVector{<:Real}}: Default: nothing

  • mult_variable_constraints::Union{Nothing, Real, AbstractVector{<:Real}}: Default: nothing

  • mult_variable_box_lower::Union{Nothing, Real, AbstractVector{<:Real}}: Default: nothing

  • mult_variable_box_upper::Union{Nothing, Real, AbstractVector{<:Real}}: Default: nothing

  • control_constraints::Union{Nothing, Function}: Default: nothing

  • mult_control_constraints::Union{Nothing, Function}: Default: nothing

  • state_constraints::Union{Nothing, Function}: Default: nothing

  • mult_state_constraints::Union{Nothing, Function}: Default: nothing

  • mixed_constraints::Union{Nothing, Function}: Default: nothing

  • mult_mixed_constraints::Union{Nothing, Function}: Default: nothing

  • mult_state_box_lower::Union{Nothing, Function}: Default: nothing

  • mult_state_box_upper::Union{Nothing, Function}: Default: nothing

  • mult_control_box_lower::Union{Nothing, Function}: Default: nothing

  • mult_control_box_upper::Union{Nothing, Function}: Default: nothing

source
CTBase.OptimalControlSolutionMethod
OptimalControlSolution(
    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.

source
CTBase.OptimalControlSolutionMethod
OptimalControlSolution(
    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.

source
CTBase.ParsingErrorType
struct ParsingError <: CTException

Exception thrown for syntax error during abstract parsing.

Fields

  • var::String
source
CTBase.StateConstraintType
struct 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 and variable, respectively true and false by default
  • DataType, Autonomous/NonAutonomous and NonFixed/Fixed, respectively Autonomous and Fixed 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)
Warning

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]
source
CTBase.StateConstraintMethod
StateConstraint(
    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)
source
CTBase.StateConstraintMethod
StateConstraint(
    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)
source
CTBase.StateConstraintMethod

Return 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]
source
CTBase.UnauthorizedCallType
struct UnauthorizedCall <: CTException

Exception thrown when a call to a function is not authorized.

Fields

  • var::String
source
CTBase.VariableConstraintType
struct 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]])
Warning

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]
source
CTBase.VariableConstraintMethod

Return the value of the VariableConstraint function.

julia> V = VariableConstraint(v -> [v[1]^2, 2v[2]])
julia> V([1, -1])
[1, -2]
source
CTBase.VectorFieldType
struct 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 and variable, respectively true and false by default
  • DataType, Autonomous/NonAutonomous and NonFixed/Fixed, respectively Autonomous and Fixed 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)
Warning

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]
source
CTBase.VectorFieldMethod
VectorField(
    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)
source
CTBase.VectorFieldMethod
VectorField(
    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)
source
CTBase.VectorFieldMethod

Return 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]
source
CTBase.:⋅Method
⋅(
    X::Function,
    f::Function
) -> CTBase.var"#133#135"{VectorField{var"#s178", Autonomous, Fixed}, <:Function} where var"#s178"<: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
source
CTBase.:⋅Method
⋅(
    X::VectorField{<:Function, Autonomous},
    f::Function
) -> CTBase.var"#133#135"{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
source
CTBase.:⋅Method
⋅(
    X::VectorField{<:Function, NonAutonomous},
    f::Function
) -> CTBase.var"#137#139"{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
source
CTBase.LieMethod
Lie(
    X::Function,
    f::Function;
    autonomous,
    variable
) -> Function

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
source
CTBase.LieMethod
Lie(X::VectorField, f::Function) -> Function

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
source
CTBase.LieMethod
Lie(
    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]
source
CTBase.LieMethod
Lie(
    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]
source
CTBase.LiftMethod
Lift(X::Function; autonomous, variable) -> 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
source
CTBase.LiftMethod
Lift(
    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
source
CTBase.ModelMethod
Model(
    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: either Autonomous or NonAutonomous. Default is Autonomous. And either NonFixed or Fixed. Default is Fixed.

Examples

julia> ocp = Model()
julia> ocp = Model(NonAutonomous)
julia> ocp = Model(Autonomous, NonFixed)
Note
  • 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.
source
CTBase.ModelMethod
Model(
;
    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: either true or false. Default is true.
  • variable: either true or false. Default is false.

Examples

julia> ocp = Model()
julia> ocp = Model(autonomous=false)
julia> ocp = Model(autonomous=false, variable=true)
Note
  • 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.
source
CTBase.PoissonMethod
Poisson(
    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
source
CTBase.PoissonMethod
Poisson(
    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
source
CTBase.PoissonMethod
Poisson(
    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
source
CTBase.PoissonMethod
Poisson(
    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
source
CTBase.PoissonMethod
Poisson(
    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
source
CTBase.PoissonMethod
Poisson(
    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
source
CTBase.__OCPModelMethod
__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.

source
CTBase.addMethod
add(
    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,))
source
CTBase.addMethod
add(
    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,)
source
CTBase.boundary_constraints!Method
boundary_constraints!(
    sol::OptimalControlSolution,
    boundary_constraints::Union{Real, AbstractVector{<:Real}}
)

Set the boundary constraints.

source
CTBase.boundary_constraintsMethod
boundary_constraints(
    sol::OptimalControlSolution
) -> Union{Nothing, Real, AbstractVector{<:Real}}

Return the boundary constraints of the optimal control solution or nothing.

source
CTBase.constraint!Method
constraint!(
    ocp::OptimalControlModel{T<:TimeDependence, V<:VariableDependence},
    type::Symbol;
    rg,
    f,
    lb,
    ub,
    val,
    label
)

Add a constraint to an optimal control problem, denoted ocp.

Note
  • 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)
source
CTBase.constraintMethod
constraint(
    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
source
CTBase.constraint_typeMethod
constraint_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
source
CTBase.constraintsMethod
constraints(ocp::OptimalControlModel) -> Dict{Symbol, Tuple}

Return the constraints of the ocp or nothing.

source
CTBase.constraints_labelsMethod
constraints_labels(
    ocp::OptimalControlModel
) -> Base.KeySet{Symbol, Dict{Symbol, Tuple}}

Return the labels of the constraints as a Base.keys.

source
CTBase.control!Function
control!(ocp::OptimalControlModel, m::Integer)
control!(ocp::OptimalControlModel, m::Integer, name::String)
control!(
    ocp::OptimalControlModel,
    m::Integer,
    name::String,
    components_names::Vector{String}
)

Define the control dimension and possibly the names of each coordinate.

Note

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₂"]
source
CTBase.controlMethod
control(
    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
source
CTBase.control_components_namesMethod
control_components_names(
    ocp::OptimalControlModel
) -> Union{Nothing, Vector{String}}

Return the names of the components of the control of the optimal control problem or nothing.

source
CTBase.control_components_namesMethod
control_components_names(
    sol::OptimalControlSolution
) -> Union{Nothing, Vector{String}}

Return the names of the components of the control of the optimal control solution or nothing.

source
CTBase.control_constraintsMethod
control_constraints(
    sol::OptimalControlSolution
) -> Union{Nothing, Function}

Return the control constraints of the optimal control solution or nothing.

source
CTBase.control_dimensionMethod
control_dimension(
    ocp::OptimalControlModel
) -> Union{Nothing, Integer}

Return the dimention of the control of the optimal control problem or nothing.

source
CTBase.control_dimensionMethod
control_dimension(
    sol::OptimalControlSolution
) -> Union{Nothing, Integer}

Return the dimension of the control of the optimal control solution or nothing.

source
CTBase.control_discretizedMethod
control_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
source
CTBase.control_nameMethod
control_name(
    ocp::OptimalControlModel
) -> Union{Nothing, String}

Return the name of the control of the optimal control problem or nothing.

source
CTBase.control_nameMethod
control_name(
    sol::OptimalControlSolution
) -> Union{Nothing, String}

Return the name of the control of the optimal control solution or nothing.

source
CTBase.costate!Method
costate!(sol::OptimalControlSolution, costate::Function)

Set the costate.

source
CTBase.costateMethod
costate(
    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)
source
CTBase.costate_discretizedMethod
costate_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
source
CTBase.criterionMethod
criterion(
    ocp::OptimalControlModel
) -> Union{Nothing, Symbol}

Return the criterion (:min or :max) of the optimal control problem or nothing.

source
CTBase.ct_repl_update_modelMethod
ct_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.

source
CTBase.dim_boundary_constraintsMethod
dim_boundary_constraints(
    ocp::OptimalControlModel
) -> Union{Nothing, Integer}

Return the dimension of the boundary constraints (nothing if not knonw). Information is updated after nlp_constraints! is called.

source
CTBase.dim_control_constraintsMethod
dim_control_constraints(
    ocp::OptimalControlModel
) -> Union{Nothing, Integer}

Return the dimension of nonlinear control constraints (nothing if not knonw). Information is updated after nlp_constraints! is called.

source
CTBase.dim_control_rangeMethod
dim_control_range(
    ocp::OptimalControlModel
) -> Union{Nothing, Integer}

Return the dimension of range constraints on control (nothing if not knonw). Information is updated after nlp_constraints! is called.

source
CTBase.dim_mixed_constraintsMethod
dim_mixed_constraints(
    ocp::OptimalControlModel
) -> Union{Nothing, Integer}

Return the dimension of nonlinear mixed constraints (nothing if not knonw). Information is updated after nlp_constraints! is called.

source
CTBase.dim_path_constraintsMethod
dim_path_constraints(ocp::OptimalControlModel) -> Any

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.

source
CTBase.dim_state_constraintsMethod
dim_state_constraints(
    ocp::OptimalControlModel
) -> Union{Nothing, Integer}

Return the dimension of nonlinear state constraints (nothing if not knonw). Information is updated after nlp_constraints! is called.

source
CTBase.dim_state_rangeMethod
dim_state_range(
    ocp::OptimalControlModel
) -> Union{Nothing, Integer}

Return the dimension of range constraints on state (nothing if not knonw). Information is updated after nlp_constraints! is called.

source
CTBase.dim_variable_constraintsMethod
dim_variable_constraints(
    ocp::OptimalControlModel
) -> Union{Nothing, Integer}

Return the dimension of nonlinear variable constraints (nothing if not knonw). Information is updated after nlp_constraints! is called.

source
CTBase.dim_variable_rangeMethod
dim_variable_range(
    ocp::OptimalControlModel
) -> Union{Nothing, Integer}

Return the dimension of range constraints on variable (nothing if not knonw). Information is updated after nlp_constraints! is called.

source
CTBase.dynamics!Method
dynamics!(
    ocp::OptimalControlModel{T<:TimeDependence, V<:VariableDependence},
    f::Function
)

Set the dynamics.

Note

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)
source
CTBase.dynamicsMethod
dynamics(
    ocp::OptimalControlModel
) -> Union{Nothing, Dynamics, Dynamics!}

Return the dynamics of the optimal control problem or nothing.

source
CTBase.final_timeMethod
final_time(
    ocp::OptimalControlModel
) -> Union{Nothing, Index, Real}

Return the final time of the optimal control problem or nothing.

source
CTBase.final_time_nameMethod
final_time_name(
    ocp::OptimalControlModel
) -> Union{Nothing, String}

Return the name of the final time of the optimal control problem or nothing.

source
CTBase.final_time_nameMethod
final_time_name(
    sol::OptimalControlSolution
) -> Union{Nothing, String}

Return the name of final time of the optimal control solution or nothing.

source
CTBase.getFullDescriptionMethod
getFullDescription(
    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)
source
CTBase.has_free_final_timeMethod
has_free_final_time(ocp::OptimalControlModel) -> Bool

Return true if the model has been defined with free final time.

source
CTBase.has_lagrange_costMethod
has_lagrange_cost(ocp::OptimalControlModel) -> Bool

Return true if the model has been defined with lagrange cost.

source
CTBase.has_mayer_costMethod
has_mayer_cost(ocp::OptimalControlModel) -> Bool

Return true if the model has been defined with mayer cost.

source
CTBase.infos!Method
infos!(
    sol::OptimalControlSolution,
    infos::Dict{Symbol, Any}
)

Set the additional infos.

source
CTBase.infosMethod
infos(sol::OptimalControlSolution) -> Dict{Symbol, Any}

Return a dictionary of additional infos depending on the solver or nothing.

source
CTBase.initial_timeMethod
initial_time(
    ocp::OptimalControlModel
) -> Union{Nothing, Index, Real}

Return the initial time of the optimal control problem or nothing.

source
CTBase.initial_time_nameMethod
initial_time_name(
    ocp::OptimalControlModel
) -> Union{Nothing, String}

Return the name of the initial time of the optimal control problem or nothing.

source
CTBase.initial_time_nameMethod
initial_time_name(
    sol::OptimalControlSolution
) -> Union{Nothing, String}

Return the name of the initial time of the optimal control solution or nothing.

source
CTBase.is_autonomousMethod
is_autonomous(ocp::OptimalControlModel{Autonomous}) -> Bool

Return true if the model is autonomous.

source
CTBase.is_fixedMethod
is_fixed(
    ocp::OptimalControlModel{<:TimeDependence, Fixed}
) -> Bool

Return true if the model is fixed (= has no variable).

source
CTBase.is_in_placeMethod
is_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.

source
CTBase.is_maxMethod
is_max(ocp::OptimalControlModel) -> Bool

Return true if the criterion type of ocp is :max.

source
CTBase.is_minMethod
is_min(ocp::OptimalControlModel) -> Bool

Return true if the criterion type of ocp is :min.

source
CTBase.is_time_dependentMethod
is_time_dependent(ocp::OptimalControlModel) -> Bool

Return true if the model has been defined as time dependent.

source
CTBase.iterations!Method
iterations!(sol::OptimalControlSolution, iterations::Int64)

Set the number of iterations.

source
CTBase.iterationsMethod
iterations(
    sol::OptimalControlSolution
) -> Union{Nothing, Int64}

Return the number of iterations (if solved by an iterative method) of the optimal control solution or nothing.

source
CTBase.lagrangeMethod
lagrange(
    ocp::OptimalControlModel
) -> Union{Nothing, Lagrange, Lagrange!}

Return the Lagrange part of the cost of the optimal control problem or nothing.

source
CTBase.mayerMethod
mayer(
    ocp::OptimalControlModel
) -> Union{Nothing, Mayer, Mayer!}

Return the Mayer part of the cost of the optimal control problem or nothing.

source
CTBase.message!Method
message!(sol::OptimalControlSolution, message::String)

Set the message of stopping.

source
CTBase.messageMethod
message(
    sol::OptimalControlSolution
) -> Union{Nothing, String}

Return the message associated to the stopping criterion of the optimal control solution or nothing.

source
CTBase.mixed_constraints!Method
mixed_constraints!(
    sol::OptimalControlSolution,
    mixed_constraints::Function
)

Set the mixed state/control constraints.

source
CTBase.mixed_constraintsMethod
mixed_constraints(
    sol::OptimalControlSolution
) -> Union{Nothing, Function}

Return the mixed state-control constraints of the optimal control solution or nothing.

source
CTBase.model_expression!Method
model_expression!(
    ocp::OptimalControlModel,
    model_expression::Expr
)

Set the model expression of the optimal control problem or nothing.

source
CTBase.model_expressionMethod
model_expression(
    ocp::OptimalControlModel
) -> Union{Nothing, Expr}

Return the model expression of the optimal control problem or nothing.

source
CTBase.mult_boundary_constraints!Method
mult_boundary_constraints!(
    sol::OptimalControlSolution,
    mult_boundary_constraints::Union{Real, AbstractVector{<:Real}}
)

Set the multipliers to the boundary constraints.

source
CTBase.mult_boundary_constraintsMethod
mult_boundary_constraints(
    sol::OptimalControlSolution
) -> Union{Nothing, Real, AbstractVector{<:Real}}

Return the multipliers to the boundary constraints of the optimal control solution or nothing.

source
CTBase.mult_control_box_lower!Method
mult_control_box_lower!(
    sol::OptimalControlSolution,
    mult_control_box_lower::Function
)

Set the multipliers to the control lower bounds.

source
CTBase.mult_control_box_lowerMethod
mult_control_box_lower(
    sol::OptimalControlSolution
) -> Union{Nothing, Function}

Return the multipliers to the control lower bounds of the optimal control solution or nothing.

source
CTBase.mult_control_box_upper!Method
mult_control_box_upper!(
    sol::OptimalControlSolution,
    mult_control_box_upper::Function
)

Set the multipliers to the control upper bounds.

source
CTBase.mult_control_box_upperMethod
mult_control_box_upper(
    sol::OptimalControlSolution
) -> Union{Nothing, Function}

Return the multipliers to the control upper bounds of the optimal control solution or nothing.

source
CTBase.mult_control_constraintsMethod
mult_control_constraints(
    sol::OptimalControlSolution
) -> Union{Nothing, Function}

Return the multipliers to the control constraints of the optimal control solution or nothing.

source
CTBase.mult_mixed_constraints!Method
mult_mixed_constraints!(
    sol::OptimalControlSolution,
    mult_mixed_constraints::Function
)

Set the multipliers to the mixed state/control constraints.

source
CTBase.mult_mixed_constraintsMethod
mult_mixed_constraints(
    sol::OptimalControlSolution
) -> Union{Nothing, Function}

Return the multipliers to the mixed state-control constraints of the optimal control solution or nothing.

source
CTBase.mult_state_box_lower!Method
mult_state_box_lower!(
    sol::OptimalControlSolution,
    mult_state_box_lower::Function
)

Set the multipliers to the state lower bounds.

source
CTBase.mult_state_box_lowerMethod
mult_state_box_lower(
    sol::OptimalControlSolution
) -> Union{Nothing, Function}

Return the multipliers to the state lower bounds of the optimal control solution or nothing.

source
CTBase.mult_state_box_upper!Method
mult_state_box_upper!(
    sol::OptimalControlSolution,
    mult_state_box_upper::Function
)

Set the multipliers to the state upper bounds.

source
CTBase.mult_state_box_upperMethod
mult_state_box_upper(
    sol::OptimalControlSolution
) -> Union{Nothing, Function}

Return the multipliers to the state upper bounds of the optimal control solution or nothing.

source
CTBase.mult_state_constraints!Method
mult_state_constraints!(
    sol::OptimalControlSolution,
    mult_state_constraints::Function
)

Set the multipliers to the state constraints.

source
CTBase.mult_state_constraintsMethod
mult_state_constraints(
    sol::OptimalControlSolution
) -> Union{Nothing, Function}

Return the multipliers to the state constraints of the optimal control solution or nothing.

source
CTBase.mult_variable_box_lower!Method
mult_variable_box_lower!(
    sol::OptimalControlSolution,
    mult_variable_box_lower::Union{Real, AbstractVector{<:Real}}
)

Set the multipliers to the variable lower bounds.

source
CTBase.mult_variable_box_lowerMethod
mult_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.

source
CTBase.mult_variable_box_upper!Method
mult_variable_box_upper!(
    sol::OptimalControlSolution,
    mult_variable_box_upper::Union{Real, AbstractVector{<:Real}}
)

Set the multipliers to the variable upper bounds.

source
CTBase.mult_variable_box_upperMethod
mult_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.

source
CTBase.mult_variable_constraints!Method
mult_variable_constraints!(
    sol::OptimalControlSolution,
    mult_variable_constraints::Union{Real, AbstractVector{<:Real}}
)

Set the multipliers to the variable constraints.

source
CTBase.mult_variable_constraintsMethod
mult_variable_constraints(
    sol::OptimalControlSolution
) -> Union{Nothing, Real, AbstractVector{<:Real}}

Return the multipliers to the variable constraints of the optimal control solution or nothing.

source
CTBase.nlp_constraints!Method
nlp_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).

Note
  • 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)
source
CTBase.objective!Method
objective!(
    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.

Note

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
source
CTBase.objective!Method
objective!(
    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.

Note

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
Warning

If you set twice the objective, only the last one will be taken into account.

source
CTBase.objectiveMethod
objective(
    sol::OptimalControlSolution
) -> Union{Nothing, Real}

Return the objective value of the optimal control solution or nothing.

source
CTBase.removeMethod
remove(
    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,)
source
CTBase.remove_constraint!Method
remove_constraint!(ocp::OptimalControlModel, label::Symbol)

Remove a labeled constraint.

Example

julia> remove_constraint!(ocp, :con)
source
CTBase.replace_callMethod
replace_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)
source
CTBase.replace_callMethod
replace_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])
source
CTBase.state!Function
state!(ocp::OptimalControlModel, n::Integer)
state!(ocp::OptimalControlModel, n::Integer, name::String)
state!(
    ocp::OptimalControlModel,
    n::Integer,
    name::String,
    components_names::Vector{String}
)

Define the state dimension and possibly the names of each component.

Note

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₂"]
source
CTBase.stateMethod
state(
    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)
source
CTBase.state_components_namesMethod
state_components_names(
    ocp::OptimalControlModel
) -> Union{Nothing, Vector{String}}

Return the names of the components of the state of the optimal control problem or nothing.

source
CTBase.state_components_namesMethod
state_components_names(
    sol::OptimalControlSolution
) -> Union{Nothing, Vector{String}}

Return the names of the components of the state of the optimal control solution or nothing.

source
CTBase.state_constraintsMethod
state_constraints(
    sol::OptimalControlSolution
) -> Union{Nothing, Function}

Return the state constraints of the optimal control solution or nothing.

source
CTBase.state_dimensionMethod
state_dimension(
    ocp::OptimalControlModel
) -> Union{Nothing, Integer}

Return the dimension of the state of the optimal control problem or nothing.

source
CTBase.state_dimensionMethod
state_dimension(
    sol::OptimalControlSolution
) -> Union{Nothing, Integer}

Return the dimension of the state of the optimal control solution or nothing.

source
CTBase.state_discretizedMethod
state_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
source
CTBase.state_nameMethod
state_name(
    ocp::OptimalControlModel
) -> Union{Nothing, String}

Return the name of the state of the optimal control problem or nothing.

source
CTBase.state_nameMethod
state_name(
    sol::OptimalControlSolution
) -> Union{Nothing, String}

Return the name of the state of the optimal control solution or nothing.

source
CTBase.stopping!Method
stopping!(sol::OptimalControlSolution, stopping::Symbol)

Set the stopping criterion.

source
CTBase.stoppingMethod
stopping(
    sol::OptimalControlSolution
) -> Union{Nothing, Symbol}

Return the stopping criterion (a Symbol) of the optimal control solution or nothing.

source
CTBase.successMethod
success(sol::OptimalControlSolution) -> Union{Nothing, Bool}

Return the true if the solver has finished successfully of false if not, or nothing.

source
CTBase.time!Method
time!(
    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.

Note

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  
source
CTBase.time_grid!Method
time_grid!(
    sol::OptimalControlSolution,
    time_grid::Union{StepRangeLen, AbstractVector{<:Real}}
)

Set the time grid.

source
CTBase.time_gridMethod
time_grid(
    sol::OptimalControlSolution
) -> Union{Nothing, StepRangeLen, AbstractVector{<:Real}}

Return the time grid of the optimal control solution or nothing.

source
CTBase.time_nameMethod
time_name(
    ocp::OptimalControlModel
) -> Union{Nothing, String}

Return the name of the time component of the optimal control problem or nothing.

source
CTBase.time_nameMethod
time_name(
    sol::OptimalControlSolution
) -> Union{Nothing, String}

Return the name of the time component of the optimal control solution or nothing.

source
CTBase.variable!Function
variable!(ocp::OptimalControlModel, q::Integer)
variable!(
    ocp::OptimalControlModel,
    q::Integer,
    name::String
)
variable!(
    ocp::OptimalControlModel,
    q::Integer,
    name::String,
    components_names::Vector{String}
)

Define the variable dimension and possibly the names of each component.

Note

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₂" ])
source
CTBase.variableMethod
variable(
    sol::OptimalControlSolution
) -> Union{Nothing, Real, AbstractVector{<:Real}}

Return the variable of the optimal control solution or nothing.

julia> v  = variable(sol)
source
CTBase.variable_components_namesMethod
variable_components_names(
    ocp::OptimalControlModel
) -> Union{Nothing, Vector{String}}

Return the names of the components of the variable of the optimal control problem or nothing.

source
CTBase.variable_components_namesMethod
variable_components_names(
    sol::OptimalControlSolution
) -> Union{Nothing, Vector{String}}

Return the names of the components of the variable of the optimal control solution or nothing.

source
CTBase.variable_constraints!Method
variable_constraints!(
    sol::OptimalControlSolution,
    variable_constraints::Union{Real, AbstractVector{<:Real}}
)

Set the variable constraints.

source
CTBase.variable_constraintsMethod
variable_constraints(
    sol::OptimalControlSolution
) -> Union{Nothing, Real, AbstractVector{<:Real}}

Return the variable constraints of the optimal control solution or nothing.

source
CTBase.variable_dimensionMethod
variable_dimension(
    ocp::OptimalControlModel
) -> Union{Nothing, Integer}

Return the dimension of the variable of the optimal control problem or nothing.

source
CTBase.variable_dimensionMethod
variable_dimension(
    sol::OptimalControlSolution
) -> Union{Nothing, Integer}

Return the dimension of the variable of the optimal control solution or nothing.

source
CTBase.variable_nameMethod
variable_name(
    ocp::OptimalControlModel
) -> Union{Nothing, String}

Return the name of the variable of the optimal control problem or nothing.

source
CTBase.variable_nameMethod
variable_name(
    sol::OptimalControlSolution
) -> Union{Nothing, String}

Return the name of the variable of the optimal control solution or nothing.

source
CTBase.∂ₜMethod
∂ₜ(f) -> CTBase.var"#142#144"

Partial derivative wrt time of a function.

Example

julia> ∂ₜ((t,x) -> t*x)(0,8)
8
source
CTBase.@LieMacro

Macros 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
source
CTBase.@LieMacro

Macros 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
#
source
CTBase.@LieMacro

Macros 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)
#
source
CTBase.@defMacro

Define 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
source