diff --git a/docs/src/api-print.md b/docs/src/api-print.md index 970a5f72..2b0e2dc3 100644 --- a/docs/src/api-print.md +++ b/docs/src/api-print.md @@ -42,7 +42,7 @@ ocp = Model() state!(ocp, 2, "x", ["r", "v"]) # dimension of the state with the names of the components control!(ocp, 1) # dimension of the control -time!(ocp, [0, 1], "s") # initial and final time, with the name of the variable time +time!(ocp, t0=0, tf=1, name="s") # initial and final time, with the name of the variable time constraint!(ocp, :initial, lb=[-1, 0], ub=[-1, 0]) constraint!(ocp, :final , lb=[ 0, 0], ub=[ 0, 0]) diff --git a/src/model.jl b/src/model.jl index 2a7f5862..30bbbc45 100644 --- a/src/model.jl +++ b/src/model.jl @@ -340,7 +340,9 @@ end """ $(TYPEDSIGNATURES) -Fix initial time, final time is free and given by the variable at the provided index. +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 @@ -349,166 +351,88 @@ Fix initial time, final time is free and given by the variable at the provided i # Examples ```jldoctest -julia> time!(ocp, 0, Index(2), "t") +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 ``` -""" -function time!(ocp::OptimalControlModel{<: TimeDependence, NonFixed}, t0::Time, indf::Index, name::String=__time_name()) - __check_variable_set(ocp) - __is_time_set(ocp) && throw(UnauthorizedCall("the time has already been set. Use time! once.")) - (indf.val > ocp.variable_dimension) && throw(IncorrectArgument("out of range index of variable")) - # - ocp.initial_time = t0 - ocp.final_time = indf - ocp.time_name = name - ocp.initial_time_name = t0 isa Integer ? string(t0) : string(round(t0, digits=2)) - ocp.final_time_name = ocp.variable_components_names[indf] - nothing # to force to return nothing -end - -function time!(ocp::OptimalControlModel, t0::Time, indf::Index, name::Symbol) - time!(ocp, t0, indf, string(name)) -end - -""" -$(TYPEDSIGNATURES) -Fix final time, initial time is free and given by the variable at the provided index. +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". -# Examples ```jldoctest -julia> time!(ocp, Index(2), 1, "t") +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 ``` """ -function time!(ocp::OptimalControlModel{<: TimeDependence, NonFixed}, ind0::Index, tf::Time, name::String=__time_name()) - __check_variable_set(ocp) - __is_time_set(ocp) && throw(UnauthorizedCall("the time has already been set. Use time! once.")) - (ind0.val > ocp.variable_dimension) && throw(IncorrectArgument("out of range index of variable")) - ocp.initial_time = ind0 - ocp.final_time = tf - ocp.time_name = name - ocp.initial_time_name = ocp.variable_components_names[ind0] - ocp.final_time_name = tf isa Integer ? string(tf) : string(round(tf, digits=2)) - nothing # to force to return nothing -end - -function time!(ocp::OptimalControlModel, ind0::Index, tf::Time, name::Symbol) - time!(ocp, ind0, tf, string(name)) -end +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, + name::Union{String, Symbol}=__time_name()) where VT -""" -$(TYPEDSIGNATURES) + # check if the problem has been set to Variable or NonVariable + VT == NonFixed && (!isnothing(ind0) || !isnothing(indf)) && __check_variable_set(ocp) -Initial and final times are free and given by the variable at the provided indices. + # check if indices are in 1:q + q = ocp.variable_dimension + !isnothing(ind0) && !(1 ≤ ind0 ≤ q) && throw(IncorrectArgument("the index of t0 variable must be contained in 1:$q")) + !isnothing(indf) && !(1 ≤ indf ≤ q) && throw(IncorrectArgument("the index of tf variable must be contained in 1:$q")) -# Examples -```jldoctest -julia> time!(ocp, Index(2), Index(3), "t") -``` -""" -function time!(ocp::OptimalControlModel{<: TimeDependence, NonFixed}, ind0::Index, indf::Index, name::String=__time_name()) - __check_variable_set(ocp) + # check if the function has been already called __is_time_set(ocp) && throw(UnauthorizedCall("the time has already been set. Use time! once.")) - (ind0.val > ocp.variable_dimension) && throw(IncorrectArgument("out of range index of variable")) - (indf.val > ocp.variable_dimension) && throw(IncorrectArgument("out of range index of variable")) - ocp.initial_time = ind0 - ocp.final_time = indf - ocp.time_name = name - ocp.initial_time_name = ocp.variable_components_names[ind0] - ocp.final_time_name = ocp.variable_components_names[indf] - nothing # to force to return nothing -end - -function time!(ocp::OptimalControlModel, ind0::Index, indf::Index, name::Symbol) - time!(ocp, ind0, indf, string(name)) -end - -""" -$(TYPEDSIGNATURES) - -Fix initial and final times to `times[1]` and `times[2]`, respectively. - -# Examples - -```jldoctest -julia> time!(ocp, [ 0, 1 ]) -julia> ocp.initial_time -0 -julia> ocp.final_time -1 -julia> ocp.time_name -"t" - -julia> time!(ocp, [ 0, 1 ], "s") -julia> ocp.initial_time -0 -julia> ocp.final_time -1 -julia> ocp.time_name -"s" - -julia> time!(ocp, [ 0, 1 ], :s) -julia> ocp.initial_time -0 -julia> ocp.final_time -1 -julia> ocp.time_name -"s" -``` -""" -function time!(ocp::OptimalControlModel, times::Times, name::String=__time_name()) - (length(times) != 2) && throw(IncorrectArgument("times must be of dimension 2")) - time!(ocp, times[1], times[2], name) -end - -function time!(ocp::OptimalControlModel, times::Times, name::Symbol) - time!(ocp, times, string(name)) -end - -""" -$(TYPEDSIGNATURES) -Fix initial and final times to `times[1]` and `times[2]`, respectively. + # check consistency + !isnothing(t0) && !isnothing(ind0) && throw(IncorrectArgument("Providing t0 and ind0 has no sense. The initial time cannot be fixed and free.")) + isnothing(t0) && isnothing(ind0) && throw(IncorrectArgument("Please either provide the value of the initial time t0 (if fixed) or its index in the variable of ocp (if free).")) + !isnothing(tf) && !isnothing(indf) && throw(IncorrectArgument("Providing tf and indf has no sense. The final time cannot be fixed and free.")) + isnothing(tf) && isnothing(indf) && throw(IncorrectArgument("Please either provide the value of the final time tf (if fixed) or its index in the variable of ocp (if free).")) -# Examples + VT == Fixed && !isnothing(ind0) && throw(IncorrectArgument("You cannot have the initial time free (ind0 is provided) and the ocp non variable.")) + VT == Fixed && !isnothing(indf) && throw(IncorrectArgument("You cannot have the final time free (indf is provided) and the ocp non variable.")) -```jldoctest -julia> time!(ocp, 0, 1) -julia> ocp.initial_time -0 -julia> ocp.final_time -1 -julia> ocp.time_name -"t" + # + name = name isa String ? name : string(name) -julia> time!(ocp, 0, 1, "s") -julia> ocp.initial_time -0 -julia> ocp.final_time -1 -julia> ocp.time_name -"s" + # core + @match (t0, ind0, tf, indf) begin + (::Time, ::Nothing, ::Time, ::Nothing) => begin # (t0, tf) + 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)) + end + (::Nothing, ::Integer, ::Time, ::Nothing) => begin # (ind0, tf) + ocp.initial_time = Index(ind0) + ocp.final_time = tf + ocp.time_name = name + ocp.initial_time_name = ocp.variable_components_names[ind0] + ocp.final_time_name = tf isa Integer ? string(tf) : string(round(tf, digits=2)) + end + (::Time, ::Nothing, ::Nothing, ::Integer) => 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.final_time_name = ocp.variable_components_names[indf] + end + (::Nothing, ::Integer, ::Nothing, ::Integer) => begin # (ind0, indf) + ocp.initial_time = Index(ind0) + ocp.final_time = Index(indf) + ocp.time_name = name + ocp.initial_time_name = ocp.variable_components_names[ind0] + ocp.final_time_name = ocp.variable_components_names[indf] + end + _ => throw(IncorrectArgument("Provided arguments are inconsistent.")) + end -julia> time!(ocp, 0, 1, :s) -julia> ocp.initial_time -0 -julia> ocp.final_time -1 -julia> ocp.time_name -"s" -``` -""" -function time!(ocp::OptimalControlModel, t0::Time, tf::Time, name::String=__time_name()) - __is_time_set(ocp) && throw(UnauthorizedCall("the time has already been set. Use time! once.")) - 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)) nothing # to force to return nothing -end -function time!(ocp::OptimalControlModel, t0::Time, tf::Time, name::Symbol) - time!(ocp, t0, tf, string(name)) end """ diff --git a/src/onepass.jl b/src/onepass.jl index 37cf35d1..f099d8c7 100644 --- a/src/onepass.jl +++ b/src/onepass.jl @@ -198,26 +198,26 @@ p_time!(p, ocp, t, t0, tf; log=false) = begin p.tf = tf tt = QuoteNode(t) code = @match (has(t0, p.v), has(tf, p.v)) begin - (false, false) => :( time!($ocp, $t0, $tf, $tt) ) + (false, false) => :( time!($ocp; t0=$t0, tf=$tf, name=$tt) ) (true , false) => @match t0 begin - :( $v1[$i] ) && if (v1 == p.v) end => :( time!($ocp, Index($i), $tf, $tt) ) + :( $v1[$i] ) && if (v1 == p.v) end => :( time!($ocp; ind0=$i, tf=$tf, name=$tt) ) :( $v1 ) && if (v1 == p.v) end => quote ($ocp.variable_dimension ≠ 1) && throw(IncorrectArgument("variable must be of dimension one for a time")) - time!($ocp, Index(1), $tf, $tt) end + time!($ocp; ind0=1, tf=$tf, name=$tt) end _ => return __throw("bad time declaration", p.lnum, p.line) end (false, true ) => @match tf begin - :( $v1[$i] ) && if (v1 == p.v) end => :( time!($ocp, $t0, Index($i), $tt) ) + :( $v1[$i] ) && if (v1 == p.v) end => :( time!($ocp; t0=$t0, indf=$i, name=$tt) ) :( $v1 ) && if (v1 == p.v) end => quote ($ocp.variable_dimension ≠ 1) && throw(IncorrectArgument("variable must be of dimension one for a time")) - time!($ocp, $t0, Index(1), $tt) end + time!($ocp; t0=$t0, indf=1, name=$tt) end _ => return __throw("bad time declaration", p.lnum, p.line) end _ => @match (t0, tf) begin (:( $v1[$i] ), :( $v2[$j] )) && if (v1 == v2 == p.v) end => - :( time!($ocp, Index($i), Index($j), $tt) ) + :( time!($ocp; ind0=$i, indf=$j, name=$tt) ) _ => return __throw("bad time declaration", p.lnum, p.line) end end diff --git a/test/runtests.jl b/test/runtests.jl index 97ee2850..0f0eaf2e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -9,55 +9,8 @@ const has = CTBase.has const replace_call = CTBase.replace_call const constraint_type = CTBase.constraint_type -function __constraint!( - ocp::OptimalControlModel{<: TimeDependence, V}, - type::Symbol, - rg::Index, - lb::Union{ctVector,Nothing}, - ub::Union{ctVector,Nothing}, - label::Symbol=CTBase.__constraint_label()) where {V <: VariableDependence} - - constraint!(ocp, type, rg=rg.val, f=nothing, lb=lb, ub=ub, label=label) - nothing # to force to return nothing - -end - -function __constraint!( - ocp::OptimalControlModel{<: TimeDependence, V}, - type::Symbol, - rg::OrdinalRange{<:Integer}, - lb::Union{ctVector,Nothing}, - ub::Union{ctVector,Nothing}, - label::Symbol=CTBase.__constraint_label()) where {V <: VariableDependence} - - constraint!(ocp, type, rg=rg, f=nothing, lb=lb, ub=ub, label=label) - nothing # to force to return nothing - -end - -function __constraint!( - ocp::OptimalControlModel, - type::Symbol, - lb::Union{ctVector,Nothing}, - ub::Union{ctVector,Nothing}, - label::Symbol=CTBase.__constraint_label()) - - constraint!(ocp, type, rg=nothing, f=nothing, lb=lb, ub=ub, label=label) - nothing # to force to return nothing - -end - -function __constraint!( - ocp::OptimalControlModel{T, V}, - type::Symbol, - f::Function, - lb::Union{ctVector,Nothing}, - ub::Union{ctVector,Nothing}, - label::Symbol=CTBase.__constraint_label()) where {T, V} - - constraint!(ocp, type, rg=nothing, f=f, lb=lb, ub=ub, label=label) - nothing # to force to return nothing -end +# +include("utils.jl") # @testset verbose = true showtiming = true "Base" begin diff --git a/test/test_model.jl b/test/test_model.jl index 8e2f9a17..56229668 100644 --- a/test/test_model.jl +++ b/test/test_model.jl @@ -56,11 +56,11 @@ end ocp = Model() - i == 2 && begin time!(ocp, 0, 1) end + i == 2 && begin __time!(ocp, 0, 1) end i == 3 && begin state!(ocp, 2) end i == 4 && begin control!(ocp, 1) end - i == 5 && begin time!(ocp, 0, 1); state!(ocp, 2) end - i == 6 && begin time!(ocp, 0, 1); control!(ocp, 1) end + i == 5 && begin __time!(ocp, 0, 1); state!(ocp, 2) end + i == 6 && begin __time!(ocp, 0, 1); control!(ocp, 1) end i == 7 && begin state!(ocp, 2); control!(ocp, 1) end # constraint! 1 @@ -147,57 +147,48 @@ end ocp = Model(variable=true) @test !CTBase.__is_time_set(ocp) variable!(ocp, 1) - time!(ocp, 0, Index(1)) + __time!(ocp, 0, Index(1)) @test CTBase.__is_time_set(ocp) ocp = Model(variable=true) variable!(ocp, 1) - time!(ocp, Index(1), 1) + __time!(ocp, Index(1), 1) @test CTBase.__is_time_set(ocp) ocp = Model() - time!(ocp, 0, 1) + __time!(ocp, 0, 1) @test CTBase.__is_time_set(ocp) ocp = Model() - time!(ocp, [0, 1]) - @test CTBase.__is_time_set(ocp) - - ocp = Model() - @test_throws MethodError time!(ocp, 0, Index(1)) - @test_throws MethodError time!(ocp, Index(1), 1) + @test_throws MethodError __time!(ocp, 0, Index(1)) + @test_throws MethodError __time!(ocp, Index(1), 1) ocp = Model(variable=true) - @test_throws UnauthorizedCall time!(ocp, 0, Index(1)) - @test_throws UnauthorizedCall time!(ocp, Index(1), 1) + @test_throws UnauthorizedCall __time!(ocp, 0, Index(1)) + @test_throws UnauthorizedCall __time!(ocp, Index(1), 1) ocp = Model(variable=true) variable!(ocp, 1) - time!(ocp, 0, Index(1)) - @test_throws UnauthorizedCall time!(ocp, 0, Index(1)) - @test_throws UnauthorizedCall time!(ocp, Index(1), 1) - @test_throws UnauthorizedCall time!(ocp, [0, 1]) - @test_throws UnauthorizedCall time!(ocp, 0, 1) + __time!(ocp, 0, Index(1)) + @test_throws UnauthorizedCall __time!(ocp, 0, Index(1)) + @test_throws UnauthorizedCall __time!(ocp, Index(1), 1) + @test_throws UnauthorizedCall __time!(ocp, 0, 1) ocp = Model(variable=true) variable!(ocp, 1) - time!(ocp, Index(1), 1) - @test_throws UnauthorizedCall time!(ocp, 0, Index(1)) - @test_throws UnauthorizedCall time!(ocp, Index(1), 1) - @test_throws UnauthorizedCall time!(ocp, [0, 1]) - @test_throws UnauthorizedCall time!(ocp, 0, 1) + __time!(ocp, Index(1), 1) + @test_throws UnauthorizedCall __time!(ocp, 0, Index(1)) + @test_throws UnauthorizedCall __time!(ocp, Index(1), 1) + @test_throws UnauthorizedCall __time!(ocp, 0, 1) ocp = Model(variable=true) - time!(ocp, [0, 1]) - @test_throws UnauthorizedCall time!(ocp, 0, Index(1)) - @test_throws UnauthorizedCall time!(ocp, Index(1), 1) - @test_throws UnauthorizedCall time!(ocp, [0, 1]) + @test_throws UnauthorizedCall __time!(ocp, 0, Index(1)) + @test_throws UnauthorizedCall __time!(ocp, Index(1), 1) ocp = Model(variable=true) - time!(ocp, 0, 1) - @test_throws UnauthorizedCall time!(ocp, 0, Index(1)) - @test_throws UnauthorizedCall time!(ocp, Index(1), 1) - @test_throws UnauthorizedCall time!(ocp, [0, 1]) + __time!(ocp, 0, 1) + @test_throws UnauthorizedCall __time!(ocp, 0, Index(1)) + @test_throws UnauthorizedCall __time!(ocp, Index(1), 1) end @testset "Index" begin @@ -394,38 +385,19 @@ end @testset "time!" begin # initial and final times ocp = Model() - time!(ocp, 0, 1) + __time!(ocp, 0, 1) @test ocp.initial_time == 0 @test ocp.final_time == 1 @test ocp.time_name == "t" ocp = Model() - time!(ocp, 0, 1, "s") + __time!(ocp, 0, 1, "s") @test ocp.initial_time == 0 @test ocp.final_time == 1 @test ocp.time_name == "s" ocp = Model() - time!(ocp, 0, 1, :s) - @test ocp.initial_time == 0 - @test ocp.final_time == 1 - @test ocp.time_name == "s" - - # initial and final times (bis) - ocp = Model() - time!(ocp, [0, 1]) - @test ocp.initial_time == 0 - @test ocp.final_time == 1 - @test ocp.time_name == "t" - - ocp = Model() - time!(ocp, [0, 1], "s") - @test ocp.initial_time == 0 - @test ocp.final_time == 1 - @test ocp.time_name == "s" - - ocp = Model() - time!(ocp, [0, 1], :s) + __time!(ocp, 0, 1, :s) @test ocp.initial_time == 0 @test ocp.final_time == 1 @test ocp.time_name == "s" @@ -433,21 +405,21 @@ end # initial time ocp = Model(variable=true) variable!(ocp, 1) - time!(ocp, 0, Index(1)) + __time!(ocp, 0, Index(1)) @test ocp.initial_time == 0 @test ocp.final_time == Index(1) @test ocp.time_name == "t" ocp = Model(variable=true) variable!(ocp, 1) - time!(ocp, 0, Index(1), "s") + __time!(ocp, 0, Index(1), "s") @test ocp.initial_time == 0 @test ocp.final_time == Index(1) @test ocp.time_name == "s" ocp = Model(variable=true) variable!(ocp, 1) - time!(ocp, 0, Index(1), :s) + __time!(ocp, 0, Index(1), :s) @test ocp.initial_time == 0 @test ocp.final_time == Index(1) @test ocp.time_name == "s" @@ -455,21 +427,21 @@ end # final time ocp = Model(variable=true) variable!(ocp, 1) - time!(ocp, Index(1), 1) + __time!(ocp, Index(1), 1) @test ocp.initial_time == Index(1) @test ocp.final_time == 1 @test ocp.time_name == "t" ocp = Model(variable=true) variable!(ocp, 1) - time!(ocp, Index(1), 1, "s") + __time!(ocp, Index(1), 1, "s") @test ocp.initial_time == Index(1) @test ocp.final_time == 1 @test ocp.time_name == "s" ocp = Model(variable=true) variable!(ocp, 1) - time!(ocp, Index(1), 1, :s) + __time!(ocp, Index(1), 1, :s) @test ocp.initial_time == Index(1) @test ocp.final_time == 1 @test ocp.time_name == "s" @@ -477,7 +449,7 @@ end @testset "is_min vs is_max" begin ocp = Model() - time!(ocp, 0, 1) + __time!(ocp, 0, 1) state!(ocp, 2) control!(ocp, 1) objective!(ocp, :mayer, (x0, xf) -> x0[1] + xf[2]) @@ -485,7 +457,7 @@ end @test !is_max(ocp) ocp = Model() - time!(ocp, 0, 1) + __time!(ocp, 0, 1) state!(ocp, 2) control!(ocp, 1) objective!(ocp, :mayer, (x0, xf) -> x0[1] + xf[2], :max) @@ -493,7 +465,7 @@ end @test !is_min(ocp) ocp = Model() - time!(ocp, 0, 1) + __time!(ocp, 0, 1) state!(ocp, 2) control!(ocp, 1) objective!(ocp, :lagrange, (x, u) -> 0.5u^2) @@ -501,7 +473,7 @@ end @test !is_max(ocp) ocp = Model() - time!(ocp, 0, 1) + __time!(ocp, 0, 1) state!(ocp, 2) control!(ocp, 1) objective!(ocp, :lagrange, (x, u) -> 0.5u^2, :max) @@ -509,7 +481,7 @@ end @test !is_min(ocp) ocp = Model() - time!(ocp, 0, 1) + __time!(ocp, 0, 1) state!(ocp, 2) control!(ocp, 1) objective!(ocp, :bolza, (x0, xf) -> x0[1] + xf[2], (x, u) -> x[1]^2 + u^2) # the control is of dimension 1 @@ -517,7 +489,7 @@ end @test !is_max(ocp) ocp = Model() - time!(ocp, 0, 1) + __time!(ocp, 0, 1) state!(ocp, 2) control!(ocp, 1) objective!(ocp, :bolza, (x0, xf) -> x0[1] + xf[2], (x, u) -> x[1]^2 + u^2, :max) # the control is of dimension 1 @@ -528,21 +500,21 @@ end @testset "constraint! 1" begin - ocp = Model(); time!(ocp, 0, 1); state!(ocp, 1); control!(ocp, 1) + ocp = Model(); __time!(ocp, 0, 1); state!(ocp, 1); control!(ocp, 1) @test_throws IncorrectArgument __constraint!(ocp, :initial, [0, 1], [0, 1], :c0) __constraint!(ocp, :initial, 0, 0, :c0) __constraint!(ocp, :final, 1, 1, :cf) @test constraint(ocp, :c0)(12, ∅) == 12 @test constraint(ocp, :cf)(∅, 12) == 12 - ocp = Model(); time!(ocp, 0, 1); state!(ocp, 2); control!(ocp, 1) + ocp = Model(); __time!(ocp, 0, 1); state!(ocp, 2); control!(ocp, 1) __constraint!(ocp, :initial, [0, 1], [0, 1], :c0) __constraint!(ocp, :final, [1, 2], [1, 2], :cf) @test constraint(ocp, :c0)([12, 13], ∅) == [12, 13] @test constraint(ocp, :cf)(∅, [12, 13]) == [12, 13] # constraint already exists - ocp = Model(); time!(ocp, 0, 1); state!(ocp, 1); control!(ocp, 1) + ocp = Model(); __time!(ocp, 0, 1); state!(ocp, 1); control!(ocp, 1) __constraint!(ocp, :initial, 0, 0, :c) @test_throws UnauthorizedCall __constraint!(ocp, :final, 0, 0, :c) @@ -550,7 +522,7 @@ end @testset "constraint! 2" begin - ocp = Model(); time!(ocp, 0, 1); state!(ocp, 1); control!(ocp, 1) + ocp = Model(); __time!(ocp, 0, 1); state!(ocp, 1); control!(ocp, 1) x = 12 x0 = 0 xf = 1 @@ -564,14 +536,14 @@ end @test constraint(ocp, :c00)(x, ∅) == x @test constraint(ocp, :cff)(∅, x) == x - ocp = Model(); time!(ocp, 0, 1); state!(ocp, 2); control!(ocp, 1) + ocp = Model(); __time!(ocp, 0, 1); state!(ocp, 2); control!(ocp, 1) x = [12, 13] x0 = [0, 1] xf = [1, 2] @test_throws IncorrectArgument __constraint!(ocp, :initial, Index(2), x0, x0, :c0) @test_throws IncorrectArgument __constraint!(ocp, :final, Index(2), xf, xf, :cf) - ocp = Model(); time!(ocp, 0, 1); state!(ocp, 2); control!(ocp, 1) + ocp = Model(); __time!(ocp, 0, 1); state!(ocp, 2); control!(ocp, 1) x = [12, 13] x0 = [0, 1] xf = [1, 2] @@ -581,7 +553,7 @@ end @test constraint(ocp, :cf)(∅, x) == x[1:2] # constraint already exists - ocp = Model(); time!(ocp, 0, 1); state!(ocp, 2); control!(ocp, 1) + ocp = Model(); __time!(ocp, 0, 1); state!(ocp, 2); control!(ocp, 1) __constraint!(ocp, :initial, Index(1), 0, 0, :c) @test_throws UnauthorizedCall __constraint!(ocp, :final, Index(1), 0, 0, :c) @@ -589,7 +561,7 @@ end @testset "constraint! 3" begin - ocp = Model(); time!(ocp, 0, 1); state!(ocp, 1); control!(ocp, 1) + ocp = Model(); __time!(ocp, 0, 1); state!(ocp, 1); control!(ocp, 1) __constraint!(ocp, :initial, 0, 1, :c0) __constraint!(ocp, :final, 1, 2, :cf) __constraint!(ocp, :control, 0, 1, :cu) @@ -599,7 +571,7 @@ end @test constraint(ocp, :cu)(12) == 12 @test constraint(ocp, :cs)(12) == 12 - ocp = Model(); time!(ocp, 0, 1); state!(ocp, 2); control!(ocp, 2) + ocp = Model(); __time!(ocp, 0, 1); state!(ocp, 2); control!(ocp, 2) __constraint!(ocp, :initial, [0, 1], [1, 2], :c0) __constraint!(ocp, :final, [1, 2], [2, 3], :cf) __constraint!(ocp, :control, [0, 1], [1, 2], :cu) @@ -610,7 +582,7 @@ end @test constraint(ocp, :cs)([12, 13]) == [12, 13] # constraint already exists - ocp = Model(); time!(ocp, 0, 1); state!(ocp, 1); control!(ocp, 1) + ocp = Model(); __time!(ocp, 0, 1); state!(ocp, 1); control!(ocp, 1) __constraint!(ocp, :initial, 0, 1, :c) @test_throws UnauthorizedCall __constraint!(ocp, :final, 0, 1, :c) @@ -618,7 +590,7 @@ end @testset "constraint! 4" begin - ocp = Model(); time!(ocp, 0, 1); state!(ocp, 1); control!(ocp, 1) + ocp = Model(); __time!(ocp, 0, 1); state!(ocp, 1); control!(ocp, 1) __constraint!(ocp, :initial, Index(1), 0, 1, :c0) __constraint!(ocp, :final, Index(1), 1, 2, :cf) __constraint!(ocp, :control, Index(1), 0, 1, :cu) @@ -628,13 +600,13 @@ end @test constraint(ocp, :cu)(12) == 12 @test constraint(ocp, :cs)(12) == 12 - ocp = Model(); time!(ocp, 0, 1); state!(ocp, 2); control!(ocp, 2) + ocp = Model(); __time!(ocp, 0, 1); state!(ocp, 2); control!(ocp, 2) @test_throws IncorrectArgument __constraint!(ocp, :initial, Index(2), [0, 1], [1, 2], :c0) @test_throws IncorrectArgument __constraint!(ocp, :final, Index(2), [1, 2], [2, 3], :cf) @test_throws IncorrectArgument __constraint!(ocp, :control, Index(2), [0, 1], [1, 2], :cu) @test_throws IncorrectArgument __constraint!(ocp, :state, Index(2), [0, 1], [1, 2], :cs) - ocp = Model(); time!(ocp, 0, 1); state!(ocp, 2); control!(ocp, 2) + ocp = Model(); __time!(ocp, 0, 1); state!(ocp, 2); control!(ocp, 2) __constraint!(ocp, :initial, 1:2, [0, 1], [1, 2], :c0) __constraint!(ocp, :final, 1:2, [1, 2], [2, 3], :cf) __constraint!(ocp, :control, 1:2, [0, 1], [1, 2], :cu) @@ -645,7 +617,7 @@ end @test constraint(ocp, :cs)([12, 13]) == [12, 13] # constraint already exists - ocp = Model(); time!(ocp, 0, 1); state!(ocp, 2); control!(ocp, 1) + ocp = Model(); __time!(ocp, 0, 1); state!(ocp, 2); control!(ocp, 1) __constraint!(ocp, :initial, Index(1), 0, 1, :c) @test_throws UnauthorizedCall __constraint!(ocp, :final, Index(1), 0, 1, :c) @@ -653,7 +625,7 @@ end @testset "constraint! 5" begin - ocp = Model(); time!(ocp, 0, 1); state!(ocp, 1); control!(ocp, 1) + ocp = Model(); __time!(ocp, 0, 1); state!(ocp, 1); control!(ocp, 1) __constraint!(ocp, :boundary, (x0, xf) -> x0+xf, 0, 0, :cb) __constraint!(ocp, :control, u->u, 0, 0, :cu) __constraint!(ocp, :state, x->x, 0, 0, :cs) @@ -663,7 +635,7 @@ end @test constraint(ocp, :cs)(12) == 12 @test constraint(ocp, :cm)(12, 13) == 12+13 - ocp = Model(); time!(ocp, 0, 1); state!(ocp, 2); control!(ocp, 2) + ocp = Model(); __time!(ocp, 0, 1); state!(ocp, 2); control!(ocp, 2) __constraint!(ocp, :boundary, (x0, xf) -> x0[1]+xf[1], 0, 0, :cb) __constraint!(ocp, :control, u->u[1], 0, 0, :cu) __constraint!(ocp, :state, x->x[1], 0, 0, :cs) @@ -673,7 +645,7 @@ end @test constraint(ocp, :cs)([12, 13]) == 12 @test constraint(ocp, :cm)([12, 13], [14, 15]) == 12+14 - ocp = Model(); time!(ocp, 0, 1); state!(ocp, 3); control!(ocp, 3) + ocp = Model(); __time!(ocp, 0, 1); state!(ocp, 3); control!(ocp, 3) __constraint!(ocp, :boundary, (x0, xf) -> [x0[1]+xf[1], x0[2]+xf[2]], [0, 0], [0, 0], :cb) __constraint!(ocp, :control, u->u[1:2], [0, 0], [0, 0], :cu) __constraint!(ocp, :state, x->x[1:2], [0, 0], [0, 0], :cs) @@ -684,7 +656,7 @@ end @test constraint(ocp, :cm)([12, 13, 14], [15, 16, 17]) == [12+15, 13+16] # constraint already exists - ocp = Model(); time!(ocp, 0, 1); state!(ocp, 2); control!(ocp, 1) + ocp = Model(); __time!(ocp, 0, 1); state!(ocp, 2); control!(ocp, 1) __constraint!(ocp, :control, u->u, 0, 1, :c) @test_throws UnauthorizedCall __constraint!(ocp, :control, u->u, 0, 1, :c) @@ -692,7 +664,7 @@ end @testset "constraint! 6" begin - ocp = Model(); time!(ocp, 0, 1); state!(ocp, 1); control!(ocp, 1) + ocp = Model(); __time!(ocp, 0, 1); state!(ocp, 1); control!(ocp, 1) __constraint!(ocp, :boundary, (x0, xf) -> x0+xf, 0, 1, :cb) __constraint!(ocp, :control, u->u, 0, 1, :cu) __constraint!(ocp, :state, x->x, 0, 1, :cs) @@ -702,7 +674,7 @@ end @test constraint(ocp, :cs)(12) == 12 @test constraint(ocp, :cm)(12, 13) == 12+13 - ocp = Model(); time!(ocp, 0, 1); state!(ocp, 2); control!(ocp, 2) + ocp = Model(); __time!(ocp, 0, 1); state!(ocp, 2); control!(ocp, 2) __constraint!(ocp, :boundary, (x0, xf) -> x0[1]+xf[1], 0, 1, :cb) __constraint!(ocp, :control, u->u[1], 0, 1, :cu) __constraint!(ocp, :state, x->x[1], 0, 1, :cs) @@ -712,7 +684,7 @@ end @test constraint(ocp, :cs)([12, 13]) == 12 @test constraint(ocp, :cm)([12, 13], [14, 15]) == 12+14 - ocp = Model(); time!(ocp, 0, 1); state!(ocp, 2); control!(ocp, 1) + ocp = Model(); __time!(ocp, 0, 1); state!(ocp, 2); control!(ocp, 1) __constraint!(ocp, :boundary, (x0, xf) -> [x0[1]+xf[1], x0[2]+xf[2]], [0, 0], [1, 1], :cb) __constraint!(ocp, :control, u->u[1:2], [0, 0], [1, 1], :cu) __constraint!(ocp, :state, x->x[1:2], [0, 0], [1, 1], :cs) @@ -732,7 +704,7 @@ end x0 = 7 xf = 8 ocp = Model(variable=true) - time!(ocp, 0, 1) + __time!(ocp, 0, 1) variable!(ocp, 4) state!(ocp, 1) control!(ocp, 1) @@ -757,7 +729,7 @@ end x0 = 7 xf = 8 ocp = Model(variable=true) - time!(ocp, 0, 1) + __time!(ocp, 0, 1) variable!(ocp, 4) state!(ocp, 1) control!(ocp, 1) @@ -784,19 +756,19 @@ end @testset "constraint! 9" begin - ocp = Model(); time!(ocp, 0, 1); state!(ocp, 1); control!(ocp, 1) + ocp = Model(); __time!(ocp, 0, 1); state!(ocp, 1); control!(ocp, 1) dynamics!(ocp, (x, u) -> x+u) @test ocp.dynamics(1, 2) == 3 - ocp = Model(); time!(ocp, 0, 1); state!(ocp, 2); control!(ocp, 2) + ocp = Model(); __time!(ocp, 0, 1); state!(ocp, 2); control!(ocp, 2) dynamics!(ocp, (x, u) -> x[1]+u[1]) @test ocp.dynamics([1, 2], [3, 4]) == 4 - ocp = Model(); time!(ocp, 0, 1); state!(ocp, 2); control!(ocp, 2) + ocp = Model(); __time!(ocp, 0, 1); state!(ocp, 2); control!(ocp, 2) dynamics!(ocp, (x, u) -> [x[1]+u[1], x[2]+u[2]]) @test ocp.dynamics([1, 2], [3, 4]) == [4, 6] - ocp = Model(); time!(ocp, 0, 1); state!(ocp, 2); control!(ocp, 1) + ocp = Model(); __time!(ocp, 0, 1); state!(ocp, 2); control!(ocp, 1) dynamics!(ocp, (x, u) -> [x[1]+u, x[2]+u]) @test ocp.dynamics([1, 2], 3) == [4, 5] @@ -804,7 +776,7 @@ end @testset "constraint! 10" begin - ocp = Model(autonomous=false); time!(ocp, 0, 1); state!(ocp, 1); control!(ocp, 1) + ocp = Model(autonomous=false); __time!(ocp, 0, 1); state!(ocp, 1); control!(ocp, 1) __constraint!(ocp, :initial, 0, 1, :c0) __constraint!(ocp, :final, 1, 2, :cf) @test constraint(ocp, :c0)(12, ∅) == 12 @@ -816,31 +788,31 @@ end dummy(u) = u^2 + u - ocp = Model(variable=true); time!(ocp, 0, 1); state!(ocp, 1); control!(ocp, 1); variable!(ocp,3) + ocp = Model(variable=true); __time!(ocp, 0, 1); state!(ocp, 1); control!(ocp, 1); variable!(ocp,3) __constraint!(ocp, :state, 0, 1, :c0) __constraint!(ocp, :control, dummy, 1, 1, :c1) __constraint!(ocp, :variable, 1:2:3, [-Inf,-Inf], [0,0], :c2) - ocp_bis = Model(variable=true); time!(ocp_bis, 0, 1); state!(ocp_bis, 1); control!(ocp_bis, 1); variable!(ocp_bis,3) + ocp_bis = Model(variable=true); __time!(ocp_bis, 0, 1); state!(ocp_bis, 1); control!(ocp_bis, 1); variable!(ocp_bis,3) constraint!(ocp_bis, :state, lb=0, ub=1, label=:c0) constraint!(ocp_bis, :control, f=dummy, ub=1, lb=1, label=:c1) constraint!(ocp_bis, :variable, rg=1:2:3, ub=[0,0], label=:c2) @test ocp.constraints == ocp_bis.constraints - ocp_ter = Model(variable=true); time!(ocp_ter, 0, 1); state!(ocp_ter, 3); control!(ocp_ter, 1); variable!(ocp_ter,1) + ocp_ter = Model(variable=true); __time!(ocp_ter, 0, 1); state!(ocp_ter, 3); control!(ocp_ter, 1); variable!(ocp_ter,1) __constraint!(ocp_ter, :variable, 1, 1, :c0) __constraint!(ocp_ter, :control, dummy, 1, Inf, :c1) __constraint!(ocp_ter, :state, 1:2:3, [0,0], [0,0], :c2) - ocp_quad = Model(variable=true); time!(ocp_quad, 0, 1); state!(ocp_quad, 3); control!(ocp_quad, 1); variable!(ocp_quad,1) + ocp_quad = Model(variable=true); __time!(ocp_quad, 0, 1); state!(ocp_quad, 3); control!(ocp_quad, 1); variable!(ocp_quad,1) constraint!(ocp_quad, :variable, lb=1, ub=1, label=:c0) constraint!(ocp_quad, :control, f=dummy, lb=1, label=:c1) constraint!(ocp_quad, :state, rg=1:2:3, lb=[0,0], ub=[0,0], label=:c2) @test ocp_ter.constraints == ocp_quad.constraints - ocp_error = ocp_error = Model(variable=true); time!(ocp_error, 0, 1); state!(ocp_error, 3); control!(ocp_error, 1); variable!(ocp_error,1) + ocp_error = ocp_error = Model(variable=true); __time!(ocp_error, 0, 1); state!(ocp_error, 3); control!(ocp_error, 1); variable!(ocp_error,1) @test_throws UnauthorizedCall constraint!(ocp_error, :variable) @test_throws UnauthorizedCall constraint!(ocp_error, :control, f=dummy, label=:c1) @test_throws UnauthorizedCall constraint!(ocp_error, :state, rg=1:2:3, label=:c2) @@ -851,7 +823,7 @@ end @testset "remove_constraint! and constraints_labels" begin - ocp = Model(); time!(ocp, 0, 1); state!(ocp, 1); control!(ocp, 1) + ocp = Model(); __time!(ocp, 0, 1); state!(ocp, 1); control!(ocp, 1) __constraint!(ocp, :boundary, (x0, xf) -> x0+xf, 0, 1, :cb) __constraint!(ocp, :control, u->u, 0, 1, :cu) k = constraints_labels(ocp) @@ -866,7 +838,7 @@ end @testset "nlp_constraints without variable" begin - ocp = Model(); time!(ocp, 0, 1); state!(ocp, 2); control!(ocp, 1) + ocp = Model(); __time!(ocp, 0, 1); state!(ocp, 2); control!(ocp, 1) __constraint!(ocp, :initial, Index(2), 10, 10, :ci) __constraint!(ocp, :final, Index(1), 1, 1, :cf) __constraint!(ocp, :control, 0, 1, :cu) @@ -922,7 +894,7 @@ end @testset "nlp_constraints with variable" begin ocp = Model(variable=true) - time!(ocp, 0, 1) + __time!(ocp, 0, 1) variable!(ocp, 4) state!(ocp, 2) control!(ocp, 1) @@ -990,35 +962,35 @@ end @test_throws UnauthorizedCall objective!(ocp, :bolza, (t0, x0, tf, xf) -> 0.5x0^2, (x, u) -> 0.5u^2) ocp = Model() - time!(ocp, 0, 1) + __time!(ocp, 0, 1) state!(ocp, 1) control!(ocp, 1) objective!(ocp, :lagrange, (x, u) -> 0.5u^2) @test ocp.lagrange(1, 2) == 2 ocp = Model() - time!(ocp, 0, 1) + __time!(ocp, 0, 1) state!(ocp, 2) control!(ocp, 2) objective!(ocp, :lagrange, (x, u) -> 0.5u[1]^2) @test ocp.lagrange([1, 2], [3, 4]) == 4.5 ocp = Model() - time!(ocp, 0, 1) + __time!(ocp, 0, 1) state!(ocp, 1) control!(ocp, 1) objective!(ocp, :mayer, (x0, xf) -> 0.5x0^2) @test ocp.mayer(2, 3) == 2 ocp = Model() - time!(ocp, 0, 1) + __time!(ocp, 0, 1) state!(ocp, 2) control!(ocp, 2) objective!(ocp, :mayer, (x0, xf) -> 0.5x0[1]^2) @test ocp.mayer([2, 3], [5, 6]) == 2 ocp = Model() - time!(ocp, 0, 1) + __time!(ocp, 0, 1) state!(ocp, 1) control!(ocp, 1) objective!(ocp, :bolza, (x0, xf) -> 0.5x0^2, (x, u) -> 0.5u^2) @@ -1026,7 +998,7 @@ end @test ocp.lagrange(1, 2) == 2 ocp = Model() - time!(ocp, 0, 1) + __time!(ocp, 0, 1) state!(ocp, 2) control!(ocp, 2) objective!(ocp, :bolza, (x0, xf) -> 0.5x0[1]^2, (x, u) -> 0.5u[1]^2) @@ -1034,7 +1006,7 @@ end @test ocp.lagrange([1, 2], [3, 4]) == 4.5 ocp = Model() - time!(ocp, 0, 1) + __time!(ocp, 0, 1) state!(ocp, 2) control!(ocp, 2) objective!(ocp, :lagrange, (x, u) -> 0.5u[1]^2) @@ -1042,7 +1014,7 @@ end @test isnothing(ocp.mayer) ocp = Model() - time!(ocp, 0, 1) + __time!(ocp, 0, 1) state!(ocp, 2) control!(ocp, 2) objective!(ocp, :mayer, (x0, xf) -> 0.5x0[1]^2) @@ -1058,8 +1030,8 @@ end @test_throws UnauthorizedCall variable!(ocp, 1) ocp = Model() - time!(ocp, 0, 1) - @test_throws UnauthorizedCall time!(ocp, 0, 1) + __time!(ocp, 0, 1) + @test_throws UnauthorizedCall __time!(ocp, 0, 1) ocp = Model() state!(ocp, 1) @@ -1070,28 +1042,28 @@ end @test_throws UnauthorizedCall control!(ocp, 1) ocp = Model() - time!(ocp, 0, 1) + __time!(ocp, 0, 1) state!(ocp, 1) control!(ocp, 1) dynamics!(ocp, (x, u) -> x + u) @test_throws UnauthorizedCall dynamics!(ocp, (x, u) -> x + u) ocp = Model() - time!(ocp, 0, 1) + __time!(ocp, 0, 1) state!(ocp, 1) control!(ocp, 1) objective!(ocp, :mayer, (x0, xf) -> x0 + xf) @test_throws UnauthorizedCall objective!(ocp, :mayer, (x0, xf) -> x0 + xf) ocp = Model() - time!(ocp, 0, 1) + __time!(ocp, 0, 1) state!(ocp, 1) control!(ocp, 1) objective!(ocp, :lagrange, (x, u) -> x + u) @test_throws UnauthorizedCall objective!(ocp, :lagrange, (x, u) -> x + u) ocp = Model() - time!(ocp, 0, 1) + __time!(ocp, 0, 1) state!(ocp, 1) control!(ocp, 1) objective!(ocp, :bolza, (x0, xf) -> x0 + xf, (x, u) -> x + u) diff --git a/test/test_print.jl b/test/test_print.jl index 9d51cba1..e780703a 100644 --- a/test/test_print.jl +++ b/test/test_print.jl @@ -7,7 +7,7 @@ function test_print() ocp = Model(autonomous=false) state!(ocp, 2, "state", ["r", "v"]) # dimension of the state with the names of the components control!(ocp, 1) # dimension of the control - time!(ocp, 0, 1, "s") # initial and final time, with the name of the variable time + __time!(ocp, 0, 1, "s") # initial and final time, with the name of the variable time __constraint!(ocp, :initial, [-1, 0], [-1, 0]) __constraint!(ocp, :final , [ 0, 0], [0, 0]) A = [ 0 1 @@ -27,7 +27,7 @@ function test_print() ocp = Model(autonomous=false) state!(ocp, 1, "y") # dimension of the state with the names of the components control!(ocp, 1, "v") # dimension of the control - time!(ocp, 0, 1, "s") # initial and final time, with the name of the variable time + __time!(ocp, 0, 1, "s") # initial and final time, with the name of the variable time __constraint!(ocp, :initial, -1, -1) __constraint!(ocp, :final , 0, 0) dynamics!(ocp, (t, x, u) -> x+u) @@ -44,7 +44,7 @@ function test_print() variable!(ocp, 1) state!(ocp, 1, "y") # dimension of the state with the names of the components control!(ocp, 2) # dimension of the control - time!(ocp, 0, Index(1), "s") # initial and final time, with the name of the variable time + __time!(ocp, 0, Index(1), "s") # initial and final time, with the name of the variable time __constraint!(ocp, :initial, -1, -1) __constraint!(ocp, :final , 0, 0) dynamics!(ocp, (t, x, u) -> x+u) diff --git a/test/utils.jl b/test/utils.jl new file mode 100644 index 00000000..d0a2b080 --- /dev/null +++ b/test/utils.jl @@ -0,0 +1,85 @@ +# time! + +function __time!(ocp::OptimalControlModel{<: TimeDependence, NonFixed}, t0::Time, indf::Index, name::String=CTBase.__time_name()) + time!(ocp; t0=t0, indf=indf.val, name=name) +end + +function __time!(ocp::OptimalControlModel, t0::Time, indf::Index, name::Symbol) + time!(ocp; t0=t0, indf=indf.val, name=name) +end + +function __time!(ocp::OptimalControlModel{<: TimeDependence, NonFixed}, ind0::Index, tf::Time, name::String=CTBase.__time_name()) + time!(ocp; ind0=ind0.val, tf=tf, name=name) +end + +function __time!(ocp::OptimalControlModel, ind0::Index, tf::Time, name::Symbol) + time!(ocp; ind0=ind0.val, tf=tf, name=name) +end + +function __time!(ocp::OptimalControlModel{<: TimeDependence, NonFixed}, ind0::Index, indf::Index, name::String=CTBase.__time_name()) + time!(ocp; ind0=ind0.val, indf=indf.val, name=name) +end + +function __time!(ocp::OptimalControlModel, ind0::Index, indf::Index, name::Symbol) + time!(ocp; ind0=ind0.val, indf=indf.val, name=name) +end + +function __time!(ocp::OptimalControlModel, t0::Time, tf::Time, name::String=CTBase.__time_name()) + time!(ocp; t0=t0, tf=tf, name=name) +end + +function __time!(ocp::OptimalControlModel, t0::Time, tf::Time, name::Symbol) + time!(ocp; t0=t0, tf=tf, name=name) +end + +# constraint! + +function __constraint!( + ocp::OptimalControlModel{<: TimeDependence, V}, + type::Symbol, + rg::Index, + lb::Union{ctVector,Nothing}, + ub::Union{ctVector,Nothing}, + label::Symbol=CTBase.__constraint_label()) where {V <: VariableDependence} + + constraint!(ocp, type, rg=rg.val, f=nothing, lb=lb, ub=ub, label=label) + nothing # to force to return nothing + +end + +function __constraint!( + ocp::OptimalControlModel{<: TimeDependence, V}, + type::Symbol, + rg::OrdinalRange{<:Integer}, + lb::Union{ctVector,Nothing}, + ub::Union{ctVector,Nothing}, + label::Symbol=CTBase.__constraint_label()) where {V <: VariableDependence} + + constraint!(ocp, type, rg=rg, f=nothing, lb=lb, ub=ub, label=label) + nothing # to force to return nothing + +end + +function __constraint!( + ocp::OptimalControlModel, + type::Symbol, + lb::Union{ctVector,Nothing}, + ub::Union{ctVector,Nothing}, + label::Symbol=CTBase.__constraint_label()) + + constraint!(ocp, type, rg=nothing, f=nothing, lb=lb, ub=ub, label=label) + nothing # to force to return nothing + +end + +function __constraint!( + ocp::OptimalControlModel{T, V}, + type::Symbol, + f::Function, + lb::Union{ctVector,Nothing}, + ub::Union{ctVector,Nothing}, + label::Symbol=CTBase.__constraint_label()) where {T, V} + + constraint!(ocp, type, rg=nothing, f=f, lb=lb, ub=ub, label=label) + nothing # to force to return nothing +end \ No newline at end of file