Skip to content

Commit f2d509e

Browse files
committed
CliqueTrees
1 parent 3bb5690 commit f2d509e

28 files changed

+26
-3888
lines changed

Project.toml

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,14 @@ version = "0.2.0"
77
AMD = "14f7f29c-3bd6-536c-9a0b-7339e30b5a3e"
88
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
99
Catlab = "134e5e36-593f-5add-ad60-77f754baafbe"
10-
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
11-
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
10+
CliqueTrees = "60701a23-6482-424a-84db-faee86b9b1f8"
1211
MLStyle = "d8e11817-5142-5d16-987a-aa16d5891078"
1312
PartialFunctions = "570af359-4316-4cb7-8c74-252c00c2016b"
14-
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
15-
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
16-
Sparspak = "e56a9233-b9d6-4f03-8d0f-1825330902ac"
17-
18-
[weakdeps]
19-
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
20-
Laplacians = "6f8e5838-0efe-5de0-80a3-5fb4f8dbb1de"
21-
Metis = "2679e427-3c69-5b7f-982b-ece356f1e94b"
22-
TreeWidthSolver = "7d267fc5-9ace-409f-a54c-cd2374872a55"
23-
24-
[extensions]
25-
GraphsExt = "Graphs"
26-
LaplaciansExt = "Laplacians"
27-
MetisExt = "Metis"
28-
TreeWidthSolverExt = "TreeWidthSolver"
2913

3014
[compat]
31-
AMD = "0.5"
3215
AbstractTrees = "0.4"
3316
Catlab = "0.16"
34-
DataStructures = "0.18"
35-
Graphs = "1.12"
36-
Laplacians = "1.1"
17+
CliqueTrees = "0.5.1"
3718
MLStyle = "0.4"
38-
Metis = "1"
3919
PartialFunctions = "1.1"
40-
Reexport = "1.2.2"
41-
Sparspak = "0.3"
42-
TreeWidthSolver = "0.3"
4320
julia = "1.10"

ext/GraphsExt.jl

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

ext/LaplaciansExt.jl

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

ext/MetisExt.jl

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

ext/TreeWidthSolverExt.jl

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

src/StructuredDecompositions.jl

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
module StructuredDecompositions
22

33

4-
using Reexport
5-
6-
7-
include("junction_trees/JunctionTrees.jl")
84
include("decompositions/Decompositions.jl")
95
include("functor_utils/FunctorUtils.jl")
106
include("deciding_sheaves/DecidingSheaves.jl")
117

128

13-
@reexport using .JunctionTrees
14-
15-
169
end

src/decompositions/Decompositions.jl

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,23 @@ export StructuredDecomposition, StrDecomp,
55
𝐃, bags, adhesions, adhesionSpans,
66
77

8-
using ..JunctionTrees
9-
using ..JunctionTrees: PermutationOrAlgorithm, EliminationAlgorithm, SupernodeType, DEFAULT_ELIMINATION_ALGORITHM, DEFAULT_SUPERNODE_TYPE
8+
using AbstractTrees
9+
using CliqueTrees
10+
using CliqueTrees: PermutationOrAlgorithm, EliminationAlgorithm, SupernodeType, DEFAULT_ELIMINATION_ALGORITHM, DEFAULT_SUPERNODE_TYPE
1011

1112
using PartialFunctions
1213
using MLStyle
1314

14-
using Base: DEFAULT_STABLE, ForwardOrdering
15-
using Base.Threads
1615
using Catlab
1716
using Catlab.CategoricalAlgebra
1817
using Catlab.Graphs
1918
using Catlab.Graphs: add_edges!
2019
using Catlab.ACSetInterface
2120
using Catlab.CategoricalAlgebra.Diagrams
22-
using SparseArrays: getcolptr
23-
using SparseArrays
2421

2522
import Catlab.CategoricalAlgebra.Diagrams: ob_map, hom_map, colimit, limit
2623

2724
include("str_decomps.jl")
28-
include("junction_trees.jl")
25+
include("clique_trees.jl")
2926

