Skip to content

Commit bff2d16

Browse files
committed
Implement postprocess_star_bicoloring and postprocess_acyclic_bicoloring
1 parent 011a62d commit bff2d16

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

src/coloring.jl

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ end
8080

8181
"""
8282
star_coloring(
83-
g::AdjacencyGraph, vertices_in_order::AbstractVector, postprocessing::Bool;
84-
forced_colors::Union{AbstractVector,Nothing}=nothing
83+
g::AdjacencyGraph, vertices_in_order::AbstractVector, bicoloring::Bool, postprocessing::Bool;
84+
postprocessing_minimizes::Symbol=:all_colors, forced_colors::Union{AbstractVector,Nothing}=nothing
8585
)
8686
8787
Compute a star coloring of all vertices in the adjacency graph `g` and return a tuple `(color, star_set)`, where
@@ -109,8 +109,9 @@ The optional `forced_colors` keyword argument is used to enforce predefined vert
109109
function star_coloring(
110110
g::AdjacencyGraph{T},
111111
vertices_in_order::AbstractVector{<:Integer},
112-
postprocessing::Bool,
113-
postprocessing_minimizes::Symbol;
112+
bicoloring::Bool,
113+
postprocessing::Bool;
114+
postprocessing_minimizes::Symbol=:all_colors,
114115
forced_colors::Union{AbstractVector{<:Integer},Nothing}=nothing,
115116
) where {T<:Integer}
116117
# Initialize data structures
@@ -169,7 +170,7 @@ function star_coloring(
169170
if postprocessing
170171
# Reuse the vector forbidden_colors to compute offsets during post-processing
171172
offsets = forbidden_colors
172-
postprocess!(color, star_set, g, offsets, postprocessing_minimizes)
173+
postprocess!(color, star_set, g, offsets, bicoloring, postprocessing_minimizes)
173174
end
174175
return color, star_set
175176
end
@@ -251,7 +252,8 @@ struct StarSet{T}
251252
end
252253

253254
"""
254-
acyclic_coloring(g::AdjacencyGraph, vertices_in_order::AbstractVector, postprocessing::Bool)
255+
acyclic_coloring(g::AdjacencyGraph, vertices_in_order::AbstractVector, bicoloring::Bool, postprocessing::Bool;
256+
postprocessing_minimizes::Symbol=:all_colors)
255257
256258
Compute an acyclic coloring of all vertices in the adjacency graph `g` and return a tuple `(color, tree_set)`, where
257259
@@ -276,8 +278,9 @@ If `postprocessing=true`, some colors might be replaced with `0` (the "neutral"
276278
function acyclic_coloring(
277279
g::AdjacencyGraph{T},
278280
vertices_in_order::AbstractVector{<:Integer},
279-
postprocessing::Bool,
280-
postprocessing_minimizes::Symbol,
281+
bicoloring::Bool,
282+
postprocessing::Bool;
283+
postprocessing_minimizes::Symbol=:all_colors,
281284
) where {T<:Integer}
282285
# Initialize data structures
283286
nv = nb_vertices(g)
@@ -349,7 +352,7 @@ function acyclic_coloring(
349352
if postprocessing
350353
# Reuse the vector forbidden_colors to compute offsets during post-processing
351354
offsets = forbidden_colors
352-
postprocess!(color, tree_set, g, offsets, postprocessing_minimizes)
355+
postprocess!(color, tree_set, g, offsets, bicoloring, postprocessing_minimizes)
353356
end
354357
return color, tree_set
355358
end

src/interface.jl

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ It is passed as an argument to the main function [`coloring`](@ref).
7373
GreedyColoringAlgorithm(order=NaturalOrder(); postprocessing=false, postprocessing_minimizes=:all_colors, decompression=:direct)
7474
7575
- `order::Union{AbstractOrder,Tuple}`: the order in which the columns or rows are colored, which can impact the number of colors. Can also be a tuple of different orders to try out, from which the best order (the one with the lowest total number of colors) will be used.
76-
- `postprocessing::Bool`: whether or not the coloring will be refined by assigning the neutral color `0` to some vertices.
77-
- `postprocessing_minimizes::Symbol`: either `:all_colors`, `:row_colors` or `:column_colors`. The options `:row_colors` and `:column_colors` are only available for bicoloring. Otherwise, the setting defaults to `:all_colors`.
76+
- `postprocessing::Bool`: whether or not the coloring will be refined by assigning the neutral color `0` to some vertices. This option does not affect row or column colorings.
77+
- `postprocessing_minimizes::Symbol`: either `:all_colors`, `:row_colors` or `:column_colors`. This option only applies to star and acyclic bicolorings.
7878
- `decompression::Symbol`: either `:direct` or `:substitution`. Usually `:substitution` leads to fewer colors, at the cost of a more expensive coloring (and decompression). When `:substitution` is not applicable, it falls back on `:direct` decompression.
7979
8080
!!! warning
@@ -284,9 +284,10 @@ function _coloring(
284284
forced_colors::Union{AbstractVector{<:Integer},Nothing}=nothing,
285285
)
286286
ag = AdjacencyGraph(A; augmented_graph=false)
287+
bicoloring = false
287288
color_and_star_set_by_order = map(algo.orders) do order
288289
vertices_in_order = vertices(ag, order)
289-
return star_coloring(ag, vertices_in_order, algo.postprocessing, :all_colors; forced_colors)
290+
return star_coloring(ag, vertices_in_order, bicoloring, algo.postprocessing; forced_colors)
290291
end
291292
color, star_set = argmin(maximum first, color_and_star_set_by_order)
292293
if speed_setting isa WithResult
@@ -305,9 +306,10 @@ function _coloring(
305306
symmetric_pattern::Bool,
306307
) where {R}
307308
ag = AdjacencyGraph(A; augmented_graph=false)
309+
bicoloring = false
308310
color_and_tree_set_by_order = map(algo.orders) do order
309311
vertices_in_order = vertices(ag, order)
310-
return acyclic_coloring(ag, vertices_in_order, algo.postprocessing, :all_colors)
312+
return acyclic_coloring(ag, vertices_in_order, bicoloring, algo.postprocessing)
311313
end
312314
color, tree_set = argmin(maximum first, color_and_tree_set_by_order)
313315
if speed_setting isa WithResult
@@ -328,10 +330,12 @@ function _coloring(
328330
) where {R}
329331
A_and_Aᵀ, edge_to_index = bidirectional_pattern(A; symmetric_pattern)
330332
ag = AdjacencyGraph(A_and_Aᵀ, edge_to_index; augmented_graph=true)
333+
bicoloring = true
334+
postprocessing_minimizes = algo.postprocessing_minimizes
331335
outputs_by_order = map(algo.orders) do order
332336
vertices_in_order = vertices(ag, order)
333337
_color, _star_set = star_coloring(
334-
ag, vertices_in_order, algo.postprocessing, algo.postprocessing_minimizes; forced_colors
338+
ag, vertices_in_order, bicoloring, algo.postprocessing; postprocessing_minimizes, forced_colors
335339
)
336340
(_row_color, _column_color, _symmetric_to_row, _symmetric_to_column) = remap_colors(
337341
eltype(ag), _color, maximum(_color), size(A)...
@@ -375,9 +379,11 @@ function _coloring(
375379
) where {R}
376380
A_and_Aᵀ, edge_to_index = bidirectional_pattern(A; symmetric_pattern)
377381
ag = AdjacencyGraph(A_and_Aᵀ, edge_to_index; augmented_graph=true)
382+
bicoloring = true
383+
postprocessing_minimizes = algo.postprocessing_minimizes
378384
outputs_by_order = map(algo.orders) do order
379385
vertices_in_order = vertices(ag, order)
380-
_color, _tree_set = acyclic_coloring(ag, vertices_in_order, algo.postprocessing, algo.postprocessing_minimizes)
386+
_color, _tree_set = acyclic_coloring(ag, vertices_in_order, bicoloring, algo.postprocessing; postprocessing_minimizes)
381387
(_row_color, _column_color, _symmetric_to_row, _symmetric_to_column) = remap_colors(
382388
eltype(ag), _color, maximum(_color), size(A)...
383389
)

0 commit comments

Comments
 (0)