Skip to content

Commit

Permalink
added <= and >=
Browse files Browse the repository at this point in the history
  • Loading branch information
jbcaillau committed Aug 12, 2024
1 parent 7306fd8 commit 2ddb475
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/onepass.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ end
__init_aliases(;max_dim=20) = begin
al = OrderedDict{Symbol, Union{Real, Symbol, Expr}}()
for i 1:max_dim al[Symbol(:R, ctupperscripts(i))] = :( R^$i ) end
al[:<=] = :
al[:>=] = :
al[:derivative] = :∂
al[:integral] = :∫
al
Expand Down
31 changes: 29 additions & 2 deletions test/test_onepass.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2393,8 +2393,8 @@ end

# ---------------------------------------------------------------
# ---------------------------------------------------------------
@testset "derivative and integral non unicode keywords" begin
println("derivative and integral non unicode keywords testset...")
@testset "non unicode keywords" begin
println("non unicode keywords testset...")

# --------------------------------
# min
Expand All @@ -2421,6 +2421,33 @@ end
@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

0 comments on commit 2ddb475

Please sign in to comment.