66
77"""
88 struct ColoringResult
9- result::SparseMatrixColorings .TreeSetColoringResult
9+ result::SMC .TreeSetColoringResult
1010 local_indices::Vector{Int} # map from local to global indices
1111 end
1212
1313Wrapper around TreeSetColoringResult that also stores local_indices mapping.
1414"""
15- struct ColoringResult{R<: SparseMatrixColorings .AbstractColoringResult }
15+ struct ColoringResult{R<: SMC .AbstractColoringResult }
1616 result:: R
1717 local_indices:: Vector{Int} # map from local to global indices
1818end
2121 _hessian_color_preprocess(
2222 edgelist,
2323 num_total_var,
24- algo::SparseMatrixColorings .GreedyColoringAlgorithm,
24+ algo::SMC .GreedyColoringAlgorithm,
2525 seen_idx = MOI.Nonlinear.Coloring.IndexedSet(0),
2626 )
2727
@@ -35,7 +35,7 @@ SparseMatrixColorings.
3535function _hessian_color_preprocess (
3636 edgelist,
3737 num_total_var,
38- algo:: SparseMatrixColorings .GreedyColoringAlgorithm ,
38+ algo:: SMC .GreedyColoringAlgorithm ,
3939 seen_idx = MOI. Nonlinear. Coloring. IndexedSet (0 ),
4040)
4141 resize! (seen_idx, num_total_var)
@@ -45,6 +45,10 @@ function _hessian_color_preprocess(
4545 push! (seen_idx, j)
4646 push! (I, i)
4747 push! (J, j)
48+ if i != j
49+ push! (I, j)
50+ push! (J, i)
51+ end
4852 end
4953 local_indices = sort! (collect (seen_idx))
5054 empty! (seen_idx)
@@ -56,12 +60,12 @@ function _hessian_color_preprocess(
5660 # The I and J vectors are already empty, which is correct
5761 # For the result, we'll create a minimal valid structure with a diagonal element
5862 # Note: This case should rarely occur in practice
59- S = SparseArrays. spdiagm (0 => [true ])
60- problem = SparseMatrixColorings . ColoringProblem (;
63+ S = SMC . SparsityPatternCSC ( SparseArrays. spdiagm (0 => [true ]) )
64+ problem = SMC . ColoringProblem (;
6165 structure = :symmetric ,
6266 partition = :column ,
6367 )
64- tree_result = SparseMatrixColorings . coloring (S, problem, algo)
68+ tree_result = SMC . coloring (S, problem, algo)
6569 result = ColoringResult (tree_result, Int[])
6670 return I, J, result
6771 end
@@ -78,19 +82,16 @@ function _hessian_color_preprocess(
7882
7983 # Create sparsity pattern matrix
8084 n = length (local_indices)
81- S = SparseArrays. spzeros (Bool, n, n)
82- for k in eachindex (I)
83- i, j = I[k], J[k]
84- S[i, j] = true
85- S[j, i] = true # symmetric
86- end
85+ S = SMC. SparsityPatternCSC (
86+ SparseArrays. sparse (I, J, trues (length (I)), n, n, & )
87+ )
8788
88- # Perform coloring using SparseMatrixColorings
89- problem = SparseMatrixColorings . ColoringProblem (;
89+ # Perform coloring using SMC
90+ problem = SMC . ColoringProblem (;
9091 structure = :symmetric ,
9192 partition = :column ,
9293 )
93- tree_result = SparseMatrixColorings . coloring (S, problem, algo)
94+ tree_result = SMC . coloring (S, problem, algo)
9495
9596 # Reconstruct I and J from the tree structure (matching original _indirect_recover_structure)
9697 # First add all diagonal elements
@@ -148,7 +149,7 @@ Allocate a seed matrix for the coloring result.
148149"""
149150function _seed_matrix (result:: ColoringResult )
150151 n = length (result. local_indices)
151- ncolors = SparseMatrixColorings . ncolors (result. result)
152+ ncolors = SMC . ncolors (result. result)
152153 return Matrix {Float64} (undef, n, ncolors)
153154end
154155
@@ -158,10 +159,10 @@ end
158159Prepare the seed matrix R for Hessian computation.
159160"""
160161function _prepare_seed_matrix! (R, result:: ColoringResult )
161- color = SparseMatrixColorings . column_colors (result. result)
162+ color = SMC . column_colors (result. result)
162163 N = length (result. local_indices)
163164 @assert N == size (R, 1 )
164- @assert size (R, 2 ) == SparseMatrixColorings . ncolors (result. result)
165+ @assert size (R, 2 ) == SMC . ncolors (result. result)
165166 fill! (R, 0.0 )
166167 for i in 1 : N
167168 if color[i] > 0
@@ -190,7 +191,7 @@ function _recover_from_matmat!(
190191 stored_values:: AbstractVector{T} ,
191192) where {T}
192193 tree_result = result. result
193- color = SparseMatrixColorings . column_colors (tree_result)
194+ color = SMC . column_colors (tree_result)
194195 N = length (result. local_indices)
195196 # Compute number of off-diagonal nonzeros from the length of V
196197 # V contains N diagonal elements + nnz_offdiag off-diagonal elements
0 commit comments