mirror of
https://github.com/ANL-CEEESA/MIPLearn.jl.git
synced 2025-12-06 08:28:52 -06:00
compute_tableau: Reduce memory requirements
This commit is contained in:
@@ -377,7 +377,7 @@ function collect_gmi_FisSal2011(
|
||||
assert_eq(data_s.constr_lhs * sol_opt_s, data_s.constr_lb)
|
||||
end
|
||||
|
||||
@info "Standard form model has $(length(data.var_lb)) vars, $(length(data.constr_lb)) constrs"
|
||||
@info "Standard form model has $(length(data_s.var_lb)) vars, $(length(data_s.constr_lb)) constrs"
|
||||
|
||||
for round = 1:max_rounds
|
||||
log_prefix = ' '
|
||||
|
||||
@@ -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
|
||||
@timeit "Sparsify" begin
|
||||
tableau_lhs[abs.(tableau_lhs) .<= tol] .= 0
|
||||
tableau_lhs = sparse(tableau_lhs)
|
||||
end
|
||||
end
|
||||
end
|
||||
@timeit "Build sparse matrix" begin
|
||||
tableau_lhs = sparse(tableau_lhs_I, tableau_lhs_J, tableau_lhs_V, length(rows), ncols)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user