@@ -88,100 +88,100 @@ end;
8888end ;
8989
9090@testset " Bidirectional coloring" begin
91- problem = ColoringProblem (; structure= :nonsymmetric , partition= :bidirectional )
92- order = RandomOrder (StableRNG (0 ), 0 )
93-
94- @testset " Anti-diagonal" begin
95- A = sparse ([0 0 0 1 ; 0 0 1 0 ; 0 1 0 0 ; 1 0 0 0 ])
96-
97- result = coloring (
98- A, problem, GreedyColoringAlgorithm {:direct} (; postprocessing= false )
99- )
100- @test ncolors (result) == 2
101-
102- result = coloring (
103- A, problem, GreedyColoringAlgorithm {:direct} (; postprocessing= true )
104- )
105- @test ncolors (result) == 1
106-
107- result = coloring (
108- A, problem, GreedyColoringAlgorithm {:substitution} (; postprocessing= false )
109- )
110- @test ncolors (result) == 2
111-
112- result = coloring (
113- A, problem, GreedyColoringAlgorithm {:substitution} (; postprocessing= true )
114- )
115- @test ncolors (result) == 1
116- end
91+ @testset " postprocessing_minimizes = $target " for target in (:all_colors , :row_colors , :column_colors )
92+ problem = ColoringProblem (; structure= :nonsymmetric , partition= :bidirectional )
93+ order = RandomOrder (StableRNG (0 ), 0 )
11794
118- @testset " Triangle " begin
119- A = sparse ([1 1 0 ; 0 1 1 ; 1 0 1 ])
95+ @testset " Anti-diagonal " begin
96+ A = sparse ([0 0 0 1 ; 0 0 1 0 ; 0 1 0 0 ; 1 0 0 0 ])
12097
121- result = coloring (
122- A, problem, GreedyColoringAlgorithm {:direct} (; postprocessing= true )
123- )
124- @test ncolors (result) == 3
98+ result = coloring (
99+ A, problem, GreedyColoringAlgorithm {:direct} (; postprocessing= false ),
100+ )
101+ @test ncolors (result) == 2
125102
126- result = coloring (
127- A, problem, GreedyColoringAlgorithm {:substitution} (; postprocessing= true )
128- )
129- @test ncolors (result) == 3
130- end
103+ result = coloring (
104+ A, problem, GreedyColoringAlgorithm {:direct} (; postprocessing= true , postprocessing_minimizes= target),
105+ )
106+ @test ncolors (result) == 1
131107
132- @testset " Rectangle" begin
133- A = spzeros (Bool, 10 , 20 )
134- A[:, 1 ] .= 1
135- A[:, end ] .= 1
136- A[1 , :] .= 1
137- A[end , :] .= 1
138-
139- result = coloring (
140- A, problem, GreedyColoringAlgorithm {:direct} (order; postprocessing= false )
141- )
142- @test ncolors (result) == 6 # two more than necessary
143- result = coloring (
144- A, problem, GreedyColoringAlgorithm {:direct} (order; postprocessing= true )
145- )
146- @test ncolors (result) == 4 # optimal number
147-
148- result = coloring (
149- A, problem, GreedyColoringAlgorithm {:substitution} (order; postprocessing= false )
150- )
151- @test ncolors (result) == 6 # two more than necessary
152- result = coloring (
153- A, problem, GreedyColoringAlgorithm {:substitution} (order; postprocessing= true )
154- )
155- @test ncolors (result) == 4 # optimal number
156- end
108+ result = coloring (
109+ A, problem, GreedyColoringAlgorithm {:substitution} (; postprocessing= false ),
110+ )
111+ @test ncolors (result) == 2
157112
158- @testset " Arrowhead" begin
159- A = spzeros (Bool, 10 , 10 )
160- for i in axes (A, 1 )
161- A[1 , i] = 1
162- A[i, 1 ] = 1
163- A[i, i] = 1
113+ result = coloring (
114+ A, problem, GreedyColoringAlgorithm {:substitution} (; postprocessing= true , postprocessing_minimizes= target),
115+ )
116+ @test ncolors (result) == 1
164117 end
165118
166- result = coloring (
167- A, problem, GreedyColoringAlgorithm {:direct} (order; postprocessing= true )
168- )
169- @test ncolors (coloring (A, problem, GreedyColoringAlgorithm {:substitution} (order))) <
170- ncolors (coloring (A, problem, GreedyColoringAlgorithm {:direct} (order)))
119+ @testset " Triangle" begin
120+ A = sparse ([1 1 0 ; 0 1 1 ; 1 0 1 ])
121+
122+ result = coloring (
123+ A, problem, GreedyColoringAlgorithm {:direct} (; postprocessing= true , postprocessing_minimizes= target),
124+ )
125+ @test ncolors (result) == 3
126+
127+ result = coloring (
128+ A, problem, GreedyColoringAlgorithm {:substitution} (; postprocessing= true , postprocessing_minimizes= target),
129+ )
130+ @test ncolors (result) == 3
131+ end
132+
133+ @testset " Rectangle" begin
134+ A = spzeros (Bool, 10 , 20 )
135+ A[:, 1 ] .= 1
136+ A[:, end ] .= 1
137+ A[1 , :] .= 1
138+ A[end , :] .= 1
139+
140+ result = coloring (
141+ A, problem, GreedyColoringAlgorithm {:direct} (order; postprocessing= false ),
142+ )
143+ @test ncolors (result) == 6 # two more than necessary
144+ result = coloring (
145+ A, problem, GreedyColoringAlgorithm {:direct} (order; postprocessing= true , postprocessing_minimizes= target),
146+ )
147+ @test ncolors (result) == 4 # optimal number
148+
149+ result = coloring (
150+ A, problem, GreedyColoringAlgorithm {:substitution} (order; postprocessing= false ),
151+ )
152+ @test ncolors (result) == 6 # two more than necessary
153+ result = coloring (
154+ A, problem, GreedyColoringAlgorithm {:substitution} (order; postprocessing= true , postprocessing_minimizes= target),
155+ )
156+ @test ncolors (result) == 4 # optimal number
157+ end
158+
159+ @testset " Arrowhead" begin
160+ A = spzeros (Bool, 10 , 10 )
161+ for i in axes (A, 1 )
162+ A[1 , i] = 1
163+ A[i, 1 ] = 1
164+ A[i, i] = 1
165+ end
166+
167+ result = coloring (
168+ A, problem, GreedyColoringAlgorithm {:direct} (order; postprocessing= true , postprocessing_minimizes= target),
169+ )
170+ @test ncolors (coloring (A, problem, GreedyColoringAlgorithm {:substitution} (order))) <
171+ ncolors (coloring (A, problem, GreedyColoringAlgorithm {:direct} (order)))
172+
173+ @test ncolors (
174+ coloring (
175+ A,
176+ problem,
177+ GreedyColoringAlgorithm {:substitution} (order; postprocessing= true , postprocessing_minimizes= target),
178+ ),
179+ ) < ncolors (
180+ coloring (
181+ A, problem, GreedyColoringAlgorithm {:direct} (order; postprocessing= true , postprocessing_minimizes= target),
182+ ),
183+ )
171184
172- @test ncolors (
173- coloring (
174- A,
175- problem,
176- GreedyColoringAlgorithm {:substitution} (order; postprocessing= true ),
177- ),
178- ) < ncolors (
179- coloring (
180- A, problem, GreedyColoringAlgorithm {:direct} (order; postprocessing= true )
181- ),
182- )
183-
184- @testset " postprocessing_minimizes = $target " for target in (:all_colors , :row_colors , :column_colors )
185185 test_bicoloring_decompression (
186186 A,
187187 problem,
0 commit comments