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)
|
assert_eq(data_s.constr_lhs * sol_opt_s, data_s.constr_lb)
|
||||||
end
|
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
|
for round = 1:max_rounds
|
||||||
log_prefix = ' '
|
log_prefix = ' '
|
||||||
|
|||||||
@@ -74,11 +74,20 @@ function compute_tableau(
|
|||||||
end
|
end
|
||||||
|
|
||||||
@timeit "Compute tableau" begin
|
@timeit "Compute tableau" begin
|
||||||
@timeit "Initialize" begin
|
@timeit "Initialize sparse arrays" begin
|
||||||
tableau_rhs = zeros(length(rows))
|
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
|
end
|
||||||
for k in eachindex(1:length(rows))
|
|
||||||
|
for k in eachindex(rows)
|
||||||
@timeit "Prepare inputs" begin
|
@timeit "Prepare inputs" begin
|
||||||
i = rows[k]
|
i = rows[k]
|
||||||
e = zeros(nrows)
|
e = zeros(nrows)
|
||||||
@@ -87,14 +96,23 @@ function compute_tableau(
|
|||||||
@timeit "Solve" begin
|
@timeit "Solve" begin
|
||||||
sol = factor \ e
|
sol = factor \ e
|
||||||
end
|
end
|
||||||
@timeit "Multiply" begin
|
@timeit "Compute row" begin
|
||||||
tableau_lhs[k, :] = sol' * data.constr_lhs
|
tableau_row = sol' * data.constr_lhs
|
||||||
tableau_rhs[k] = sol' * data.constr_ub
|
tableau_rhs[k] = sol' * data.constr_ub
|
||||||
end
|
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
|
end
|
||||||
@timeit "Sparsify" begin
|
@timeit "Build sparse matrix" begin
|
||||||
tableau_lhs[abs.(tableau_lhs) .<= tol] .= 0
|
tableau_lhs = sparse(tableau_lhs_I, tableau_lhs_J, tableau_lhs_V, length(rows), ncols)
|
||||||
tableau_lhs = sparse(tableau_lhs)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user