Skip to content

Commit

Permalink
Fix show for problems with variables containing constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed May 10, 2024
1 parent 1b3a4bb commit eb6fdd7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/utilities/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,16 @@ function TreePrint.print_tree(io::IO, p::Problem, args...; kwargs...)
args...;
kwargs...,
)
if !isempty(p.constraints)
all_constraints = copy(p.constraints)
for leaf in AbstractTrees.Leaves(p)
if leaf isa AbstractVariable
append!(all_constraints, get_constraints(leaf))
end
end
if !isempty(all_constraints)
TreePrint.print_tree(
io,
ProblemConstraintsRoot(p.constraints),
ProblemConstraintsRoot(all_constraints),
args...;
kwargs...,
)
Expand Down
10 changes: 10 additions & 0 deletions test/test_utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1325,6 +1325,16 @@ function test_Constant_complex()
return
end

function test_show_with_variable_constraints()
x = Variable()
add_constraint!(x, x >= 1)
p = minimize(x)
tree = sprint(show, p)
@test occursin("subject to", tree)
@test occursin("≥ constraint (affine)", tree)
return
end

end # TestUtilities

TestUtilities.runtests()

0 comments on commit eb6fdd7

Please sign in to comment.