Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the linear solver CholmodSQD #92

Merged
merged 1 commit into from
Mar 24, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 additions & 11 deletions src/KKT/cholmod.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ mutable struct CholmodSQD <: CholmodSolver

# Problem data
A::SparseMatrixCSC{Float64}
θ::Vector{Float64}
θ::Vector{Float64} # diagonal scaling
regP::Vector{Float64} # primal-dual regularization
regD::Vector{Float64} # dual regularization
ξ::Vector{Float64} # right-hand side of the augmented system

# Left-hand side matrix
S::SparseMatrixCSC{Float64, Int} # TODO: use `CHOLMOD.Sparse` instead
Expand All @@ -70,6 +71,9 @@ mutable struct CholmodSQD <: CholmodSolver
function CholmodSQD(A::AbstractMatrix{Float64})
m, n = size(A)
θ = ones(Float64, n)
regP = ones(Float64, n)
regD = ones(Float64, m)
ξ = zeros(Float64, n+m)

S = [
spdiagm(0 => -θ) A';
Expand All @@ -79,7 +83,7 @@ mutable struct CholmodSQD <: CholmodSolver
# TODO: Symbolic factorization only
F = ldlt(Symmetric(S))

return new(m, n, A, θ, ones(Float64, n), ones(Float64, m), S, F)
return new(m, n, A, θ, regP, regD, ξ, S, F)
end

end
Expand Down Expand Up @@ -148,15 +152,24 @@ function solve!(
)
m, n = kkt.m, kkt.n

# Set-up right-hand side
ξ = [ξd; ξp]
# Set-up the right-hand side
@inbounds for i in 1:n
kkt.ξ[i] = ξd[i]
end
@inbounds for i in 1:m
kkt.ξ[i+n] = ξp[i]
end

# Solve augmented system
d = kkt.F \ ξ
d = kkt.F \ kkt.ξ

# Recover dx, dy
@views dx .= d[1:n]
@views dy .= d[(n+1):(m+n)]
@inbounds for i in 1:n
dx[i] = d[i]
end
@inbounds for i in 1:m
dy[i] = d[i+n]
end

# Iterative refinement
# TODO:
Expand Down Expand Up @@ -186,15 +199,15 @@ end

Linear solver for the 2x2 augmented system
```
[-(Θ⁻¹ + Rp) Aᵀ] [dx] = [xi_d]
[ A Rd] [dy] [xi_p]
[-(Θ⁻¹ + Rp) Aᵀ] [dx] = [ξd]
[ A Rd] [dy] [ξp]
```
with ``A`` sparse.

Uses a Cholesky factorization of the positive definite normal equations system
```
(A * ((Θ⁻¹ + Rp)⁻¹ * Aᵀ + Rd) dy = xi_p + A * (θ⁻¹ + Rp)⁻¹ * xi_d
dx = (Θ⁻¹ + Rp)⁻¹ * (Aᵀ * dy - xi_d)
(A * ((Θ⁻¹ + Rp)⁻¹ * Aᵀ + Rd) dy = ξp + A * (θ⁻¹ + Rp)⁻¹ * ξd
dx = (Θ⁻¹ + Rp)⁻¹ * (Aᵀ * dy - ξd)
```
"""
mutable struct CholmodSPD <: CholmodSolver
Expand Down