Model building is slow when adding a large number of constraints, but the model necessitates a certain type of refrencing of constraints

You’re recomputing in the constraint expressions over and over again:
the constraint you compute is essentially tr(S, vi'vj) which means it will need quadratic computation with the size of vs. But You can precompute vi'*S for all necessary is to cut compute to linear time per (i,j) pair.
Your vertex set here is fully dense, but I assume it’s only to make MWE simpler.

Try something like this:

@time begin
        VS = map(1:n) do i # assumes Vertex_Set_Dict is dense
            vi = Vertex_Set_Dict[i].vector
            @expression(model, [dot(vi, c) for c in eachcol(S)])
        end

        Edge_con = Dict(
            (i, j) => let
                vj = Vertex_Set_Dict[j].vector
                @constraint(model, dot(VS[i], vj) >= 0)
            end for (i, j) in Inclusion_Set
        )

problem formulation with this is already below 0.5s even for n = 300 on my computer.

EDIT:
On a freshly updated JuMP just adding those ~45_000 constraints to the model results in 0.172214 seconds (1.40 M allocations: 66.347 MiB, 10.63% gc time)
That’s ~31 allocations per constraint, @blegat is this a number you expect? looks too large to me?

[4076af6c] JuMP v1.23.6
1 Like