Skip to content

Commit 8096bae

Browse files
committed
added: clearer pretty-print of objects with trees
1 parent f2f5b2e commit 8096bae

File tree

7 files changed

+60
-49
lines changed

7 files changed

+60
-49
lines changed

src/controller/explicitmpc.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,15 @@ end
177177
setconstraint!(::ExplicitMPC; kwargs...) = error("ExplicitMPC does not support constraints.")
178178

179179
function Base.show(io::IO, mpc::ExplicitMPC)
180-
Hp, Hc = mpc.Hp, mpc.Hc
181-
nu, nd = mpc.estim.model.nu, mpc.estim.model.nd
182-
nx̂, nym, nyu = mpc.estim.nx̂, mpc.estim.nym, mpc.estim.nyu
180+
estim, model = mpc.estim, mpc.estim.model
181+
Hp, Hc, nϵ = mpc.Hp, mpc.Hc, mpc.
182+
nu, nd = model.nu, model.nd
183+
nx̂, nym, nyu = estim.nx̂, estim.nym, estim.nyu
183184
n = maximum(ndigits.((Hp, Hc, nu, nx̂, nym, nyu, nd))) + 1
184-
println(io, "$(nameof(typeof(mpc))) controller with a sample time Ts = "*
185-
"$(mpc.estim.model.Ts) s, "*
186-
"$(nameof(typeof(mpc.estim))) estimator and:")
187-
println(io, "$(lpad(Hp, n)) prediction steps Hp")
188-
println(io, "$(lpad(Hc, n)) control steps Hc")
185+
println(io, "$(nameof(typeof(mpc))) controller with a sample time Ts = $(model.Ts) s:")
186+
println(io, "├ estimator: $(nameof(typeof(mpc.estim)))")
187+
println(io, "├ model: $(nameof(typeof(model)))")
188+
println(io, "└ dimensions:")
189189
print_estim_dim(io, mpc.estim, n)
190190
end
191191

src/estimator/internal_model.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -355,10 +355,10 @@ end
355355
function print_estim_dim(io::IO, estim::InternalModel, n)
356356
nu, nd = estim.model.nu, estim.model.nd
357357
nx̂, nym, nyu = estim.nx̂, estim.nym, estim.nyu
358-
println(io, "$(lpad(nu, n)) manipulated inputs u")
359-
println(io, "$(lpad(nx̂, n)) estimated states x̂")
360-
println(io, "$(lpad(nym, n)) measured outputs ym")
361-
println(io, "$(lpad(nyu, n)) unmeasured outputs yu")
362-
print(io, "$(lpad(nd, n)) measured disturbances d")
358+
println(io, "$(lpad(nu, n)) manipulated inputs u")
359+
println(io, "$(lpad(nx̂, n)) estimated states x̂")
360+
println(io, "$(lpad(nym, n)) measured outputs ym")
361+
println(io, "$(lpad(nyu, n)) unmeasured outputs yu")
362+
print(io, "$(lpad(nd, n)) measured disturbances d")
363363
end
364364

src/estimator/mhe.jl

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ include("mhe/construct.jl")
22
include("mhe/execute.jl")
33

44
function Base.show(io::IO, estim::MovingHorizonEstimator)
5-
nu, nd = estim.model.nu, estim.model.nd
5+
model = estim.model
6+
nu, nd = model.nu, model.nd
67
nx̂, nym, nyu = estim.nx̂, estim.nym, estim.nyu
78
n = maximum(ndigits.((nu, nx̂, nym, nyu, nd))) + 1
8-
println(io, "$(nameof(typeof(estim))) estimator with a sample time "*
9-
"Ts = $(estim.model.Ts) s, $(JuMP.solver_name(estim.optim)) optimizer, "*
10-
"$(nameof(typeof(estim.model))) and:")
9+
println(io, "$(nameof(typeof(estim))) estimator with a sample time Ts = $(model.Ts) s:")
10+
println(io, "├ model: $(nameof(typeof(model)))")
11+
println(io, "├ optimizer: $(JuMP.solver_name(estim.optim)) ")
12+
println(io, "└ dimensions:")
1113
print_estim_dim(io, estim, n)
1214
end
1315

