mirror of
https://github.com/ANL-CEEESA/MIPLearn.jl.git
synced 2025-12-06 08:28:52 -06:00
compute_tableau: Improve efficiency
This commit is contained in:
@@ -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,33 +73,45 @@ 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 = zeros(length(rows))
|
tableau_rhs::Array{Float64} = zeros(length(rows))
|
||||||
tableau_lhs_I = Int[]
|
tableau_lhs_I::Array{Int} = Int[]
|
||||||
tableau_lhs_J = Int[]
|
tableau_lhs_J::Array{Int} = Int[]
|
||||||
tableau_lhs_V = Float64[]
|
tableau_lhs_V::Array{Float64} = Float64[]
|
||||||
|
estimated_nnz::Int = length(rows) * ncols ÷ 20
|
||||||
|
sizehint!(tableau_lhs_I, estimated_nnz)
|
||||||
|
sizehint!(tableau_lhs_J, estimated_nnz)
|
||||||
|
sizehint!(tableau_lhs_V, estimated_nnz)
|
||||||
|
e::Array{Float64} = zeros(nrows)
|
||||||
|
sol::Array{Float64} = zeros(nrows)
|
||||||
|
tableau_row::Array{Float64} = zeros(ncols)
|
||||||
|
end
|
||||||
|
|
||||||
# Heuristic: 5% sparsity
|
A = data.constr_lhs'
|
||||||
estimated_nnz = max(div(length(rows) * ncols, 20), length(rows))
|
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
|
||||||
|
|
||||||
|
@timeit "Compute row" begin
|
||||||
|
mul!(tableau_row, A, sol)
|
||||||
|
tableau_rhs[k] = dot(sol, b)
|
||||||
|
end
|
||||||
|
|
||||||
|
needed_space = length(tableau_lhs_I) + ncols
|
||||||
|
if needed_space > estimated_nnz
|
||||||
|
@timeit "Grow arrays" begin
|
||||||
|
estimated_nnz *= 2
|
||||||
sizehint!(tableau_lhs_I, estimated_nnz)
|
sizehint!(tableau_lhs_I, estimated_nnz)
|
||||||
sizehint!(tableau_lhs_J, estimated_nnz)
|
sizehint!(tableau_lhs_J, estimated_nnz)
|
||||||
sizehint!(tableau_lhs_V, estimated_nnz)
|
sizehint!(tableau_lhs_V, estimated_nnz)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
for k in eachindex(rows)
|
|
||||||
@timeit "Prepare inputs" begin
|
|
||||||
i = rows[k]
|
|
||||||
e = zeros(nrows)
|
|
||||||
e[i] = 1.0
|
|
||||||
end
|
|
||||||
@timeit "Solve" begin
|
|
||||||
sol = factor \ e
|
|
||||||
end
|
|
||||||
@timeit "Compute row" begin
|
|
||||||
tableau_row = sol' * data.constr_lhs
|
|
||||||
tableau_rhs[k] = sol' * data.constr_ub
|
|
||||||
end
|
|
||||||
@timeit "Collect nonzeros" begin
|
@timeit "Collect nonzeros" begin
|
||||||
for j in 1:ncols
|
for j in 1:ncols
|
||||||
val = tableau_row[j]
|
val = tableau_row[j]
|
||||||
@@ -111,10 +123,16 @@ function compute_tableau(
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
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
|
@timeit "Build sparse matrix" begin
|
||||||
tableau_lhs = sparse(tableau_lhs_I, tableau_lhs_J, tableau_lhs_V, length(rows), ncols)
|
tableau_lhs = sparse(tableau_lhs_I, tableau_lhs_J, tableau_lhs_V, length(rows), ncols)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
@timeit "Compute tableau objective row" begin
|
@timeit "Compute tableau objective row" begin
|
||||||
sol = factor \ obj_b
|
sol = factor \ obj_b
|
||||||
|
|||||||
Reference in New Issue
Block a user