Skip to content

Commit ef9f444

Browse files
committed
Add ordering algorithm: PerfectEliminationOrder
1 parent 003360b commit ef9f444

5 files changed

Lines changed: 50 additions & 33 deletions

File tree

Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@ version = "0.4.14"
55

66
[deps]
77
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
8-
CliqueTrees = "60701a23-6482-424a-84db-faee86b9b1f8"
98
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
109
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
1110
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1211
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1312
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1413

1514
[weakdeps]
15+
CliqueTrees = "60701a23-6482-424a-84db-faee86b9b1f8"
1616
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
1717

1818
[extensions]
19+
SparseMatrixColoringsCliqueTreesExt = "CliqueTrees"
1920
SparseMatrixColoringsColorsExt = "Colors"
2021

2122
[compat]
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module SparseMatrixColoringsCliqueTreesExt
2+
3+
using CliqueTrees: CliqueTrees
4+
using SparseArrays
5+
using SparseMatrixColorings: SparseMatrixColorings, AdjacencyGraph, BipartiteGraph, PerfectEliminationOrder, pattern
6+
7+
function SparseMatrixColorings.vertices(g::AdjacencyGraph{T}, order::PerfectEliminationOrder) where T
8+
S = pattern(g)
9+
10+
# construct matrix with sparsity pattern S
11+
M = SparseMatrixCSC{Bool, T}(size(S)..., S.colptr, rowvals(S), ones(Bool, nnz(S)))
12+
13+
# can also use alg=CliqueTrees.LexBFS()
14+
order, _ = CliqueTrees.permutation(M; alg=CliqueTrees.MCS())
15+
16+
return reverse!(order)
17+
end
18+
19+
function SparseMatrixColorings.vertices(bg::BipartiteGraph{T}, ::Val{side}, order::PerfectEliminationOrder) where {T, side}
20+
S = pattern(g, Val(side))
21+
22+
# construct matrix with sparsity pattern S
23+
M = SparseMatrixCSC{Bool, T}(size(S)..., S.colptr, rowvals(S), ones(Bool, nnz(S)))
24+
25+
# can also use alg=CliqueTrees.LexBFS()
26+
order, _ = CliqueTrees.permutation(M; alg=CliqueTrees.MCS())
27+
28+
return reverse!(order)
29+
30+
end
31+
32+
end # module

src/SparseMatrixColorings.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ module SparseMatrixColorings
1111

1212
using ADTypes: ADTypes
1313
using Base.Iterators: Iterators
14-
using CliqueTrees: CliqueTrees
1514
using DataStructures: DisjointSets, find_root!, root_union!, num_groups
1615
using DocStringExtensions: README, EXPORTS, SIGNATURES, TYPEDEF, TYPEDFIELDS
1716
using LinearAlgebra:
@@ -50,7 +49,6 @@ include("result.jl")
5049
include("matrices.jl")
5150
include("interface.jl")
5251
include("constant.jl")
53-
include("chordal.jl")
5452
include("adtypes.jl")
5553
include("decompression.jl")
5654
include("check.jl")
@@ -59,8 +57,9 @@ include("show_colors.jl")
5957

6058
export NaturalOrder, RandomOrder, LargestFirst
6159
export DynamicDegreeBasedOrder, SmallestLast, IncidenceDegree, DynamicLargestFirst
60+
export PerfectEliminationOrder
6261
export ColoringProblem, GreedyColoringAlgorithm, AbstractColoringResult
63-
export ConstantColoringAlgorithm, ChordalColoringAlgorithm
62+
export ConstantColoringAlgorithm
6463
export coloring, fast_coloring
6564
export column_colors, row_colors, ncolors
6665
export column_groups, row_groups

src/chordal.jl

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/order.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,3 +301,17 @@ Instance of [`AbstractOrder`](@ref) which sorts vertices from lowest to highest
301301
- [`DynamicDegreeBasedOrder`](@ref)
302302
"""
303303
const DynamicLargestFirst = DynamicDegreeBasedOrder{:forward,:low2high}
304+
305+
"""
306+
PerfectEliminationOrder
307+
308+
Instance of [`AbstractOrder`](@ref) which sorts the vertices of a chordal graph in a perfect elimination order.
309+
310+
!!! danger
311+
This order is implemented as a package extension and requires loading CliqueTrees.jl.
312+
313+
# References
314+
315+
- [Simple Linear-Time Algorithms to Test Chordality of Graphs, Test Acyclicity of Hypergraphs, and Selectively Reduce Acyclic Hypergraphs](https://epubs.siam.org/doi/10.1137/0213035), Tarjan and Yannakakis (1984)
316+
"""
317+
struct PerfectEliminationOrder <: AbstractOrder end

0 commit comments

Comments
 (0)