@@ -16,11 +18,12 @@ function print_estim_dim(io::IO, estim::MovingHorizonEstimator, n)
1618
nu, nd = estim.model.nu, estim.model.nd
1719
nx̂, nym, nyu = estim.nx̂, estim.nym, estim.nyu
1820
He, nϵ = estim.He, estim.
19-
println(io, "$(lpad(He, n)) estimation steps He")
20-
println(io, "$(lpad(nϵ, n)) slack variable ϵ (estimation constraints)")
21-
println(io, "$(lpad(nu, n)) manipulated inputs u ($(sum(estim.nint_u)) integrating states)")
22-
println(io, "$(lpad(nx̂, n)) estimated states x̂")
23-
println(io, "$(lpad(nym, n)) measured outputs ym ($(sum(estim.nint_ym)) integrating states)")
24-
println(io, "$(lpad(nyu, n)) unmeasured outputs yu")
25-
print(io, "$(lpad(nd, n)) measured disturbances d")
21+
niu, niym = sum(estim.nint_u), sum(estim.nint_ym)
22+
println(io, "$(lpad(He, n)) estimation steps He")
23+
println(io, "$(lpad(nϵ, n)) slack variable ϵ (estimation constraints)")
24+
println(io, "$(lpad(nu, n)) manipulated inputs u ($niu integrating states)")
25+
println(io, "$(lpad(nx̂, n)) estimated states x̂")
26+
println(io, "$(lpad(nym, n)) measured outputs ym ($niym integrating states)")
27+
println(io, "$(lpad(nyu, n)) unmeasured outputs yu")
28+
print(io, "$(lpad(nd, n)) measured disturbances d")
2629
end

src/model/nonlinmodel.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ h!(y0, model::NonLinModel, x0, d0, p) = model.h!(y0, x0, d0, p)
308308
include("solver.jl")
309309

310310
function detailstr(model::NonLinModel{<:Real, <:RungeKutta{N}}) where N
311-
return ", $(nameof(typeof(model.solver)))($N) solver"
311+
return "solver: $(nameof(typeof(model.solver)))($N)"
312312
end
313-
detailstr(::NonLinModel{<:Real, <:EmptySolver}) = ", empty solver"
313+
detailstr(::NonLinModel{<:Real, <:EmptySolver}) = "solver: empty"
314314
detailstr(::NonLinModel) = ""

src/predictive_control.jl

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,20 @@ include("controller/linmpc.jl")
2727
include("controller/nonlinmpc.jl")
2828

2929
function Base.show(io::IO, mpc::PredictiveController)
30+
estim, model = mpc.estim, mpc.estim.model
3031
Hp, Hc, nϵ = mpc.Hp, mpc.Hc, mpc.
31-
nu, nd = mpc.estim.model.nu, mpc.estim.model.nd
32-
nx̂, nym, nyu = mpc.estim.nx̂, mpc.estim.nym, mpc.estim.nyu
32+
nu, nd = model.nu, model.nd
33+
nx̂, nym, nyu = estim.nx̂, estim.nym, estim.nyu
3334
n = maximum(ndigits.((Hp, Hc, nu, nx̂, nym, nyu, nd))) + 1
34-
println(io, "$(nameof(typeof(mpc))) controller with a sample time Ts = "*
35-
"$(mpc.estim.model.Ts) s, $(JuMP.solver_name(mpc.optim)) optimizer, "*
36-
"$(nameof(typeof(mpc.transcription))) transcription, "*
37-
"$(nameof(typeof(mpc.estim))) estimator and:")
38-
println(io, "$(lpad(Hp, n)) prediction steps Hp")
39-
println(io, "$(lpad(Hc, n)) control steps Hc")
40-
println(io, "$(lpad(nϵ, n)) slack variable ϵ (control constraints)")
35+
println(io, "$(nameof(typeof(mpc))) controller with a sample time Ts = $(model.Ts) s:")
36+
println(io, "├ estimator: $(nameof(typeof(mpc.estim)))")
37+
println(io, "├ model: $(nameof(typeof(model)))")
38+
println(io, "├ optimizer: $(JuMP.solver_name(mpc.optim)) ")
39+
println(io, "├ transcription: $(nameof(typeof(mpc.transcription)))")
40+
println(io, "└ dimensions:")
41+
println(io, "$(lpad(Hp, n)) prediction steps Hp")
42+
println(io, "$(lpad(Hc, n)) control steps Hc")
43+
println(io, "$(lpad(nϵ, n)) slack variable ϵ (control constraints)")
4144
print_estim_dim(io, mpc.estim, n)
4245
end
4346

