@@ -8,6 +8,7 @@ using SparseMatrixColorings:
88 what_fig_61,
99 efficient_fig_1,
1010 efficient_fig_4
11+ using StableRNGs
1112using Test
1213
1314@testset " Column coloring & decompression" begin
8586 test_coloring_decompression (A0, problem, algo; B0, color0)
8687 end
8788end ;
89+
90+ @testset " Bidirectional coloring" begin
91+ problem = ColoringProblem (; structure= :nonsymmetric , partition= :bidirectional )
92+ order = RandomOrder (StableRNG (0 ), 0 )
93+
94+ @testset " Triangle" begin
95+ A = sparse ([1 1 0 ; 0 1 1 ; 1 0 1 ])
96+
97+ result = coloring (
98+ A, problem, GreedyColoringAlgorithm {:direct} (; postprocessing= true )
99+ )
100+ @test ncolors (result) == 3
101+
102+ result = coloring (
103+ A, problem, GreedyColoringAlgorithm {:substitution} (; postprocessing= true )
104+ )
105+ @test ncolors (result) == 3
106+ end
107+
108+ @testset " Rectangle" begin
109+ A = spzeros (Bool, 10 , 20 )
110+ A[:, 1 ] .= 1
111+ A[:, end ] .= 1
112+ A[1 , :] .= 1
113+ A[end , :] .= 1
114+
115+ result = coloring (
116+ A, problem, GreedyColoringAlgorithm {:direct} (order; postprocessing= false )
117+ )
118+ @test ncolors (result) == 6 # two more than necessary
119+ result = coloring (
120+ A, problem, GreedyColoringAlgorithm {:direct} (order; postprocessing= true )
121+ )
122+ @test ncolors (result) == 4 # optimal number
123+
124+ result = coloring (
125+ A, problem, GreedyColoringAlgorithm {:substitution} (order; postprocessing= false )
126+ )
127+ @test ncolors (result) == 6 # two more than necessary
128+ result = coloring (
129+ A, problem, GreedyColoringAlgorithm {:substitution} (order; postprocessing= true )
130+ )
131+ @test ncolors (result) == 4 # optimal number
132+ end
133+
134+ @testset " Arrowhead" begin
135+ A = spzeros (Bool, 10 , 10 )
136+ for i in axes (A, 1 )
137+ A[1 , i] = 1
138+ A[i, 1 ] = 1
139+ A[i, i] = 1
140+ end
141+
142+ result = coloring (
143+ A, problem, GreedyColoringAlgorithm {:direct} (order; postprocessing= true )
144+ )
145+ @test ncolors (coloring (A, problem, GreedyColoringAlgorithm {:substitution} (order))) <
146+ ncolors (coloring (A, problem, GreedyColoringAlgorithm {:direct} (order)))
147+
148+ @test ncolors (
149+ coloring (
150+ A,
151+ problem,
152+ GreedyColoringAlgorithm {:substitution} (order; postprocessing= true ),
153+ ),
154+ ) < ncolors (
155+ coloring (
156+ A, problem, GreedyColoringAlgorithm {:direct} (order; postprocessing= true )
157+ ),
158+ )
159+ end
160+ end
0 commit comments