-
Notifications
You must be signed in to change notification settings - Fork 0
Reorder #95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@jbcaillau Just for fun. Reordering the problem before parsing. |
@ocots what is it supposed to do 😅? note that PRAGMA is inactivated for |
ps. you mean just for fun or just for |
For fun. 😁 |
julia> e = quote
tf ∈ R, variable
t ∈ [t0, tf], time
x = (r, v, m) ∈ R³, state
u ∈ R, control
x(t0) == [r0, v0, m0]
m(tf) == mf, (1)
0 ≤ u(t) ≤ 1
r(t) ≥ r0
0 ≤ v(t) ≤ vmax
PRAGMA(1+1)
ẋ(t) == F0(x(t)) + u(t) * F1(x(t))
r(tf) → max
end;
julia> code = CTParser.order(e)
quote
(tf ∈ R, variable)
(t ∈ [t0, tf], time)
(u ∈ R, control)
x = ((r, v, m) ∈ R³, state)
x(t0) == [r0, v0, m0]
(m(tf) == mf, 1)
0 ≤ u(t) ≤ 1
r(t) ≥ r0
0 ≤ v(t) ≤ vmax
PRAGMA(1 + 1)
ẋ(t) == F0(x(t)) + u(t) * F1(x(t))
r(tf) → max
end and # Wrong order
julia> e = quote
u ∈ R, control
x(t0) == [r0, v0, m0]
r(tf) → max
x = (r, v, m) ∈ R³, state
t ∈ [t0, tf], time
m(tf) == mf, (1)
0 ≤ u(t) ≤ 1
r(t) ≥ r0
0 ≤ v(t) ≤ vmax
ẋ(t) == F0(x(t)) + u(t) * F1(x(t))
PRAGMA(1+1)
tf ∈ R, variable
end;
julia> code = CTParser.order(e)
quote
(tf ∈ R, variable)
(t ∈ [t0, tf], time)
(u ∈ R, control)
x = ((r, v, m) ∈ R³, state)
x(t0) == [r0, v0, m0]
(m(tf) == mf, 1)
0 ≤ u(t) ≤ 1
r(t) ≥ r0
0 ≤ v(t) ≤ vmax
ẋ(t) == F0(x(t)) + u(t) * F1(x(t))
PRAGMA(1 + 1)
r(tf) → max
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice
But I haven't introduced it in the One pass more :-) It is not ready for merge. |
@ocots what about this PR? |
In stand by |
@jbcaillau What do you prefer? julia> o = CTParser.@def begin
u ∈ R, control
x(t0) == [r0, v0, m0]
r(tf) → max
x = (r, v, m) ∈ R³, state
t ∈ [t0, tf], time
m(tf) == mf, (1)
0 ≤ u(t) ≤ 1
r(t) ≥ r0
0 ≤ v(t) ≤ vmax
ẋ(t) == F0(x(t)) + u(t) * F1(x(t))
PRAGMA(1+1)
tf ∈ R, variable
end
Abstract definition:
tf ∈ R, variable
t ∈ [t0, tf], time
u ∈ R, control
x = ((r, v, m) ∈ R³, state)
x(t0) == [r0, v0, m0]
m(tf) == mf, 1
0 ≤ u(t) ≤ 1
r(t) ≥ r0
0 ≤ v(t) ≤ vmax
ẋ(t) == F0(x(t)) + u(t) * F1(x(t))
PRAGMA(1 + 1)
r(tf) → max
The (autonomous) optimal control problem is of the form:
minimize J(x, u, tf) = g(x(0), x(tf), tf)
subject to
ẋ(t) = f(x(t), u(t), tf), t in [0, tf] a.e.,
ϕ₋ ≤ ϕ(x(0), x(tf), tf) ≤ ϕ₊,
x₋ ≤ x(t) ≤ x₊,
u₋ ≤ u(t) ≤ u₊,
where x(t) = (r(t), v(t), m(t)) ∈ R³, u(t) ∈ R and tf ∈ R.
Declarations (* required):
╭──────────┬────────┬────────┬──────────┬─────────────┬───────────┬────────────╮
│ variable │ times* │ state* │ control* │ constraints │ dynamics* │ objective* │
├──────────┼────────┼────────┼──────────┼─────────────┼───────────┼────────────┤
│ V │ V │ V │ V │ V │ V │ V │
╰──────────┴────────┴────────┴──────────┴─────────────┴───────────┴────────────╯ or julia> o = CTParser.@def begin
u ∈ R, control
x(t0) == [r0, v0, m0]
r(tf) → max
x = (r, v, m) ∈ R³, state
t ∈ [t0, tf], time
m(tf) == mf, (1)
0 ≤ u(t) ≤ 1
r(t) ≥ r0
0 ≤ v(t) ≤ vmax
ẋ(t) == F0(x(t)) + u(t) * F1(x(t))
PRAGMA(1+1)
tf ∈ R, variable
end
Abstract definition:
u ∈ R, control
x(t0) == [r0, v0, m0]
r(tf) → max
x = ((r, v, m) ∈ R³, state)
t ∈ [t0, tf], time
m(tf) == mf, 1
0 ≤ u(t) ≤ 1
r(t) ≥ r0
0 ≤ v(t) ≤ vmax
ẋ(t) == F0(x(t)) + u(t) * F1(x(t))
PRAGMA(1 + 1)
tf ∈ R, variable
The (autonomous) optimal control problem is of the form:
minimize J(x, u, tf) = g(x(0), x(tf), tf)
subject to
ẋ(t) = f(x(t), u(t), tf), t in [0, tf] a.e.,
ϕ₋ ≤ ϕ(x(0), x(tf), tf) ≤ ϕ₊,
x₋ ≤ x(t) ≤ x₊,
u₋ ≤ u(t) ≤ u₊,
where x(t) = (r(t), v(t), m(t)) ∈ R³, u(t) ∈ R and tf ∈ R.
Declarations (* required):
╭──────────┬────────┬────────┬──────────┬─────────────┬───────────┬────────────╮
│ variable │ times* │ state* │ control* │ constraints │ dynamics* │ objective* │
├──────────┼────────┼────────┼──────────┼─────────────┼───────────┼────────────┤
│ V │ V │ V │ V │ V │ V │ V │
╰──────────┴────────┴────────┴──────────┴─────────────┴───────────┴────────────╯ |
@ocots i don't get the point 😅 is the point to reorder the definition so that it makes sense? |
:-) Actually, in the first case I store in the definition, the reordered code while in the second case I store the original one. The idea is actually to reorder the code to help parsing but not sure it is a good idea... |
Not enough robust for the moment. This does not work: oo = @def begin
λ ∈ R^2, variable
tf = λ₂
t ∈ [0, tf], time
x ∈ R, state
u ∈ R, control
ẋ(t) == u(t)
tf → min
end because I replace the aliases after variable, time, state and control. julia> e = quote
λ ∈ R^2, variable
tf = λ₂
t ∈ [0, tf], time
x ∈ R, state
u ∈ R, control
ẋ(t) == u(t)
tf → min
end
quote
#= REPL[4]:2 =#
(λ ∈ R ^ 2, variable)
#= REPL[4]:3 =#
tf = λ₂
#= REPL[4]:4 =#
(t ∈ [0, tf], time)
#= REPL[4]:5 =#
(x ∈ R, state)
#= REPL[4]:6 =#
(u ∈ R, control)
#= REPL[4]:7 =#
ẋ(t) == u(t)
#= REPL[4]:8 =#
tf → min
end
julia> code = CTParser.reorder(e)
quote
(λ ∈ R ^ 2, variable)
(t ∈ [0, tf], time)
(x ∈ R, state)
(u ∈ R, control)
tf = λ₂
ẋ(t) == u(t)
tf → min
end
julia> o = eval(CTParser.def_fun(code))
Line 2: (t ∈ [0, tf], time)
ERROR: UndefVarError: `tf` not defined in `Main`
Suggestion: check for spelling errors or missing imports.
Stacktrace:
[1] top-level scope
@ ~/Research/logiciels/dev/control-toolbox/CTParser.jl/src/onepass.jl:109
caused by: UndefVarError: `tf` not defined in `Main`
Suggestion: check for spelling errors or missing imports.
Stacktrace:
[1] top-level scope
@ ~/Research/logiciels/dev/control-toolbox/CTParser.jl/src/onepass.jl:106 |
@ocots indeed. order matters (for aliases, yes). looks error prone to me 😬 |
so you insist 🙃? |
Yes to have something which works! Even if we throw it to trash. I have made something less strict that works always when you reorder something that already works. But to be sure, if the parsing is ok without reordering, I do not reorder. I do it only if needed. So it is a little help. |
No description provided.