Skip to content

Commit 0279098

Browse files
committed
Add tests for ordering algorithm PerfectEliminationOrder.
1 parent ef9f444 commit 0279098

3 files changed

Lines changed: 30 additions & 7 deletions

File tree

ext/SparseMatrixColoringsCliqueTreesExt.jl

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,35 @@ module SparseMatrixColoringsCliqueTreesExt
22

33
using CliqueTrees: CliqueTrees
44
using SparseArrays
5-
using SparseMatrixColorings: SparseMatrixColorings, AdjacencyGraph, BipartiteGraph, PerfectEliminationOrder, pattern
5+
using SparseMatrixColorings:
6+
SparseMatrixColorings, AdjacencyGraph, BipartiteGraph, PerfectEliminationOrder, pattern
67

7-
function SparseMatrixColorings.vertices(g::AdjacencyGraph{T}, order::PerfectEliminationOrder) where T
8+
function SparseMatrixColorings.vertices(
9+
g::AdjacencyGraph{T}, order::PerfectEliminationOrder
10+
) where {T}
811
S = pattern(g)
912

1013
# construct matrix with sparsity pattern S
11-
M = SparseMatrixCSC{Bool, T}(size(S)..., S.colptr, rowvals(S), ones(Bool, nnz(S)))
14+
M = SparseMatrixCSC{Bool,T}(size(S)..., S.colptr, rowvals(S), ones(Bool, nnz(S)))
1215

1316
# can also use alg=CliqueTrees.LexBFS()
1417
order, _ = CliqueTrees.permutation(M; alg=CliqueTrees.MCS())
1518

1619
return reverse!(order)
1720
end
1821

19-
function SparseMatrixColorings.vertices(bg::BipartiteGraph{T}, ::Val{side}, order::PerfectEliminationOrder) where {T, side}
20-
S = pattern(g, Val(side))
22+
function SparseMatrixColorings.vertices(
23+
bg::BipartiteGraph{T}, ::Val{side}, order::PerfectEliminationOrder
24+
) where {T,side}
25+
S = pattern(bg, Val(side))
2126

2227
# construct matrix with sparsity pattern S
23-
M = SparseMatrixCSC{Bool, T}(size(S)..., S.colptr, rowvals(S), ones(Bool, nnz(S)))
28+
M = SparseMatrixCSC{Bool,T}(size(S)..., S.colptr, rowvals(S), ones(Bool, nnz(S)))
2429

2530
# can also use alg=CliqueTrees.LexBFS()
2631
order, _ = CliqueTrees.permutation(M; alg=CliqueTrees.MCS())
2732

2833
return reverse!(order)
29-
3034
end
3135

3236
end # module

test/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ BlockArrays = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
77
BlockBandedMatrices = "ffab5731-97b5-5995-9138-79e8c1846df0"
88
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
99
Chairmarks = "0ca39b1e-fe0b-4e98-acfc-b1656634c4de"
10+
CliqueTrees = "60701a23-6482-424a-84db-faee86b9b1f8"
1011
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
1112
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
1213
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"

test/order.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using CliqueTrees: CliqueTrees
2+
using BandedMatrices
13
using LinearAlgebra
24
using SparseArrays
35
using SparseMatrixColorings
@@ -7,6 +9,7 @@ using SparseMatrixColorings:
79
LargestFirst,
810
NaturalOrder,
911
RandomOrder,
12+
PerfectEliminationOrder,
1013
degree_dist2,
1114
nb_vertices,
1215
valid_dynamic_order,
@@ -110,3 +113,18 @@ end;
110113
end
111114
end
112115
end;
116+
117+
@testset "PerfectEliminationOrder" begin
118+
problem1 = ColoringProblem(; structure=:symmetric, partition=:column)
119+
problem2 = ColoringProblem(; structure=:nonsymmetric, partition=:column)
120+
algorithm = GreedyColoringAlgorithm(
121+
PerfectEliminationOrder(); decompression=:substitution
122+
)
123+
124+
for (n, m) in ((800, 80), (400, 40), (200, 20), (100, 10))
125+
perm = randperm(n)
126+
matrix = permute!(sparse(Symmetric(brand(n, n, m, 0), :L)), perm, perm)
127+
@test ncolors(coloring(matrix, problem1, algorithm)) == 1m + 1
128+
@test ncolors(coloring(matrix, problem2, algorithm)) == 2m + 1
129+
end
130+
end

0 commit comments

Comments
 (0)