197197AbstractTrees. children (p:: ProblemObjectiveRoot ) = (p. objective,)
198198
199199function AbstractTrees. printnode (io:: IO , p:: ProblemObjectiveRoot )
200- return print (io, string (p. head))
200+ return print (io, " " , string (p. head))
201201end
202202
203203struct ProblemConstraintsRoot
207207AbstractTrees. children (p:: ProblemConstraintsRoot ) = p. constraints
208208
209209function AbstractTrees. printnode (io:: IO , p:: ProblemConstraintsRoot )
210- return print (io, " subject to" )
210+ return print (io, " subject to" )
211211end
212212
213213function TreePrint. print_tree (io:: IO , p:: Problem , args... ; kwargs... )
@@ -234,17 +234,40 @@ function TreePrint.print_tree(io::IO, p::Problem, args...; kwargs...)
234234 return
235235end
236236
237+ function _to_underscore (n:: Integer )
238+ x = Iterators. partition (digits (n), 3 )
239+ return join (reverse (join .(reverse .(x))), ' _' )
240+ end
241+
242+ function _str_with_elements (x, y)
243+ xs, ys = _to_underscore (x), _to_underscore (y)
244+ return " $xs ($ys scalar elements)"
245+ end
246+
237247function Base. show (io:: IO , p:: Problem )
238- TreePrint. print_tree (io, p, MAXDEPTH[], MAXWIDTH[])
239- if p. status == MOI. OPTIMIZE_NOT_CALLED
240- print (io, " \n status: `solve!` not called yet" )
241- else
242- print (io, " \n termination status: $(p. status) " )
243- print (io, " \n primal status: $(primal_status (p)) " )
244- print (io, " \n dual status: $(dual_status (p)) " )
245- end
246- if p. status == " solved"
247- print (io, " with optimal value of $(round (p. optval, digits= 4 )) " )
248+ # Print problem statistics
249+ counts = Counts (p)
250+ println (io, " Problem statistics" )
251+ var_str = _str_with_elements (counts. n_variables, counts. n_scalar_variables)
252+ println (io, " number of variables : " , var_str)
253+ con_str =
254+ _str_with_elements (counts. n_constraints, counts. n_scalar_constraints)
255+ println (io, " number of constraints : " , con_str)
256+ println (io, " number of coefficients : " , counts. n_nonzeros)
257+ println (io, " number of atoms : " , counts. n_atoms)
258+ println (io)
259+ # Print solution summary
260+ println (io, " Solution summary" )
261+ println (io, " termination status : " , p. status)
262+ println (io, " primal status : " , primal_status (p))
263+ println (io, " dual status : " , dual_status (p))
264+ if p. status == MOI. OPTIMAL && p. optval != = nothing
265+ println (io, " objective value : " , round (p. optval; digits = 4 ))
248266 end
267+ println (io)
268+ # Expression tree
269+ println (io, " Expression graph" )
270+ # We offset the depth by 1 so things are printed with a three-space offset.
271+ TreePrint. print_tree (io, p, MAXDEPTH[] + 1 , MAXWIDTH[]; depth = 1 )
249272 return
250273end
0 commit comments