I don’t think they are all the same, it’s just that the same variable appears many times before another variable shows up. If you set
Convex.MAXWIDTH[] = typemax(Int);
Convex.MAXDEPTH[] = typemax(Int);
to unrestrict the amount of printing, and then print the final constraint
, you’ll see other ids too if you scroll down enough.
As a possibly nicer way to check this, we can use the fact that Convex.jl’s objects support the AbstractTree interface. First, we modify main
to return constraint
, and then run
constraint = main()
using AbstractTrees
counts = Dict()
for node in AbstractTrees.Leaves(constraint)
if node isa Convex.Variable
current_count = get(counts, node.id_hash, 0)
counts[node.id_hash] = current_count + 1
end
end
which yields
julia> counts
Dict{Any,Any} with 5 entries:
0x21104573583c0ed2 => 1681
0x3c713c740f42a9bb => 1681
0xf335f373fd14a1c0 => 1681
0x764bd22d8542bb71 => 1681
0x94d7782e4003012a => 1681
That is, we’ve found 5 different variables, which each appear 1681 times in constraints
. Note I used AbstractTrees.Leaves
which only iterates over the “leaves” of the tree, meaning the nodes with no children, since this is where variables appear; in other cases you might want a depth-first search or similar (shown in the linked docs).