Skip to content

Commit 5f313ef

Browse files
committed
Update AdjacencyGraph
1 parent d58ad6c commit 5f313ef

File tree

4 files changed

+20
-22
lines changed

4 files changed

+20
-22
lines changed

src/coloring.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ end
8080

8181
"""
8282
star_coloring(
83-
g::AdjacencyGraph, vertices_in_order::AbstractVector, bicoloring::Bool, postprocessing::Bool;
83+
g::AdjacencyGraph, vertices_in_order::AbstractVector, postprocessing::Bool;
8484
postprocessing_minimizes::Symbol=:all_colors, forced_colors::Union{AbstractVector,Nothing}=nothing
8585
)
8686
@@ -109,7 +109,6 @@ 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-
bicoloring::Bool,
113112
postprocessing::Bool;
114113
postprocessing_minimizes::Symbol=:all_colors,
115114
forced_colors::Union{AbstractVector{<:Integer},Nothing}=nothing,
@@ -170,7 +169,7 @@ function star_coloring(
170169
if postprocessing
171170
# Reuse the vector forbidden_colors to compute offsets during post-processing
172171
offsets = forbidden_colors
173-
postprocess!(color, star_set, g, offsets, bicoloring, postprocessing_minimizes)
172+
postprocess!(color, star_set, g, offsets, postprocessing_minimizes)
174173
end
175174
return color, star_set
176175
end
@@ -252,7 +251,7 @@ struct StarSet{T}
252251
end
253252

254253
"""
255-
acyclic_coloring(g::AdjacencyGraph, vertices_in_order::AbstractVector, bicoloring::Bool, postprocessing::Bool;
254+
acyclic_coloring(g::AdjacencyGraph, vertices_in_order::AbstractVector, postprocessing::Bool;
256255
postprocessing_minimizes::Symbol=:all_colors)
257256
258257
Compute an acyclic coloring of all vertices in the adjacency graph `g` and return a tuple `(color, tree_set)`, where
@@ -278,7 +277,6 @@ If `postprocessing=true`, some colors might be replaced with `0` (the "neutral"
278277
function acyclic_coloring(
279278
g::AdjacencyGraph{T},
280279
vertices_in_order::AbstractVector{<:Integer},
281-
bicoloring::Bool,
282280
postprocessing::Bool;
283281
postprocessing_minimizes::Symbol=:all_colors,
284282
) where {T<:Integer}
@@ -352,7 +350,7 @@ function acyclic_coloring(
352350
if postprocessing
353351
# Reuse the vector forbidden_colors to compute offsets during post-processing
354352
offsets = forbidden_colors
355-
postprocess!(color, tree_set, g, offsets, bicoloring, postprocessing_minimizes)
353+
postprocess!(color, tree_set, g, offsets, postprocessing_minimizes)
356354
end
357355
return color, tree_set
358356
end

src/graph.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ The adjacency graph of a symmetric matrix `A ∈ ℝ^{n × n}` is `G(A) = (V, E)
227227
struct AdjacencyGraph{T<:Integer,augmented_graph}
228228
S::SparsityPatternCSC{T}
229229
edge_to_index::Vector{T}
230+
bicoloring::Bool
231+
original_size::Tuple{Int,Int}
230232
end
231233

232234
Base.eltype(::AdjacencyGraph{T}) where {T} = T
@@ -235,15 +237,17 @@ function AdjacencyGraph(
235237
S::SparsityPatternCSC{T},
236238
edge_to_index::Vector{T}=build_edge_to_index(S);
237239
augmented_graph::Bool=false,
240+
bicoloring::Bool=false,
241+
original_size::Tuple{Int,Int}=size(S),
238242
) where {T}
239-
return AdjacencyGraph{T,augmented_graph}(S, edge_to_index)
243+
return AdjacencyGraph{T,augmented_graph}(S, edge_to_index, bicoloring, original_size)
240244
end
241245

242-
function AdjacencyGraph(A::SparseMatrixCSC; augmented_graph::Bool=false)
246+
function AdjacencyGraph(A::SparseMatrixCSC; augmented_graph::Bool=false, original_size::Tuple{Int,Int}=size(A))
243247
return AdjacencyGraph(SparsityPatternCSC(A); augmented_graph)
244248
end
245249

246-
function AdjacencyGraph(A::AbstractMatrix; augmented_graph::Bool=false)
250+
function AdjacencyGraph(A::AbstractMatrix; augmented_graph::Bool=false, original_size::Tuple{Int,Int}=size(A))
247251
return AdjacencyGraph(SparseMatrixCSC(A); augmented_graph)
248252
end
249253

src/interface.jl

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,10 @@ function _coloring(
283283
symmetric_pattern::Bool;
284284
forced_colors::Union{AbstractVector{<:Integer},Nothing}=nothing,
285285
)
286-
ag = AdjacencyGraph(A; augmented_graph=false)
287-
bicoloring = false
286+
ag = AdjacencyGraph(A; augmented_graph=false, original_size=size(A))
288287
color_and_star_set_by_order = map(algo.orders) do order
289288
vertices_in_order = vertices(ag, order)
290-
return star_coloring(ag, vertices_in_order, bicoloring, algo.postprocessing; forced_colors)
289+
return star_coloring(ag, vertices_in_order, algo.postprocessing; forced_colors)
291290
end
292291
color, star_set = argmin(maximum first, color_and_star_set_by_order)
293292
if speed_setting isa WithResult
@@ -305,11 +304,10 @@ function _coloring(
305304
decompression_eltype::Type{R},
306305
symmetric_pattern::Bool,
307306
) where {R}
308-
ag = AdjacencyGraph(A; augmented_graph=false)
309-
bicoloring = false
307+
ag = AdjacencyGraph(A; augmented_graph=false, original_size=size(A))
310308
color_and_tree_set_by_order = map(algo.orders) do order
311309
vertices_in_order = vertices(ag, order)
312-
return acyclic_coloring(ag, vertices_in_order, bicoloring, algo.postprocessing)
310+
return acyclic_coloring(ag, vertices_in_order, algo.postprocessing)
313311
end
314312
color, tree_set = argmin(maximum first, color_and_tree_set_by_order)
315313
if speed_setting isa WithResult
@@ -329,13 +327,12 @@ function _coloring(
329327
forced_colors::Union{AbstractVector{<:Integer},Nothing}=nothing,
330328
) where {R}
331329
A_and_Aᵀ, edge_to_index = bidirectional_pattern(A; symmetric_pattern)
332-
ag = AdjacencyGraph(A_and_Aᵀ, edge_to_index; augmented_graph=true)
333-
bicoloring = true
330+
ag = AdjacencyGraph(A_and_Aᵀ, edge_to_index; augmented_graph=true, original_size=size(A))
334331
postprocessing_minimizes = algo.postprocessing_minimizes
335332
outputs_by_order = map(algo.orders) do order
336333
vertices_in_order = vertices(ag, order)
337334
_color, _star_set = star_coloring(
338-
ag, vertices_in_order, bicoloring, algo.postprocessing; postprocessing_minimizes, forced_colors
335+
ag, vertices_in_order, algo.postprocessing; postprocessing_minimizes, forced_colors
339336
)
340337
(_row_color, _column_color, _symmetric_to_row, _symmetric_to_column) = remap_colors(
341338
eltype(ag), _color, maximum(_color), size(A)...
@@ -378,12 +375,11 @@ function _coloring(
378375
symmetric_pattern::Bool,
379376
) where {R}
380377
A_and_Aᵀ, edge_to_index = bidirectional_pattern(A; symmetric_pattern)
381-
ag = AdjacencyGraph(A_and_Aᵀ, edge_to_index; augmented_graph=true)
382-
bicoloring = true
378+
ag = AdjacencyGraph(A_and_Aᵀ, edge_to_index; augmented_graph=true, original_size=size(A))
383379
postprocessing_minimizes = algo.postprocessing_minimizes
384380
outputs_by_order = map(algo.orders) do order
385381
vertices_in_order = vertices(ag, order)
386-
_color, _tree_set = acyclic_coloring(ag, vertices_in_order, bicoloring, algo.postprocessing; postprocessing_minimizes)
382+
_color, _tree_set = acyclic_coloring(ag, vertices_in_order, algo.postprocessing; postprocessing_minimizes)
387383
(_row_color, _column_color, _symmetric_to_row, _symmetric_to_column) = remap_colors(
388384
eltype(ag), _color, maximum(_color), size(A)...
389385
)

test/suitesparse.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ what_table_41_42 = CSV.read(
146146
bicoloring = false
147147
postprocessing = false
148148
vertices_in_order = vertices(ag, NaturalOrder())
149-
color_N, _ = star_coloring(ag, vertices_in_order, bicoloring, postprocessing)
149+
color_N, _ = star_coloring(ag, vertices_in_order, postprocessing)
150150
@test_skip row[:KS1] <= length(unique(color_N)) <= row[:KS2] # TODO: find better
151151
yield()
152152
end

0 commit comments

Comments
 (0)