3027
end
Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,30 @@
33
alg::PermutationOrAlgorithm=DEFAULT_ELIMINATION_ALGORITHM,
44
snd::SupernodeType=DEFAULT_SUPERNODE_TYPE)
55
6-
Construct a structured decomposition of a simple graph. See [`junctiontree`](@ref) for the meaning of `alg` and `snd`.
6+
Construct a structured decomposition of a simple graph. See [`cliquetree`](@ref) for the meaning of `alg` and `snd`.
77
"""
88
function StrDecomp(graph::HasGraph; alg::PermutationOrAlgorithm=DEFAULT_ELIMINATION_ALGORITHM, snd::SupernodeType=DEFAULT_SUPERNODE_TYPE)
9-
label, tree = junctiontree(adjacency_matrix(graph); alg, snd)
10-
relative!(tree)
9+
label, tree = cliquetree(symmetrize(graph); alg, snd)
1110
n = length(tree)
1211
shape = Graph(n)
1312

14-
for i in 1:n - 1
15-
add_edge!(shape, parentindex(tree, i), i)
13+
for i in 1:n
14+
j = parentindex(tree, i)
15+
16+
if !isnothing(j)
17+
add_edge!(shape, j, i)
18+
end
1619
end
1720

1821
diagram = FinDomFunctor(homomorphisms(graph, label, tree)..., ∫(shape))
1922
StrDecomp(shape, diagram, Decomposition, dom(diagram))
2023
end
2124

2225

23-
function homomorphisms(graph::HasGraph, label::AbstractVector, tree::JunctionTree)
26+
function homomorphisms(graph::HasGraph, label::AbstractVector, tree::CliqueTree)
2427
m = length(collect(rootindices(tree)))
2528
n = length(tree)
29+
relative = relatives(tree)
2630
subgraph = Vector{Any}(undef, 2n - m)
2731
homomorphism = Vector{Any}(undef, 2n - 2m)
2832

@@ -43,7 +47,7 @@ function homomorphisms(graph::HasGraph, label::AbstractVector, tree::JunctionTre
4347
subgraph[n + k] = induced_subgraph(graph, view(label, separator(tree, i)))
4448

4549
# separator(i) → bag(j)
46-
homomorphism[k] = induced_homomorphism(subgraph[n + k], subgraph[j], relative(tree, i))
50+
homomorphism[k] = induced_homomorphism(subgraph[n + k], subgraph[j], CliqueTrees.neighbors(relative, i))
4751

4852
# separator(i) → bag(i)
4953
homomorphism[n - m + k] = induced_homomorphism(subgraph[n + k], subgraph[i], length(residual(tree, i)) .+ eachindex(separator(tree, i)))
@@ -72,24 +76,13 @@ function induced_homomorphism(domain::HasGraph, codomain::HasGraph, V::AbstractV
7276
end
7377

7478

75-
# Construct the adjacency matrix of an undirected graph.
76-
function adjacency_matrix(graph::HasGraph)
77-
symmetric = SymmetricGraph(nv(graph))
78-
add_edges!(symmetric, src(graph), tgt(graph))
79-
adjacency_matrix(symmetric)
79+
function symmetrize(graph::AbstractSymmetricGraph)
80+
graph
8081
end
8182

8283

83-
function adjacency_matrix(graph::AbstractSymmetricGraph)
84-
matrix = spzeros(Bool, Int, nv(graph), nv(graph))
85-
sizehint!(rowvals(matrix), ne(graph))
86-
87-
for v in vertices(graph)
88-
append!(rowvals(matrix), neighbors(graph, v))
89-
getcolptr(matrix)[v + 1] = length(rowvals(matrix)) + 1
90-
end
91-
92-
resize!(nonzeros(matrix), ne(graph))
93-
fill!(nonzeros(matrix), true)
94-
matrix
84+
function symmetrize(graph::HasGraph)
85+
symmetric = SymmetricGraph(nv(graph))
86+
add_edges!(symmetric, src(graph), tgt(graph))
87+
symmetric
9588
end

src/junction_trees/JunctionTrees.jl

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

0 commit comments

Comments
 (0)