src/sim_model.jl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -372,12 +372,14 @@ function Base.show(io::IO, model::SimModel)
372372
nu, nd = model.nu, model.nd
373373
nx, ny = model.nx, model.ny
374374
n = maximum(ndigits.((nu, nx, ny, nd))) + 1
375-
println(io, "$(nameof(typeof(model))) with a sample time Ts = $(model.Ts) s"*
376-
"$(detailstr(model)) and:")
377-
println(io, "$(lpad(nu, n)) manipulated inputs u")
378-
println(io, "$(lpad(nx, n)) states x")
379-
println(io, "$(lpad(ny, n)) outputs y")
380-
print(io, "$(lpad(nd, n)) measured disturbances d")
375+
details = detailstr(model)
376+
println(io, "$(nameof(typeof(model))) with a sample time Ts = $(model.Ts) s:")
377+
!isempty(details) && println(io, "$details")
378+
println(io, "└ dimensions:")
379+
println(io, "$(lpad(nu, n)) manipulated inputs u")
380+
println(io, "$(lpad(nx, n)) states x")
381+
println(io, "$(lpad(ny, n)) outputs y")
382+
print(io, "$(lpad(nd, n)) measured disturbances d")
381383
end
382384

383385
"Functor allowing callable `SimModel` object as an alias for `evaloutput`."

src/state_estim.jl

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,24 @@ include("estimator/internal_model.jl")
2929
include("estimator/manual.jl")
3030

3131
function Base.show(io::IO, estim::StateEstimator)
32-
nu, nd = estim.model.nu, estim.model.nd
32+
model = estim.model
33+
nu, nd = model.nu, model.nd
3334
nx̂, nym, nyu = estim.nx̂, estim.nym, estim.nyu
3435
n = maximum(ndigits.((nu, nx̂, nym, nyu, nd))) + 1
35-
println(io, "$(nameof(typeof(estim))) estimator with a sample time "*
36-
"Ts = $(estim.model.Ts) s, $(nameof(typeof(estim.model))) and:")
36+
println(io, "$(nameof(typeof(estim))) estimator with a sample time Ts = $(model.Ts) s:")
37+
println(io, "├ model: $(nameof(typeof(estim.model)))")
38+
println(io, "└ dimensions:")
3739
print_estim_dim(io, estim, n)
3840
end
3941

4042
"Print the overall dimensions of the state estimator `estim` with left padding `n`."
4143
function print_estim_dim(io::IO, estim::StateEstimator, n)
4244
nu, nd = estim.model.nu, estim.model.nd
4345
nx̂, nym, nyu = estim.nx̂, estim.nym, estim.nyu
44-
println(io, "$(lpad(nu, n)) manipulated inputs u ($(sum(estim.nint_u)) integrating states)")
45-
println(io, "$(lpad(nx̂, n)) estimated states x̂")
46-
println(io, "$(lpad(nym, n)) measured outputs ym ($(sum(estim.nint_ym)) integrating states)")
47-
println(io, "$(lpad(nyu, n)) unmeasured outputs yu")
48-
print(io, "$(lpad(nd, n)) measured disturbances d")
46+
niu, niym = sum(estim.nint_u), sum(estim.nint_ym)
47+
println(io, "$(lpad(nu, n)) manipulated inputs u ($niu integrating states)")
48+
println(io, "$(lpad(nx̂, n)) estimated states x̂")
49+
println(io, "$(lpad(nym, n)) measured outputs ym ($niym integrating states)")
50+
println(io, "$(lpad(nyu, n)) unmeasured outputs yu")
51+
print(io, "$(lpad(nd, n)) measured disturbances d")
4952
end

0 commit comments

Comments
 (0)