|
|
|
@ -74,11 +74,20 @@ function compute_tableau(
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@timeit "Compute tableau" begin
|
|
|
|
|
@timeit "Initialize" begin
|
|
|
|
|
@timeit "Initialize sparse arrays" begin
|
|
|
|
|
tableau_rhs = zeros(length(rows))
|
|
|
|
|
tableau_lhs = zeros(length(rows), ncols)
|
|
|
|
|
tableau_lhs_I = Int[]
|
|
|
|
|
tableau_lhs_J = Int[]
|
|
|
|
|
tableau_lhs_V = Float64[]
|
|
|
|
|
|
|
|
|
|
# Heuristic: 5% sparsity
|
|
|
|
|
estimated_nnz = max(div(length(rows) * ncols, 20), length(rows))
|
|
|
|
|
sizehint!(tableau_lhs_I, estimated_nnz)
|
|
|
|
|
sizehint!(tableau_lhs_J, estimated_nnz)
|
|
|
|
|
sizehint!(tableau_lhs_V, estimated_nnz)
|
|
|
|
|
end
|
|
|
|
|
for k in eachindex(1:length(rows))
|
|
|
|
|
|
|
|
|
|
for k in eachindex(rows)
|
|
|
|
|
@timeit "Prepare inputs" begin
|
|
|
|
|
i = rows[k]
|
|
|
|
|
e = zeros(nrows)
|
|
|
|
@ -87,14 +96,23 @@ function compute_tableau(
|
|
|
|
|
@timeit "Solve" begin
|
|
|
|
|
sol = factor \ e
|
|
|
|
|
end
|
|
|
|
|
@timeit "Multiply" begin
|
|
|
|
|
tableau_lhs[k, :] = sol' * data.constr_lhs
|
|
|
|
|
@timeit "Compute row" begin
|
|
|
|
|
tableau_row = sol' * data.constr_lhs
|
|
|
|
|
tableau_rhs[k] = sol' * data.constr_ub
|
|
|
|
|
end
|
|
|
|
|
@timeit "Collect nonzeros" begin
|
|
|
|
|
for j in 1:ncols
|
|
|
|
|
val = tableau_row[j]
|
|
|
|
|
if abs(val) > tol
|
|
|
|
|
push!(tableau_lhs_I, k)
|
|
|
|
|
push!(tableau_lhs_J, j)
|
|
|
|
|
push!(tableau_lhs_V, val)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
@timeit "Sparsify" begin
|
|
|
|
|
tableau_lhs[abs.(tableau_lhs) .<= tol] .= 0
|
|
|
|
|
tableau_lhs = sparse(tableau_lhs)
|
|
|
|
|
@timeit "Build sparse matrix" begin
|
|
|
|
|
tableau_lhs = sparse(tableau_lhs_I, tableau_lhs_J, tableau_lhs_V, length(rows), ncols)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|