mirror of
https://github.com/ANL-CEEESA/MIPLearn.jl.git
synced 2025-12-06 16:38:51 -06:00
compute_tableau: Compute directly in compressed row format
This commit is contained in:
@@ -74,15 +74,15 @@ function compute_tableau(
|
|||||||
factor = klu(sparse(lhs_b'))
|
factor = klu(sparse(lhs_b'))
|
||||||
end
|
end
|
||||||
|
|
||||||
@timeit "Initialize sparse arrays" begin
|
@timeit "Initialize arrays" begin
|
||||||
tableau_rhs::Array{Float64} = zeros(length(rows))
|
num_rows = length(rows)
|
||||||
tableau_lhs_I::Array{Int} = Int[]
|
tableau_rhs::Array{Float64} = zeros(num_rows)
|
||||||
tableau_lhs_J::Array{Int} = Int[]
|
tableau_rowptr::Array{Int} = zeros(Int, num_rows + 1)
|
||||||
tableau_lhs_V::Array{Float64} = Float64[]
|
tableau_colval::Array{Int} = Int[]
|
||||||
estimated_nnz::Int = round(length(rows) * ncols * estimated_density)
|
tableau_nzval::Array{Float64} = Float64[]
|
||||||
sizehint!(tableau_lhs_I, estimated_nnz)
|
estimated_nnz::Int = round(num_rows * ncols * estimated_density)
|
||||||
sizehint!(tableau_lhs_J, estimated_nnz)
|
sizehint!(tableau_colval, estimated_nnz)
|
||||||
sizehint!(tableau_lhs_V, estimated_nnz)
|
sizehint!(tableau_nzval, estimated_nnz)
|
||||||
e::Array{Float64} = zeros(nrows)
|
e::Array{Float64} = zeros(nrows)
|
||||||
sol::Array{Float64} = zeros(nrows)
|
sol::Array{Float64} = zeros(nrows)
|
||||||
tableau_row::Array{Float64} = zeros(ncols)
|
tableau_row::Array{Float64} = zeros(ncols)
|
||||||
@@ -90,49 +90,48 @@ function compute_tableau(
|
|||||||
|
|
||||||
A = data.constr_lhs'
|
A = data.constr_lhs'
|
||||||
b = data.constr_ub
|
b = data.constr_ub
|
||||||
|
tableau_rowptr[1] = 1
|
||||||
|
|
||||||
for k in eachindex(rows)
|
@timeit "Process rows" begin
|
||||||
@timeit "Solve" begin
|
for k in eachindex(rows)
|
||||||
fill!(e, 0.0)
|
@timeit "Solve" begin
|
||||||
e[rows[k]] = 1.0
|
fill!(e, 0.0)
|
||||||
ldiv!(sol, factor, e)
|
e[rows[k]] = 1.0
|
||||||
end
|
ldiv!(sol, factor, e)
|
||||||
|
|
||||||
@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_J, estimated_nnz)
|
|
||||||
sizehint!(tableau_lhs_V, estimated_nnz)
|
|
||||||
end
|
end
|
||||||
end
|
@timeit "Compute row" begin
|
||||||
|
mul!(tableau_row, A, sol)
|
||||||
@timeit "Collect nonzeros" begin
|
tableau_rhs[k] = dot(sol, b)
|
||||||
for j in 1:ncols
|
end
|
||||||
val = tableau_row[j]
|
needed_space = length(tableau_colval) + ncols
|
||||||
if abs(val) > tol
|
if needed_space > estimated_nnz
|
||||||
push!(tableau_lhs_I, k)
|
@timeit "Grow arrays" begin
|
||||||
push!(tableau_lhs_J, j)
|
estimated_nnz *= 2
|
||||||
push!(tableau_lhs_V, val)
|
sizehint!(tableau_colval, estimated_nnz)
|
||||||
|
sizehint!(tableau_nzval, estimated_nnz)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@timeit "Collect nonzeros for row" begin
|
||||||
|
for j in 1:ncols
|
||||||
|
val = tableau_row[j]
|
||||||
|
if abs(val) > tol
|
||||||
|
push!(tableau_colval, j)
|
||||||
|
push!(tableau_nzval, val)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
tableau_rowptr[k + 1] = length(tableau_colval) + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@timeit "Shrink arrays" begin
|
@timeit "Shrink arrays" begin
|
||||||
sizehint!(tableau_lhs_I, 0)
|
sizehint!(tableau_colval, length(tableau_colval))
|
||||||
sizehint!(tableau_lhs_J, 0)
|
sizehint!(tableau_nzval, length(tableau_nzval))
|
||||||
sizehint!(tableau_lhs_V, 0)
|
|
||||||
end
|
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_transposed = SparseMatrixCSC(ncols, num_rows, tableau_rowptr, tableau_colval, tableau_nzval)
|
||||||
|
tableau_lhs = transpose(tableau_lhs_transposed)
|
||||||
end
|
end
|
||||||
|
|
||||||
@timeit "Compute tableau objective row" begin
|
@timeit "Compute tableau objective row" begin
|
||||||
|
|||||||
Reference in New Issue
Block a user