compute_tableau: Improve efficiency

fs11_01
Alinson S. Xavier 2 months ago
parent 4158fccf12
commit 1296182744

@ -296,7 +296,7 @@ function compute_gmi(data::ProblemData, tableau::Tableau)::ConstraintSet
end end
end end
end end
@timeit "Resize arrays to actual size" begin @timeit "Resize arrays to actual size" begin
resize!(lhs_I, nnz_count) resize!(lhs_I, nnz_count)
resize!(lhs_J, nnz_count) resize!(lhs_J, nnz_count)

@ -271,7 +271,7 @@ function collect_gmi_FisSal2011(
max_pool_size_mb = 1024, max_pool_size_mb = 1024,
optimizer, optimizer,
silent_solver=true, silent_solver=true,
time_limit = 900, time_limit = 3_600,
variant = :fast, variant = :fast,
) )
variant in [:subg, :hybr, :fast, :faster] || error("unknown variant: $variant") variant in [:subg, :hybr, :fast, :faster] || error("unknown variant: $variant")
@ -638,7 +638,8 @@ function collect_gmi_FisSal2011(
if round == 1 if round == 1
@printf( @printf(
" %8s %10s %9s %9s %9s %9s %4s %8s %8s %8s\n", " %8s %8s %10s %9s %9s %9s %9s %4s %8s %8s %8s\n",
"time",
"round", "round",
"obj", "obj",
"cl_curr", "cl_curr",
@ -659,8 +660,9 @@ function collect_gmi_FisSal2011(
if log_should_print if log_should_print
last_print_time = time() last_print_time = time()
@printf( @printf(
"%c %8d %10.3e %9.2e %9.2e %9d %9.2f %4d %8.2e %8.2e %8.2e\n", "%c %8.2f %8d %10.3e %9.2e %9.2e %9d %9.2f %4d %8.2e %8.2e %8.2e\n",
log_prefix, log_prefix,
time() - initial_time,
round, round,
obj_curr, obj_curr,
gapcl_curr, gapcl_curr,

@ -73,47 +73,65 @@ function compute_tableau(
factor = klu(sparse(lhs_b')) factor = klu(sparse(lhs_b'))
end end
@timeit "Compute tableau" begin @timeit "Initialize sparse arrays" begin
@timeit "Initialize sparse arrays" begin tableau_rhs::Array{Float64} = zeros(length(rows))
tableau_rhs = zeros(length(rows)) tableau_lhs_I::Array{Int} = Int[]
tableau_lhs_I = Int[] tableau_lhs_J::Array{Int} = Int[]
tableau_lhs_J = Int[] tableau_lhs_V::Array{Float64} = Float64[]
tableau_lhs_V = Float64[] estimated_nnz::Int = length(rows) * ncols ÷ 20
sizehint!(tableau_lhs_I, estimated_nnz)
# Heuristic: 5% sparsity sizehint!(tableau_lhs_J, estimated_nnz)
estimated_nnz = max(div(length(rows) * ncols, 20), length(rows)) sizehint!(tableau_lhs_V, estimated_nnz)
sizehint!(tableau_lhs_I, estimated_nnz) e::Array{Float64} = zeros(nrows)
sizehint!(tableau_lhs_J, estimated_nnz) sol::Array{Float64} = zeros(nrows)
sizehint!(tableau_lhs_V, estimated_nnz) tableau_row::Array{Float64} = zeros(ncols)
end
A = data.constr_lhs'
b = data.constr_ub
for k in eachindex(rows)
@timeit "Solve" begin
fill!(e, 0.0)
e[rows[k]] = 1.0
ldiv!(sol, factor, e)
end end
for k in eachindex(rows) @timeit "Compute row" begin
@timeit "Prepare inputs" begin mul!(tableau_row, A, sol)
i = rows[k] tableau_rhs[k] = dot(sol, b)
e = zeros(nrows) end
e[i] = 1.0
end needed_space = length(tableau_lhs_I) + ncols
@timeit "Solve" begin if needed_space > estimated_nnz
sol = factor \ e @timeit "Grow arrays" begin
end estimated_nnz *= 2
@timeit "Compute row" begin sizehint!(tableau_lhs_I, estimated_nnz)
tableau_row = sol' * data.constr_lhs sizehint!(tableau_lhs_J, estimated_nnz)
tableau_rhs[k] = sol' * data.constr_ub sizehint!(tableau_lhs_V, estimated_nnz)
end end
@timeit "Collect nonzeros" begin end
for j in 1:ncols
val = tableau_row[j] @timeit "Collect nonzeros" begin
if abs(val) > tol for j in 1:ncols
push!(tableau_lhs_I, k) val = tableau_row[j]
push!(tableau_lhs_J, j) if abs(val) > tol
push!(tableau_lhs_V, val) push!(tableau_lhs_I, k)
end push!(tableau_lhs_J, j)
push!(tableau_lhs_V, val)
end end
end end
end end
@timeit "Build sparse matrix" begin end
tableau_lhs = sparse(tableau_lhs_I, tableau_lhs_J, tableau_lhs_V, length(rows), ncols)
end @timeit "Shrink arrays" begin
sizehint!(tableau_lhs_I, 0)
sizehint!(tableau_lhs_J, 0)
sizehint!(tableau_lhs_V, 0)
end
@timeit "Build sparse matrix" begin
tableau_lhs = sparse(tableau_lhs_I, tableau_lhs_J, tableau_lhs_V, length(rows), ncols)
end end
@timeit "Compute tableau objective row" begin @timeit "Compute tableau objective row" begin

Loading…
Cancel
Save