diff --git a/src/checking.jl b/src/checking.jl index 99f248cf..6375904b 100644 --- a/src/checking.jl +++ b/src/checking.jl @@ -18,7 +18,7 @@ Throw ```UnauthorizedCall``` exception if the state of an ocp is not set. """ function __check_state_set(ocp::OptimalControlModel) - __is_state_not_set(ocp) && throw(UnauthorizedCall("the state dimension has to be set before. Use state!.")) + __is_state_not_set(ocp) && throw(UnauthorizedCall("the state dimension has to be set before.")) end """ @@ -28,7 +28,7 @@ Throw ```UnauthorizedCall``` exception if the control of an ocp is not set. """ function __check_control_set(ocp::OptimalControlModel) - __is_control_not_set(ocp) && throw(UnauthorizedCall("the control dimension has to be set before. Use control!.")) + __is_control_not_set(ocp) && throw(UnauthorizedCall("the control dimension has to be set before.")) end """ @@ -38,7 +38,7 @@ Throw ```UnauthorizedCall``` exception if the time of an ocp is not set. """ function __check_is_time_set(ocp::OptimalControlModel) - __is_time_not_set(ocp) && throw(UnauthorizedCall("the time dimension has to be set before. Use time!.")) + __is_time_not_set(ocp) && throw(UnauthorizedCall("the time dimension has to be set before.")) end """ @@ -48,7 +48,7 @@ Throw ```UnauthorizedCall``` exception if the variable of an ocp is not set. """ function __check_variable_set(ocp::OptimalControlModel{<:TimeDependence, NonFixed}) - __is_variable_not_set(ocp) && throw(UnauthorizedCall("the variable dimension has to be set before. Use variable!.")) + __is_variable_not_set(ocp) && throw(UnauthorizedCall("the variable dimension has to be set before.")) end """ diff --git a/src/model.jl b/src/model.jl index 93a6569d..d59bcedb 100644 --- a/src/model.jl +++ b/src/model.jl @@ -174,7 +174,7 @@ function variable!( # checkings is_fixed(ocp) && throw(UnauthorizedCall("the ocp has no variable, you cannot use variable! function.")) - __is_variable_set(ocp) && throw(UnauthorizedCall("the variable has already been set. Use variable! once.")) + __is_variable_set(ocp) && throw(UnauthorizedCall("the variable has already been set.")) (q > 1) && (size(components_names, 1) ≠ q) && throw(IncorrectArgument("the number of variable names must be equal to the variable dimension")) ocp.variable_dimension = q @@ -256,7 +256,7 @@ function state!( components_names::Vector{String}=__state_components_names(n, name)) # checkings - __is_state_set(ocp) && throw(UnauthorizedCall("the state has already been set. Use state! once.")) + __is_state_set(ocp) && throw(UnauthorizedCall("the state has already been set.")) (n > 1) && (size(components_names, 1) ≠ n) && throw(IncorrectArgument("the number of state names must be equal to the state dimension")) ocp.state_dimension = n @@ -342,7 +342,7 @@ function control!( components_names::Vector{String}=__control_components_names(m, name)) # checkings - __is_control_set(ocp) && throw(UnauthorizedCall("the control has already been set. Use control! once.")) + __is_control_set(ocp) && throw(UnauthorizedCall("the control has already been set.")) (m > 1) && (size(components_names, 1) ≠ m) && throw(IncorrectArgument("the number of control names must be equal to the control dimension")) ocp.control_dimension = m @@ -425,7 +425,7 @@ function time!( !isnothing(indf) && !(1 ≤ indf ≤ q) && throw(IncorrectArgument("the index of tf variable must be contained in 1:$q")) # check if the function has been already called - __is_time_set(ocp) && throw(UnauthorizedCall("the time has already been set. Use time! once.")) + __is_time_set(ocp) && throw(UnauthorizedCall("the time has already been set.")) # check consistency !isnothing(t0) && !isnothing(ind0) && throw(IncorrectArgument("Providing t0 and ind0 has no sense. The initial time cannot be fixed and free.")) @@ -673,7 +673,7 @@ function dynamics!(ocp::OptimalControlModel{T, V}, f::Function) where {T <: Time # we check if the dimensions and times have been set __check_all_set(ocp) - __is_dynamics_set(ocp) && throw(UnauthorizedCall("the dynamics has already been set. Use dynamics! once.")) + __is_dynamics_set(ocp) && throw(UnauthorizedCall("the dynamics has already been set.")) ocp.dynamics = Dynamics(f, T, V) @@ -710,7 +710,7 @@ function objective!(ocp::OptimalControlModel{T, V}, type::Symbol, f::Function, # we check if the dimensions and times have been set __check_all_set(ocp) - __is_objective_set(ocp) && throw(UnauthorizedCall("the objective has already been set. Use objective! once.")) + __is_objective_set(ocp) && throw(UnauthorizedCall("the objective has already been set.")) # check the validity of the criterion !__is_criterion_valid(criterion) && throw(IncorrectArgument("the following criterion is not valid: " * String(criterion) * @@ -755,7 +755,7 @@ function objective!(ocp::OptimalControlModel{T, V}, type::Symbol, g::Function, f # we check if the dimensions and times have been set __check_all_set(ocp) - __is_objective_set(ocp) && throw(UnauthorizedCall("the objective has already been set. Use objective! once.")) + __is_objective_set(ocp) && throw(UnauthorizedCall("the objective has already been set.")) # check the validity of the criterion !__is_criterion_valid(criterion) && throw(IncorrectArgument("the following criterion is not valid: " * String(criterion) * diff --git a/src/onepass.jl b/src/onepass.jl index ebf8e501..1651cf21 100644 --- a/src/onepass.jl +++ b/src/onepass.jl @@ -30,9 +30,13 @@ $(TYPEDEF) t_dep::Bool=false end -__init_aliases() = begin +__init_aliases(;max_dim=20) = begin al = OrderedDict{Symbol, Union{Real, Symbol, Expr}}() - for i ∈ 1:9 al[Symbol(:R, ctupperscripts(i))] = :( R^$i ) end + for i ∈ 1:max_dim al[Symbol(:R, ctupperscripts(i))] = :( R^$i ) end + al[:<=] = :≤ + al[:>=] = :≥ + al[:derivative] = :∂ + al[:integral] = :∫ al end diff --git a/test/test_onepass.jl b/test/test_onepass.jl index ff95caa4..e2f49648 100644 --- a/test/test_onepass.jl +++ b/test/test_onepass.jl @@ -2389,7 +2389,65 @@ end ∫( u(t)^2 ) / 2 → min # forbidden end +end + +# --------------------------------------------------------------- +# --------------------------------------------------------------- +@testset "non unicode keywords" begin + println("non unicode keywords testset...") + # -------------------------------- + # min + t0 = 0 + tf = 1 + @def o begin + t ∈ [ t0, tf ], time + x ∈ R^2, state + u ∈ R, control + x(t0) == [ -1, 0 ], (1) + x(tf) == [ 0, 0 ] + derivative(x)(t) == A * x(t) + B * u(t) + integral( 0.5u(t)^2 ) → min + end + x = [ 1, 2 ] + x0 = 2 * x + xf = 3 * x + u = -1 + A = [ 0 1 + 0 0 ] + B = [ 0 + 1 ] + @test constraint(o, :eq1)(x0, xf) == x0 + @test o.dynamics(x, u) == A * x + B * u + @test o.lagrange(x, u) == 0.5u^2 + @test o.criterion == :min + + @def o begin + z ∈ R, variable + t ∈ [ 0, 1 ], time + x ∈ R², state + u ∈ R, control + r = x₁ + v = x₂ + 0 <= r(0) - z <= 1, (1) + 0 <= v(1)^2 <= 1, (2) + [ 0, 0 ] <= x(0) <= [ 1, 1 ], (♡) + z >= 0, (3) + ẋ(t) == [ v(t), r(t)^2 + z ] + ∫( u(t)^2 + z * x₁(t) ) → min + end + x0 = [ 2, 3 ] + xf = [ 4, 5 ] + x = [ 1, 2 ] + u = 3 + z = 4 + @test constraint(o, :eq1)(x0, xf, z) == x0[1] - z + @test constraint(o, :eq2)(x0, xf, z) == xf[2]^2 + @test constraint(o, Symbol("♡"))(x0, xf, z) == x0 + @test constraint(o, :eq3)(z) == z + @test o.dynamics(x, u, z) == [ x[2], x[1]^2 + z ] + @test o.lagrange(x, u, z) == u^2 + z * x[1] + end end \ No newline at end of file