Skip to content

Commit 58e4b75

Browse files
committed
Merge branch 'main' into onepass
2 parents 1b70320 + 9c156ad commit 58e4b75

File tree

2 files changed

+32
-16
lines changed

2 files changed

+32
-16
lines changed

src/onepass.jl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# onepass
22
# todo:
3-
# - for all p_... functions, write: code = quote ... end; __wrap(code, p.lnum, p.line)
43
# - cannot call solve if problem not fully defined (dynamics not defined...)
54
# - doc: explain projections wrt to t0, tf, t; (...x1...x2...)(t) -> ...gensym1...gensym2... (most internal first)
65
# - test non autonomous cases
@@ -37,14 +36,14 @@ __init_aliases() = begin
3736
al
3837
end
3938

40-
__throw(ex, n, line) = begin
41-
quote
42-
info = string("\nLine ", $n, ": ", $line)
43-
throw(ParsingError(info * "\n" * $ex))
44-
end
39+
__throw(ex, n, line) = quote
40+
local info
41+
info = string("\nLine ", $n, ": ", $line)
42+
throw(ParsingError(info * "\n" * $ex))
4543
end
4644

4745
__wrap(e, n, line) = quote
46+
local ex
4847
try
4948
$e
5049
catch ex

src/print.jl

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,23 @@ function Base.show(io::IO, ::MIME"text/plain", ocp::OptimalControlModel{<: TimeD
2929
@assert hasproperty(ocp.model_expression, :head)
3030

3131
#
32-
#println(io)
32+
println(io)
33+
printstyled(io, "The ", bold=true)
34+
is_time_dependent(ocp) ? printstyled(io, "(non autonomous) ", bold=true) : printstyled(io, "(autonomous) ", bold=true)
35+
printstyled(io, "optimal control problem is given by:\n", bold=true)
36+
println(io)
3337

3438
# print the code
35-
tab = 0
39+
tab = 4
3640
code = striplines(ocp.model_expression)
3741
@match code.head begin
3842
:block => [__print(code.args[i], io, tab) for i eachindex(code.args)]
3943
_ => __print(code, io, tab)
4044
end
41-
42-
elseif __is_complete(ocp) # print the model if is is complete
45+
46+
end
47+
48+
if __is_complete(ocp) # print the model if is is complete
4349

4450
# dimensions
4551
x_dim = ocp.state_dimension
@@ -68,8 +74,11 @@ function Base.show(io::IO, ::MIME"text/plain", ocp::OptimalControlModel{<: TimeD
6874
control_args_names = t_ * u_name * "(" * t_name * ")" * _v
6975

7076
#
71-
printstyled(io, "Optimal control problem of the form:\n")
72-
println(io, "")
77+
println(io)
78+
printstyled(io, "The ", bold=true)
79+
is_time_dependent(ocp) ? printstyled(io, "(non autonomous) ", bold=true) : printstyled(io, "(autonomous) ", bold=true)
80+
printstyled(io, "optimal control problem is of the form:\n", bold=true)
81+
println(io)
7382

7483
# J
7584
printstyled(io, " minimize ", color=:blue); print(io, "J(" * x_name * ", " * u_name * _v * ") = ")
@@ -178,14 +187,22 @@ function Base.show(io::IO, ::MIME"text/plain", ocp::OptimalControlModel{<: TimeD
178187

179188
end
180189

190+
#
191+
println(io)
192+
printstyled(io, "Declarations ", bold=true)
193+
printstyled(io, "(* required):\n", bold=false)
194+
#println(io)
195+
181196
# print table of settings
182-
header = [ "times", "state", "control"]
183-
is_variable_dependent(ocp) && push!(header, "variable")
184-
push!(header, "dynamics", "objective", "constraints")
197+
header = [ "times*", "state*", "control*"]
198+
#is_variable_dependent(ocp) && push!(header, "variable")
199+
push!(header, "variable")
200+
push!(header, "dynamics*", "objective*", "constraints")
185201
data = hcat(__is_time_not_set(ocp) ? "" : "",
186202
__is_state_not_set(ocp) ? "" : "",
187203
__is_control_not_set(ocp) ? "" : "")
188-
is_variable_dependent(ocp) && begin
204+
#is_variable_dependent(ocp) &&
205+
begin
189206
(data = hcat(data,
190207
__is_variable_not_set(ocp) ? "" : ""))
191208
end

0 commit comments

Comments
 (0)