Skip to content

Commit de2b491

Browse files
Merge pull request #10 from EdoAlvarezR/master
Beautify display of OptimizationParameters
2 parents 9c24656 + e0a056a commit de2b491

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "OptimizationParameters"
22
uuid = "7e4d55e1-29a6-451b-8e82-71170a6dda04"
33
authors = ["Taylor McDonnell <taylor.golden.mcdonnell@gmail.com> and contributors"]
4-
version = "0.1.0"
4+
version = "0.1.1"
55

66
[deps]
77
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"

src/OptimizationParameters.jl

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,67 @@ end
2222
Base.size(::OptimizationParameter{S, TX, TF, TB, DV}) where {S, TX, TF, TB, DV} = S
2323
Base.eltype(::OptimizationParameter{S, TX, TF, TB, DV}) where {S, TX, TF, TB, DV} = TX
2424

25+
function Base.show(io::IO, op::OptimizationParameter{S, TX, TF, TB, DV}
26+
) where {S, TX, TF, TB, DV}
27+
28+
type = DV ? "Design variable" : "Constant"
29+
30+
println(io, "$(type) OptimizationParameter (type $(TX), size $(size(op)))")
31+
println(io, "├─ description:\t$(op.description)")
32+
if DV
33+
println(io, "├─ value:\t$(op.x0)")
34+
println(io, "├─ lower bound:\t$(op.lb)")
35+
println(io, "├─ upper bound:\t$(op.ub)")
36+
println(io, "└─ scaling:\t$(op.scaling)")
37+
else
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
82+
end
83+
84+
end
85+
2586
"""
2687
OptimizationParameter(x0; lb=-Inf, ub=Inf, scaling=1.0, dv=false, description="")
2788

0 commit comments

Comments
 (0)