|
22 | 22 | Base.size(::OptimizationParameter{S, TX, TF, TB, DV}) where {S, TX, TF, TB, DV} = S |
23 | 23 | Base.eltype(::OptimizationParameter{S, TX, TF, TB, DV}) where {S, TX, TF, TB, DV} = TX |
24 | 24 |
|
| 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 | + |
25 | 86 | """ |
26 | 87 | OptimizationParameter(x0; lb=-Inf, ub=Inf, scaling=1.0, dv=false, description="") |
27 | 88 |
|
|
0 commit comments