8888end ;
8989
9090@testset " Bidirectional coloring" begin
91+ color_stats = Dict (" Anti-diagonal" => Dict (:direct => Dict (:all_colors => (0 ,0 ), :row_colors => (0 ,0 ), :column_colors => (0 ,0 )),
92+ :substitution => Dict (:all_colors => (0 ,0 ), :row_colors => (0 ,0 ), :column_colors => (0 ,0 ))),
93+ " Triangle" => Dict (:direct => Dict (:all_colors => (0 ,0 ), :row_colors => (0 ,0 ), :column_colors => (0 ,0 )),
94+ :substitution => Dict (:all_colors => (0 ,0 ), :row_colors => (0 ,0 ), :column_colors => (0 ,0 ))),
95+ " Rectangle" => Dict (:direct => Dict (:all_colors => (0 ,0 ), :row_colors => (0 ,0 ), :column_colors => (0 ,0 )),
96+ :substitution => Dict (:all_colors => (0 ,0 ), :row_colors => (0 ,0 ), :column_colors => (0 ,0 ))),
97+ " Arrowhead" => Dict (:direct => Dict (:all_colors => (0 ,0 ), :row_colors => (0 ,0 ), :column_colors => (0 ,0 )),
98+ :substitution => Dict (:all_colors => (0 ,0 ), :row_colors => (0 ,0 ), :column_colors => (0 ,0 ))))
99+
91100 @testset " postprocessing_minimizes = $target " for target in (:all_colors , :row_colors , :column_colors )
92101 problem = ColoringProblem (; structure= :nonsymmetric , partition= :bidirectional )
93102 order = RandomOrder (StableRNG (0 ), 0 )
104113 A, problem, GreedyColoringAlgorithm {:direct} (; postprocessing= true , postprocessing_minimizes= target),
105114 )
106115 @test ncolors (result) == 1
116+ color_stats[" Anti-diagonal" ][:direct ][target] = (row_colors (result) |> maximum, column_colors (result) |> maximum)
107117
108118 result = coloring (
109119 A, problem, GreedyColoringAlgorithm {:substitution} (; postprocessing= false ),
114124 A, problem, GreedyColoringAlgorithm {:substitution} (; postprocessing= true , postprocessing_minimizes= target),
115125 )
116126 @test ncolors (result) == 1
127+ color_stats[" Anti-diagonal" ][:substitution ][target] = (row_colors (result) |> maximum, column_colors (result) |> maximum)
117128 end
118129
119130 @testset " Triangle" begin
@@ -123,11 +134,13 @@ end;
123134 A, problem, GreedyColoringAlgorithm {:direct} (; postprocessing= true , postprocessing_minimizes= target),
124135 )
125136 @test ncolors (result) == 3
137+ color_stats[" Triangle" ][:direct ][target] = (row_colors (result) |> maximum, column_colors (result) |> maximum)
126138
127139 result = coloring (
128140 A, problem, GreedyColoringAlgorithm {:substitution} (; postprocessing= true , postprocessing_minimizes= target),
129141 )
130142 @test ncolors (result) == 3
143+ color_stats[" Triangle" ][:substitution ][target] = (row_colors (result) |> maximum, column_colors (result) |> maximum)
131144 end
132145
133146 @testset " Rectangle" begin
145158 A, problem, GreedyColoringAlgorithm {:direct} (order; postprocessing= true , postprocessing_minimizes= target),
146159 )
147160 @test ncolors (result) == 4 # optimal number
161+ color_stats[" Rectangle" ][:direct ][target] = (row_colors (result) |> maximum, column_colors (result) |> maximum)
148162
149163 result = coloring (
150164 A, problem, GreedyColoringAlgorithm {:substitution} (order; postprocessing= false ),
154168 A, problem, GreedyColoringAlgorithm {:substitution} (order; postprocessing= true , postprocessing_minimizes= target),
155169 )
156170 @test ncolors (result) == 4 # optimal number
171+ color_stats[" Rectangle" ][:substitution ][target] = (row_colors (result) |> maximum, column_colors (result) |> maximum)
157172 end
158173
159174 @testset " Arrowhead" begin
@@ -164,23 +179,20 @@ end;
164179 A[i, i] = 1
165180 end
166181
167- result = coloring (
168- A, problem, GreedyColoringAlgorithm {:direct} (order; postprocessing= true , postprocessing_minimizes= target),
169- )
170182 @test ncolors (coloring (A, problem, GreedyColoringAlgorithm {:substitution} (order))) <
171183 ncolors (coloring (A, problem, GreedyColoringAlgorithm {:direct} (order)))
172184
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- ),
185+ result_direct = coloring (
186+ A, problem, GreedyColoringAlgorithm {:direct} (order; postprocessing= true , postprocessing_minimizes= target),
183187 )
188+ color_stats[" Arrowhead" ][:direct ][target] = (row_colors (result_direct) |> maximum, column_colors (result_direct) |> maximum)
189+
190+ result_substitution = coloring (
191+ A, problem, GreedyColoringAlgorithm {:substitution} (order; postprocessing= true , postprocessing_minimizes= target),
192+ )
193+ color_stats[" Arrowhead" ][:substitution ][target] = (row_colors (result_substitution) |> maximum, column_colors (result_substitution) |> maximum)
194+
195+ @test ncolors (result_substitution) < ncolors (result_direct)
184196
185197 test_bicoloring_decompression (
186198 A,
@@ -197,4 +209,16 @@ end;
197209 )
198210 end
199211 end
212+
213+ @testset " Variants of post-processing" begin
214+ for problem in (" Anti-diagonal" , " Triangle" , " Rectangle" , " Arrowhead" )
215+ for mode in (:direct , :substitution )
216+ (num_row_colors1, num_column_colors1) = color_stats[problem][mode][:row_colors ]
217+ (num_row_colors2, num_column_colors2) = color_stats[problem][mode][:all_colors ]
218+ (num_row_colors3, num_column_colors3) = color_stats[problem][mode][:column_colors ]
219+ @test num_row_colors1 ≤ num_row_colors2 ≤ num_row_colors3
220+ @test num_column_colors3 ≤ num_column_colors2 ≤ num_column_colors1
221+ end
222+ end
223+ end
200224end ;
0 commit comments