Skip to content

Commit 6295a60

Browse files
authored
Merge pull request #28 from control-toolbox/27-dev-remove-exponent-aliases
removed exponent aliases for variable, state and control; not yet for…
2 parents ff5d046 + b144f33 commit 6295a60

2 files changed

Lines changed: 21 additions & 30 deletions

File tree

src/onepass.jl

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,9 @@ function p_alias!(p, p_ocp, a, e; log=false)
224224
a isa Symbol || return __throw("forbidden alias name: $a", p.lnum, p.line)
225225
aa = QuoteNode(a)
226226
ee = QuoteNode(e)
227-
for i in 1:9
228-
p.aliases[Symbol(a, CTBase.ctupperscripts(i))] = :($a^$i)
229-
end
227+
#for i in 1:9
228+
# p.aliases[Symbol(a, CTBase.ctupperscripts(i))] = :($a^$i) # todo: remove? (cf. such aliases now removed for variable, state and control)
229+
#end
230230
p.aliases[a] = e
231231
code = :(LineNumberNode(0, "alias: " * string($aa) * " = " * string($ee)))
232232
return __wrap(code, p.lnum, p.line)
@@ -246,13 +246,10 @@ function p_variable!(p, p_ocp, v, q; components_names=nothing, log=false)
246246
qq = q isa Int ? q : 9
247247
for i in 1:qq
248248
p.aliases[Symbol(v, CTBase.ctindices(i))] = :($v[$i])
249-
end # make: v₁, v₂... if the variable is named v
249+
end # make v₁, v₂... if the variable is named v
250250
for i in 1:qq
251251
p.aliases[Symbol(v, i)] = :($v[$i])
252-
end # make: v1, v2... if the variable is named v
253-
for i in 1:9
254-
p.aliases[Symbol(v, CTBase.ctupperscripts(i))] = :($v^$i)
255-
end # make: v¹, v²... if the variable is named v
252+
end # make v1, v2... if the variable is named v
256253
if (isnothing(components_names))
257254
code = :($prefix.variable!($p_ocp, $q, $vv))
258255
else
@@ -326,13 +323,10 @@ function p_state!(p, p_ocp, x, n; components_names=nothing, log=false)
326323
nn = n isa Int ? n : 9
327324
for i in 1:nn
328325
p.aliases[Symbol(x, CTBase.ctindices(i))] = :($x[$i])
329-
end # Make x₁, x₂... if the state is named x
326+
end # make x₁, x₂... if the state is named x
330327
for i in 1:nn
331328
p.aliases[Symbol(x, i)] = :($x[$i])
332-
end # Make x1, x2... if the state is named x
333-
for i in 1:9
334-
p.aliases[Symbol(x, CTBase.ctupperscripts(i))] = :($x^$i)
335-
end # Make x¹, x²... if the state is named x
329+
end # make x1, x2... if the state is named x
336330
if (isnothing(components_names))
337331
code = :($prefix.state!($p_ocp, $n, $xx))
338332
else
@@ -362,13 +356,10 @@ function p_control!(p, p_ocp, u, m; components_names=nothing, log=false)
362356
mm = m isa Int ? m : 9
363357
for i in 1:mm
364358
p.aliases[Symbol(u, CTBase.ctindices(i))] = :($u[$i])
365-
end # make: u₁, u₂... if the control is named u
359+
end # make u₁, u₂... if the control is named u
366360
for i in 1:mm
367361
p.aliases[Symbol(u, i)] = :($u[$i])
368-
end # make: u1, u2... if the control is named u
369-
for i in 1:9
370-
p.aliases[Symbol(u, CTBase.ctupperscripts(i))] = :($u^$i)
371-
end # make: u¹, u²... if the control is named u
362+
end # make u1, u2... if the control is named u
372363
if (isnothing(components_names))
373364
code = :($prefix.control!($p_ocp, $m, $uu))
374365
else

test/test_onepass.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ function test_onepass()
749749
r = y₃
750750
v = y₄
751751
aa = y₁
752-
(s) == [aa(s), r²(s) + w(s) + z₁, 0, 0]
752+
(s) == [aa(s), r(s)^2 + w(s) + z₁, 0, 0]
753753
0 => min # generic (untested)
754754
end
755755
z = [5, 6]
@@ -780,8 +780,8 @@ function test_onepass()
780780
w R, control
781781
r = y₃
782782
v = y₄
783-
aa = y₁(s) + v³ + z₂
784-
(s) == [aa(s) + w(s)^2, r²(s), 0, 0]
783+
aa = y₁(s) + v^3 + z₂
784+
(s) == [aa(s) + w(s)^2, r(s)^2, 0, 0]
785785
0 => min # generic (untested)
786786
end
787787
z = [5, 6]
@@ -798,8 +798,8 @@ function test_onepass()
798798
w R, control
799799
r = y₃
800800
v = y₄
801-
aa = y₁(0) + v³ + z₂
802-
(__t) == [aa(__t) + (w^2)(__t), r²(__t), 0, 0]
801+
aa = y₁(0) + v^3 + z₂
802+
(__t) == [aa(__t) + (w^2)(__t), r(__t)^2, 0, 0]
803803
aa(0) + y₂(z₁) min
804804
end
805805
z = [5, 6]
@@ -823,7 +823,7 @@ function test_onepass()
823823
u R, control
824824
r = x₁
825825
v = x₂
826-
w = r¹ + 2v³
826+
w = r + 2v^3
827827
r(0) + w(tf) - tf^2 == 0, (1)
828828
derivative(x)(t) == x(t) # generic (untested)
829829
0 => min # generic (untested)
@@ -2548,8 +2548,8 @@ function test_onepass()
25482548
w R, control
25492549
r = y₃
25502550
v = y₄
2551-
aa = y₁(s) + v³ + z₂
2552-
(s) == [aa(s) + (w^2)(s), r²(s), 0, 0]
2551+
aa = y₁(s) + v^3 + z₂
2552+
(s) == [aa(s) + (w^2)(s), r(s)^2, 0, 0]
25532553
r(0) + v(z₁) + z₂ min
25542554
end
25552555
z = [5, 6]
@@ -2567,7 +2567,7 @@ function test_onepass()
25672567
w R, control
25682568
r = y₃
25692569
v = y₄
2570-
aa = y₁ + v³ + z₂
2570+
aa = y₁ + v^3 + z₂
25712571
aa(0) + y₂(z₁) min
25722572
derivative(y)(s) == y(s) # generic (untested)
25732573
end
@@ -2583,8 +2583,8 @@ function test_onepass()
25832583
w R, control
25842584
r = y₃
25852585
v = y₄
2586-
aa = y₁(__t) + v³ + z₂
2587-
(__t) == [aa(__t) + (w^2)(__t), r²(__t), 0, 0]
2586+
aa = y₁(__t) + v^3 + z₂
2587+
(__t) == [aa(__t) + (w^2)(__t), r(__t)^2, 0, 0]
25882588
aa(0) + y₂(z₁) min
25892589
end
25902590
z = [5, 6]
@@ -2805,4 +2805,4 @@ function test_onepass()
28052805
@test __dynamics(o)(0, x, u, z) == [x[2], x[1]^2 + z[1]]
28062806
@test lagrange(o)(0, x, u, z) == u[1]^2 + z[1] * x[1]
28072807
end
2808-
end
2808+
end

0 commit comments

Comments
 (0)