Skip to content

Commit e0a056a

Browse files
committed
Beautify display of OptimizationParameter name tuples and dicts
1 parent ff776bd commit e0a056a

File tree

1 file changed

+45
-2
lines changed

1 file changed

+45
-2
lines changed

src/OptimizationParameters.jl

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,52 @@ function Base.show(io::IO, op::OptimizationParameter{S, TX, TF, TB, DV}
3333
println(io, "├─ value:\t$(op.x0)")
3434
println(io, "├─ lower bound:\t$(op.lb)")
3535
println(io, "├─ upper bound:\t$(op.ub)")
36-
print(io, "└─ scaling:\t$(op.scaling)")
36+
println(io, "└─ scaling:\t$(op.scaling)")
3737
else
38-
print(io, "└─ value:\t$(op.x0)")
38+
println(io, "└─ value:\t$(op.x0)")
39+
end
40+
41+
end
42+
43+
function Base.show(io::IO, ops::Union{NamedTuple{<:Any, <:Tuple{Vararg{OptimizationParameter}}}, AbstractDict{<:Any, <:OptimizationParameter}})
44+
45+
ndv = sum(count(op.dv) for op in ops)
46+
nconst = sum(length(op.dv) - count(op.dv) for op in ops)
47+
48+
println(io, "$(typeof(ops).name.name) of $(length(ops)) OptimizationParameters")
49+
50+
# Print design variables
51+
println(io, "")
52+
println(io, "├─ $(ndv) design variables")
53+
54+
count_ndv = 0
55+
for (name, op) in pairs(ops)
56+
this_ndv = count(op.dv)
57+
if this_ndv >= 1
58+
59+
count_ndv += this_ndv
60+
61+
branch = count_ndv == ndv ? "└─" : "├─"
62+
63+
println(io, "$(branch) $(rpad(name, 15)):\t$(rpad(op.x0, 15))\t(between $(op.lb) and $(op.ub), scaled by $(op.scaling))")
64+
end
65+
end
66+
67+
# Print constants
68+
println(io, "")
69+
println(io, "└─ $(nconst) constants")
70+
71+
count_nconst = 0
72+
for (name, op) in pairs(ops)
73+
this_nconst = length(op.dv) - count(op.dv)
74+
if this_nconst >= 1
75+
76+
count_nconst += this_nconst
77+
78+
branch = count_nconst == nconst ? "└─" : "├─"
79+
80+
println(io, " $(branch) $(rpad(name, 15)):\t$(op.x0)")
81+
end
3982
end
4083

4184
end

0 commit comments

Comments
 (0)