[JuMP] Speeding up constraint violation inspection

Your issue is building this expression. See Performance tips · JuMP

A simple fix might be:

function inspector(model, TAXA)
    τ = value.(model[:τ])
    x = value.(model[:x])
    triples = Dict{Int, NTuple{3,Int}}()
    for q in TAXA
        worst = 0
        for (i,j,p) in combinations(TAXA,3) 
            q ∉ (i,j,p) || continue
            violation = 2(τ[i,j]+τ[j,q]+τ[p,q]) - τ[i,j] - τ[i,p] - τ[j,p] - (8 + 6*sum(x[q,v,2] for v in TAXA if v∉(i,j,p,q)))
            if violation < worst 
                worst = violation
                triples[q] = (i,j,p)
            end
        end
    end

Now your for loop operate on Float64, not JuMP expressions.

1 Like