Skip to content

Commit

Permalink
Merge pull request #316 from control-toolbox/integer
Browse files Browse the repository at this point in the history
Integer
  • Loading branch information
ocots authored Dec 12, 2024
2 parents 0b8a8e7 + 307e262 commit 060ac84
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 37 deletions.
22 changes: 11 additions & 11 deletions ext/plot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ $(TYPEDEF)
A leaf of a plot tree.
"""
struct PlotLeaf <: AbstractPlotTreeElement
value::Tuple{Symbol, Integer}
PlotLeaf(value::Tuple{Symbol, Integer}) = new(value)
value::Tuple{Symbol, Int}
PlotLeaf(value::Tuple{Symbol, Int}) = new(value)
end

"""
Expand Down Expand Up @@ -41,7 +41,7 @@ function __plot_time!(
p::Union{Plots.Plot, Plots.Subplot},
sol::OptimalControlSolution,
s::Symbol,
i::Integer,
i::Int,
time::Symbol;
t_label,
label::String,
Expand Down Expand Up @@ -103,7 +103,7 @@ Plot the i-th component of a vectorial function of time `f(t) ∈ Rᵈ` where `f
function __plot_time(
sol::OptimalControlSolution,
s::Symbol,
i::Integer,
i::Int,
time::Symbol;
t_label,
label::String,
Expand Down Expand Up @@ -187,7 +187,7 @@ $(TYPEDSIGNATURES)
Plot a leaf.
"""
function __plot_tree(leaf::PlotLeaf, depth::Integer; kwargs...)
function __plot_tree(leaf::PlotLeaf, depth::Int; kwargs...)
return Plots.plot()
end

Expand All @@ -196,7 +196,7 @@ $(TYPEDSIGNATURES)
Plot a node.
"""
function __plot_tree(node::PlotNode, depth::Integer = 0; kwargs...)
function __plot_tree(node::PlotNode, depth::Int = 0; kwargs...)
#
subplots = ()
#
Expand Down Expand Up @@ -612,8 +612,8 @@ corresponding respectively to the argument `xx` and the argument `yy`.
"""
@recipe function f(
sol::OptimalControlSolution,
xx::Union{Symbol, Tuple{Symbol, Integer}},
yy::Union{Symbol, Tuple{Symbol, Integer}},
xx::Union{Symbol, Tuple{Symbol, Int}},
yy::Union{Symbol, Tuple{Symbol, Int}},
time::Symbol = :default,
)

Expand All @@ -629,8 +629,8 @@ end

function recipe_label(
sol::OptimalControlSolution,
xx::Union{Symbol, Tuple{Symbol, Integer}},
yy::Union{Symbol, Tuple{Symbol, Integer}},
xx::Union{Symbol, Tuple{Symbol, Int}},
yy::Union{Symbol, Tuple{Symbol, Int}},
)

#
Expand Down Expand Up @@ -661,7 +661,7 @@ Get the data for plotting.
"""
function __get_data_plot(
sol::OptimalControlSolution,
xx::Union{Symbol, Tuple{Symbol, Integer}};
xx::Union{Symbol, Tuple{Symbol, Int}};
time::Symbol = :default,
)
T = time_grid(sol)
Expand Down
4 changes: 2 additions & 2 deletions src/CTBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,10 @@ Type alias for a dimension. This is used to define the dimension of the state sp
the costate space, the control space, etc.
```@example
julia> const Dimension = Integer
julia> const Dimension = Int
```
"""
const Dimension = Integer
const Dimension = Int

#
"""
Expand Down
10 changes: 5 additions & 5 deletions src/onepass.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ $(TYPEDEF)
x::Union{Symbol, Nothing} = nothing
u::Union{Symbol, Nothing} = nothing
aliases::OrderedDict{Symbol, Union{Real, Symbol, Expr}} = __init_aliases()
lnum::Integer = 0
lnum::Int = 0
line::String = ""
t_dep::Bool = false
end
Expand Down Expand Up @@ -199,7 +199,7 @@ p_variable!(p, ocp, v, q; components_names = nothing, log = false) = begin
v isa Symbol || return __throw("forbidden variable name: $v", p.lnum, p.line)
p.v = v
vv = QuoteNode(v)
qq = q isa Integer ? q : 9
qq = q isa Int ? q : 9
for i 1:qq
p.aliases[Symbol(v, ctindices(i))] = :($v[$i])
end # make: v₁, v₂... if the variable is named v
Expand Down Expand Up @@ -283,7 +283,7 @@ p_state!(p, ocp, x, n; components_names = nothing, log = false) = begin
x isa Symbol || return __throw("forbidden state name: $x", p.lnum, p.line)
p.x = x
xx = QuoteNode(x)
nn = n isa Integer ? n : 9
nn = n isa Int ? n : 9
for i 1:nn
p.aliases[Symbol(x, ctindices(i))] = :($x[$i])
end # Make x₁, x₂... if the state is named x
Expand Down Expand Up @@ -314,7 +314,7 @@ p_control!(p, ocp, u, m; components_names = nothing, log = false) = begin
u isa Symbol || return __throw("forbidden control name: $u", p.lnum, p.line)
p.u = u
uu = QuoteNode(u)
mm = m isa Integer ? m : 9
mm = m isa Int ? m : 9
for i 1:mm
p.aliases[Symbol(u, ctindices(i))] = :($u[$i])
end # make: u₁, u₂... if the control is named u
Expand All @@ -341,7 +341,7 @@ end
p_constraint!(p, ocp, e1, e2, e3, label = gensym(); log = false) = begin
c_type = constraint_type(e2, p.t, p.t0, p.tf, p.x, p.u, p.v)
log && println("constraint ($c_type): $e1$e2$e3, ($label)")
label isa Integer && (label = Symbol(:eq, label))
label isa Int && (label = Symbol(:eq, label))
label isa Symbol || return __throw("forbidden label: $label", p.lnum, p.line)
llabel = QuoteNode(label)
code = @match c_type begin
Expand Down
20 changes: 10 additions & 10 deletions src/optimal_control_model-setters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,8 @@ function time!(
ocp::OptimalControlModel{<:TimeDependence, VT};
t0::Union{Time, Nothing} = nothing,
tf::Union{Time, Nothing} = nothing,
ind0::Union{Integer, Nothing} = nothing,
indf::Union{Integer, Nothing} = nothing,
ind0::Union{Int, Nothing} = nothing,
indf::Union{Int, Nothing} = nothing,
name::Union{String, Symbol} = __time_name(),
) where {VT}

Expand Down Expand Up @@ -417,24 +417,24 @@ function time!(
ocp.initial_time = t0
ocp.final_time = tf
ocp.time_name = name
ocp.initial_time_name = t0 isa Integer ? string(t0) : string(round(t0, digits = 2))
ocp.final_time_name = tf isa Integer ? string(tf) : string(round(tf, digits = 2))
ocp.initial_time_name = t0 isa Int ? string(t0) : string(round(t0, digits = 2))
ocp.final_time_name = tf isa Int ? string(tf) : string(round(tf, digits = 2))
end
(::Nothing, ::Integer, ::Time, ::Nothing) => begin # (ind0, tf)
(::Nothing, ::Int, ::Time, ::Nothing) => begin # (ind0, tf)
ocp.initial_time = Index(ind0)
ocp.final_time = tf
ocp.time_name = name
ocp.initial_time_name = variable_components_names(ocp)[ind0]
ocp.final_time_name = tf isa Integer ? string(tf) : string(round(tf, digits = 2))
ocp.final_time_name = tf isa Int ? string(tf) : string(round(tf, digits = 2))
end
(::Time, ::Nothing, ::Nothing, ::Integer) => begin # (t0, indf)
(::Time, ::Nothing, ::Nothing, ::Int) => begin # (t0, indf)
ocp.initial_time = t0
ocp.final_time = Index(indf)
ocp.time_name = name
ocp.initial_time_name = t0 isa Integer ? string(t0) : string(round(t0, digits = 2))
ocp.initial_time_name = t0 isa Int ? string(t0) : string(round(t0, digits = 2))
ocp.final_time_name = variable_components_names(ocp)[indf]
end
(::Nothing, ::Integer, ::Nothing, ::Integer) => begin # (ind0, indf)
(::Nothing, ::Int, ::Nothing, ::Int) => begin # (ind0, indf)
ocp.initial_time = Index(ind0)
ocp.final_time = Index(indf)
ocp.time_name = name
Expand Down Expand Up @@ -521,7 +521,7 @@ julia> constraint!(ocp, :mixed; f = (t, x, u, v) -> x[1]*v[2]-u, lb=0, ub=1)
function constraint!(
ocp::OptimalControlModel{T, V},
type::Symbol;
rg::Union{OrdinalRange{<:Integer}, Index, Integer, Nothing} = nothing,
rg::Union{OrdinalRange{<:Int}, Index, Int, Nothing} = nothing,
f::Union{Function, Nothing} = nothing,
lb::Union{ctVector, Nothing} = nothing,
ub::Union{ctVector, Nothing} = nothing,
Expand Down
6 changes: 3 additions & 3 deletions src/optimal_control_solution-setters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function __OptimalControlSolution(
costate::Union{Nothing, Function} = nothing,
time_grid::Union{Nothing, TimesDisc} = nothing,
variable::Union{Nothing, Variable} = nothing,
iterations::Union{Nothing, Integer} = nothing,
iterations::Union{Nothing, Int} = nothing,
stopping::Union{Nothing, Symbol} = nothing,
message::Union{Nothing, String} = nothing,
success::Union{Nothing, Bool} = nothing,
Expand Down Expand Up @@ -103,7 +103,7 @@ function OptimalControlSolution(
variable::Union{Nothing, Variable} = nothing,
costate::Union{Nothing, Function} = nothing,
time_grid::Union{Nothing, TimesDisc} = nothing,
iterations::Union{Nothing, Integer} = nothing,
iterations::Union{Nothing, Int} = nothing,
stopping::Union{Nothing, Symbol} = nothing,
message::Union{Nothing, String} = nothing,
success::Union{Nothing, Bool} = nothing,
Expand Down Expand Up @@ -170,7 +170,7 @@ function OptimalControlSolution(
variable::Variable,
costate::Union{Nothing, Function} = nothing,
time_grid::Union{Nothing, TimesDisc} = nothing,
iterations::Union{Nothing, Integer} = nothing,
iterations::Union{Nothing, Int} = nothing,
stopping::Union{Nothing, Symbol} = nothing,
message::Union{Nothing, String} = nothing,
success::Union{Nothing, Bool} = nothing,
Expand Down
12 changes: 6 additions & 6 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ $(TYPEDSIGNATURES)
Return `i` ∈ [0, 9] as a subscript.
"""
function ctindice(i::Integer)::Char
function ctindice(i::Int)::Char
if i < 0 || i > 9
throw(IncorrectArgument("the indice must be between 0 and 9"))
end
Expand All @@ -15,7 +15,7 @@ $(TYPEDSIGNATURES)
Return `i` > 0 as a subscript.
"""
function ctindices(i::Integer)::String
function ctindices(i::Int)::String
if i < 0
throw(IncorrectArgument("the indice must be positive"))
end
Expand All @@ -31,7 +31,7 @@ $(TYPEDSIGNATURES)
Return `i` ∈ [0, 9] as an upperscript.
"""
function ctupperscript(i::Integer)::Char
function ctupperscript(i::Int)::Char
if i < 0 || i > 9
throw(IncorrectArgument("the upperscript must be between 0 and 9"))
end
Expand All @@ -57,7 +57,7 @@ $(TYPEDSIGNATURES)
Return `i` > 0 as an upperscript.
"""
function ctupperscripts(i::Integer)::String
function ctupperscripts(i::Int)::String
if i < 0
throw(IncorrectArgument("the upperscript must be positive"))
end
Expand Down Expand Up @@ -165,7 +165,7 @@ $(TYPEDSIGNATURES)
Transforms `x` to a Vector{<:Vector{<:ctNumber}}.
"""
function vec2vec(x::Vector{<:ctNumber}, n::Integer)::Vector{<:Vector{<:ctNumber}}
function vec2vec(x::Vector{<:ctNumber}, n::Int)::Vector{<:Vector{<:ctNumber}}
y = [x[1:n]]
for i = (n + 1):n:(length(x) - n + 1)
y = vcat(y, [x[i:(i + n - 1)]])
Expand Down Expand Up @@ -203,7 +203,7 @@ Transforms `x` to a Vector{<:Vector{<:ctNumber}}.
"""
function matrix2vec(
x::Matrix{<:ctNumber},
dim::Integer = __matrix_dimension_stock(),
dim::Int = __matrix_dimension_stock(),
)::Vector{<:Vector{<:ctNumber}}
m, n = size(x)
y = nothing
Expand Down
Binary file modified test/solution_test.jld2
Binary file not shown.

0 comments on commit 060ac84

Please sign in to comment.